aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java')
-rw-r--r--app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java b/app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java
index 92986b8..7d4cfa8 100644
--- a/app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java
+++ b/app/src/main/java/moe/yuuta/gplicense/LicenseChecker.java
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.ServiceConnection;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Handler;
import android.os.HandlerThread;
@@ -27,8 +26,11 @@ import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
-import moe.yuuta.gplicense.ipc.ILicenseResultListener;
-import moe.yuuta.gplicense.ipc.ILicensingService;
+import moe.yuuta.ext.ConnCallback;
+import moe.yuuta.ext.IPCResultListener;
+import moe.yuuta.ext.IService;
+import moe.yuuta.ext.LicServiceConn;
+import moe.yuuta.ext.ResultCallback;
import moe.yuuta.gplicense.util.Base64;
import moe.yuuta.gplicense.util.Base64DecoderException;
import moe.yuuta.workmode.BuildConfig;
@@ -44,7 +46,7 @@ import moe.yuuta.workmode.BuildConfig;
* Must also provide the Base64-encoded RSA public key associated with your developer account. The
* public key is obtainable from the publisher site.
*/
-public class LicenseChecker implements ServiceConnection {
+public class LicenseChecker implements ConnCallback {
private static final Logger logger = XLog.tag("LCK").build();
private static final String KEY_FACTORY_ALGORITHM = "RSA";
@@ -55,7 +57,7 @@ public class LicenseChecker implements ServiceConnection {
private static final SecureRandom RANDOM = new SecureRandom();
private static final boolean DEBUG_LICENSE_ERROR = BuildConfig.DEBUG;
- private ILicensingService mService;
+ private IService mService;
private PublicKey mPublicKey;
private final Context mContext;
@@ -70,6 +72,8 @@ public class LicenseChecker implements ServiceConnection {
private final Set<LicenseValidator> mChecksInProgress = new HashSet<LicenseValidator>();
private final Queue<LicenseValidator> mPendingChecks = new LinkedList<LicenseValidator>();
+ private LicServiceConn mConn;
+
/**
* @param context a Context
* @param policy implementation of Policy
@@ -118,7 +122,7 @@ public class LicenseChecker implements ServiceConnection {
* recommend obfuscating the string that is passed into bindService using another method of your
* own devising.
* <p>
- * source string: "com.android.vending.licensing.ILicensingService"
+ * source string: "com.android.vending.licensing.IService"
* <p>
*
* @param callback
@@ -127,7 +131,7 @@ public class LicenseChecker implements ServiceConnection {
// If we have a valid recent LICENSED response, we can skip asking
// Market.
if (mPolicy.allowAccess()) {
- logger.i("Using cached license response");
+ logger.i("Using cached response");
callback.allow(Policy.LICENSED);
} else {
LicenseValidator validator = new LicenseValidator(mPolicy, new NullDeviceLimiter(),
@@ -136,12 +140,13 @@ public class LicenseChecker implements ServiceConnection {
if (mService == null) {
logger.i("Binding to service.");
try {
+ mConn = new LicServiceConn(this);
boolean bindResult = mContext
.bindService(
new Intent(
new String(
// Base64 encoded -
- // com.android.vending.licensing.ILicensingService
+ // com.android.vending.licensing.IService
// Consider encoding this in another way in your
// code to improve security
Base64.decode(
@@ -163,7 +168,7 @@ public class LicenseChecker implements ServiceConnection {
// com.android.vending
Base64.decode(
"Y29tLmFuZHJvaWQudmVuZGluZw=="))),
- this, // ServiceConnection.
+ mConn, // ServiceConnection.
Context.BIND_AUTO_CREATE);
if (bindResult) {
mPendingChecks.offer(validator);
@@ -188,12 +193,12 @@ public class LicenseChecker implements ServiceConnection {
while ((validator = mPendingChecks.poll()) != null) {
try {
logger.i("Executing on service for " + validator.getPackageName());
- mService.checkLicense(
+ mService.exec(
validator.getNonce(), validator.getPackageName(),
- new ResultListener(validator));
+ new IPCResultListener(new ResultListener(validator)));
mChecksInProgress.add(validator);
} catch (RemoteException e) {
- logger.w("RemoteException in checkLicense call.", e);
+ logger.w("RemoteException in exec call.", e);
handleServiceConnectionError(validator);
}
}
@@ -206,7 +211,7 @@ public class LicenseChecker implements ServiceConnection {
}
}
- private class ResultListener extends ILicenseResultListener.Stub {
+ private class ResultListener implements ResultCallback {
private final LicenseValidator mValidator;
private Runnable mOnTimeout;
@@ -226,6 +231,7 @@ public class LicenseChecker implements ServiceConnection {
// Runs in IPC thread pool. Post it to the Handler, so we can guarantee
// either this or the timeout runs.
+ @Override
public void verifyLicense(final int responseCode, final String signedData,
final String signature) {
mHandler.post(() -> {
@@ -280,11 +286,13 @@ public class LicenseChecker implements ServiceConnection {
}
}
+ @Override
public synchronized void onServiceConnected(ComponentName name, IBinder service) {
- mService = ILicensingService.Stub.asInterface(service);
+ mService = IService.Stub.asInterface(service);
runChecks();
}
+ @Override
public synchronized void onServiceDisconnected(ComponentName name) {
// Called when the connection with the service has been
// unexpectedly disconnected. That is, Market crashed.
@@ -311,7 +319,7 @@ public class LicenseChecker implements ServiceConnection {
private void cleanupService() {
if (mService != null) {
try {
- mContext.unbindService(this);
+ mContext.unbindService(mConn);
} catch (IllegalArgumentException e) {
// Somehow we've already been unbound. This is a non-fatal
// error.