private List<IntentFilter> getIntentFiltersForComponent( ComponentName componentName, Map<ComponentName, List<IntentFilter>> filterMap) throws NameNotFoundException { List<IntentFilter> filters = filterMap.get(componentName); if (filters != null) { return new ArrayList<>(filters); } throw new NameNotFoundException(componentName + " doesn't exist"); }
private void clearIntentFilterForComponent( ComponentName componentName, Map<ComponentName, List<IntentFilter>> filterMap) throws NameNotFoundException { List<IntentFilter> filters = filterMap.get(componentName); if (filters != null) { filters.clear(); return; } throw new NameNotFoundException(componentName + " doesn't exist"); }
private void addIntentFilterForComponent( ComponentName componentName, IntentFilter filter, Map<ComponentName, List<IntentFilter>> filterMap) throws NameNotFoundException { // Existing components should have an entry in respective filterMap. // It is OK to search over all filter maps, as it is impossible to have the same component name // being of two comopnent types (like activity and service at the same time). List<IntentFilter> filters = filterMap.get(componentName); if (filters != null) { filters.add(filter); return; } throw new NameNotFoundException(componentName + " doesn't exist"); }
Intent i; PackageManager manager = getPackageManager(); try { i = manager.getLaunchIntentForPackage("com.example.schoolToolApp"); if (i == null) throw new PackageManager.NameNotFoundException(); i.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(i); } catch (PackageManager.NameNotFoundException e) { }
public OnClickListener ButtonClicked = new OnClickListener() { public void onClick(View v) { Intent i; PackageManager manager = getPackageManager(); try { i = manager.getLaunchIntentForPackage("com.mycompany.mygame"); if (i == null) throw new PackageManager.NameNotFoundException(); i.addCategory(Intent.CATEGORY_LAUNCHER); startActivity(i); } catch (PackageManager.NameNotFoundException e) { InstallAPK downloadAndInstall = new InstallAPK(); progress.setCancelable(false); progress.setMessage("Downloading..."); downloadAndInstall.setContext(getApplicationContext(), progress); downloadAndInstall.execute("http://xyz/android/gamedownload.aspx?name=mygame.apk"); } } };
throw new PackageManager.NameNotFoundException(name + " is not an application process"); throw new PackageManager.NameNotFoundException(name + " is not an application process");
throw new NameNotFoundException("Component not found: " + component);
@Override public PackageInfo getPackageInfo(final String pkg, final int flags) throws NameNotFoundException { final PackageInfo info = mCondom.proceed(OutboundType.GET_PACKAGE_INFO, pkg, null, new CondomCore.WrappedValueProcedureThrows<PackageInfo, NameNotFoundException>() { @Override public PackageInfo proceed() throws NameNotFoundException { return CondomPackageManager.super.getPackageInfo(pkg, flags); } }); if (info == null) throw new NameNotFoundException(pkg); if ((flags & PackageManager.GET_PERMISSIONS) != 0 && ! mCondom.getSpoofPermissions().isEmpty() && mCondom.getPackageName().equals(pkg)) { final List<String> requested_permissions = info.requestedPermissions == null ? new ArrayList<String>() : new ArrayList<>(Arrays.asList(info.requestedPermissions)); final List<String> missing_permissions = new ArrayList<>(mCondom.getSpoofPermissions()); missing_permissions.removeAll(requested_permissions); if (! missing_permissions.isEmpty()) { requested_permissions.addAll(missing_permissions); info.requestedPermissions = requested_permissions.toArray(new String[requested_permissions.size()]); } // Even if all permissions to spoof are already requested, the permission granted state still requires amending. if (SDK_INT >= JELLY_BEAN) { final int[] req_permissions_flags = info.requestedPermissionsFlags == null ? new int[requested_permissions.size()] : Arrays.copyOf(info.requestedPermissionsFlags, requested_permissions.size()); for (int i = 0; i < info.requestedPermissions.length; i++) if (mCondom.shouldSpoofPermission(info.requestedPermissions[i])) req_permissions_flags[i] = PackageInfo.REQUESTED_PERMISSION_GRANTED; info.requestedPermissionsFlags = req_permissions_flags; } } return info; }
&& (Build.VERSION.SDK_INT >= 24 ? isApplicationEnabled : true); if ((flags & MATCH_DISABLED_COMPONENTS) == 0 && !isEnabledForFiltering) { throw new NameNotFoundException("Disabled component: " + componentInfo); final int applicationFlags = applicationInfo.flags; if ((applicationFlags & ApplicationInfo.FLAG_SYSTEM) != ApplicationInfo.FLAG_SYSTEM) { throw new NameNotFoundException("Not system component: " + componentInfo); && isValidComponentInfo(componentInfo) && hiddenPackages.contains(componentInfo.applicationInfo.packageName)) { throw new NameNotFoundException("Uninstalled package: " + componentInfo);
throw new NameNotFoundException(packageName); throw new NameNotFoundException("Package is hidden, can't find");
/** * Sets up the PackageManager to return what we expect depending on whether app is installed. * @param isInstalled true to simulate that app is installed */ private void setupPackageManagerForApp(boolean isInstalled, boolean hasValidSignature) throws Exception { if (isInstalled) { PackageInfo packageInfo = new PackageInfo(); when(mMockPackageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_SIGNATURES)) .thenReturn(packageInfo); Signature signature = mock(Signature.class); packageInfo.signatures = new Signature[]{signature}; if (hasValidSignature) { when(Utility.sha1hash(signature.toByteArray())).thenReturn(APP_HASH); } } else { when(mMockPackageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_SIGNATURES)) .thenThrow(new PackageManager.NameNotFoundException()); } } }
private void applyFlagsToApplicationInfo(@Nullable ApplicationInfo appInfo, int flags) throws NameNotFoundException { if (appInfo == null) { return; } String packageName = appInfo.packageName; Integer stateOverride = applicationEnabledSettingMap.get(packageName); if (stateOverride == null) { stateOverride = COMPONENT_ENABLED_STATE_DEFAULT; } appInfo.enabled = (appInfo.enabled && stateOverride == COMPONENT_ENABLED_STATE_DEFAULT) || stateOverride == COMPONENT_ENABLED_STATE_ENABLED; if (deletedPackages.contains(packageName)) { appInfo.flags &= ~FLAG_INSTALLED; } if ((flags & MATCH_ALL) != 0 && Build.VERSION.SDK_INT >= 23) { return; } if ((flags & MATCH_UNINSTALLED_PACKAGES) == 0 && (appInfo.flags & FLAG_INSTALLED) == 0) { throw new NameNotFoundException("Package not installed: " + packageName); } if ((flags & MATCH_UNINSTALLED_PACKAGES) == 0 && hiddenPackages.contains(packageName)) { throw new NameNotFoundException("Package hidden: " + packageName); } }
@Implementation protected List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws NameNotFoundException { List<PermissionInfo> result = new ArrayList<>(); for (PermissionInfo permissionInfo : extraPermissions.values()) { if (Objects.equals(permissionInfo.group, group)) { result.add(permissionInfo); } } for (PackageInfo packageInfo : packageInfos.values()) { if (packageInfo.permissions != null) { for (PermissionInfo permission : packageInfo.permissions) { if (Objects.equals(group, permission.group)) { result.add(createCopyPermissionInfo(permission, flags)); } } } } if (result.isEmpty()) { throw new NameNotFoundException(group); } return result; }
@Implementation protected PermissionInfo getPermissionInfo(String name, int flags) throws NameNotFoundException { PermissionInfo permissionInfo = extraPermissions.get(name); if (permissionInfo != null) { return permissionInfo; } for (PackageInfo packageInfo : packageInfos.values()) { if (packageInfo.permissions != null) { for (PermissionInfo permission : packageInfo.permissions) { if (name.equals(permission.name)) { return createCopyPermissionInfo(permission, flags); } } } } throw new NameNotFoundException(name); }
@Implementation protected Resources getResourcesForApplication(String appPackageName) throws NameNotFoundException { if (context.getPackageName().equals(appPackageName)) { return context.getResources(); } else if (packageInfos.containsKey(appPackageName)) { Resources appResources = resources.get(appPackageName); if (appResources == null) { appResources = new Resources(new AssetManager(), null, null); resources.put(appPackageName, appResources); } return appResources; } throw new NameNotFoundException(appPackageName); }
@Implementation(minSdk = JELLY_BEAN_MR2) protected int getPackageUid(String packageName, int flags) throws NameNotFoundException { Integer uid = uidForPackage.get(packageName); if (uid == null) { throw new NameNotFoundException(packageName); } return uid; }
@Implementation protected ApplicationInfo getApplicationInfo(String packageName, int flags) throws NameNotFoundException { PackageInfo packageInfo = getPackageInfo(packageName, flags); if (packageInfo.applicationInfo == null) { throw new NameNotFoundException("Package found but without application info"); } // Maybe query app infos from overridden resolveInfo as well? return packageInfo.applicationInfo; }
@HiddenApi @Implementation(minSdk = P) protected boolean isPackageSuspended(String packageName) throws NameNotFoundException { PackageSetting setting = packageSettings.get(packageName); if (setting == null) { throw new NameNotFoundException(packageName); } return setting.isSuspended(); }
/** @see ShadowPackageManager#addPermissionGroupInfo(android.content.pm.PermissionGroupInfo) */ @Implementation protected PermissionGroupInfo getPermissionGroupInfo(String name, int flags) throws NameNotFoundException { if (permissionGroups.containsKey(name)) { return new PermissionGroupInfo(permissionGroups.get(name)); } throw new NameNotFoundException(name); }
@Test public void testUnresolvablePackageInfo() throws NameNotFoundException { Context context = mock(Context.class, Answers.RETURNS_DEEP_STUBS.get()); String packageName = "my.package"; when(context.getPackageName()).thenReturn(packageName); when(context.getPackageManager().getPackageInfo(packageName, 0)) .thenThrow(new NameNotFoundException("test")); Key key = ApplicationVersionSignature.obtain(context); assertNotNull(key); }