private static void logIntent(int intentType, Intent intent, int callerUid, String resolvedType) { // The component shouldn't be null, but let's double check just to be safe ComponentName cn = intent.getComponent(); String shortComponent = null; if (cn != null) { shortComponent = cn.flattenToShortString(); } String callerPackages = null; int callerPackageCount = 0; IPackageManager pm = AppGlobals.getPackageManager(); if (pm != null) { try { String[] callerPackagesArray = pm.getPackagesForUid(callerUid); if (callerPackagesArray != null) { callerPackageCount = callerPackagesArray.length; callerPackages = joinPackages(callerPackagesArray); } } catch (RemoteException ex) { Slog.e(TAG, "Remote exception while retrieving packages", ex); } } EventLogTags.writeIfwIntentMatched( intentType, shortComponent, callerUid, callerPackageCount, callerPackages, intent.getAction(), resolvedType, intent.getDataString(), intent.getFlags()); }
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); } }
private void runGrantRevokePermission(boolean grant) { String pkg = nextArg(); if (pkg == null) { System.err.println("Error: no package specified"); showUsage(); return; } String perm = nextArg(); if (perm == null) { System.err.println("Error: no permission specified"); showUsage(); return; } try { if (grant) { mPm.grantPermission(pkg, perm); } else { mPm.revokePermission(pkg, perm); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } catch (IllegalArgumentException e) { System.err.println("Bad argument: " + e.toString()); showUsage(); } catch (SecurityException e) { System.err.println("Operation not allowed: " + e.toString()); } }
public static void exec(int location, Context context) { try { IPackageManager mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); mPm.setInstallLocation(location); } catch (Exception ex) { ex.printStackTrace(); } }
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; } }
/** * Helper to check if this device has FEATURE_NFC, but without using a context. Equivalent to * context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC) */ private static boolean hasNfcFeature() { IPackageManager pm = ActivityThread.getPackageManager(); if (pm == null) { Log.e(TAG, "Cannot get package manager, assuming no NFC feature"); return false; } try { return pm.hasSystemFeature(PackageManager.FEATURE_NFC); } catch (RemoteException e) { Log.e(TAG, "Package manager query failed, assuming no NFC feature", e); return false; } }
private void runSetPermissionEnforced() { final String permission = nextArg(); if (permission == null) { System.err.println("Error: no permission specified"); showUsage(); return; } final String enforcedRaw = nextArg(); if (enforcedRaw == null) { System.err.println("Error: no enforcement specified"); showUsage(); return; } final boolean enforced = Boolean.parseBoolean(enforcedRaw); try { mPm.setPermissionEnforced(permission, enforced); } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } catch (IllegalArgumentException e) { System.err.println("Bad argument: " + e.toString()); showUsage(); } catch (SecurityException e) { System.err.println("Operation not allowed: " + e.toString()); } }
/** * Lists all of the features supported by the current device. * * <p>pm list features */ private void runListFeatures() { try { List<FeatureInfo> list = new ArrayList<FeatureInfo>(); FeatureInfo[] rawList = mPm.getSystemAvailableFeatures(); for (int i = 0; i < rawList.length; i++) { list.add(rawList[i]); } // Sort by name Collections.sort( list, new Comparator<FeatureInfo>() { public int compare(FeatureInfo o1, FeatureInfo o2) { if (o1.name == o2.name) return 0; if (o1.name == null) return -1; if (o2.name == null) return 1; return o1.name.compareTo(o2.name); } }); int count = (list != null) ? list.size() : 0; for (int p = 0; p < count; p++) { FeatureInfo fi = list.get(p); System.out.print("feature:"); if (fi.name != null) System.out.println(fi.name); else System.out.println("reqGlEsVersion=0x" + Integer.toHexString(fi.reqGlEsVersion)); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
/** * Lists all of the libraries supported by the current device. * * <p>pm list libraries */ private void runListLibraries() { try { List<String> list = new ArrayList<String>(); String[] rawList = mPm.getSystemSharedLibraryNames(); for (int i = 0; i < rawList.length; i++) { list.add(rawList[i]); } // Sort by name Collections.sort( list, new Comparator<String>() { public int compare(String o1, String o2) { if (o1 == o2) return 0; if (o1 == null) return -1; if (o2 == null) return 1; return o1.compareTo(o2); } }); int count = (list != null) ? list.size() : 0; for (int p = 0; p < count; p++) { String lib = list.get(p); System.out.print("library:"); System.out.println(lib); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private void runSetEnabledSetting(int state) { int userId = 0; String option = nextOption(); if (option != null && option.equals("--user")) { String optionData = nextOptionData(); if (optionData == null || !isNumber(optionData)) { System.err.println("Error: no USER_ID specified"); showUsage(); return; } else { userId = Integer.parseInt(optionData); } } String pkg = nextArg(); if (pkg == null) { System.err.println("Error: no package or component specified"); showUsage(); return; } ComponentName cn = ComponentName.unflattenFromString(pkg); if (cn == null) { try { mPm.setApplicationEnabledSetting(pkg, state, 0, userId); System.err.println( "Package " + pkg + " new state: " + enabledSettingToString(mPm.getApplicationEnabledSetting(pkg, userId))); } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } } else { try { mPm.setComponentEnabledSetting(cn, state, 0, userId); System.err.println( "Component " + cn.toShortString() + " new state: " + enabledSettingToString(mPm.getComponentEnabledSetting(cn, userId))); } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } } }
void init() { try { mInstallLocation = mPm.getInstallLocation(); } catch (RemoteException e) { Log.e("CanBeOnSdCardChecker", "Is Package Manager running?"); return; } }
/** * Using the restrictions provided (categories & packages), generate a list of activities that we * can actually switch to. * * @return Returns true if it could successfully build a list of target activities */ private boolean getMainApps() { try { final int N = mMainCategories.size(); for (int i = 0; i < N; i++) { Intent intent = new Intent(Intent.ACTION_MAIN); String category = mMainCategories.get(i); if (category.length() > 0) { intent.addCategory(category); } List<ResolveInfo> mainApps = mPm.queryIntentActivities(intent, null, 0); if (mainApps == null || mainApps.size() == 0) { System.err.println("// Warning: no activities found for category " + category); continue; } if (mVerbose >= 2) { // very verbose System.out.println("// Selecting main activities from category " + category); } final int NA = mainApps.size(); for (int a = 0; a < NA; a++) { ResolveInfo r = mainApps.get(a); String packageName = r.activityInfo.applicationInfo.packageName; if (checkEnteringPackage(packageName)) { if (mVerbose >= 2) { // very verbose System.out.println( "// + Using main activity " + r.activityInfo.name + " (from package " + packageName + ")"); } mMainApps.add(new ComponentName(packageName, r.activityInfo.name)); } else { if (mVerbose >= 3) { // very very verbose System.out.println( "// - NOT USING main activity " + r.activityInfo.name + " (from package " + packageName + ")"); } } } } } catch (RemoteException e) { System.err.println("** Failed talking with package manager!"); return false; } if (mMainApps.size() == 0) { System.out.println("** No activities found to run, monkey aborted."); return false; } return true; }
/** * Lists all of the installed instrumentation, or all for a given package * * <p>pm list instrumentation [package] [-f] */ private void runListInstrumentation() { int flags = 0; // flags != 0 is only used to request meta-data boolean showPackage = false; String targetPackage = null; try { String opt; while ((opt = nextArg()) != null) { if (opt.equals("-f")) { showPackage = true; } else if (opt.charAt(0) != '-') { targetPackage = opt; } else { System.err.println("Error: Unknown option: " + opt); showUsage(); return; } } } catch (RuntimeException ex) { System.err.println("Error: " + ex.toString()); showUsage(); return; } try { List<InstrumentationInfo> list = mPm.queryInstrumentation(targetPackage, flags); // Sort by target package Collections.sort( list, new Comparator<InstrumentationInfo>() { public int compare(InstrumentationInfo o1, InstrumentationInfo o2) { return o1.targetPackage.compareTo(o2.targetPackage); } }); int count = (list != null) ? list.size() : 0; for (int p = 0; p < count; p++) { InstrumentationInfo ii = list.get(p); System.out.print("instrumentation:"); if (showPackage) { System.out.print(ii.sourceDir); System.out.print("="); } ComponentName cn = new ComponentName(ii.packageName, ii.name); System.out.print(cn.flattenToShortString()); System.out.print(" (target="); System.out.print(ii.targetPackage); System.out.println(")"); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
/** * 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); } }
private void runTrimCaches() { String size = nextArg(); if (size == null) { System.err.println("Error: no size specified"); showUsage(); return; } int len = size.length(); long multiplier = 1; if (len > 1) { char c = size.charAt(len - 1); if (c == 'K' || c == 'k') { multiplier = 1024L; } else if (c == 'M' || c == 'm') { multiplier = 1024L * 1024L; } else if (c == 'G' || c == 'g') { multiplier = 1024L * 1024L * 1024L; } else { System.err.println("Invalid suffix: " + c); showUsage(); return; } size = size.substring(0, len - 1); } long sizeVal; try { sizeVal = Long.parseLong(size) * multiplier; } catch (NumberFormatException e) { System.err.println("Error: expected number at: " + size); showUsage(); return; } ClearDataObserver obs = new ClearDataObserver(); try { mPm.freeStorageAndNotify(sizeVal, obs); synchronized (obs) { while (!obs.finished) { try { obs.wait(); } catch (InterruptedException e) { } } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } catch (IllegalArgumentException e) { System.err.println("Bad argument: " + e.toString()); showUsage(); } catch (SecurityException e) { System.err.println("Operation not allowed: " + e.toString()); } }
public String getSavedNetworkSummary() { if (mConfig != null) { PackageManager pm = mContext.getPackageManager(); String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID); int userId = UserHandle.getUserId(mConfig.creatorUid); ApplicationInfo appInfo = null; if (mConfig.creatorName != null && mConfig.creatorName.equals(systemName)) { appInfo = mContext.getApplicationInfo(); } else { try { IPackageManager ipm = AppGlobals.getPackageManager(); appInfo = ipm.getApplicationInfo(mConfig.creatorName, 0 /* flags */, userId); } catch (RemoteException rex) { } } if (appInfo != null && !appInfo.packageName.equals(mContext.getString(R.string.settings_package)) && !appInfo.packageName.equals(mContext.getString(R.string.certinstaller_package))) { return mContext.getString(R.string.saved_network, appInfo.loadLabel(pm)); } } return ""; }
@Override public void revokeRuntimePermission(String packageName, String permission, int userId) throws RemoteException { synchronized (mLock) { throwIfCalledByNotTrustedUidLocked(); throwIfShutdownLocked(); throwIfNotConnectedLocked(); } final long identity = Binder.clearCallingIdentity(); try { mPackageManager.revokeRuntimePermission(packageName, permission, userId); } finally { Binder.restoreCallingIdentity(identity); } }
@SuppressWarnings("unchecked") private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags, int userId) throws RemoteException { final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>(); PackageInfo lastItem = null; ParceledListSlice<PackageInfo> slice; do { final String lastKey = lastItem != null ? lastItem.packageName : null; slice = pm.getInstalledPackages(flags, lastKey, userId); lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR); } while (!slice.isLastSlice()); return packageInfos; }
/** Lists all the known permission groups. */ private void runListPermissionGroups() { try { List<PermissionGroupInfo> pgs = mPm.getAllPermissionGroups(0); int count = pgs.size(); for (int p = 0; p < count; p++) { PermissionGroupInfo pgi = pgs.get(p); System.out.print("permission group:"); System.out.println(pgi.name); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private void runInstall() { int installFlags = 0; String opt; while ((opt = nextOption()) != null) { if (opt.equals("-l")) { installFlags |= PackageManager.FORWARD_LOCK_PACKAGE; } else if (opt.equals("-r")) { installFlags |= PackageManager.REPLACE_EXISTING_PACKAGE; } else { System.err.println("Error: Unknown option: " + opt); showUsage(); return; } } String apkFilePath = nextArg(); System.err.println("\tpkg: " + apkFilePath); if (apkFilePath == null) { System.err.println("Error: no package specified"); showUsage(); return; } PackageInstallObserver obs = new PackageInstallObserver(); try { mPm.installPackage(Uri.fromFile(new File(apkFilePath)), obs, installFlags); synchronized (obs) { while (!obs.finished) { try { obs.wait(); } catch (InterruptedException e) { } } if (obs.result == PackageManager.INSTALL_SUCCEEDED) { System.out.println("Success"); } else { System.err.println("Failure [" + installFailureToString(obs.result) + "]"); } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private Resources getResources(PackageItemInfo pii) { Resources res = mResourceCache.get(pii.packageName); if (res != null) return res; try { ApplicationInfo ai = mPm.getApplicationInfo(pii.packageName, 0, 0); AssetManager am = new AssetManager(); am.addAssetPath(ai.publicSourceDir); res = new Resources(am, null, null); mResourceCache.put(pii.packageName, res); return res; } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); return null; } }
private void runGetInstallLocation() { try { int loc = mPm.getInstallLocation(); String locStr = "invalid"; if (loc == PackageHelper.APP_INSTALL_AUTO) { locStr = "auto"; } else if (loc == PackageHelper.APP_INSTALL_INTERNAL) { locStr = "internal"; } else if (loc == PackageHelper.APP_INSTALL_EXTERNAL) { locStr = "external"; } System.out.println(loc + "[" + locStr + "]"); } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private boolean deletePackage(String pkg, int unInstallFlags) { PackageDeleteObserver obs = new PackageDeleteObserver(); try { mPm.deletePackage(pkg, obs, unInstallFlags); synchronized (obs) { while (!obs.finished) { try { obs.wait(); } catch (InterruptedException e) { } } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } return obs.result; }
private void preInstall() { String path = nextArg(); int i; System.err.println("\t preInstall path: " + path); if (path == null) { System.err.println("Error: no package specified"); showUsage(); return; } File[] files = new File(path).listFiles(); for (File apkFilePath : files) { System.err.println("\tpkg: " + apkFilePath); PackageInstallObserver obs = new PackageInstallObserver(); try { mPm.installPackage(Uri.fromFile(apkFilePath), obs, 0, null); System.err.println("\t pkg----1------: "); synchronized (obs) { while (!obs.finished) { try { System.err.println("\t pkg----2------: "); obs.wait(); System.err.println("\t pkg----3------: "); } catch (InterruptedException e) { System.err.println("\t pkg----4------: "); } } if (obs.result == PackageManager.INSTALL_SUCCEEDED) { System.out.println("Success"); } else { System.err.println("Failure [" + installFailureToString(obs.result) + "]"); } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } } System.err.println("\t preInstall path: " + path + " ok"); }
/** Lists all the installed packages. */ private void runListPackages(boolean showApplicationPackage) { try { String opt; while ((opt = nextOption()) != null) { if (opt.equals("-l")) { // old compat } else if (opt.equals("-lf")) { showApplicationPackage = true; } else if (opt.equals("-f")) { showApplicationPackage = true; } else { System.err.println("Error: Unknown option: " + opt); showUsage(); return; } } } catch (RuntimeException ex) { System.err.println("Error: " + ex.toString()); showUsage(); return; } try { List<PackageInfo> packages = mPm.getInstalledPackages(0 /* all */); int count = packages.size(); for (int p = 0; p < count; p++) { PackageInfo info = packages.get(p); System.out.print("package:"); if (showApplicationPackage) { System.out.print(info.applicationInfo.sourceDir); System.out.print("="); } System.out.println(info.packageName); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private void runSetInstallLocation() { int loc; String arg = nextArg(); if (arg == null) { System.err.println("Error: no install location specified."); return; } try { loc = Integer.parseInt(arg); } catch (NumberFormatException e) { System.err.println("Error: install location has to be a number."); return; } try { if (!mPm.setInstallLocation(loc)) { System.err.println("Error: install location has to be a number."); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
/** Lists all the installed packages. */ private void runListPackages(boolean showApplicationPackage) { int getFlags = 0; boolean listDisabled = false, listEnabled = false; boolean listSystem = false, listThirdParty = false; boolean listInstaller = false; int userId = UserHandle.USER_OWNER; try { String opt; while ((opt = nextOption()) != null) { if (opt.equals("-l")) { // old compat } else if (opt.equals("-lf")) { showApplicationPackage = true; } else if (opt.equals("-f")) { showApplicationPackage = true; } else if (opt.equals("-d")) { listDisabled = true; } else if (opt.equals("-e")) { listEnabled = true; } else if (opt.equals("-s")) { listSystem = true; } else if (opt.equals("-3")) { listThirdParty = true; } else if (opt.equals("-i")) { listInstaller = true; } else if (opt.equals("--user")) { userId = Integer.parseInt(nextArg()); } else if (opt.equals("-u")) { getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES; } else { System.err.println("Error: Unknown option: " + opt); return; } } } catch (RuntimeException ex) { System.err.println("Error: " + ex.toString()); return; } String filter = nextArg(); try { final List<PackageInfo> packages = getInstalledPackages(mPm, getFlags, userId); int count = packages.size(); for (int p = 0; p < count; p++) { PackageInfo info = packages.get(p); if (filter != null && !info.packageName.contains(filter)) { continue; } final boolean isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; if ((!listDisabled || !info.applicationInfo.enabled) && (!listEnabled || info.applicationInfo.enabled) && (!listSystem || isSystem) && (!listThirdParty || !isSystem)) { System.out.print("package:"); if (showApplicationPackage) { System.out.print(info.applicationInfo.sourceDir); System.out.print("="); } System.out.print(info.packageName); if (listInstaller) { System.out.print(" installer="); System.out.print(mPm.getInstallerPackageName(info.packageName)); } System.out.println(); } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private void runInstall() { int installFlags = PackageManager.INSTALL_ALL_USERS; String installerPackageName = null; String opt; String algo = null; byte[] iv = null; byte[] key = null; String macAlgo = null; byte[] macKey = null; byte[] tag = null; String originatingUriString = null; String referrer = null; while ((opt = nextOption()) != null) { if (opt.equals("-l")) { installFlags |= PackageManager.INSTALL_FORWARD_LOCK; } else if (opt.equals("-r")) { installFlags |= PackageManager.INSTALL_REPLACE_EXISTING; } else if (opt.equals("-i")) { installerPackageName = nextOptionData(); if (installerPackageName == null) { System.err.println("Error: no value specified for -i"); return; } } else if (opt.equals("-t")) { installFlags |= PackageManager.INSTALL_ALLOW_TEST; } else if (opt.equals("-s")) { // Override if -s option is specified. installFlags |= PackageManager.INSTALL_EXTERNAL; } else if (opt.equals("-f")) { // Override if -s option is specified. installFlags |= PackageManager.INSTALL_INTERNAL; } else if (opt.equals("-d")) { installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE; } else if (opt.equals("--algo")) { algo = nextOptionData(); if (algo == null) { System.err.println("Error: must supply argument for --algo"); return; } } else if (opt.equals("--iv")) { iv = hexToBytes(nextOptionData()); if (iv == null) { System.err.println("Error: must supply argument for --iv"); return; } } else if (opt.equals("--key")) { key = hexToBytes(nextOptionData()); if (key == null) { System.err.println("Error: must supply argument for --key"); return; } } else if (opt.equals("--macalgo")) { macAlgo = nextOptionData(); if (macAlgo == null) { System.err.println("Error: must supply argument for --macalgo"); return; } } else if (opt.equals("--mackey")) { macKey = hexToBytes(nextOptionData()); if (macKey == null) { System.err.println("Error: must supply argument for --mackey"); return; } } else if (opt.equals("--tag")) { tag = hexToBytes(nextOptionData()); if (tag == null) { System.err.println("Error: must supply argument for --tag"); return; } } else if (opt.equals("--originating-uri")) { originatingUriString = nextOptionData(); if (originatingUriString == null) { System.err.println("Error: must supply argument for --originating-uri"); return; } } else if (opt.equals("--referrer")) { referrer = nextOptionData(); if (referrer == null) { System.err.println("Error: must supply argument for --referrer"); return; } } else { System.err.println("Error: Unknown option: " + opt); return; } } final ContainerEncryptionParams encryptionParams; if (algo != null || iv != null || key != null || macAlgo != null || macKey != null || tag != null) { if (algo == null || iv == null || key == null) { System.err.println("Error: all of --algo, --iv, and --key must be specified"); return; } if (macAlgo != null || macKey != null || tag != null) { if (macAlgo == null || macKey == null || tag == null) { System.err.println("Error: all of --macalgo, --mackey, and --tag must " + "be specified"); return; } } try { final SecretKey encKey = new SecretKeySpec(key, "RAW"); final SecretKey macSecretKey; if (macKey == null || macKey.length == 0) { macSecretKey = null; } else { macSecretKey = new SecretKeySpec(macKey, "RAW"); } encryptionParams = new ContainerEncryptionParams( algo, new IvParameterSpec(iv), encKey, macAlgo, null, macSecretKey, tag, -1, -1, -1); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); return; } } else { encryptionParams = null; } final Uri apkURI; final Uri verificationURI; final Uri originatingURI; final Uri referrerURI; if (originatingUriString != null) { originatingURI = Uri.parse(originatingUriString); } else { originatingURI = null; } if (referrer != null) { referrerURI = Uri.parse(referrer); } else { referrerURI = null; } // Populate apkURI, must be present final String apkFilePath = nextArg(); System.err.println("\tpkg: " + apkFilePath); if (apkFilePath != null) { apkURI = Uri.fromFile(new File(apkFilePath)); } else { System.err.println("Error: no package specified"); return; } // Populate verificationURI, optionally present final String verificationFilePath = nextArg(); if (verificationFilePath != null) { System.err.println("\tver: " + verificationFilePath); verificationURI = Uri.fromFile(new File(verificationFilePath)); } else { verificationURI = null; } PackageInstallObserver obs = new PackageInstallObserver(); try { VerificationParams verificationParams = new VerificationParams( verificationURI, originatingURI, referrerURI, VerificationParams.NO_UID, null); mPm.installPackageWithVerificationAndEncryption( apkURI, obs, installFlags, installerPackageName, verificationParams, encryptionParams); synchronized (obs) { while (!obs.finished) { try { obs.wait(); } catch (InterruptedException e) { } } if (obs.result == PackageManager.INSTALL_SUCCEEDED) { System.out.println("Success"); } else { System.err.println("Failure [" + installFailureToString(obs.result) + "]"); } } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }
private void doListPermissions( ArrayList<String> groupList, boolean groups, boolean labels, boolean summary, int startProtectionLevel, int endProtectionLevel) throws RemoteException { for (int i = 0; i < groupList.size(); i++) { String groupName = groupList.get(i); String prefix = ""; if (groups) { if (i > 0) System.out.println(""); if (groupName != null) { PermissionGroupInfo pgi = mPm.getPermissionGroupInfo(groupName, 0); if (summary) { Resources res = getResources(pgi); if (res != null) { System.out.print(loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel) + ": "); } else { System.out.print(pgi.name + ": "); } } else { System.out.println((labels ? "+ " : "") + "group:" + pgi.name); if (labels) { System.out.println(" package:" + pgi.packageName); Resources res = getResources(pgi); if (res != null) { System.out.println(" label:" + loadText(pgi, pgi.labelRes, pgi.nonLocalizedLabel)); System.out.println( " description:" + loadText(pgi, pgi.descriptionRes, pgi.nonLocalizedDescription)); } } } } else { System.out.println(((labels && !summary) ? "+ " : "") + "ungrouped:"); } prefix = " "; } List<PermissionInfo> ps = mPm.queryPermissionsByGroup(groupList.get(i), 0); int count = ps.size(); boolean first = true; for (int p = 0; p < count; p++) { PermissionInfo pi = ps.get(p); if (groups && groupName == null && pi.group != null) { continue; } final int base = pi.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE; if (base < startProtectionLevel || base > endProtectionLevel) { continue; } if (summary) { if (first) { first = false; } else { System.out.print(", "); } Resources res = getResources(pi); if (res != null) { System.out.print(loadText(pi, pi.labelRes, pi.nonLocalizedLabel)); } else { System.out.print(pi.name); } } else { System.out.println(prefix + (labels ? "+ " : "") + "permission:" + pi.name); if (labels) { System.out.println(prefix + " package:" + pi.packageName); Resources res = getResources(pi); if (res != null) { System.out.println( prefix + " label:" + loadText(pi, pi.labelRes, pi.nonLocalizedLabel)); System.out.println( prefix + " description:" + loadText(pi, pi.descriptionRes, pi.nonLocalizedDescription)); } System.out.println( prefix + " protectionLevel:" + PermissionInfo.protectionToString(pi.protectionLevel)); } } } if (summary) { System.out.println(""); } } }
/** Lists all the permissions in a group. */ private void runListPermissions() { try { boolean labels = false; boolean groups = false; boolean userOnly = false; boolean summary = false; boolean dangerousOnly = false; String opt; while ((opt = nextOption()) != null) { if (opt.equals("-f")) { labels = true; } else if (opt.equals("-g")) { groups = true; } else if (opt.equals("-s")) { groups = true; labels = true; summary = true; } else if (opt.equals("-u")) { userOnly = true; } else if (opt.equals("-d")) { dangerousOnly = true; } else { System.err.println("Error: Unknown option: " + opt); return; } } String grp = nextOption(); ArrayList<String> groupList = new ArrayList<String>(); if (groups) { List<PermissionGroupInfo> infos = mPm.getAllPermissionGroups(0); for (int i = 0; i < infos.size(); i++) { groupList.add(infos.get(i).name); } groupList.add(null); } else { groupList.add(grp); } if (dangerousOnly) { System.out.println("Dangerous Permissions:"); System.out.println(""); doListPermissions( groupList, groups, labels, summary, PermissionInfo.PROTECTION_DANGEROUS, PermissionInfo.PROTECTION_DANGEROUS); if (userOnly) { System.out.println("Normal Permissions:"); System.out.println(""); doListPermissions( groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_NORMAL); } } else if (userOnly) { System.out.println("Dangerous and Normal Permissions:"); System.out.println(""); doListPermissions( groupList, groups, labels, summary, PermissionInfo.PROTECTION_NORMAL, PermissionInfo.PROTECTION_DANGEROUS); } else { System.out.println("All Permissions:"); System.out.println(""); doListPermissions(groupList, groups, labels, summary, -10000, 10000); } } catch (RemoteException e) { System.err.println(e.toString()); System.err.println(PM_NOT_RUNNING_ERR); } }