From 6b9acbbfcfe63400b149a5358b9bd2a6b75c86d4 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 13:23:05 -0500 Subject: [PATCH 01/11] Update dependencies --- app/build.gradle | 14 +++++++------- build.gradle | 6 +++++- gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/build.gradle | 18 +++++++++--------- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6274d56..5b8596c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "com.github.javiersantos.piracychecker.demo" minSdkVersion 14 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -23,8 +23,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:design:25.3.1' - compile 'com.android.support:cardview-v7:25.3.1' - compile project(':library') + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:design:27.0.2' + implementation 'com.android.support:cardview-v7:27.0.2' + implementation project(':library') } \ No newline at end of file diff --git a/build.gradle b/build.gradle index ee02430..4a6271a 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,12 @@ buildscript { repositories { + google() jcenter() + maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -14,7 +16,9 @@ buildscript { allprojects { repositories { + google() jcenter() + maven { url 'https://jitpack.io' } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c5a01e0..d1383ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Mar 12 01:52:21 CET 2017 +#Mon Jan 8 01:52:21 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/library/build.gradle b/library/build.gradle index 6215a43..d5dc8dd 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.3" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { consumerProguardFiles 'proguard-rules.pro' - minSdkVersion 11 - targetSdkVersion 25 - versionCode 7 - versionName "1.1" + minSdkVersion 14 + targetSdkVersion 27 + versionCode 12 + versionName "1.2" } buildTypes { release { @@ -20,6 +20,6 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.3.1' -} + api fileTree(dir: 'libs', include: ['*.jar']) + api 'com.android.support:appcompat-v7:27.0.2' +} \ No newline at end of file From afd6e956aca038195986a1d7ce153996f83b2e2e Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:25:12 -0500 Subject: [PATCH 02/11] Reformat code --- .../javiersantos/licensing/AESObfuscator.java | 12 +- .../licensing/APKExpansionPolicy.java | 42 ++- .../javiersantos/licensing/DeviceLimiter.java | 4 +- .../licensing/LibraryChecker.java | 33 ++- .../licensing/LibraryCheckerCallback.java | 12 +- .../licensing/LibraryValidator.java | 15 +- .../javiersantos/licensing/Obfuscator.java | 18 +- .../github/javiersantos/licensing/Policy.java | 6 +- .../licensing/PreferenceObfuscator.java | 6 +- .../javiersantos/licensing/ResponseData.java | 8 +- .../licensing/ServerManagedPolicy.java | 31 +- .../javiersantos/licensing/StrictPolicy.java | 8 +- .../javiersantos/licensing/util/Base64.java | 278 +++++++++++------- .../licensing/util/URIQueryDecoder.java | 8 +- .../piracychecker/LibraryUtils.java | 108 ++++--- .../piracychecker/PiracyChecker.java | 45 +-- .../piracychecker/PiracyCheckerDialog.java | 7 +- .../piracychecker/PiracyCheckerUtils.java | 2 - .../activities/LicenseActivity.java | 18 +- .../enums/PiracyCheckerCallback.java | 19 +- .../enums/PiracyCheckerError.java | 6 +- .../piracychecker/enums/PirateApp.java | 8 +- 22 files changed, 434 insertions(+), 260 deletions(-) diff --git a/library/src/main/java/com/github/javiersantos/licensing/AESObfuscator.java b/library/src/main/java/com/github/javiersantos/licensing/AESObfuscator.java index 53707ec..ea80843 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/AESObfuscator.java +++ b/library/src/main/java/com/github/javiersantos/licensing/AESObfuscator.java @@ -47,10 +47,12 @@ public class AESObfuscator implements Obfuscator { private Cipher mDecryptor; /** - * @param salt an array of random bytes to use for each (un)obfuscation - * @param applicationId application identifier, e.g. the package name - * @param deviceId device identifier. Use as many sources as possible to create this unique - * identifier. + * @param salt + * an array of random bytes to use for each (un)obfuscation + * @param applicationId + * application identifier, e.g. the package name + * @param deviceId + * device identifier. Use as many sources as possible to create this unique identifier. */ public AESObfuscator(byte[] salt, String applicationId, String deviceId) { try { @@ -92,7 +94,7 @@ public String unobfuscate(String obfuscated, String key) throws ValidationExcept int headerIndex = result.indexOf(header + key); if (headerIndex != 0) { throw new ValidationException("Header not found (invalid data or key)" + ":" + - obfuscated); + obfuscated); } return result.substring(header.length() + key.length(), result.length()); } catch (Base64DecoderException | IllegalBlockSizeException | BadPaddingException e) { diff --git a/library/src/main/java/com/github/javiersantos/licensing/APKExpansionPolicy.java b/library/src/main/java/com/github/javiersantos/licensing/APKExpansionPolicy.java index 5501d35..8ede292 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/APKExpansionPolicy.java +++ b/library/src/main/java/com/github/javiersantos/licensing/APKExpansionPolicy.java @@ -72,8 +72,10 @@ public class APKExpansionPolicy implements Policy { private Vector mExpansionFileSizes = new Vector<>(); /** - * @param context The context for the current application - * @param obfuscator An obfuscator to be used with preferences. + * @param context + * The context for the current application + * @param obfuscator + * An obfuscator to be used with preferences. */ public APKExpansionPolicy(Context context, Obfuscator obfuscator) { // Import old values @@ -82,7 +84,7 @@ public APKExpansionPolicy(Context context, Obfuscator obfuscator) { mLastResponse = Integer.parseInt( mPreferences.getString(PREF_LAST_RESPONSE, Integer.toString(Policy.RETRY))); mValidityTimestamp = Long.parseLong(mPreferences.getString(PREF_VALIDITY_TIMESTAMP, - DEFAULT_VALIDITY_TIMESTAMP)); + DEFAULT_VALIDITY_TIMESTAMP)); mRetryUntil = Long.parseLong(mPreferences.getString(PREF_RETRY_UNTIL, DEFAULT_RETRY_UNTIL)); mMaxRetries = Long.parseLong(mPreferences.getString(PREF_MAX_RETRIES, DEFAULT_MAX_RETRIES)); mRetryCount = Long.parseLong(mPreferences.getString(PREF_RETRY_COUNT, DEFAULT_RETRY_COUNT)); @@ -108,8 +110,10 @@ public void resetPolicy() { * client should ignore retry errors until
  • GR: the number of retry errors that the client * should ignore * - * @param response the result from validating the server response - * @param rawData the raw server response data + * @param response + * the result from validating the server response + * @param rawData + * the raw server response data */ public void processServerResponse(int response, ResponseData rawData) { @@ -160,7 +164,8 @@ public void processServerResponse(int response, * Set the last license response received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param l the response + * @param l + * the response */ private void setLastResponse(int l) { mLastResponseTime = System.currentTimeMillis(); @@ -176,7 +181,8 @@ public long getRetryCount() { * Set the current retry count and add to preferences. You must manually call * PreferenceObfuscator.commit() to commit these changes to disk. * - * @param c the new retry count + * @param c + * the new retry count */ private void setRetryCount(long c) { mRetryCount = c; @@ -191,7 +197,8 @@ public long getValidityTimestamp() { * Set the last validity timestamp (VT) received from the server and add to preferences. You * must manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param validityTimestamp the VT string received + * @param validityTimestamp + * the VT string received */ private void setValidityTimestamp(String validityTimestamp) { Long lValidityTimestamp; @@ -216,7 +223,8 @@ public long getRetryUntil() { * Set the retry until timestamp (GT) received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param retryUntil the GT string received + * @param retryUntil + * the GT string received */ private void setRetryUntil(String retryUntil) { Long lRetryUntil; @@ -241,7 +249,8 @@ public long getMaxRetries() { * Set the max retries value (GR) as received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param maxRetries the GR string received + * @param maxRetries + * the GR string received */ private void setMaxRetries(String maxRetries) { Long lMaxRetries; @@ -272,8 +281,9 @@ public int getExpansionURLCount() { * Gets the expansion URL. Since these URLs are not committed to preferences, this will always * return null if there has not been an LVL fetch in the current session. * - * @param index the index of the URL to fetch. This value will be either MAIN_FILE_URL_INDEX or - * PATCH_FILE_URL_INDEX + * @param index + * the index of the URL to fetch. This value will be either MAIN_FILE_URL_INDEX or + * PATCH_FILE_URL_INDEX */ public String getExpansionURL(int index) { if (index < mExpansionURLs.size()) { @@ -286,9 +296,11 @@ public String getExpansionURL(int index) { * Sets the expansion URL. Expansion URL's are not committed to preferences, but are instead * intended to be stored when the license response is processed by the front-end. * - * @param index the index of the expansion URL. This value will be either MAIN_FILE_URL_INDEX or - * PATCH_FILE_URL_INDEX - * @param URL the URL to set + * @param index + * the index of the expansion URL. This value will be either MAIN_FILE_URL_INDEX or + * PATCH_FILE_URL_INDEX + * @param URL + * the URL to set */ public void setExpansionURL(int index, String URL) { if (index >= mExpansionURLs.size()) { diff --git a/library/src/main/java/com/github/javiersantos/licensing/DeviceLimiter.java b/library/src/main/java/com/github/javiersantos/licensing/DeviceLimiter.java index e471ef6..5f83ace 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/DeviceLimiter.java +++ b/library/src/main/java/com/github/javiersantos/licensing/DeviceLimiter.java @@ -34,7 +34,9 @@ public interface DeviceLimiter { /** * Checks if this device is allowed to use the given user's license. * - * @param userId the user whose license the server responded with + * @param userId + * the user whose license the server responded with + * * @return LICENSED if the device is allowed, NOT_LICENSED if not, RETRY if an error occurs */ int isDeviceAllowed(String userId); diff --git a/library/src/main/java/com/github/javiersantos/licensing/LibraryChecker.java b/library/src/main/java/com/github/javiersantos/licensing/LibraryChecker.java index 8e1ca00..899bf0d 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/LibraryChecker.java +++ b/library/src/main/java/com/github/javiersantos/licensing/LibraryChecker.java @@ -82,10 +82,15 @@ public class LibraryChecker implements ServiceConnection { private Handler mHandler; /** - * @param context a Context - * @param policy implementation of Policy - * @param encodedPublicKey Base64-encoded RSA public key - * @throws IllegalArgumentException if encodedPublicKey is invalid + * @param context + * a Context + * @param policy + * implementation of Policy + * @param encodedPublicKey + * Base64-encoded RSA public key + * + * @throws IllegalArgumentException + * if encodedPublicKey is invalid */ public LibraryChecker(Context context, Policy policy, String encodedPublicKey) { mContext = context; @@ -101,8 +106,11 @@ public LibraryChecker(Context context, Policy policy, String encodedPublicKey) { /** * Generates a PublicKey instance from a string containing the Base64-encoded public key. * - * @param encodedPublicKey Base64-encoded public key - * @throws IllegalArgumentException if encodedPublicKey is invalid + * @param encodedPublicKey + * Base64-encoded public key + * + * @throws IllegalArgumentException + * if encodedPublicKey is invalid */ private static PublicKey generatePublicKey(String encodedPublicKey) { try { @@ -125,7 +133,9 @@ private static PublicKey generatePublicKey(String encodedPublicKey) { /** * Get version code for the application package name. * - * @param packageName application package name + * @param packageName + * application package name + * * @return the version code or empty string if package not found */ private static String getVersionCode(Context context, String packageName) { @@ -152,7 +162,8 @@ public synchronized void checkAccess(LibraryCheckerCallback callback) { callback.allow(Policy.LICENSED); } else { LibraryValidator validator = new LibraryValidator(mPolicy, new NullDeviceLimiter(), - callback, generateNonce(), mPackageName, mVersionCode); + callback, generateNonce(), + mPackageName, mVersionCode); if (mService == null) { Log.i(TAG, "Binding to licensing service."); @@ -303,7 +314,7 @@ private int generateNonce() { return RANDOM.nextInt(); } - private class ResultListener extends ILicenseResultListener.Stub { + public class ResultListener extends ILicenseResultListener.Stub { private static final int ERROR_CONTACTING_SERVER = 0x101; private static final int ERROR_INVALID_PACKAGE_NAME = 0x102; private static final int ERROR_NON_MATCHING_UID = 0x103; @@ -333,7 +344,7 @@ public void run() { if (mChecksInProgress.contains(mValidator)) { clearTimeout(); mValidator.check(mPublicKey, responseCode, signedData, - Calendar.getInstance(), signature); + Calendar.getInstance(), signature); finishCheck(mValidator); } if (DEBUG_LICENSE_ERROR) { @@ -358,7 +369,7 @@ public void run() { if (logResponse) { String android_id = Secure.getString(mContext.getContentResolver(), - Secure.ANDROID_ID); + Secure.ANDROID_ID); Date date = new Date(); Log.d(TAG, "Server Failure: " + stringError); Log.d(TAG, "Android ID: " + android_id); diff --git a/library/src/main/java/com/github/javiersantos/licensing/LibraryCheckerCallback.java b/library/src/main/java/com/github/javiersantos/licensing/LibraryCheckerCallback.java index 25d08d8..93abcdc 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/LibraryCheckerCallback.java +++ b/library/src/main/java/com/github/javiersantos/licensing/LibraryCheckerCallback.java @@ -41,17 +41,19 @@ public interface LibraryCheckerCallback { /** * Allow use. App should proceed as normal. * - * @param reason Policy.LICENSED or Policy.RETRY typically. (although in theory the policy can - * return Policy.NOT_LICENSED here as well) + * @param reason + * Policy.LICENSED or Policy.RETRY typically. (although in theory the policy can return + * Policy.NOT_LICENSED here as well) */ void allow(int reason); /** * Don't allow use. App should inform user and take appropriate action. * - * @param reason Policy.NOT_LICENSED or Policy.RETRY. (although in theory the policy can return - * Policy.LICENSED here as well --- perhaps the call to the LVL took too long, for - * example) + * @param reason + * Policy.NOT_LICENSED or Policy.RETRY. (although in theory the policy can return + * Policy.LICENSED here as well --- perhaps the call to the LVL took too long, for + * example) */ void dontAllow(int reason); diff --git a/library/src/main/java/com/github/javiersantos/licensing/LibraryValidator.java b/library/src/main/java/com/github/javiersantos/licensing/LibraryValidator.java index 9baf243..508dca7 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/LibraryValidator.java +++ b/library/src/main/java/com/github/javiersantos/licensing/LibraryValidator.java @@ -79,12 +79,17 @@ public String getPackageName() { /** * Verifies the response from server and calls appropriate callback method. * - * @param publicKey public key associated with the developer account - * @param responseCode server response code - * @param signedData signed data from server - * @param signature server signature + * @param publicKey + * public key associated with the developer account + * @param responseCode + * server response code + * @param signedData + * signed data from server + * @param signature + * server signature */ - public void check(PublicKey publicKey, int responseCode, String signedData, Calendar calendar, String signature) { + public void check(PublicKey publicKey, int responseCode, String signedData, Calendar calendar, + String signature) { String userId = null; // Skip signature check for unsuccessful requests ResponseData data = null; diff --git a/library/src/main/java/com/github/javiersantos/licensing/Obfuscator.java b/library/src/main/java/com/github/javiersantos/licensing/Obfuscator.java index a6a5494..e82015b 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/Obfuscator.java +++ b/library/src/main/java/com/github/javiersantos/licensing/Obfuscator.java @@ -29,8 +29,11 @@ public interface Obfuscator { /** * Obfuscate a string that is being stored into shared preferences. * - * @param original The data that is to be obfuscated. - * @param key The key for the data that is to be obfuscated. + * @param original + * The data that is to be obfuscated. + * @param key + * The key for the data that is to be obfuscated. + * * @return A transformed version of the original data. */ String obfuscate(String original, String key); @@ -38,10 +41,15 @@ public interface Obfuscator { /** * Undo the transformation applied to data by the obfuscate() method. * - * @param obfuscated The data that is to be un-obfuscated. - * @param key The key for the data that is to be obfuscated. + * @param obfuscated + * The data that is to be un-obfuscated. + * @param key + * The key for the data that is to be obfuscated. + * * @return The original data transformed by the obfuscate() method. - * @throws ValidationException Optionally thrown if a data integrity check fails. + * + * @throws ValidationException + * Optionally thrown if a data integrity check fails. */ String unobfuscate(String obfuscated, String key) throws ValidationException; } diff --git a/library/src/main/java/com/github/javiersantos/licensing/Policy.java b/library/src/main/java/com/github/javiersantos/licensing/Policy.java index 3d65dd7..3c8e94e 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/Policy.java +++ b/library/src/main/java/com/github/javiersantos/licensing/Policy.java @@ -46,8 +46,10 @@ public interface Policy { * Provide results from contact with the license server. Retry counts are incremented if the * current value of response is RETRY. Results will be used for any future policy decisions. * - * @param response the result from validating the server response - * @param rawData the raw server response data, can be null for RETRY + * @param response + * the result from validating the server response + * @param rawData + * the raw server response data, can be null for RETRY */ void processServerResponse(int response, ResponseData rawData); diff --git a/library/src/main/java/com/github/javiersantos/licensing/PreferenceObfuscator.java b/library/src/main/java/com/github/javiersantos/licensing/PreferenceObfuscator.java index 8f6da05..2bc6b73 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/PreferenceObfuscator.java +++ b/library/src/main/java/com/github/javiersantos/licensing/PreferenceObfuscator.java @@ -34,8 +34,10 @@ public class PreferenceObfuscator { /** * Constructor. * - * @param sp A SharedPreferences instance provided by the system. - * @param o The Obfuscator to use when reading or writing data. + * @param sp + * A SharedPreferences instance provided by the system. + * @param o + * The Obfuscator to use when reading or writing data. */ public PreferenceObfuscator(SharedPreferences sp, Obfuscator o) { mPreferences = sp; diff --git a/library/src/main/java/com/github/javiersantos/licensing/ResponseData.java b/library/src/main/java/com/github/javiersantos/licensing/ResponseData.java index 3d515f7..4ccb4b6 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/ResponseData.java +++ b/library/src/main/java/com/github/javiersantos/licensing/ResponseData.java @@ -39,9 +39,13 @@ public class ResponseData { /** * Parses response string into ResponseData. * - * @param responseData response data string + * @param responseData + * response data string + * * @return ResponseData object - * @throws IllegalArgumentException upon parsing error + * + * @throws IllegalArgumentException + * upon parsing error */ public static ResponseData parse(String responseData) { // Must parse out main response data and response-specific data. diff --git a/library/src/main/java/com/github/javiersantos/licensing/ServerManagedPolicy.java b/library/src/main/java/com/github/javiersantos/licensing/ServerManagedPolicy.java index e352de5..103e671 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/ServerManagedPolicy.java +++ b/library/src/main/java/com/github/javiersantos/licensing/ServerManagedPolicy.java @@ -62,8 +62,10 @@ public class ServerManagedPolicy implements Policy { private PreferenceObfuscator mPreferences; /** - * @param context The context for the current application - * @param obfuscator An obfuscator to be used with preferences. + * @param context + * The context for the current application + * @param obfuscator + * An obfuscator to be used with preferences. */ public ServerManagedPolicy(Context context, Obfuscator obfuscator) { // Import old values @@ -72,7 +74,7 @@ public ServerManagedPolicy(Context context, Obfuscator obfuscator) { mLastResponse = Integer.parseInt( mPreferences.getString(PREF_LAST_RESPONSE, Integer.toString(Policy.RETRY))); mValidityTimestamp = Long.parseLong(mPreferences.getString(PREF_VALIDITY_TIMESTAMP, - DEFAULT_VALIDITY_TIMESTAMP)); + DEFAULT_VALIDITY_TIMESTAMP)); mRetryUntil = Long.parseLong(mPreferences.getString(PREF_RETRY_UNTIL, DEFAULT_RETRY_UNTIL)); mMaxRetries = Long.parseLong(mPreferences.getString(PREF_MAX_RETRIES, DEFAULT_MAX_RETRIES)); mRetryCount = Long.parseLong(mPreferences.getString(PREF_RETRY_COUNT, DEFAULT_RETRY_COUNT)); @@ -85,8 +87,10 @@ public ServerManagedPolicy(Context context, Obfuscator obfuscator) { * client should ignore retry errors until
  • GR: the number of retry errors that the client * should ignore * - * @param response the result from validating the server response - * @param rawData the raw server response data + * @param response + * the result from validating the server response + * @param rawData + * the raw server response data */ public void processServerResponse(int response, ResponseData rawData) { @@ -119,7 +123,8 @@ public void processServerResponse(int response, ResponseData rawData) { * Set the last license response received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param l the response + * @param l + * the response */ private void setLastResponse(int l) { mLastResponseTime = System.currentTimeMillis(); @@ -135,7 +140,8 @@ public long getRetryCount() { * Set the current retry count and add to preferences. You must manually call * PreferenceObfuscator.commit() to commit these changes to disk. * - * @param c the new retry count + * @param c + * the new retry count */ private void setRetryCount(long c) { mRetryCount = c; @@ -150,7 +156,8 @@ public long getValidityTimestamp() { * Set the last validity timestamp (VT) received from the server and add to preferences. You * must manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param validityTimestamp the VT string received + * @param validityTimestamp + * the VT string received */ private void setValidityTimestamp(String validityTimestamp) { Long lValidityTimestamp; @@ -175,7 +182,8 @@ public long getRetryUntil() { * Set the retry until timestamp (GT) received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param retryUntil the GT string received + * @param retryUntil + * the GT string received */ private void setRetryUntil(String retryUntil) { Long lRetryUntil; @@ -200,7 +208,8 @@ public long getMaxRetries() { * Set the max retries value (GR) as received from the server and add to preferences. You must * manually call PreferenceObfuscator.commit() to commit these changes to disk. * - * @param maxRetries the GR string received + * @param maxRetries + * the GR string received */ private void setMaxRetries(String maxRetries) { Long lMaxRetries; @@ -219,7 +228,7 @@ private void setMaxRetries(String maxRetries) { /** * {@inheritDoc} - * + *

    * This implementation allows access if either:

    1. a LICENSED response was received * within the validity period
    2. a RETRY response was received in the last minute, and we are * under the RETRY count or in the RETRY period.
    diff --git a/library/src/main/java/com/github/javiersantos/licensing/StrictPolicy.java b/library/src/main/java/com/github/javiersantos/licensing/StrictPolicy.java index 150d723..c2b0446 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/StrictPolicy.java +++ b/library/src/main/java/com/github/javiersantos/licensing/StrictPolicy.java @@ -37,8 +37,10 @@ public StrictPolicy() { * Process a new response from the license server. Since we aren't performing any caching, this * equates to reading the LicenseResponse. Any ResponseData provided is ignored. * - * @param response the result from validating the server response - * @param rawData the raw server response data + * @param response + * the result from validating the server response + * @param rawData + * the raw server response data */ public void processServerResponse(int response, ResponseData rawData) { mLastResponse = response; @@ -46,7 +48,7 @@ public void processServerResponse(int response, ResponseData rawData) { /** * {@inheritDoc} - * + *

    * This implementation allows access if and only if a LICENSED response was received the last * time the server was contacted. */ diff --git a/library/src/main/java/com/github/javiersantos/licensing/util/Base64.java b/library/src/main/java/com/github/javiersantos/licensing/util/Base64.java index deeae36..1f63918 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/util/Base64.java +++ b/library/src/main/java/com/github/javiersantos/licensing/util/Base64.java @@ -36,7 +36,7 @@ /** * Base64 converter class. This code is not a full-blown MIME encoder; it simply converts binary * data to base64 data and back. - * + *

    *

    Note {@link CharBase64} is a GWT-compatible implementation of this class. */ public class Base64 { @@ -65,62 +65,69 @@ public class Base64 { */ private final static byte[] ALPHABET = {(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', - (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', - (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', - (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', - (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', - (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', - (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', - (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', - (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', - (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', - (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', - (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', - (byte) '9', (byte) '+', (byte) '/'}; + (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', + (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', + (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', + (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', + (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', + (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', + (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', + (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', + (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', + (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', + (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', + (byte) '9', (byte) '+', (byte) '/'}; /** * The 64 valid web safe Base64 values. */ private final static byte[] WEBSAFE_ALPHABET = {(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', - (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', - (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', - (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', - (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', - (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', - (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', - (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', - (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', - (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', - (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', - (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', - (byte) '9', (byte) '-', (byte) '_'}; + (byte) 'G', (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', + (byte) 'L', (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', + (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', + (byte) 'V', (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', + (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', + (byte) 'f', (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', + (byte) 'k', (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', + (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', + (byte) 'u', (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', + (byte) 'z', (byte) '0', (byte) '1', (byte) '2', (byte) '3', + (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', + (byte) '9', (byte) '-', (byte) '_'}; /** * Translates a Base64 value to either its 6-bit reconstruction value or a negative number * indicating some other meaning. **/ private final static byte[] DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8 - -5, -5, // Whitespace: Tab and Linefeed - -9, -9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26 - -9, -9, -9, -9, -9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42 - 62, // Plus sign at decimal 43 - -9, -9, -9, // Decimal 44 - 46 - 63, // Slash at decimal 47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine - -9, -9, -9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9, -9, -9, // Decimal 62 - 64 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N' - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z' - -9, -9, -9, -9, -9, -9, // Decimal 91 - 96 - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm' - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z' - -9, -9, -9, -9, -9 // Decimal 123 - 127 + -5, -5, // Whitespace: Tab and Linefeed + -9, -9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, + // Decimal 14 - 26 + -9, -9, -9, -9, -9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, + // Decimal 33 - 42 + 62, // Plus sign at decimal 43 + -9, -9, -9, // Decimal 44 - 46 + 63, // Slash at decimal 47 + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + // Numbers zero through nine + -9, -9, -9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9, -9, -9, // Decimal 62 - 64 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + // Letters 'A' through 'N' + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + // Letters 'O' through 'Z' + -9, -9, -9, -9, -9, -9, // Decimal 91 - 96 + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + // Letters 'a' through 'm' + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + // Letters 'n' through 'z' + -9, -9, -9, -9, -9 // Decimal 123 - 127 /* ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 @@ -138,27 +145,27 @@ public class Base64 { */ private final static byte[] WEBSAFE_DECODABET = {-9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8 - -5, -5, // Whitespace: Tab and Linefeed - -9, -9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26 - -9, -9, -9, -9, -9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 44 - 62, // Dash '-' sign at decimal 45 - -9, -9, // Decimal 46-47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine - -9, -9, -9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9, -9, -9, // Decimal 62 - 64 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N' - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z' - -9, -9, -9, -9, // Decimal 91-94 - 63, // Underscore '_' at decimal 95 - -9, // Decimal 96 - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm' - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z' - -9, -9, -9, -9, -9 // Decimal 123 - 127 + -5, -5, // Whitespace: Tab and Linefeed + -9, -9, // Decimal 11 - 12 + -5, // Whitespace: Carriage Return + -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26 + -9, -9, -9, -9, -9, // Decimal 27 - 31 + -5, // Whitespace: Space + -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 44 + 62, // Dash '-' sign at decimal 45 + -9, -9, // Decimal 46-47 + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine + -9, -9, -9, // Decimal 58 - 60 + -1, // Equals sign at decimal 61 + -9, -9, -9, // Decimal 62 - 64 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N' + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z' + -9, -9, -9, -9, // Decimal 91-94 + 63, // Underscore '_' at decimal 95 + -9, // Decimal 96 + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm' + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z' + -9, -9, -9, -9, -9 // Decimal 123 - 127 /* ,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 128 - 139 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 @@ -193,13 +200,21 @@ private Base64() { * destination array. The actual number of significant bytes in your array is given * by numSigBytes. * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param numSigBytes the number of significant bytes in your array - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @param alphabet is the encoding alphabet + * @param source + * the array to convert + * @param srcOffset + * the index where conversion begins + * @param numSigBytes + * the number of significant bytes in your array + * @param destination + * the array to hold the conversion + * @param destOffset + * the index where output will be put + * @param alphabet + * is the encoding alphabet + * * @return the destination array + * * @since 1.3 */ private static byte[] encode3to4(byte[] source, int srcOffset, @@ -249,7 +264,9 @@ private static byte[] encode3to4(byte[] source, int srcOffset, * Encodes a byte array into Base64 notation. Equivalent to calling {@code encodeBytes(source, * 0, source.length)} * - * @param source The data to convert + * @param source + * The data to convert + * * @since 1.4 */ public static String encode(byte[] source) { @@ -259,9 +276,11 @@ public static String encode(byte[] source) { /** * Encodes a byte array into web safe Base64 notation. * - * @param source The data to convert - * @param doPadding is {@code true} to pad result with '=' chars if it does not fall on 3 byte - * boundaries + * @param source + * The data to convert + * @param doPadding + * is {@code true} to pad result with '=' chars if it does not fall on 3 byte + * boundaries */ public static String encodeWebSafe(byte[] source, boolean doPadding) { return encode(source, 0, source.length, WEBSAFE_ALPHABET, doPadding); @@ -270,12 +289,18 @@ public static String encodeWebSafe(byte[] source, boolean doPadding) { /** * Encodes a byte array into Base64 notation. * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @param alphabet is the encoding alphabet - * @param doPadding is {@code true} to pad result with '=' chars if it does not fall on 3 byte - * boundaries + * @param source + * The data to convert + * @param off + * Offset in array where conversion should begin + * @param len + * Length of data to convert + * @param alphabet + * is the encoding alphabet + * @param doPadding + * is {@code true} to pad result with '=' chars if it does not fall on 3 byte + * boundaries + * * @since 1.4 */ public static String encode(byte[] source, int off, int len, byte[] alphabet, @@ -298,11 +323,17 @@ public static String encode(byte[] source, int off, int len, byte[] alphabet, /** * Encodes a byte array into Base64 notation. * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @param alphabet is the encoding alphabet - * @param maxLineLength maximum length of one line. + * @param source + * The data to convert + * @param off + * Offset in array where conversion should begin + * @param len + * Length of data to convert + * @param alphabet + * is the encoding alphabet + * @param maxLineLength + * maximum length of one line. + * * @return the BASE64-encoded byte array */ @SuppressLint("Assert") @@ -368,12 +399,19 @@ public static byte[] encode(byte[] source, int off, int len, byte[] alphabet, * destination array. This method returns the actual number of bytes that were * converted from the Base64 encoding. * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @param decodabet the decodabet for decoding Base64 content + * @param source + * the array to convert + * @param srcOffset + * the index where conversion begins + * @param destination + * the array to hold the conversion + * @param destOffset + * the index where output will be put + * @param decodabet + * the decodabet for decoding Base64 content + * * @return the number of decoded bytes converted + * * @since 1.3 */ private static int decode4to3(byte[] source, int srcOffset, @@ -415,8 +453,11 @@ private static int decode4to3(byte[] source, int srcOffset, /** * Decodes data from Base64 notation. * - * @param s the string to decode (decoded in default encoding) + * @param s + * the string to decode (decoded in default encoding) + * * @return the decoded data + * * @since 1.4 */ public static byte[] decode(String s) throws Base64DecoderException { @@ -428,7 +469,9 @@ public static byte[] decode(String s) throws Base64DecoderException { * Decodes data from web safe Base64 notation. Web safe encoding uses '-' instead of '+', '_' * instead of '/' * - * @param s the string to decode (decoded in default encoding) + * @param s + * the string to decode (decoded in default encoding) + * * @return the decoded data */ public static byte[] decodeWebSafe(String s) throws Base64DecoderException { @@ -439,8 +482,11 @@ public static byte[] decodeWebSafe(String s) throws Base64DecoderException { /** * Decodes Base64 content in byte array format and returns the decoded byte array. * - * @param source The Base64 encoded data + * @param source + * The Base64 encoded data + * * @return decoded data + * * @since 1.3 */ public static byte[] decode(byte[] source) throws Base64DecoderException { @@ -451,7 +497,9 @@ public static byte[] decode(byte[] source) throws Base64DecoderException { * Decodes web safe Base64 content in byte array format and returns the decoded data. Web safe * encoding uses '-' instead of '+', '_' instead of '/' * - * @param source the string to decode (decoded in default encoding) + * @param source + * the string to decode (decoded in default encoding) + * * @return the decoded data */ public static byte[] decodeWebSafe(byte[] source) @@ -462,10 +510,15 @@ public static byte[] decodeWebSafe(byte[] source) /** * Decodes Base64 content in byte array format and returns the decoded byte array. * - * @param source The Base64 encoded data - * @param off The offset of where to begin decoding - * @param len The length of characters to decode + * @param source + * The Base64 encoded data + * @param off + * The offset of where to begin decoding + * @param len + * The length of characters to decode + * * @return decoded data + * * @since 1.3 */ public static byte[] decode(byte[] source, int off, int len) @@ -477,9 +530,13 @@ public static byte[] decode(byte[] source, int off, int len) * Decodes web safe Base64 content in byte array format and returns the decoded byte array. Web * safe encoding uses '-' instead of '+', '_' instead of '/' * - * @param source The Base64 encoded data - * @param off The offset of where to begin decoding - * @param len The length of characters to decode + * @param source + * The Base64 encoded data + * @param off + * The offset of where to begin decoding + * @param len + * The length of characters to decode + * * @return decoded data */ public static byte[] decodeWebSafe(byte[] source, int off, int len) @@ -490,10 +547,15 @@ public static byte[] decodeWebSafe(byte[] source, int off, int len) /** * Decodes Base64 content using the supplied decodabet and returns the decoded byte array. * - * @param source The Base64 encoded data - * @param off The offset of where to begin decoding - * @param len The length of characters to decode - * @param decodabet the decodabet for decoding Base64 content + * @param source + * The Base64 encoded data + * @param off + * The offset of where to begin decoding + * @param len + * The length of characters to decode + * @param decodabet + * the decodabet for decoding Base64 content + * * @return decoded data */ @SuppressWarnings("UnusedAssignment") @@ -542,7 +604,7 @@ public static byte[] decode(byte[] source, int off, int len, byte[] decodabet) } } else { throw new Base64DecoderException("Bad Base64 input character at " + i - + ": " + source[i + off] + "(decimal)"); + + ": " + source[i + off] + "(decimal)"); } } @@ -555,7 +617,7 @@ public static byte[] decode(byte[] source, int off, int len, byte[] decodabet) if (b4Posn != 0) { if (b4Posn == 1) { throw new Base64DecoderException("single trailing character at offset " - + (len - 1)); + + (len - 1)); } b4[b4Posn++] = EQUALS_SIGN; outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn, decodabet); diff --git a/library/src/main/java/com/github/javiersantos/licensing/util/URIQueryDecoder.java b/library/src/main/java/com/github/javiersantos/licensing/util/URIQueryDecoder.java index e409146..03bf25c 100644 --- a/library/src/main/java/com/github/javiersantos/licensing/util/URIQueryDecoder.java +++ b/library/src/main/java/com/github/javiersantos/licensing/util/URIQueryDecoder.java @@ -30,9 +30,11 @@ public class URIQueryDecoder { /** * Decodes the query portion of the passed-in URI. * - * @param encodedURI the URI containing the query to decode - * @param results a map containing all query parameters. Query parameters that do not have a - * value will map to a null string + * @param encodedURI + * the URI containing the query to decode + * @param results + * a map containing all query parameters. Query parameters that do not have a value will + * map to a null string */ static public void DecodeQuery(URI encodedURI, Map results) { Scanner scanner = new Scanner(encodedURI.getRawQuery()); diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java index 1d7d8bb..5069be1 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java @@ -113,10 +113,10 @@ static PirateApp getPirateApp(Context context, boolean lpf, boolean stores) { File file4 = new File("/data/data/" + pack + ".apk"); File file5 = new File("/data/data/" + pack); File file6 = new File(context.getFilesDir().getPath() + pack + - ".apk"); + ".apk"); File file7 = new File(context.getFilesDir().getPath() + pack); File file8 = new File(Environment.getExternalStorageDirectory() + - "/Android/data/" + pack); + "/Android/data/" + pack); if (file1.exists() || file2.exists() || file3.exists() || file4.exists() || file5.exists() || file6.exists() || file7.exists() || file8.exists()) { @@ -135,14 +135,14 @@ static PirateApp getPirateApp(Context context, boolean lpf, boolean stores) { /** * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of the License at - * + *

    * http://www.apache.org/licenses/LICENSE-2.0 - * + *

    * Unless required by applicable law or agreed to in writing, software distributed under the * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions * and limitations under the License. - * + *

    * Copyright (C) 2013, Vladislav Gingo Skoumal (http://www.skoumal.net) */ static boolean isInEmulator(boolean deepCheck) { @@ -228,10 +228,10 @@ static boolean isInEmulator(boolean deepCheck) { try { File sharedFolder = new File(Environment.getExternalStorageDirectory().toString() - + File.separatorChar - + "windows" - + File.separatorChar - + "BstSharedFolder"); + + File.separatorChar + + "windows" + + File.separatorChar + + "BstSharedFolder"); if (sharedFolder.exists()) ratingCheckEmulator += 10; } catch (Exception ignored) { @@ -248,59 +248,89 @@ static boolean isDebug(Context context) { private static ArrayList getApps() { ArrayList apps = new ArrayList<>(); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "c", "h", "e", - "l", "p", "u", "s", ".", "l", "a", "c", "k", "y", "p", "a", "t", "c", "h"})); + "l", "p", "u", "s", ".", "l", "a", "c", + "k", "y", "p", "a", "t", "c", "h"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "d", "i", "m", - "o", "n", "v", "i", "d", "e", "o", ".", "l", "u", "c", "k", "y", "p", "a", "t", - "c", "h", "e", "r"})); + "o", "n", "v", "i", "d", "e", "o", ".", + "l", "u", "c", "k", "y", "p", "a", "t", + "c", "h", "e", "r"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "f", "o", "r", - "p", "d", "a", ".", "l", "p"})); + "p", "d", "a", ".", "l", "p"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "a", "n", "d", - "r", "o", "i", "d", ".", "v", "e", "n", "d", "i", "n", "g", ".", "b", "i", "l", - "l", "i", "n", "g", ".", "I", "n", "A", "p", "p", "B", "i", "l", "l", "i", "n", - "g", "S", "e", "r", "v", "i", "c", "e", ".", "L", "U", "C", "K"})); + "r", "o", "i", "d", ".", "v", "e", "n", + "d", "i", "n", "g", ".", "b", "i", "l", + "l", "i", "n", "g", ".", "I", "n", "A", + "p", "p", "B", "i", "l", "l", "i", "n", + "g", "S", "e", "r", "v", "i", "c", "e", + ".", "L", "U", "C", "K"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "a", "n", "d", - "r", "o", "i", "d", ".", "v", "e", "n", "d", "i", "n", "g", ".", "b", "i", "l", - "l", "i", "n", "g", ".", "I", "n", "A", "p", "p", "B", "i", "l", "l", "i", "n", - "g", "S", "e", "r", "v", "i", "c", "e", ".", "C", "L", "O", "N"})); + "r", "o", "i", "d", ".", "v", "e", "n", + "d", "i", "n", "g", ".", "b", "i", "l", + "l", "i", "n", "g", ".", "I", "n", "A", + "p", "p", "B", "i", "l", "l", "i", "n", + "g", "S", "e", "r", "v", "i", "c", "e", + ".", "L", "O", "C", "K"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "a", "n", "d", - "r", "o", "i", "d", ".", "v", "e", "n", "d", "i", "n", "g", ".", "b", "i", "l", - "l", "i", "n", "g", ".", "I", "n", "A", "p", "p", "B", "i", "l", "l", "i", "n", - "g", "S", "e", "r", "v", "i", "c", "e", ".", "L", "O", "C", "K"})); + "r", "o", "i", "d", ".", "v", "e", "n", + "d", "i", "n", "g", ".", "b", "i", "l", + "l", "i", "n", "g", ".", "I", "n", "A", + "p", "p", "B", "i", "l", "l", "i", "n", + "g", "S", "e", "r", "v", "i", "c", "e", + ".", "L", "A", "C", "K"})); apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "a", "n", "d", - "r", "o", "i", "d", ".", "v", "e", "n", "d", "i", "n", "g", ".", "b", "i", "l", - "l", "i", "n", "g", ".", "I", "n", "A", "p", "p", "B", "i", "l", "l", "i", "n", - "g", "S", "e", "r", "v", "i", "c", "e", ".", "L", "A", "C", "K"})); + "r", "o", "i", "d", ".", "v", "e", "n", + "d", "i", "n", "g", ".", "b", "i", "l", + "l", "i", "n", "g", ".", "I", "n", "A", + "p", "p", "B", "i", "l", "l", "i", "n", + "g", "S", "e", "r", "v", "i", "c", "e", + ".", "C", "L", "O", "N"})); + apps.add(new PirateApp("Lucky Patcher", new String[]{"c", "o", "m", ".", "a", "n", "d", + "r", "o", "i", "d", ".", "v", "e", "n", + "d", "i", "n", "g", ".", "b", "i", "l", + "l", "i", "n", "g", ".", "I", "n", "A", + "p", "p", "B", "i", "l", "l", "i", "n", + "g", "S", "e", "r", "v", "i", "c", "e", + ".", "C", "R", "A", "C"})); apps.add(new PirateApp("Uret Patcher", new String[]{"u", "r", "e", "t", ".", "j", "a", - "s", "i", "2", "1", "6", "9", ".", "p", "a", "t", "c", "h", "e", "r"})); + "s", "i", "2", "1", "6", "9", ".", "p", + "a", "t", "c", "h", "e", "r"})); apps.add(new PirateApp("Freedom", new String[]{"c", "c", ".", "m", "a", "d", "k", "i", - "t", "e", ".", "f", "r", "e", "e", "d", "o", "m"})); + "t", "e", ".", "f", "r", "e", "e", "d", "o", + "m"})); apps.add(new PirateApp("Freedom", new String[]{"c", "c", ".", "c", "z", ".", "m", "a", - "d", "k", "i", "t", "e", ".", "f", "r", "e", "e", "d", "o", "m"})); + "d", "k", "i", "t", "e", ".", "f", "r", "e", + "e", "d", "o", "m"})); apps.add(new PirateApp("CreeHack", new String[]{"o", "r", "g", ".", "c", "r", "e", "e", - "p", "l", "a", "y", "s", ".", "h", "a", "c", "k"})); + "p", "l", "a", "y", "s", ".", "h", "a", "c", + "k"})); apps.add(new PirateApp("Aptoide", new String[]{"c", "m", ".", "a", "p", "t", "o", "i", - "d", "e", ".", "p", "t"})); + "d", "e", ".", "p", "t"})); apps.add(new PirateApp("BlackMart", new String[]{"o", "r", "g", ".", "b", "l", "a", "c", - "k", "m", "a", "r", "t", ".", "m", "a", "r", "k", "e", "t"})); + "k", "m", "a", "r", "t", ".", "m", "a", + "r", "k", "e", "t"})); apps.add(new PirateApp("Mobogenie", new String[]{"c", "o", "m", ".", "m", "o", "b", "o", - "g", "e", "n", "i", "e"})); + "g", "e", "n", "i", "e"})); apps.add(new PirateApp("1Mobile", new String[]{"m", "e", ".", "o", "n", "e", "m", "o", - "b", "i", "l", "e", ".", "a", "n", "d", "r", "o", "i", "d"})); + "b", "i", "l", "e", ".", "a", "n", "d", "r", + "o", "i", "d"})); apps.add(new PirateApp("GetApk", new String[]{"c", "o", "m", ".", "r", "e", "p", "o", - "d", "r", "o", "i", "d", ".", "a", "p", "p"})); + "d", "r", "o", "i", "d", ".", "a", "p", + "p"})); apps.add(new PirateApp("GetJar", new String[]{"c", "o", "m", ".", "g", "e", "t", "j", - "a", "r", ".", "r", "e", "w", "a", "r", "d", "s"})); + "a", "r", ".", "r", "e", "w", "a", "r", "d", + "s"})); apps.add(new PirateApp("SlideMe", new String[]{"c", "o", "m", ".", "s", "l", "i", "d", - "e", "m", "e", ".", "s", "a", "m", ".", "m", "a", "n", "a", "g", "e", "r"})); + "e", "m", "e", ".", "s", "a", "m", ".", "m", + "a", "n", "a", "g", "e", "r"})); apps.add(new PirateApp("ACMarket", new String[]{"n", "e", "t", ".", "a", "p", "p", "c", - "a", "k", "e"})); + "a", "k", "e"})); return apps; } private static boolean isIntentAvailable(Context ctx, Intent intent) { final PackageManager mgr = ctx.getPackageManager(); List list = mgr.queryIntentActivities(intent, - PackageManager.MATCH_DEFAULT_ONLY); + PackageManager.MATCH_DEFAULT_ONLY); return list != null && list.size() > 0; } @@ -309,7 +339,7 @@ private static boolean hasPermissions(Context context) { return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN || !shouldAskPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) || (!(ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, - Manifest.permission.READ_EXTERNAL_STORAGE))); + Manifest.permission.READ_EXTERNAL_STORAGE))); } catch (Exception e) { return false; } diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java index 15f9f72..561120f 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java @@ -37,10 +37,13 @@ public class PiracyChecker { protected String unlicensedDialogTitle; protected String unlicensedDialogDescription; protected Display display; - @ColorRes protected int colorPrimary; - @ColorRes protected int colorPrimaryDark; + @ColorRes + protected int colorPrimary; + @ColorRes + protected int colorPrimaryDark; protected boolean withLightStatusBar; - @LayoutRes protected int layoutXML = -1; + @LayoutRes + protected int layoutXML = -1; protected boolean enableLVL; protected boolean enableSigningCertificate; protected boolean enableInstallerId; @@ -66,7 +69,7 @@ public class PiracyChecker { public PiracyChecker(Context context) { this(context, context.getString(R.string.app_unlicensed), - context.getString(R.string.app_unlicensed_description)); + context.getString(R.string.app_unlicensed_description)); } public PiracyChecker(Context context, String title, String description) { @@ -179,7 +182,7 @@ private void saveToSharedPreferences(SharedPreferences preferences) { this.preferences = ((Activity) context).getPreferences(Context.MODE_PRIVATE); } catch (Exception e) { this.preferences = context.getSharedPreferences(LIBRARY_PREFERENCES_NAME, - Context.MODE_PRIVATE); + Context.MODE_PRIVATE); } } } @@ -192,7 +195,7 @@ private void saveToSharedPreferences(String preferencesName) { this.preferences = ((Activity) context).getPreferences(Context.MODE_PRIVATE); } catch (Exception e) { this.preferences = context.getSharedPreferences(LIBRARY_PREFERENCES_NAME, - Context.MODE_PRIVATE); + Context.MODE_PRIVATE); } } } @@ -230,6 +233,7 @@ public PiracyChecker callback(PiracyCheckerCallback callback) { public void destroy() { dismissDialog(); destroyLVLChecker(); + context = null; } public void start() { @@ -248,14 +252,14 @@ public void dontAllow(@NonNull PiracyCheckerError error, @Nullable PirateApp app String dialogContent = unlicensedDialogDescription; if (app != null) dialogContent = context.getString(R.string.unauthorized_app_found, - app.getName()); + app.getName()); else if (error.equals(PiracyCheckerError.BLOCK_PIRATE_APP)) dialogContent = context.getString(R.string.unauthorized_app_blocked); if (display == Display.DIALOG) { dismissDialog(); dialog = PiracyCheckerDialog.newInstance(unlicensedDialogTitle, - dialogContent); + dialogContent); if (dialog != null) { dialog.show(context); } else { @@ -292,11 +296,17 @@ private void verify(final PiracyCheckerCallback verifyCallback) { } else { if (enableLVL) { String deviceId = Settings.Secure.getString(context.getContentResolver(), - Settings.Secure.ANDROID_ID); + Settings.Secure.ANDROID_ID); destroyLVLChecker(); - libraryLVLChecker = new LibraryChecker(context, - new ServerManagedPolicy(context, new AESObfuscator(LibraryUtils.SALT, - context.getPackageName(), deviceId)), licenseBase64); + libraryLVLChecker = + new LibraryChecker( + context, + new ServerManagedPolicy(context, + new AESObfuscator( + LibraryUtils.SALT, + context.getPackageName(), + deviceId)), + licenseBase64); libraryLVLChecker.checkAccess(new LibraryCheckerCallback() { @Override public void allow(int reason) { @@ -350,7 +360,7 @@ private boolean verifyUnauthorizedApp() { private void doExtraVerification(PiracyCheckerCallback verifyCallback, boolean possibleSuccess) { PirateApp app = LibraryUtils.getPirateApp(context, enableUnauthorizedAppsCheck, - enableStoresCheck); + enableStoresCheck); if (possibleSuccess) { if (enableDebugCheck && LibraryUtils.isDebug(context)) { if (preferences != null && saveToSharedPreferences) @@ -366,8 +376,8 @@ private void doExtraVerification(PiracyCheckerCallback verifyCallback, if (preferences != null && blockUnauthorized && app.isUnauthorized()) preferences.edit().putBoolean(preferenceBlockUnauthorized, true).apply(); verifyCallback.dontAllow(app.isUnauthorized() - ? PiracyCheckerError.PIRATE_APP_INSTALLED - : PiracyCheckerError.THIRD_PARTY_STORE_INSTALLED, app); + ? PiracyCheckerError.PIRATE_APP_INSTALLED + : PiracyCheckerError.THIRD_PARTY_STORE_INSTALLED, app); } else { if (preferences != null && saveToSharedPreferences) preferences.edit().putBoolean(preferenceSaveResult, true).apply(); @@ -380,8 +390,8 @@ private void doExtraVerification(PiracyCheckerCallback verifyCallback, if (preferences != null && blockUnauthorized && app.isUnauthorized()) preferences.edit().putBoolean(preferenceBlockUnauthorized, true).apply(); verifyCallback.dontAllow(app.isUnauthorized() - ? PiracyCheckerError.PIRATE_APP_INSTALLED - : PiracyCheckerError.THIRD_PARTY_STORE_INSTALLED, app); + ? PiracyCheckerError.PIRATE_APP_INSTALLED + : PiracyCheckerError.THIRD_PARTY_STORE_INSTALLED, app); } else { if (preferences != null && saveToSharedPreferences) preferences.edit().putBoolean(preferenceSaveResult, false).apply(); @@ -404,5 +414,4 @@ private void destroyLVLChecker() { libraryLVLChecker = null; } } - } \ No newline at end of file diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerDialog.java b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerDialog.java index 95e0e92..ef8f509 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerDialog.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerDialog.java @@ -11,7 +11,8 @@ public class PiracyCheckerDialog extends DialogFragment { private static PiracyCheckerDialog dialog; private static String mTitle, mContent; - public PiracyCheckerDialog() {} + public PiracyCheckerDialog() { + } public static PiracyCheckerDialog newInstance(String dialogTitle, String dialogContent) { dialog = new PiracyCheckerDialog(); @@ -22,7 +23,7 @@ public static PiracyCheckerDialog newInstance(String dialogTitle, String dialogC } protected void show(Context context) { - dialog.show(((Activity)context).getFragmentManager(), "[LICENSE_DIALOG]"); + dialog.show(((Activity) context).getFragmentManager(), "[LICENSE_DIALOG]"); } @NonNull @@ -30,7 +31,7 @@ protected void show(Context context) { public Dialog onCreateDialog(Bundle savedInstanceState) { setCancelable(false); return LibraryUtils.buildUnlicensedDialog(getActivity(), mTitle, - mContent); + mContent); } } diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerUtils.java b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerUtils.java index d3f5e49..e0f8a19 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerUtils.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyCheckerUtils.java @@ -3,9 +3,7 @@ import android.content.Context; public class PiracyCheckerUtils { - public static String getAPKSignature(Context context) { return LibraryUtils.getCurrentSignature(context); } - } \ No newline at end of file diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/activities/LicenseActivity.java b/library/src/main/java/com/github/javiersantos/piracychecker/activities/LicenseActivity.java index eb16d35..aa131f0 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/activities/LicenseActivity.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/activities/LicenseActivity.java @@ -16,10 +16,13 @@ public class LicenseActivity extends AppCompatActivity { private String description; - @ColorRes private int colorPrimary; - @ColorRes private int colorPrimaryDark; + @ColorRes + private int colorPrimary; + @ColorRes + private int colorPrimaryDark; private boolean withLightStatusBar; - @LayoutRes private int layoutXML; + @LayoutRes + private int layoutXML; @Override protected void onCreate(Bundle savedInstanceState) { @@ -34,9 +37,11 @@ private void getIntentData() { if (getIntent() != null) { description = getIntent().getStringExtra("content"); colorPrimary = getIntent().getIntExtra("colorPrimary", - ContextCompat.getColor(this, R.color.colorPrimary)); + ContextCompat + .getColor(this, R.color.colorPrimary)); colorPrimaryDark = getIntent().getIntExtra("colorPrimaryDark", - ContextCompat.getColor(this, R.color.colorPrimaryDark)); + ContextCompat.getColor(this, + R.color.colorPrimaryDark)); withLightStatusBar = getIntent().getBooleanExtra("withLightStatusBar", false); layoutXML = getIntent().getIntExtra("layoutXML", -1); } @@ -67,7 +72,8 @@ private void setActivityData() { View inflateView; if (layoutXML == -1) { inflateView = factory.inflate(R.layout.activity_license_default, null); - TextView activityDescription = (TextView) inflateView.findViewById(R.id.piracy_checker_description); + TextView activityDescription = + (TextView) inflateView.findViewById(R.id.piracy_checker_description); activityDescription.setText(description); } else inflateView = factory.inflate(layoutXML, null); diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerCallback.java b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerCallback.java index 527e391..5dd684e 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerCallback.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerCallback.java @@ -14,10 +14,12 @@ public abstract class PiracyCheckerCallback { * Called if the app is not valid or the user is using an unlicensed version. Check errors at * {@link PiracyCheckerError}. * - * @param error PiracyCheckerError.NOT_LICENSED, PiracyCheckerError.SIGNATURE_NOT_VALID or - * PiracyCheckerError.INVALID_INSTALLER_ID - * @param app The {@link PirateApp} that has been detected on device. Returns null in no app - * was found. + * @param error + * PiracyCheckerError.NOT_LICENSED, PiracyCheckerError.SIGNATURE_NOT_VALID or + * PiracyCheckerError.INVALID_INSTALLER_ID + * @param app + * The {@link PirateApp} that has been detected on device. Returns null in no app was + * found. */ public abstract void dontAllow(@NonNull PiracyCheckerError error, @Nullable PirateApp app); @@ -26,10 +28,11 @@ public abstract class PiracyCheckerCallback { * Called if an error with the license check occurs. Check errors at {@link * PiracyCheckerError}. * - * @param error PiracyCheckerError.INVALID_PACKAGE_NAME, PiracyCheckerError.NON_MATCHING_UID, - * PiracyCheckerError.NOT_MARKET_MANAGED, PiracyCheckerError.CHECK_IN_PROGRESS, - * PiracyCheckerError.INVALID_PUBLIC_KEY, PiracyCheckerError.MISSING_PERMISSION or - * PiracyCheckerError.UNKNOWN + * @param error + * PiracyCheckerError.INVALID_PACKAGE_NAME, PiracyCheckerError.NON_MATCHING_UID, + * PiracyCheckerError.NOT_MARKET_MANAGED, PiracyCheckerError.CHECK_IN_PROGRESS, + * PiracyCheckerError.INVALID_PUBLIC_KEY, PiracyCheckerError.MISSING_PERMISSION or + * PiracyCheckerError.UNKNOWN */ public void onError(@NonNull PiracyCheckerError error) { } diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerError.java b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerError.java index e87e973..5f77d10 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerError.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PiracyCheckerError.java @@ -7,7 +7,9 @@ public enum PiracyCheckerError { USING_DEBUG_APP("This is a debug build."), USING_APP_IN_EMULATOR("This app is being used in an emulator."), PIRATE_APP_INSTALLED("At least one pirate app has been detected on device."), - BLOCK_PIRATE_APP("At least one pirate app has been detected and the app must be reinstalled when all unauthorized apps are uninstalled.."), + BLOCK_PIRATE_APP( + "At least one pirate app has been detected and the app must be reinstalled when all " + + "unauthorized apps are uninstalled.."), THIRD_PARTY_STORE_INSTALLED("At least one third-party store has been detected on device."), // Other errors @@ -17,7 +19,7 @@ public enum PiracyCheckerError { CHECK_IN_PROGRESS("License check is in progress."), INVALID_PUBLIC_KEY("Application public key is invalid."), MISSING_PERMISSION("Application misses the \'com.android.vending.CHECK_LICENSE\' " + - "permission."), + "permission."), UNKNOWN("Unknown error."); private final String text; diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PirateApp.java b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PirateApp.java index b917448..0e63229 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/enums/PirateApp.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/enums/PirateApp.java @@ -9,10 +9,6 @@ public PirateApp(String name, String[] pack) { this.pack = pack; } - public void setPack(String[] pack) { - this.pack = pack; - } - public String getName() { return name; } @@ -21,6 +17,10 @@ public String[] getPack() { return pack; } + public void setPack(String[] pack) { + this.pack = pack; + } + public boolean isUnauthorized() { return (name.equalsIgnoreCase("Lucky Patcher") || name.equalsIgnoreCase("Freedom") || name.equalsIgnoreCase("Uret Patcher") || name.equalsIgnoreCase("CreeHack")); From 4ac925d060a2540e816bf478c723c11572272b76 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:30:48 -0500 Subject: [PATCH 03/11] Enable disabling folders check. Should fix #30 --- .../piracychecker/LibraryUtils.java | 28 ++++++++++++------- .../piracychecker/PiracyChecker.java | 8 +++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java index 5069be1..40d114b 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java @@ -85,7 +85,7 @@ static boolean verifyInstallerId(Context context, List installerID) } @SuppressLint("SdCardPath") - static PirateApp getPirateApp(Context context, boolean lpf, boolean stores) { + static PirateApp getPirateApp(Context context, boolean lpf, boolean stores, boolean folders) { if (!lpf && !stores) return null; for (PirateApp app : getApps()) { if ((lpf && app.isUnauthorized()) || (stores && !app.isUnauthorized())) { @@ -111,15 +111,22 @@ static PirateApp getPirateApp(Context context, boolean lpf, boolean stores) { File file2 = new File("/data/app/" + pack + "-2/base.apk"); File file3 = new File("/data/app/" + pack + ".apk"); File file4 = new File("/data/data/" + pack + ".apk"); - File file5 = new File("/data/data/" + pack); - File file6 = new File(context.getFilesDir().getPath() + pack + - ".apk"); - File file7 = new File(context.getFilesDir().getPath() + pack); - File file8 = new File(Environment.getExternalStorageDirectory() + - "/Android/data/" + pack); + File file5 = + new File(context.getFilesDir().getPath() + pack + ".apk"); + + boolean foldersExist = false; + if (folders) { + File file6 = new File("/data/data/" + pack); + File file7 = new File(context.getFilesDir().getPath() + pack); + File file8 = + new File(Environment.getExternalStorageDirectory() + + "/Android/data/" + pack); + foldersExist = + file6.exists() || file7.exists() || file8.exists(); + } + if (file1.exists() || file2.exists() || file3.exists() || - file4.exists() || file5.exists() || file6.exists() || - file7.exists() || file8.exists()) { + file4.exists() || file5.exists() || foldersExist) { return app; } } @@ -339,7 +346,8 @@ private static boolean hasPermissions(Context context) { return Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN || !shouldAskPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) || (!(ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, - Manifest.permission.READ_EXTERNAL_STORAGE))); + Manifest.permission + .READ_EXTERNAL_STORAGE))); } catch (Exception e) { return false; } diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java index 561120f..536b50c 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java @@ -52,6 +52,7 @@ public class PiracyChecker { protected boolean enableEmulatorCheck; protected boolean enableDeepEmulatorCheck; protected boolean enableDebugCheck; + protected boolean enableFoldersCheck; protected boolean saveToSharedPreferences; protected boolean blockUnauthorized; protected SharedPreferences preferences; @@ -158,6 +159,11 @@ public PiracyChecker enableEmulatorCheck(boolean deepCheck) { return this; } + public PiracyChecker enableFoldersCheck(boolean foldersCheck) { + this.enableFoldersCheck = foldersCheck; + return this; + } + public PiracyChecker saveResultToSharedPreferences(SharedPreferences preferences, @NonNull String preferenceName) { this.saveToSharedPreferences = true; @@ -360,7 +366,7 @@ private boolean verifyUnauthorizedApp() { private void doExtraVerification(PiracyCheckerCallback verifyCallback, boolean possibleSuccess) { PirateApp app = LibraryUtils.getPirateApp(context, enableUnauthorizedAppsCheck, - enableStoresCheck); + enableStoresCheck, enableFoldersCheck); if (possibleSuccess) { if (enableDebugCheck && LibraryUtils.isDebug(context)) { if (preferences != null && saveToSharedPreferences) From d374d1706d71ecb289e3c86edc4375bf01d1d306 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:41:07 -0500 Subject: [PATCH 04/11] Minor improvements --- .../javiersantos/piracychecker/LibraryUtils.java | 12 +++++++++++- .../javiersantos/piracychecker/PiracyChecker.java | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java index 40d114b..986f5c7 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/LibraryUtils.java @@ -107,6 +107,15 @@ static PirateApp getPirateApp(Context context, boolean lpf, boolean stores, bool } catch (Exception ignored2) { try { if (hasPermissions(context)) { + File appsContainer = new File("/data/app/"); + boolean containsFolder = false; + if (appsContainer.exists()) { + for (File f : appsContainer.listFiles()) { + if (f.getName().startsWith(pack)) + containsFolder = true; + } + } + File file1 = new File("/data/app/" + pack + "-1/base.apk"); File file2 = new File("/data/app/" + pack + "-2/base.apk"); File file3 = new File("/data/app/" + pack + ".apk"); @@ -125,7 +134,8 @@ static PirateApp getPirateApp(Context context, boolean lpf, boolean stores, bool file6.exists() || file7.exists() || file8.exists(); } - if (file1.exists() || file2.exists() || file3.exists() || + if (containsFolder || + file1.exists() || file2.exists() || file3.exists() || file4.exists() || file5.exists() || foldersExist) { return app; } diff --git a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java index 536b50c..c78574c 100644 --- a/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java +++ b/library/src/main/java/com/github/javiersantos/piracychecker/PiracyChecker.java @@ -283,6 +283,7 @@ else if (error.equals(PiracyCheckerError.BLOCK_PIRATE_APP)) if (context instanceof Activity) { ((Activity) context).finish(); } + destroy(); } } }; From c3b51b2ccc61fd5ba1b84900d8b9d2fac83a4ac3 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:51:03 -0500 Subject: [PATCH 05/11] Minor improvement to proguard rules --- library/build.gradle | 3 ++- library/proguard-rules.pro | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/build.gradle b/library/build.gradle index d5dc8dd..fe38c22 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,16 +5,17 @@ android { buildToolsVersion "27.0.3" defaultConfig { - consumerProguardFiles 'proguard-rules.pro' minSdkVersion 14 targetSdkVersion 27 versionCode 12 versionName "1.2" + consumerProguardFiles 'proguard-rules.pro' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + consumerProguardFiles 'proguard-rules.pro' } } } diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro index cac4167..4e94870 100644 --- a/library/proguard-rules.pro +++ b/library/proguard-rules.pro @@ -19,5 +19,14 @@ # Lib -keep class com.github.javiersantos.** -dontwarn com.github.javiersantos.** + # LVL --keep public class com.android.vending.licensing.ILicensingService \ No newline at end of file +-keep class com.google.** +-keep class autovalue.shaded.com.google.** +-keep class com.android.vending.billing.** +-keep public class com.android.vending.licensing.ILicensingService + +-dontwarn org.apache.** +-dontwarn com.google.** +-dontwarn autovalue.shaded.com.google.** +-dontwarn com.android.vending.billing.** \ No newline at end of file From 679e981d68514bbe7b016b0fd27af24a6cbfc266 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:56:53 -0500 Subject: [PATCH 06/11] Update README --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a89b0a..a961ebf 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ And add the library to your module **build.gradle**: ```Gradle dependencies { - compile 'com.github.javiersantos:PiracyChecker:1.1' + implementation 'com.github.javiersantos:PiracyChecker:1.1' } ``` @@ -144,6 +144,17 @@ new PiracyChecker(this) .start(); ``` +### Enable deep pirate and third-party store apps check +If you want to check if these kind of apps left some files that could make your app work as pirated still, you can enable its check as follows: +```Java +new PiracyChecker(this) + .enableFoldersCheck() + ... + .start(); +``` + +**BE CAREFUL!** This means, that some times, the app will be recognized as pirated even after those apps were uninstalled. + ### Verify if app is a debug build If your app is running on an emulator outside the development process, it gives an indication that someone other than you is trying to analyze the app. From a372ac4483bf5750daac6fe18bde1df9a33f7b3e Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:57:55 -0500 Subject: [PATCH 07/11] Update .travis.yml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93ec667..898bc9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ jdk: oraclejdk8 android: components: - - build-tools-25.0.3 - - android-25 + - build-tools-27.0.3 + - android-26 - extra-android-support - extra-google-m2repository - extra-android-m2repository @@ -16,8 +16,8 @@ before_install: before_script: - echo yes | android update sdk --no-ui --all --filter platform-tools,tools - - echo yes | android update sdk --no-ui --all --filter build-tools-25.0.3 - - echo yes | android update sdk --no-ui --all --filter android-25 + - echo yes | android update sdk --no-ui --all --filter build-tools-27.0.3 + - echo yes | android update sdk --no-ui --all --filter android-26 script: - ./gradlew clean test From 628e10dc477e04a53093033ef9fcae96940441d0 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 15:59:24 -0500 Subject: [PATCH 08/11] Update .travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 898bc9b..42794ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ jdk: oraclejdk8 android: components: - build-tools-27.0.3 - - android-26 + - android-27 - extra-android-support - extra-google-m2repository - extra-android-m2repository @@ -17,7 +17,7 @@ before_install: before_script: - echo yes | android update sdk --no-ui --all --filter platform-tools,tools - echo yes | android update sdk --no-ui --all --filter build-tools-27.0.3 - - echo yes | android update sdk --no-ui --all --filter android-26 + - echo yes | android update sdk --no-ui --all --filter android-27 script: - ./gradlew clean test From 1363c9404b74a134f8675a079a185e104b32d3fb Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 16:00:36 -0500 Subject: [PATCH 09/11] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a961ebf..b7da63b 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ And add the library to your module **build.gradle**: ```Gradle dependencies { - implementation 'com.github.javiersantos:PiracyChecker:1.1' + implementation 'com.github.javiersantos:PiracyChecker:1.2' } ``` From d1c95f7ab8daabfae4187752137d2e0523ee62ac Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 16:11:10 -0500 Subject: [PATCH 10/11] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7da63b..e3fd12a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

    Android Library

    - + @@ -277,7 +277,7 @@ new PiracyChecker(this) ``` ## License - Copyright 2017 Javier Santos + Copyright 2018 Javier Santos Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From 47a79eb7248e91b64923fc47f6ba2d00bceee203 Mon Sep 17 00:00:00 2001 From: jahirfiquitiva Date: Mon, 8 Jan 2018 18:47:38 -0500 Subject: [PATCH 11/11] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e3fd12a..8cf6a8c 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,12 @@ new PiracyChecker(this) If you want to check if these kind of apps left some files that could make your app work as pirated still, you can enable its check as follows: ```Java new PiracyChecker(this) - .enableFoldersCheck() + .enableFoldersCheck(true) ... .start(); ``` -**BE CAREFUL!** This means, that some times, the app will be recognized as pirated even after those apps were uninstalled. +**BE CAREFUL!** This means, that some times, the app will be recognized as pirated even after those pirate and third-party store apps were uninstalled. Set it to false if you don't like this behaviour/approach. ### Verify if app is a debug build If your app is running on an emulator outside the development process, it gives an indication that someone other than you is trying to analyze the app.