Example usage for android.content.pm PackageManager SIGNATURE_MATCH

List of usage examples for android.content.pm PackageManager SIGNATURE_MATCH

Introduction

In this page you can find the example usage for android.content.pm PackageManager SIGNATURE_MATCH.

Prototype

int SIGNATURE_MATCH

To view the source code for android.content.pm PackageManager SIGNATURE_MATCH.

Click Source Link

Document

Signature check result: this is returned by #checkSignatures if all signatures on the two packages match.

Usage

From source file:Main.java

public static boolean doesPackageHaveSameSignature(Context context, String productPackage) {
    int compareSignatures = context.getPackageManager().checkSignatures(context.getPackageName(),
            productPackage);//from ww  w .j av a2 s  .  co  m
    return PackageManager.SIGNATURE_MATCH == compareSignatures;
}

From source file:Main.java

public static boolean elitePresent(Context context, boolean versionCheck, int minVersion) {
    PackageManager pm = context.getPackageManager();
    int sigs = pm.checkSignatures("com.noshufou.android.su", "com.noshufou.android.su.elite");
    if (sigs != PackageManager.SIGNATURE_MATCH) {
        return false;
    } else {//from   w  w w .  j a  v  a 2  s .co m
        if (versionCheck) {
            PackageInfo pi;
            try {
                pi = pm.getPackageInfo("com.noshufou.android.su.elite", 0);
                if (pi.versionCode >= minVersion) {
                    return true;
                } else {
                    return false;
                }
            } catch (NameNotFoundException e) {
                return false;
            }
        } else {
            return true;
        }
    }
}

From source file:Main.java

public static boolean canBeStarted(Context context, Intent intent, boolean checkSignature) {
    final PackageManager manager = context.getApplicationContext().getPackageManager();
    final ResolveInfo info = manager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (info == null) {
        return false;
    }// ww w .  j  av  a2  s . c  om
    final ActivityInfo activityInfo = info.activityInfo;
    if (activityInfo == null) {
        return false;
    }
    if (!checkSignature) {
        return true;
    }
    return PackageManager.SIGNATURE_MATCH == manager.checkSignatures(context.getPackageName(),
            activityInfo.packageName);
}

From source file:org.mariotaku.twidere.util.PermissionsManager.java

public boolean checkSignature(final String pname) {
    if (mContext.getPackageName().equals(pname))
        return true;
    if (BuildConfig.DEBUG)
        return false;
    return mPackageManager.checkSignatures(pname, mContext.getPackageName()) == PackageManager.SIGNATURE_MATCH;
}

From source file:com.farmerbb.taskbar.MainActivity.java

private boolean freeVersionInstalled() {
    PackageManager pm = getPackageManager();
    try {/*from w w  w . j  av a 2  s  . c  om*/
        PackageInfo pInfo = pm.getPackageInfo(BuildConfig.BASE_APPLICATION_ID, 0);
        return pInfo.versionCode >= 68 && pm.checkSignatures(BuildConfig.BASE_APPLICATION_ID,
                BuildConfig.APPLICATION_ID) == PackageManager.SIGNATURE_MATCH;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:org.failedprojects.anjaroot.PackagesFragment.java

private boolean isDonateAppPresent() {
    int sigmatch = pm.checkSignatures("org.failedprojects.anjaroot", "org.failedprojects.anjaroot.donate");
    if (sigmatch != PackageManager.SIGNATURE_MATCH) {
        return false;
    }//from w  w w  .ja  va2 s  . c o m

    return true;
}

From source file:de.ub0r.android.lib.DonationHelper.java

/**
 * Check if ads should be hidden./* w  w w  . ja  v  a 2s.c o m*/
 * 
 * @param context
 *            {@link Context}
 * @return true if ads should be hidden
 */
public static boolean hideAds(final Context context) {
    PackageManager pm = context.getPackageManager();
    Intent donationCheck = new Intent(DONATOR_BROADCAST_CHECK);
    ResolveInfo ri = pm.resolveService(donationCheck, 0);
    // Log.d(TAG, "ri: " + ri);
    int match = PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
    if (ri != null) {
        Log.d(TAG, "found package: " + ri.serviceInfo.packageName);
        ComponentName cn = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name);
        // Log.d(TAG, "component name: " + cn);
        int i = pm.getComponentEnabledSetting(cn);
        // Log.d(TAG, "component status: " + i);
        // Log.d(TAG, "package status: " + ri.serviceInfo.enabled);
        if (i == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                || i == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && ri.serviceInfo.enabled) {
            match = pm.checkSignatures(context.getPackageName(), ri.serviceInfo.packageName);
        } else {
            Log.w(TAG, ri.serviceInfo.packageName + ": " + ri.serviceInfo.enabled);
        }
    }

    Log.i(TAG, "signature match: " + match);
    if (match != PackageManager.SIGNATURE_UNKNOWN_PACKAGE) {
        if (Math.random() < CHECK_DONATOR_LIC) {
            // verify donator license
            ComponentName cn = context.startService(donationCheck);
            Log.d(TAG, "Started service: " + cn);
            if (cn == null) {
                return false;
            }
        }
        return match == PackageManager.SIGNATURE_MATCH;
    }
    pm = null;

    // no donator app installed, check donation traditionally
    // do not drop legacy donators
    boolean ret = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(PREFS_HIDEADS, false);
    Log.d(TAG, "legacy donation check: " + ret);
    return ret;
}

From source file:biz.bokhorst.xprivacy.Util.java

private static boolean hasValidProEnablerSignature(Context context) {
    return (context.getPackageManager().checkSignatures(context.getPackageName(),
            context.getPackageName() + ".pro") == PackageManager.SIGNATURE_MATCH);
}

From source file:org.destil.gpsaveraging.MainActivity.java

/**
 * Verifies if user has bought full version.
 *///from   w w w .  j av  a  2  s  .c o m
private boolean verifyFullVersion() {
    if (BillingController.isPurchased(this, BILLING_ITEMID)) {
        return true;
    } else {
        // check for previous ad-free version
        if (getPackageManager().checkSignatures("org.destil.gpsaveraging",
                "cz.destil.gpsaveraging") == PackageManager.SIGNATURE_MATCH) {
            return true;
        }
        return false;
    }
}