Skip to content

Commit

Permalink
Allow multiple installers and add amazon app store
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed May 28, 2016
1 parent 3ce0ed5 commit 3345f04
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@
import com.google.android.vending.licensing.LicenseCheckerCallback;
import com.google.android.vending.licensing.ServerManagedPolicy;

import java.util.ArrayList;
import java.util.List;

public class PiracyChecker {
private Context context;
private String unlicensedDialogTitle, unlicensedDialogDescription;
private boolean enableLVL, enableSigningCertificate, enableInstallerId;
private String licenseBase64;
private String signature;
private InstallerID installerID;
private List<InstallerID> installerIDs;
private PiracyCheckerCallback callback;

public PiracyChecker(Context context) {
this.context = context;
this.unlicensedDialogTitle = context.getString(R.string.app_unlicensed);
this.unlicensedDialogDescription = context.getString(R.string.app_unlicensed_description);
this.installerIDs = new ArrayList<>();
}

public PiracyChecker(Context context, String title, String description) {
this.context = context;
this.unlicensedDialogTitle = title;
this.unlicensedDialogDescription = description;
this.installerIDs = new ArrayList<>();
}

public PiracyChecker(Context context, @StringRes int title, @StringRes int description) {
Expand All @@ -51,7 +56,7 @@ public PiracyChecker enableSigningCertificate(String signature) {

public PiracyChecker enableInstallerId(InstallerID installerID) {
this.enableInstallerId = true;
this.installerID = installerID;
this.installerIDs.add(installerID);
return this;
}

Expand Down Expand Up @@ -123,7 +128,7 @@ private boolean verifyInstallerId() {
boolean installerIdValid = false;

if (enableInstallerId) {
if (UtilsLibrary.verifyInstallerId(context, installerID)) {
if (UtilsLibrary.verifyInstallerId(context, installerIDs)) {
installerIdValid = true;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

class UtilsLibrary {
static final byte[] SALT = new byte[] {
Expand Down Expand Up @@ -56,10 +58,15 @@ static boolean verifySigningCertificate(Context context, String appSignature) {
return getCurrentSignature(context).equals(appSignature);
}

static boolean verifyInstallerId(Context context, InstallerID installerID) {
static boolean verifyInstallerId(Context context, List<InstallerID> installerID) {
List<String> validInstallers = new ArrayList<>();
final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

return installer != null && installer.startsWith(installerID.toString());
for (InstallerID id : installerID) {
validInstallers.addAll(id.toIDs());
}

return installer != null && validInstallers.contains(installer);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.github.javiersantos.piracychecker.enums;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public enum InstallerID {
GOOGLE_PLAY("com.android.vending");
GOOGLE_PLAY("com.android.vending|com.google.android.feedback"),
AMAZON_APP_STORE("com.amazon.venezia");

private final String text;

Expand All @@ -17,4 +23,13 @@ public String toString() {
return text;
}

public List<String> toIDs() {
if (text.contains("|")) {
String[] split = text.split("\\|");
return new ArrayList<>(Arrays.asList(split));
} else {
return new ArrayList<>(Collections.singletonList(text));
}
}

}

0 comments on commit 3345f04

Please sign in to comment.