public boolean checkSetDevicePermissions() {
   java.lang.Process process = null;
   DataOutputStream os = null;
   try {
     File f = new File(MSM_DEVICE);
     if (f.canRead() && f.canWrite() /* && f1.canRead() && f1.canWrite() */) {
       return true;
     }
     process = Runtime.getRuntime().exec("su");
     os = new DataOutputStream(process.getOutputStream());
     os.flush();
     os.writeBytes("chmod 0666 " + MSM_DEVICE + "\n");
     os.flush();
     os.writeBytes("exit\n");
     os.flush();
     process.waitFor();
   } catch (Exception e) {
     return false;
   } finally {
     try {
       if (os != null) os.close();
       process.destroy();
     } catch (Exception e) {
     }
   }
   return true;
 }
 @Override
 protected void onDestroy() {
   QtApplication.setMainActivity(null);
   super.onDestroy();
   if (m_quitApp) {
     Log.i(QtApplication.QtTAG, "onDestroy");
     if (m_debuggerProcess != null) m_debuggerProcess.destroy();
     System.exit(0); // FIXME remove it or find a better way
   }
   QtApplication.setMainActivity(null);
 }
  /**
   * Load the the versioned libs
   *
   * @return void
   */
  private void createLibsAliases() {
    // fill this array with the name of the lib and the needed versioned
    // name
    String[][] libraries = {{"libproj.so", "libproj.so.0"}
      // ,{"libgdal.so","libgdal.so.2"}
    };

    for (int i = 0; i < libraries.length; i++) {
      File lib = new File("/data/data/org.qgis.qgis/lib/" + libraries[i][0]);
      String aliasName = libraries[i][1];
      String aliasPath = getFilesDir() + "/" + aliasName;

      try {
        File alias = new File(aliasPath);
        if (!alias.exists()) {
          try {
            String str = "ln -s " + lib.getAbsolutePath() + " " + aliasPath;
            Process process = Runtime.getRuntime().exec(str);
            int res = process.waitFor();
            process.destroy();
            if (res != 0) {
              Log.i(QtTAG, "Can't use symlinks, copying '" + aliasName + " to " + aliasPath);
              try {

                BufferedOutputStream out =
                    new BufferedOutputStream(openFileOutput(aliasName, MODE_PRIVATE));
                BufferedInputStream in = new BufferedInputStream(new FileInputStream(lib));
                byte[] buff = new byte[32 * 1024];
                int len;
                while ((len = in.read(buff)) > 0) {
                  out.write(buff, 0, len);
                }
                out.flush();
                out.close();
              } catch (IOException e) {
                Log.w("ExternalStorage", "Error writing " + aliasPath, e);
              }
            } else {
              Log.i(QtTAG, "Symlinked '" + lib.getAbsolutePath() + "' to '" + aliasPath + "'");
            }

          } catch (SecurityException e) {
            Log.i(QtTAG, "Can't symlink '" + aliasName + "'", e);
          }
        }
        Log.i(QtTAG, "Loading '" + aliasPath + "'");
        System.load(aliasPath);
      } catch (SecurityException e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      } catch (Exception e) {
        Log.i(QtTAG, "Can't load '" + aliasName + "'", e);
      }
    }
  }
Beispiel #4
0
  public void run() {

    BufferedReader lsofBufferedReader = initialize();

    if (lsofBufferedReader != null) {
      while (!shutdown) {
        scanList(lsofBufferedReader);
      }
      process.destroy();
    }
  }
  /**
   * Performs file compression into a certain file or directory and have it inside the specified
   * destination file path.
   *
   * @param forarchive Directory or file to compress
   * @param destination Output file destination.
   * @return File information of the output file.
   */
  public java.io.File archive(java.io.File forarchive, String destination) {
    java.io.File _file = null;

    String _batchfilename = Application.startUpPath() + "\\archiver.bat";
    String _zip = mime.Mime.resources.sevenZip().getPath();
    if (_zip.startsWith("/")) _zip = mime.Mime.resources.sevenZip().getPath().substring(1);

    String _path = forarchive.getPath();
    if (_path.startsWith("/")) _path = forarchive.getPath().substring(1);

    String _contents = "\"" + _zip + "\" a \"" + destination + "\" " + _path + "\"";
    java.io.File _batchfile = null;

    StreamWriter _sw = new StreamWriter(_batchfilename);
    try {
      _sw.write(_contents);
      _batchfile = new java.io.File(_batchfilename);
    } catch (Exception ex) {
      _batchfile = null;
      ex.printStackTrace();
    } finally {
      _sw.close();
      _sw.dispose();
    }

    if (_batchfile != null) {
      java.lang.Process p = null;

      try {
        p = Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", _batchfilename});
        p.waitFor();
        InputStream _errorstream = p.getErrorStream();
        String _error = "";

        if (_errorstream != null) {
          int _bytecount = _errorstream.available();
          if (_bytecount > 0) {
            StringWriter _writer = new StringWriter();

            try {
              byte[] _bytes = new byte[_bytecount];
              _errorstream.read(_bytes);
              _error = new String(_bytes);
            } catch (Exception ex) {
              ex.printStackTrace();
            } finally {
              _writer.close();
              _writer = null;
              System.gc();
            }
          }
        }

        _file = new java.io.File(destination);
        if (!_file.exists()) {
          _file = null;
          System.gc();
        }
      } catch (Exception ex) {
        _file = null;
        ex.printStackTrace();
      } finally {
        if (p != null) p.destroy();
        p = null;
        System.gc();
      }

      try {
        _batchfile.delete();
      } catch (Exception ex) {
      } finally {
        _batchfile = null;
        System.gc();
      }
    }

    return _file;
  }