Skip to content

Commit

Permalink
Check preference from within Licensing service
Browse files Browse the repository at this point in the history
  • Loading branch information
fynngodau committed Dec 19, 2023
1 parent 1873285 commit ac42c13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vending-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.android.volley.toolbox.Volley;

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

import java.util.Arrays;
import java.util.LinkedList;
Expand All @@ -37,14 +38,48 @@ public class LicensingService extends Service {

private static final String KEY_V2_RESULT_JWT = "LICENSE_DATA";

private static final Uri PROFILE_PROVIDER = Uri.parse("content://com.google.android.gms.microg.profile");
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 String androidId;

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();

Expand Down Expand Up @@ -74,6 +109,11 @@ private void checkLicense(long nonce, String packageName, PackageManager package
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();

Expand Down

0 comments on commit ac42c13

Please sign in to comment.