示例#1
0
文件: Util.java 项目: paour/XPrivacy
  public static String[] getProLicenseUnchecked() {
    // Get license file name
    String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    File licenseFile = new File(storageDir + File.separator + LICENSE_FILE_NAME);
    if (!licenseFile.exists())
      licenseFile =
          new File(storageDir + File.separator + ".xprivacy" + File.separator + LICENSE_FILE_NAME);

    // Get imported license file name
    String importedLicense =
        getUserDataDirectory(Process.myUid()) + File.separator + LICENSE_FILE_NAME;

    // Import license file
    if (licenseFile.exists()) {
      try {
        File out = new File(importedLicense);
        Util.log(null, Log.WARN, "Licensing: importing " + out.getAbsolutePath());
        InputStream is = new FileInputStream(licenseFile.getAbsolutePath());
        OutputStream os = new FileOutputStream(out.getAbsolutePath());
        byte[] buffer = new byte[1024];
        int read;
        while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read);
        is.close();
        os.flush();
        os.close();

        // Protect license file
        setPermissions(out.getAbsolutePath(), 0700, Process.myUid(), Process.myUid());

        licenseFile.delete();
      } catch (Throwable ex) {
        Util.bug(null, ex);
      }
    }

    // Check license file
    licenseFile = new File(importedLicense);
    if (licenseFile.exists()) {
      // Read license
      try {
        IniFile iniFile = new IniFile(licenseFile);
        String name = iniFile.get("name", "");
        String email = iniFile.get("email", "");
        String signature = iniFile.get("signature", "");
        return new String[] {name, email, signature};
      } catch (Throwable ex) {
        bug(null, ex);
        return null;
      }
    } else Util.log(null, Log.INFO, "Licensing: no license file");
    return null;
  }