aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java')
-rw-r--r--app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java b/app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java
new file mode 100644
index 0000000..14e27f4
--- /dev/null
+++ b/app/src/main/java/moe/yuuta/gplicense/ipc/ILicensingService.java
@@ -0,0 +1,101 @@
+package moe.yuuta.gplicense.ipc;
+
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.IInterface;
+import android.os.Parcel;
+import android.os.RemoteException;
+
+import androidx.annotation.NonNull;
+
+import moe.yuuta.gplicense.util.Base64;
+import moe.yuuta.gplicense.util.Base64DecoderException;
+
+public interface ILicensingService extends IInterface {
+ abstract class Stub extends Binder implements ILicensingService {
+ private static final String DESCRIPTOR;
+
+ static {
+ try {
+ // Base64 encoded -
+ // com.android.vending.licensing.ILicensingService
+ DESCRIPTOR = new String(Base64.decode(
+ "Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U="));
+ } catch (Base64DecoderException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Stub() {
+ this.attachInterface(this, DESCRIPTOR);
+ }
+
+ public static ILicensingService asInterface(IBinder obj) {
+ if ((obj == null)) {
+ return null;
+ }
+ IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
+ if (iin instanceof ILicensingService) {
+ return (ILicensingService) iin;
+ }
+ return new ILicensingService.Stub.Proxy(obj);
+ }
+
+ @Override
+ public IBinder asBinder() {
+ return this;
+ }
+
+ @Override
+ public boolean onTransact(int code, @NonNull Parcel data, Parcel reply, int flags) throws RemoteException {
+ switch (code) {
+ case INTERFACE_TRANSACTION: {
+ reply.writeString(DESCRIPTOR);
+ return true;
+ }
+ case TRANSACTION_checkLicense: {
+ data.enforceInterface(DESCRIPTOR);
+ long nonce = data.readLong();
+ String packageName = data.readString();
+ ILicenseResultListener listener = ILicenseResultListener.Stub.asInterface(data.readStrongBinder());
+ this.checkLicense(nonce, packageName, listener);
+ return true;
+ }
+ default: {
+ return super.onTransact(code, data, reply, flags);
+ }
+ }
+ }
+
+ private static class Proxy implements ILicensingService {
+ private IBinder mRemote;
+
+ Proxy(IBinder remote) {
+ mRemote = remote;
+ }
+
+ @Override
+ public IBinder asBinder() {
+ return mRemote;
+ }
+
+ @Override
+ public void checkLicense(long nonce, String packageName, ILicenseResultListener listener) throws RemoteException {
+ Parcel args = Parcel.obtain();
+ try {
+ args.writeInterfaceToken(DESCRIPTOR);
+ args.writeLong(nonce);
+ args.writeString(packageName);
+ args.writeStrongBinder(listener != null ? listener.asBinder() : null);
+ mRemote.transact(TRANSACTION_checkLicense, args, null, IBinder.FLAG_ONEWAY);
+ } finally {
+ args.recycle();
+ }
+ }
+ }
+
+ static final int TRANSACTION_checkLicense = IBinder.FIRST_CALL_TRANSACTION;
+ }
+
+ void checkLicense(long nonce, String packageName, ILicenseResultListener listener) throws RemoteException;
+} \ No newline at end of file