@Override public boolean matches(IntentFirewall ifw, ComponentName resolvedComponent, Intent intent, int callerUid, int callerPid, String resolvedType, int receivingUid) { IPackageManager pm = AppGlobals.getPackageManager(); int packageUid = -1; try { // USER_SYSTEM here is not important. Only app id is used and getPackageUid() will // return a uid whether the app is installed for a user or not. packageUid = pm.getPackageUid(mPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, UserHandle.USER_SYSTEM); } catch (RemoteException ex) { // handled below } if (packageUid == -1) { return false; } return UserHandle.isSameApp(packageUid, callerUid); }
static boolean isPrivilegedApp(int callerUid, int callerPid) { if (callerUid == Process.SYSTEM_UID || callerUid == 0 || callerPid == Process.myPid() || callerPid == 0) { return true; } IPackageManager pm = AppGlobals.getPackageManager(); try { return (pm.getPrivateFlagsForUid(callerUid) & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; } catch (RemoteException ex) { Slog.e(IntentFirewall.TAG, "Remote exception while retrieving uid flags", ex); } return false; }
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; } }
/** * 适配 5.0以下系统 * * @param path * @param iInstallerCallback * @throws Exception */ private void installPackageLowApi(String path, final IInstallerCallback iInstallerCallback) throws Exception { final Uri uri = Uri.parse(path); final int flags = PMFlags.INSTALL_REPLACE_EXISTING; final PackageInstallObserver observer = new PackageInstallObserver(iInstallerCallback); final IPackageManager ipm = getIPackageManager(); RefInvoke.invokeMethodWithException(ipm.getClass(), "installPackage", ipm, new Class[] { Uri.class, IPackageInstallObserver.class, int.class, String.class }, new Object[] { uri, observer, flags, null }); }
public static IPackageManager getPackageManager() { if (sPackageManager != null) { //Slog.v("PackageManager", "returning cur default = " + sPackageManager); return sPackageManager; } IBinder b = ServiceManager.getService("package"); //Slog.v("PackageManager", "default service binder = " + b); sPackageManager = IPackageManager.Stub.asInterface(b); //Slog.v("PackageManager", "default service = " + sPackageManager); return sPackageManager; }
public BackupManagerController() { backupManager = IBackupManager.Stub.asInterface(ServiceManager.getService("backup")); packageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); }
public static List queryIntentReceivers(IPackageManager pm, Intent intent, int uid) { return pm.queryIntentReceivers(intent, null, 0, uid); }
public static List queryIntentActivities(IPackageManager pm, Intent intent, int uid) { return pm.queryIntentActivities(intent, null, 0, uid); }
private static IPackageManager getPackageManager() { return IPackageManager.Stub.asInterface(ServiceManager.getService("package")); }
public static IPackageManager getPackageManager() { throw new UnsupportedOperationException(); }
public static IPackageManager getPackageManager() { return null; }
/** * 反射系统IPackageManager * * @return */ private IPackageManager getIPackageManager() { IBinder iBinder = (IBinder) RefInvoke.invokeStaticMethod("android.os.ServiceManager", "getService", new Class[] { String.class }, new Object[] { "package" }); IPackageManager ipm = IPackageManager.Stub.asInterface(iBinder); return ipm; }