public void execMethodReadPrivateFileSystem(String path) {
   String line = "";
   String args[] = new String[3];
   args[0] = "chmod";
   args[1] = "777";
   args[2] = "/data/data/com.eoemobile/databases/webviewCache.db";
   try {
     java.lang.Process process = Runtime.getRuntime().exec(args);
     InputStream stderr = process.getErrorStream();
     InputStreamReader isrerr = new InputStreamReader(stderr);
     BufferedReader brerr = new BufferedReader(isrerr);
     InputStream outs = process.getInputStream();
     InputStreamReader isrout = new InputStreamReader(outs);
     BufferedReader brout = new BufferedReader(isrout);
     String errline = null;
     String result = "";
     while ((line = brerr.readLine()) != null) {
       result += line;
       result += "\n";
     }
     if (result != "") {
       errline = result;
       System.out.println(errline);
     }
     while ((line = brout.readLine()) != null) {
       result += line;
       result += "\n";
     }
     if (result != "") {
       System.out.println(result);
     }
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
Ejemplo n.º 2
0
  private void checkAndLaunchUpdate() {
    Log.i(LOG_FILE_NAME, "Checking for an update");

    int statusCode = 8; // UNEXPECTED_ERROR
    File baseUpdateDir = null;
    if (Build.VERSION.SDK_INT >= 8)
      baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");

    File updateDir = new File(new File(baseUpdateDir, "updates"), "0");

    File updateFile = new File(updateDir, "update.apk");
    File statusFile = new File(updateDir, "update.status");

    if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return;

    if (!updateFile.exists()) return;

    Log.i(LOG_FILE_NAME, "Update is available!");

    // Launch APK
    File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
    try {
      if (updateFile.renameTo(updateFileToRun)) {
        String amCmd =
            "/system/bin/am start -a android.intent.action.VIEW "
                + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://"
                + updateFileToRun.getPath();
        Log.i(LOG_FILE_NAME, amCmd);
        Runtime.getRuntime().exec(amCmd);
        statusCode = 0; // OK
      } else {
        Log.i(LOG_FILE_NAME, "Cannot rename the update file!");
        statusCode = 7; // WRITE_ERROR
      }
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error launching installer to update", e);
    }

    // Update the status file
    String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n";

    OutputStream outStream;
    try {
      byte[] buf = status.getBytes("UTF-8");
      outStream = new FileOutputStream(statusFile);
      outStream.write(buf, 0, buf.length);
      outStream.close();
    } catch (Exception e) {
      Log.i(LOG_FILE_NAME, "error writing status file", e);
    }

    if (statusCode == 0) System.exit(0);
  }
 private final void clean() {
   if (null != mBrowser) {
     mBrowser.clean();
   }
   if (null != mScreen) {
     mScreen.removeAllViews();
   }
   WidgetOneApplication app = (WidgetOneApplication) getApplication();
   app.exitApp();
   mEHandler.clean();
   mBrowserAround.clean();
   mFinish = true;
   Runtime.getRuntime().gc();
 }