Java Code Examples for android.content.pm.PackageManager#SIGNATURE_MATCH

The following examples show how to use android.content.pm.PackageManager#SIGNATURE_MATCH . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public String getStubProcessByTarget(ComponentInfo targetInfo) {
    for (ProcessItem processItem : items.values()) {
        if (processItem.pkgs.contains(targetInfo.packageName) && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
            return processItem.stubProcessName;
        } else {
            try {
                boolean signed = false;
                for (String pkg : processItem.pkgs) {
                    if (PluginManager.getInstance().checkSignatures(targetInfo.packageName, pkg) == PackageManager.SIGNATURE_MATCH) {
                        signed = true;
                        break;
                    }
                }
                if (signed && TextUtils.equals(processItem.targetProcessName, targetInfo.processName)) {
                    return processItem.stubProcessName;
                }
            } catch (Exception e) {
                Log.e(TAG, "getStubProcessByTarget:error", e);
            }
        }
    }
    return null;
}
 
Example 2
boolean isPkgCanRunInProcess(String packageName, String stubProcessName, String targetProcessName) throws RemoteException {
    for (ProcessItem item : items.values()) {
        if (TextUtils.equals(stubProcessName, item.stubProcessName)) {

            if (!TextUtils.isEmpty(item.targetProcessName) && !TextUtils.equals(item.targetProcessName, targetProcessName)) {
                continue;
            }

            if (item.pkgs.contains(packageName)) {
                return true;
            }

            boolean signed = false;
            for (String pkg : item.pkgs) {
                if (PluginManager.getInstance().checkSignatures(packageName, pkg) == PackageManager.SIGNATURE_MATCH) {
                    signed = true;
                    break;
                }
            }
            if (signed) {
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source Project: trust   File: TrustActivity.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean checkPro(Context currentContext) {
    if (currentContext == null)
        return false;
    Context newProContext;
    try {
        newProContext = currentContext.createPackageContext("eu.thedarken.trust.pro", 0);
    } catch (NameNotFoundException e) {
        return false;
    }
    if (newProContext != null) {
        if (currentContext.getPackageManager().checkSignatures(currentContext.getPackageName(), newProContext.getPackageName()) == PackageManager.SIGNATURE_MATCH) {
            return true;
        }
    }
    return false;
}
 
Example 4
boolean signaturesMatch(int uid1, int uid2) {
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        return pm.checkUidSignatures(uid1, uid2) == PackageManager.SIGNATURE_MATCH;
    } catch (RemoteException ex) {
        Slog.e(TAG, "Remote exception while checking signatures", ex);
        return false;
    }
}
 
Example 5
private static void enforcePermission(Context context) throws SecurityException {
    int cuid = Util.getAppId(Binder.getCallingUid());

    // Access package manager as system user
    long ident = Binder.clearCallingIdentity();
    try {
        // Allow system
        if (cuid == Process.SYSTEM_UID)
            return;

        // Allow same signature
        PackageManager pm = context.getPackageManager();
        int uid = pm.getApplicationInfo(BuildConfig.APPLICATION_ID, 0).uid;
        if (pm.checkSignatures(cuid, uid) == PackageManager.SIGNATURE_MATCH)
            return;

        // Allow specific signature
        String[] cpkg = pm.getPackagesForUid(cuid);
        if (cpkg.length > 0) {
            byte[] bytes = Util.getSha1Fingerprint(context, cpkg[0]);
            StringBuilder sb = new StringBuilder();
            for (byte b : bytes)
                sb.append(Integer.toString(b & 0xff, 16).toLowerCase());

            Resources resources = pm.getResourcesForApplication(BuildConfig.APPLICATION_ID);
            if (sb.toString().equals(resources.getString(R.string.pro_fingerprint)))
                return;
        }
        throw new SecurityException("Signature error cuid=" + cuid);
    } catch (Throwable ex) {
        throw new SecurityException(ex);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 6
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {

	if (args.length == 2 && args[0] instanceof String && args[1] instanceof String) {

		PackageManager pm = VirtualCore.getPM();

		String pkgNameOne = (String) args[0], pkgNameTwo = (String) args[1];
		try {
			PackageInfo pkgOne = pm.getPackageInfo(pkgNameOne, PackageManager.GET_SIGNATURES);
			PackageInfo pkgTwo = pm.getPackageInfo(pkgNameTwo, PackageManager.GET_SIGNATURES);

			Signature[] one = pkgOne.signatures;
			Signature[] two = pkgTwo.signatures;

			if (ArrayUtils.isEmpty(one)) {
				if (!ArrayUtils.isEmpty(two)) {
					return PackageManager.SIGNATURE_FIRST_NOT_SIGNED;
				} else {
					return PackageManager.SIGNATURE_NEITHER_SIGNED;
				}
			} else {
				if (ArrayUtils.isEmpty(two)) {
					return PackageManager.SIGNATURE_SECOND_NOT_SIGNED;
				} else {
					// 走到了这里说明两个包的签名都在
					if (Arrays.equals(one, two)) {
						return PackageManager.SIGNATURE_MATCH;
					} else {
						return PackageManager.SIGNATURE_NO_MATCH;
					}
				}
			}
		} catch (Throwable e) {
			// Ignore
		}
	}

	return method.invoke(who, args);
}
 
Example 7
Source Project: Taskbar   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private boolean freeVersionInstalled() {
    PackageManager pm = getPackageManager();
    try {
        PackageInfo pInfo = pm.getPackageInfo(BuildConfig.BASE_APPLICATION_ID, 0);
        return pInfo.versionCode >= 68
                && pm.checkSignatures(BuildConfig.BASE_APPLICATION_ID, getPackageName())
                == PackageManager.SIGNATURE_MATCH;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
 
Example 8
Source Project: Taskbar   File: U.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean hasSupportLibrary(Context context, int minVersion) {
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pInfo = pm.getPackageInfo(BuildConfig.SUPPORT_APPLICATION_ID, 0);
        return pInfo.versionCode >= minVersion
                && pm.checkSignatures(BuildConfig.SUPPORT_APPLICATION_ID, context.getPackageName()) == PackageManager.SIGNATURE_MATCH
                && context.getPackageName().equals(BuildConfig.BASE_APPLICATION_ID)
                && isSystemApp(context);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
 
Example 9
Source Project: SecondScreen   File: U.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean hasSupportLibrary(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(BuildConfig.SUPPORT_APPLICATION_ID, 0);
        return pm.checkSignatures(BuildConfig.SUPPORT_APPLICATION_ID, BuildConfig.APPLICATION_ID)
                == PackageManager.SIGNATURE_MATCH;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
 
Example 10
private void ensureFallbackFusedProviderPresentLocked(ArrayList<String> pkgs) {
    PackageManager pm = mContext.getPackageManager();
    String systemPackageName = mContext.getPackageName();
    ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs);

    List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser(
            new Intent(FUSED_LOCATION_SERVICE_ACTION),
            PackageManager.GET_META_DATA, mCurrentUserId);
    for (ResolveInfo rInfo : rInfos) {
        String packageName = rInfo.serviceInfo.packageName;

        // Check that the signature is in the list of supported sigs. If it's not in
        // this list the standard provider binding logic won't bind to it.
        try {
            PackageInfo pInfo;
            pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) {
                Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION +
                        ", but has wrong signature, ignoring");
                continue;
            }
        } catch (NameNotFoundException e) {
            Log.e(TAG, "missing package: " + packageName);
            continue;
        }

        // Get the version info
        if (rInfo.serviceInfo.metaData == null) {
            Log.w(TAG, "Found fused provider without metadata: " + packageName);
            continue;
        }

        int version = rInfo.serviceInfo.metaData.getInt(
                ServiceWatcher.EXTRA_SERVICE_VERSION, -1);
        if (version == 0) {
            // This should be the fallback fused location provider.

            // Make sure it's in the system partition.
            if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (D) Log.d(TAG, "Fallback candidate not in /system: " + packageName);
                continue;
            }

            // Check that the fallback is signed the same as the OS
            // as a proxy for coreApp="true"
            if (pm.checkSignatures(systemPackageName, packageName)
                    != PackageManager.SIGNATURE_MATCH) {
                if (D) {
                    Log.d(TAG, "Fallback candidate not signed the same as system: "
                            + packageName);
                }
                continue;
            }

            // Found a valid fallback.
            if (D) Log.d(TAG, "Found fallback provider: " + packageName);
            return;
        } else {
            if (D) Log.d(TAG, "Fallback candidate not version 0: " + packageName);
        }
    }

    throw new IllegalStateException("Unable to find a fused location provider that is in the "
            + "system partition with version 0 and signed with the platform certificate. "
            + "Such a package is needed to provide a default fused location provider in the "
            + "event that no other fused location provider has been installed or is currently "
            + "available. For example, coreOnly boot mode when decrypting the data "
            + "partition. The fallback must also be marked coreApp=\"true\" in the manifest");
}
 
Example 11
Source Project: AnLinux-App   File: MainUI.java    License: Apache License 2.0 4 votes vote down vote up
private boolean donationInstalled() {
    PackageManager packageManager = context.getPackageManager();
    return packageManager.checkSignatures(context.getPackageName(), "exa.lnx.d") == PackageManager.SIGNATURE_MATCH;
}
 
Example 12
Source Project: AnLinux-Adfree   File: MainUI.java    License: Apache License 2.0 4 votes vote down vote up
private boolean donationInstalled() {
    PackageManager packageManager = context.getPackageManager();
    return packageManager.checkSignatures(context.getPackageName(), "exa.lnx.d") == PackageManager.SIGNATURE_MATCH;
}
 
Example 13
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

    int uid = Binder.getCallingUid();

    PackageManager pm = getContext().getPackageManager();
    String callerPackage = pm.getPackagesForUid(uid)[0];

    Log.d("AptoideDebug", "Someone is trying to update preferences");

    int result = pm.checkSignatures(callerPackage, getContext().getPackageName());

    if(result == PackageManager.SIGNATURE_MATCH) {
        switch (uriMatcher.match(uri)) {
            case CHANGE_PREFERENCE:

                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
                SharedPreferences.Editor edit = preferences.edit();
                int changed = 0;
                for (final Map.Entry<String, Object> entry : values.valueSet()) {
                    Object value = entry.getValue();
                    if (value instanceof String) {
                        edit.putString(entry.getKey(), (String) value);
                    } else if (value instanceof Integer) {
                        edit.putInt(entry.getKey(), (Integer) value);
                    } else if (value instanceof Long) {
                        edit.putLong(entry.getKey(), (Long) value);
                    } else if (value instanceof Boolean) {

                        if(entry.getKey().equals("debugmode")){
                            Aptoide.DEBUG_MODE = (Boolean) entry.getValue();
                        }

                        edit.putBoolean(entry.getKey(), (Boolean) value);
                    } else if (value instanceof Float) {
                        edit.putFloat(entry.getKey(), (Float) value);
                    }
                    changed++;
                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(Aptoide.getContext(), "Preference set: " + entry.getKey() + "=" + entry.getValue(), Toast.LENGTH_LONG).show();
                        }
                    });
                }



                Log.d("AptoideDebug", "Commited");

                edit.commit();
                return changed;
            default:
                return 0;
        }

    }
    return 0;
}
 
Example 14
Source Project: XPrivacy   File: Util.java    License: GNU General Public License v3.0 4 votes vote down vote up
private static boolean hasValidProEnablerSignature(Context context) {
	return (context.getPackageManager()
			.checkSignatures(context.getPackageName(), context.getPackageName() + ".pro") == PackageManager.SIGNATURE_MATCH);
}