Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ed3a954 authored by Fynn Godau's avatar Fynn Godau Committed by Jonathan Klee
Browse files

Check preference from within Licensing service

parent fe2a6133
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <uses-permission android:name="org.microg.gms.permission.READ_SETTINGS" />

    <uses-permission
        android:name="android.permission.USE_CREDENTIALS"
        android:maxSdkVersion="22" />
+37 −2
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

import org.microg.gms.auth.AuthConstants;
import org.microg.gms.profile.Build;
import org.microg.gms.profile.ProfileManager;

import java.util.Arrays;
@@ -48,14 +47,45 @@ public class LicensingService extends Service {
    
    private String androidId;

    private static final Uri SETTINGS_PROVIDER = Uri.parse("content://com.google.android.gms.microg.settings/play");

    private static final String PREFERENCE_LICENSING_ENABLED = "play_licensing";

    private final ILicensingService.Stub mLicenseService = new ILicensingService.Stub() {

        private boolean shouldCheckLicense() {

            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(
                    SETTINGS_PROVIDER, new String[]{PREFERENCE_LICENSING_ENABLED}, null, null, null
                );

                if (cursor == null || cursor.getColumnCount() != 1) {
                    Log.e(TAG, "settings provider not available");
                    return false;
                } else {
                    cursor.moveToNext();
                    return cursor.getInt(0) != 0;
                }

            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }


        @Override
        public void checkLicense(long nonce, String packageName, ILicenseResultListener listener) throws RemoteException {
            Log.v(TAG, "checkLicense(" + nonce + ", " + packageName + ")");

            if (!shouldCheckLicense()) {
                Log.d(TAG, "not checking license, as it is disabled by user");
                return;
            }

            Account[] accounts = accountManager.getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE);
            PackageManager packageManager = getPackageManager();

@@ -85,6 +115,11 @@ public class LicensingService extends Service {
        public void checkLicenseV2(String packageName, ILicenseV2ResultListener listener, Bundle extraParams) throws RemoteException {
            Log.v(TAG, "checkLicenseV2(" + packageName + ", " + extraParams + ")");

            if (!shouldCheckLicense()) {
                Log.d(TAG, "not checking license, as it is disabled by user");
                return;
            }

            Account[] accounts = accountManager.getAccountsByType(AuthConstants.DEFAULT_ACCOUNT_TYPE);
            PackageManager packageManager = getPackageManager();