Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Auto import pro license file
Browse files Browse the repository at this point in the history
Fixes #703
  • Loading branch information
M66B committed Nov 9, 2013
1 parent 3d50fec commit 213b854
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog
* Permanently cache XPrivacy version and Android usage settings
* Do not display number of packages in progress dialog
* Show location for license file in about dialog
* Auto import pro license file ([issue](https://github.com/M66B/XPrivacy/issues/703))

**Version 1.10.5 TEST**

Expand Down
42 changes: 35 additions & 7 deletions src/biz/bokhorst/xprivacy/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Util {
private static boolean mPro = false;
private static boolean mLog = true;
private static boolean mLogDetermined = false;
private static String LICENSE_NAME = "XPrivacy_license.txt";

public static void log(XHook hook, int priority, String msg) {
// Check if logging enabled
Expand Down Expand Up @@ -135,13 +136,40 @@ public static String hasProLicense(Context context) {

public static String[] getLicense() {
// Get license file name
String folder = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = folder + File.separator + "XPrivacy_license.txt";
File licenseFile = new File(fileName);
if (!licenseFile.exists()) {
fileName = folder + File.separator + ".xprivacy" + File.separator + "XPrivacy_license.txt";
licenseFile = new File(fileName);
String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath();
File licenseFile = new File(storageDir + File.separator + LICENSE_NAME);
if (!licenseFile.exists())
licenseFile = new File(storageDir + File.separator + ".xprivacy" + File.separator + LICENSE_NAME);

// Get imported license file name
String packageName = Util.class.getPackage().getName();
String importedLicense = Environment.getDataDirectory() + File.separator + "data" + File.separator
+ packageName + File.separator + LICENSE_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();

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

// Check license file
licenseFile = new File(importedLicense);
if (licenseFile.exists()) {
// Read license
try {
Expand All @@ -155,7 +183,7 @@ public static String[] getLicense() {
return null;
}
} else
Util.log(null, Log.INFO, "Licensing: no license folder=" + Environment.getExternalStorageDirectory());
Util.log(null, Log.INFO, "Licensing: no license file");
return null;
}

Expand Down

0 comments on commit 213b854

Please sign in to comment.