private final void addActiveOwnerLocked(int uid, String pkg) { final IPackageManager pm = AppGlobals.getPackageManager(); final int targetUserHandle = UserHandle.getCallingUserId(); final long oldIdentity = Binder.clearCallingIdentity(); try { PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle); if (pi == null) { throw new IllegalArgumentException("Unknown package " + pkg); } if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) { throw new SecurityException("Calling uid " + uid + " does not own package " + pkg); } } catch (RemoteException e) { // Can't happen; the package manager is in the same process } finally { Binder.restoreCallingIdentity(oldIdentity); } PerUserClipboard clipboard = getClipboard(); if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) { final int N = clipboard.primaryClip.getItemCount(); for (int i = 0; i < N; i++) { grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg); } clipboard.activePermissionOwners.add(pkg); } }
/** * Displays the package file for a package. * * @param pckg */ private void displayPackageFilePath(String pckg) { try { PackageInfo info = mPm.getPackageInfo(pckg, 0, 0); if (info != null && info.applicationInfo != null) { System.out.print("package:"); System.out.println(info.applicationInfo.sourceDir); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }