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

The following examples show how to use android.content.pm.PackageManager#SIGNATURE_MATCH . 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 check out the related API usage on the sidebar.
Example 1
Source File: RunningProcessList.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: RunningProcessList.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 File: TrustActivity.java    From trust with 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
Source File: IntentFirewall.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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
Source File: XProvider.java    From XPrivacyLua with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: CheckSignatures.java    From container with GNU General Public License v3.0 5 votes vote down vote up
@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 File: MainActivity.java    From Taskbar with 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 File: U.java    From Taskbar with 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 File: U.java    From SecondScreen with 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
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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 File: MainUI.java    From AnLinux-App with 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 File: MainUI.java    From AnLinux-Adfree with 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
Source File: StubProvider.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
@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 File: Util.java    From XPrivacy with 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);
}