Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:4.1.2'
}
}

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Project-wide Gradle settings.
android.useAndroidX=true

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
4 changes: 2 additions & 2 deletions lvl_library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
compileSdkVersion 30

defaultConfig {
minSdkVersion 4
targetSdkVersion 23
targetSdkVersion 30
}

buildTypes {
Expand Down
2 changes: 0 additions & 2 deletions lvl_library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package="com.google.android.vending.licensing"
android:versionCode="2"
android:versionName="1.5">
<!-- Devices >= 3 have version of Android Market that supports licensing. -->
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="23" />
<!-- Required permission to check licensing. -->
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package com.android.vending.licensing;

oneway interface ILicenseResultListener {
interface ILicenseResultListener {
void verifyLicense(int responseCode, String signedData, String signature);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package com.android.vending.licensing;

import com.android.vending.licensing.ILicenseResultListener;

oneway interface ILicensingService {
interface ILicensingService {
void checkLicense(long nonce, String packageName, in ILicenseResultListener listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.android.vending.licensing;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
Expand Down Expand Up @@ -71,18 +72,18 @@ public class LicenseChecker implements ServiceConnection {

private ILicensingService mService;

private PublicKey mPublicKey;
private final PublicKey mPublicKey;
private final Context mContext;
private final Policy mPolicy;
/**
* A handler for running tasks on a background thread. We don't want license processing to block
* the UI thread.
*/
private Handler mHandler;
private final Handler mHandler;
private final String mPackageName;
private final String mVersionCode;
private final Set<LicenseValidator> mChecksInProgress = new HashSet<LicenseValidator>();
private final Queue<LicenseValidator> mPendingChecks = new LinkedList<LicenseValidator>();
private final Set<LicenseValidator> mChecksInProgress = new HashSet<>();
private final Queue<LicenseValidator> mPendingChecks = new LinkedList<>();

/**
* @param context a Context
Expand Down Expand Up @@ -111,7 +112,6 @@ private static PublicKey generatePublicKey(String encodedPublicKey) {
try {
byte[] decodedKey = Base64.decode(encodedPublicKey);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);

return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
} catch (NoSuchAlgorithmException e) {
// This won't happen in an Android-compatible environment.
Expand All @@ -135,7 +135,7 @@ private static PublicKey generatePublicKey(String encodedPublicKey) {
* source string: "com.android.vending.licensing.ILicensingService"
* <p>
*
* @param callback
* @param callback listener
*/
public synchronized void checkAccess(LicenseCheckerCallback callback) {
// If we have a valid recent LICENSED response, we can skip asking
Expand Down Expand Up @@ -240,7 +240,7 @@ private synchronized void finishCheck(LicenseValidator validator) {

private class ResultListener extends ILicenseResultListener.Stub {
private final LicenseValidator mValidator;
private Runnable mOnTimeout;
private final Runnable mOnTimeout;

public ResultListener(LicenseValidator validator) {
mValidator = validator;
Expand Down Expand Up @@ -292,6 +292,7 @@ public void run() {
}

if (logResponse) {
@SuppressLint("HardwareIds")
String android_id = Secure.getString(mContext.getContentResolver(),
Secure.ANDROID_ID);
Date date = new Date();
Expand Down Expand Up @@ -378,7 +379,7 @@ private int generateNonce() {
/**
* Get version code for the application package name.
*
* @param context
* @param context the current context
* @param packageName application package name
* @return the version code or empty string if package not found
*/
Expand Down
14 changes: 8 additions & 6 deletions lvl_sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
compileSdkVersion 30

defaultConfig {
applicationId "com.example.google.play.licensing"
minSdkVersion 8
targetSdkVersion 23

testApplicationId "com.example.google.play.licensing.test"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
targetSdkVersion 30
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -22,5 +20,9 @@ android {

dependencies {
implementation project(':lvl_library')
androidTestImplementation 'com.android.support.test:runner:0.5'
testImplementation "junit:junit:4.13.1"
androidTestImplementation "androidx.test:core:1.3.0"
androidTestImplementation "androidx.test:runner:1.3.0"
androidTestImplementation "androidx.test:rules:1.3.0"
androidTestImplementation "androidx.test.ext:junit:1.1.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package com.google.android.vending.licensing;

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.Obfuscator;
import com.google.android.vending.licensing.ValidationException;
import androidx.test.filters.SmallTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@

package com.google.android.vending.licensing;

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.APKExpansionPolicy;
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.ResponseData;

import android.content.Context;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@

package com.google.android.vending.licensing;

import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.Obfuscator;
import com.google.android.vending.licensing.PreferenceObfuscator;

import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
Expand All @@ -34,7 +31,6 @@

import static org.junit.Assert.assertEquals;


/**
* Test suite for PreferenceObfuscator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@

package com.google.android.vending.licensing;


import com.google.android.vending.licensing.AESObfuscator;
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.ResponseData;
import com.google.android.vending.licensing.ServerManagedPolicy;

import android.content.Context;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package com.google.android.vending.licensing;

import android.support.test.runner.AndroidJUnit4;

import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.StrictPolicy;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
5 changes: 2 additions & 3 deletions lvl_sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package="com.example.google.play.licensing"
android:versionCode="3"
android:versionName="3.0">
<!-- Required permission to check licensing. -->
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name"
Expand All @@ -27,7 +29,4 @@
</intent-filter>
</activity>
</application>
<!-- Required permission to check licensing. -->
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="23"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
import com.google.android.vending.licensing.Policy;
import com.google.android.vending.licensing.ServerManagedPolicy;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Secure;
Expand All @@ -37,8 +36,7 @@
import android.widget.TextView;

/**
* Welcome to the world of Google Play licensing. We're so glad to have you
* on board!
* Welcome to the world of Google Play licensing. We're so glad to have you on board!
* <p>
* The first thing you need to do is get your hands on your public key.
* Update the BASE64_PUBLIC_KEY constant below with the encoded public key
Expand All @@ -50,6 +48,7 @@
* licensing documentation.</a>
*/
public class MainActivity extends Activity {

private static final String BASE64_PUBLIC_KEY = "REPLACE THIS WITH YOUR PUBLIC KEY";

// Generate your own 20 random bytes, and put them here.
Expand All @@ -63,6 +62,7 @@ public class MainActivity extends Activity {

private LicenseCheckerCallback mLicenseCheckerCallback;
private LicenseChecker mChecker;

// A handler on the UI thread.
private Handler mHandler;

Expand All @@ -83,15 +83,18 @@ public void onClick(View view) {
mHandler = new Handler();

// Try to use more data here. ANDROID_ID is a single point of attack.
@SuppressLint("HardwareIds")
String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

// Library calls this when it's done.
mLicenseCheckerCallback = new MyLicenseCheckerCallback();

// Construct the LicenseChecker with a policy.
mChecker = new LicenseChecker(
this, new ServerManagedPolicy(this,
new AESObfuscator(SALT, getPackageName(), deviceId)),
BASE64_PUBLIC_KEY);

doCheck();
}

Expand All @@ -102,7 +105,7 @@ protected Dialog onCreateDialog(int id) {
.setMessage(bRetry ? R.string.unlicensed_dialog_retry_body : R.string.unlicensed_dialog_body)
.setPositiveButton(bRetry ? R.string.retry_button : R.string.restore_access_button,
new DialogInterface.OnClickListener() {
boolean mRetry = bRetry;
final boolean mRetry = bRetry;
public void onClick(DialogInterface dialog, int which) {
if ( mRetry ) {
doCheck();
Expand Down Expand Up @@ -192,5 +195,4 @@ protected void onDestroy() {
super.onDestroy();
mChecker.onDestroy();
}

}
}