List of usage examples for android.content.pm PackageManager GET_RECEIVERS
int GET_RECEIVERS
To view the source code for android.content.pm PackageManager GET_RECEIVERS.
Click Source Link
From source file:org.adaway.util.ScanAdwareLoader.java
/** * Finds all installed packages that look like they include a known ad framework *///w w w . j av a 2 s . c o m private List<PackageInfo> getAdPackages() { Set<PackageInfo> adPackages = new HashSet<PackageInfo>(); PackageManager pm = context.getPackageManager(); // It'd be simpler to just use pm.getInstalledPackages here, but apparently it's broken List<ApplicationInfo> appInfos = pm.getInstalledApplications(0); for (ApplicationInfo appInfo : appInfos) { if (canceled) { adPackages.clear(); break; } try { PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES); Log.v(Constants.TAG, "Scanning package " + pkgInfo.packageName); if (pkgInfo.activities != null) { for (ActivityInfo activity : pkgInfo.activities) { Log.v(Constants.TAG, "[ACTIVITY] " + activity.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (activity.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as activity " + activity.name); adPackages.add(pkgInfo); } } } } if (pkgInfo.receivers != null) { for (ActivityInfo receiver : pkgInfo.receivers) { Log.v(Constants.TAG, "[RECEIVER] " + receiver.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (receiver.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as receiver " + receiver.name); adPackages.add(pkgInfo); break; } } } } if (pkgInfo.services != null) { for (ServiceInfo service : pkgInfo.services) { Log.v(Constants.TAG, "[SERVICE] " + service.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (service.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as service " + service.name); adPackages.add(pkgInfo); break; } } } } } catch (Exception e) { Log.e(Constants.TAG, "Scan Adware Exception", e); } } return new ArrayList<PackageInfo>(adPackages); }
From source file:com.google.android.gcm.GCMRegistrar.java
/** * Checks that the application manifest is properly configured. * <p>/* w w w .ja va2s.c om*/ * A proper configuration means: * <ol> * <li>It creates a custom permission called * {@code PACKAGE_NAME.permission.C2D_MESSAGE}. * <li>It defines at least one {@link BroadcastReceiver} with category * {@code PACKAGE_NAME}. * <li>The {@link BroadcastReceiver}(s) uses the * {@value GCMConstants#PERMISSION_GCM_INTENTS} permission. * <li>The {@link BroadcastReceiver}(s) handles the 3 GCM intents * ({@value GCMConstants#INTENT_FROM_GCM_MESSAGE}, * {@value GCMConstants#INTENT_FROM_GCM_REGISTRATION_CALLBACK}, * and {@value GCMConstants#INTENT_FROM_GCM_LIBRARY_RETRY}). * </ol> * ...where {@code PACKAGE_NAME} is the application package. * <p> * This method should be used during development time to verify that the * manifest is properly set up, but it doesn't need to be called once the * application is deployed to the users' devices. * * @param context application context. * @throws IllegalStateException if any of the conditions above is not met. */ public static void checkManifest(Context context) { PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); String permissionName = packageName + ".permission.C2D_MESSAGE"; // check permission try { packageManager.getPermissionInfo(permissionName, PackageManager.GET_PERMISSIONS); } catch (NameNotFoundException e) { throw new IllegalStateException("Application does not define permission " + permissionName); } // check receivers PackageInfo receiversInfo; try { receiversInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_RECEIVERS); } catch (NameNotFoundException e) { throw new IllegalStateException("Could not get receivers for package " + packageName); } ActivityInfo[] receivers = receiversInfo.receivers; if (receivers == null || receivers.length == 0) { throw new IllegalStateException("No receiver for package " + packageName); } if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "number of receivers for " + packageName + ": " + receivers.length); } Set<String> allowedReceivers = new HashSet<String>(); for (ActivityInfo receiver : receivers) { if (GCMConstants.PERMISSION_GCM_INTENTS.equals(receiver.permission)) { allowedReceivers.add(receiver.name); } } if (allowedReceivers.isEmpty()) { throw new IllegalStateException( "No receiver allowed to receive " + GCMConstants.PERMISSION_GCM_INTENTS); } checkReceiver(context, allowedReceivers, GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK); checkReceiver(context, allowedReceivers, GCMConstants.INTENT_FROM_GCM_MESSAGE); }
From source file:com.github.michalbednarski.intentslab.AppComponentsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPackageName = ((AppInfoHost) getActivity()).getViewedPackageName(); final PackageManager packageManager = getActivity().getPackageManager(); ArrayList<Integer> presentSections = new ArrayList<Integer>(); try {//from w w w .java 2s .c o m final PackageInfo packageInfo = packageManager.getPackageInfo(mPackageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_PROVIDERS | PackageManager.GET_PERMISSIONS); // Scan activities and group them as exported and not exported { ArrayList<ActivityInfo> exportedActivities = new ArrayList<ActivityInfo>(); ArrayList<ActivityInfo> notExportedActivities = new ArrayList<ActivityInfo>(); if (packageInfo.activities != null && packageInfo.activities.length != 0) { for (ActivityInfo activity : packageInfo.activities) { (activity.exported ? exportedActivities : notExportedActivities).add(activity); } } if (exportedActivities.size() != 0) { mActivities = exportedActivities.toArray(new ComponentInfo[exportedActivities.size()]); presentSections.add(SECTION_ACTIVITIES); } if (notExportedActivities.size() != 0) { mActivitiesNotExported = notExportedActivities .toArray(new ComponentInfo[notExportedActivities.size()]); presentSections.add(SECTION_ACTIVITIES_NOT_EXPORTED); } } // Check receivers, services and providers if (packageInfo.receivers != null) { mReceivers = packageInfo.receivers; presentSections.add(SECTION_RECEIVERS); } if (packageInfo.services != null) { mServices = packageInfo.services; presentSections.add(SECTION_SERVICES); } if (packageInfo.providers != null) { mProviders = packageInfo.providers; presentSections.add(SECTION_PROVIDERS); } // Scan defined permissions if (packageInfo.permissions != null) { mDefinedPermissions = new String[packageInfo.permissions.length]; for (int i = 0; i < packageInfo.permissions.length; i++) { mDefinedPermissions[i] = packageInfo.permissions[i].name; } presentSections.add(SECTION_DEFINED_PERMISSIONS); } // Scan requested permissions (granted and denied) HashSet<String> testedPermissions = new HashSet<String>(); if (packageInfo.requestedPermissions != null) { ArrayList<String> grantedPermissions = new ArrayList<String>(); ArrayList<String> deniedPermissions = new ArrayList<String>(); for (String permission : packageInfo.requestedPermissions) { if (packageManager.checkPermission(permission, mPackageName) == PackageManager.PERMISSION_GRANTED) { grantedPermissions.add(permission); } else { deniedPermissions.add(permission); } testedPermissions.add(permission); } if (grantedPermissions.size() != 0) { mGrantedPermissions = grantedPermissions.toArray(new String[grantedPermissions.size()]); presentSections.add(SECTION_GRANTED_PERMISSIONS); } if (deniedPermissions.size() != 0) { mDeniedPermissions = deniedPermissions.toArray(new String[deniedPermissions.size()]); presentSections.add(SECTION_DENIED_PERMISSIONS); } } // Scan shared user packages for permissions (implicitly granted) { ArrayList<String> implicitlyGrantedPermissions = new ArrayList<String>(); for (String sharedUidPackageName : packageManager .getPackagesForUid(packageInfo.applicationInfo.uid)) { if (mPackageName.equals(sharedUidPackageName)) { continue; } final PackageInfo sharedUidPackageInfo = packageManager.getPackageInfo(sharedUidPackageName, PackageManager.GET_PERMISSIONS); if (sharedUidPackageInfo.requestedPermissions == null) { continue; } for (String permission : sharedUidPackageInfo.requestedPermissions) { if (!testedPermissions.contains(permission)) { testedPermissions.add(permission); if (packageManager.checkPermission(permission, mPackageName) == PackageManager.PERMISSION_GRANTED) { implicitlyGrantedPermissions.add(permission); } } } } if (implicitlyGrantedPermissions.size() != 0) { mImplicitlyGrantedPermissions = implicitlyGrantedPermissions .toArray(new String[implicitlyGrantedPermissions.size()]); presentSections.add(SECTION_IMPLICITLY_GRANTED_PERMISSIONS); } } // Save present sections list as array mPresentSections = new int[presentSections.size()]; for (int i = 0; i < presentSections.size(); i++) { mPresentSections[i] = presentSections.get(i); } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override Object getEntries(Context context) { PackageManager pm = context.getPackageManager(); int requestedPackageInfoFlags = type | PackageManager.GET_DISABLED_COMPONENTS | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0); boolean workAroundSmallBinderBuffer = false; List<PackageInfo> allPackages = null; try {/*from w w w .j a va 2 s. c o m*/ allPackages = pm.getInstalledPackages(requestedPackageInfoFlags); } catch (Exception e) { Log.w(TAG, "Loading all apps at once failed, retrying separately", e); } if (allPackages == null || allPackages.isEmpty()) { workAroundSmallBinderBuffer = true; allPackages = pm.getInstalledPackages(0); } ArrayList<Category> selectedApps = new ArrayList<Category>(); for (PackageInfo pack : allPackages) { // Filter out non-applications if (pack.applicationInfo == null) { continue; } // System app filter if ((((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER) & appType) == 0) { continue; } // Load component information separately if they were to big to send them all at once if (workAroundSmallBinderBuffer) { try { pack = pm.getPackageInfo(pack.packageName, requestedPackageInfoFlags); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "getPackageInfo() thrown NameNotFoundException for " + pack.packageName, e); continue; } } // Scan components ArrayList<Component> selectedComponents = new ArrayList<Component>(); if ((type & PackageManager.GET_ACTIVITIES) != 0) { scanComponents(pm, pack.activities, selectedComponents); } if ((type & PackageManager.GET_RECEIVERS) != 0) { scanComponents(pm, pack.receivers, selectedComponents); } if ((type & PackageManager.GET_SERVICES) != 0) { scanComponents(pm, pack.services, selectedComponents); } if ((type & PackageManager.GET_PROVIDERS) != 0) { scanComponents(pm, pack.providers, selectedComponents); } // Check if we filtered out all components and skip whole app if so if (selectedComponents.isEmpty()) { continue; } // Build and add app descriptor Category app = new Category(); app.title = String.valueOf(pack.applicationInfo.loadLabel(pm)); app.subtitle = pack.packageName; app.components = selectedComponents.toArray(new Component[selectedComponents.size()]); selectedApps.add(app); // Allow cancelling task if (Thread.interrupted()) { return null; } } return selectedApps.toArray(new Category[selectedApps.size()]); }
From source file:org.hansel.myAlert.LocationManagement.java
private boolean isGPSToggleable() { PackageManager pacman = getApplication().getPackageManager(); PackageInfo pacInfo = null;/*www . j a v a 2 s .c om*/ Log.v("Intenamos ver si se puede activar GPS"); try { pacInfo = pacman.getPackageInfo("com.android.settings", PackageManager.GET_RECEIVERS); } catch (NameNotFoundException e) { return false; } if (pacInfo != null) { for (ActivityInfo actInfo : pacInfo.receivers) { if (actInfo.name.equals("com.android.settings.widget.SettingsAppWidgetProvider") && actInfo.exported) { return true; } } } return false; }
From source file:com.github.michalbednarski.intentslab.browser.BrowseComponentsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (mFetcher.onOptionsItemSelected(itemId)) { setFetcher(mFetcher);/*from w w w. j a v a 2s . c o m*/ return true; } switch (itemId) { case R.id.custom_filter: FetcherOptionsDialog fetcherOptionsDialog = new FetcherOptionsDialog(); fetcherOptionsDialog.setTargetFragment(this, 0); fetcherOptionsDialog.show(getFragmentManager(), "filterOptions"); return true; case R.id.activities: case R.id.broadcasts: case R.id.services: case R.id.content_providers: { // Fetcher isn't component fetcher, otherwise it would intercept this above ComponentFetcher fetcher = new ComponentFetcher(); fetcher.type = itemId == R.id.activities ? PackageManager.GET_ACTIVITIES : itemId == R.id.broadcasts ? PackageManager.GET_RECEIVERS : itemId == R.id.services ? PackageManager.GET_SERVICES : itemId == R.id.content_providers ? PackageManager.GET_PROVIDERS : 0; if (mFetcher instanceof ApplicationFetcher) { fetcher.appType = ((ApplicationFetcher) mFetcher).appType; } setFetcher(fetcher); return true; } case R.id.applications: { if (!(mFetcher instanceof ApplicationFetcher)) { ApplicationFetcher fetcher = new ApplicationFetcher(); if (mFetcher instanceof ComponentFetcher) { fetcher.appType = ((ComponentFetcher) mFetcher).appType; } setFetcher(fetcher); } return true; } } return super.onOptionsItemSelected(item); }
From source file:com.anysoftkeyboard.addons.AddOnsFactory.java
private boolean isPackageContainAnAddon(String packageNameSchemePart) throws NameNotFoundException { PackageInfo newPackage = mContext.getPackageManager().getPackageInfo(packageNameSchemePart, PackageManager.GET_RECEIVERS + PackageManager.GET_META_DATA); if (newPackage.receivers != null) { ActivityInfo[] receivers = newPackage.receivers; for (ActivityInfo aReceiver : receivers) { //issue 904 if (aReceiver == null || aReceiver.applicationInfo == null || !aReceiver.enabled || !aReceiver.applicationInfo.enabled) continue; final XmlPullParser xml = aReceiver.loadXmlMetaData(mContext.getPackageManager(), mReceiverMetaData);/* ww w. j av a2 s .c o m*/ if (xml != null) { return true; } } } return false; }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override void initConfigurationForm(final FetcherOptionsDialog dialog) { // Disable development permission checkbox if it's not available if (!DEVELOPMENT_PERMISSIONS_SUPPORTED) { dialog.findView(R.id.permission_filter_development).setEnabled(false); }/* www.java2 s . c o m*/ // Prepare protection preset spinner { // Find current preset int currentPresetId = PROTECTION_PRESETS.length; // "Custom" if nothing found if (!testWritePermissionForProviders) { for (int i = 0; i < PROTECTION_PRESETS.length; i++) { if (protection == PROTECTION_PRESETS[i]) { currentPresetId = i; dialog.findView(R.id.permission_filter_details).setVisibility(View.GONE); break; } } } // Fill spinner Spinner protectionPresetSpinner = (Spinner) dialog.findView(R.id.permission_filter_spinner); Activity activity = dialog.getActivity(); protectionPresetSpinner .setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, new String[] { activity.getString(R.string.permission_filter_show_all), // 0 activity.getString(R.string.permission_filter_show_exported), // 1 activity.getString(R.string.permission_filter_show_obtainable), // 2 activity.getString(R.string.permission_filter_world_accessible), // 3 activity.getString(R.string.filter_custom) // 4 })); protectionPresetSpinner.setSelection(currentPresetId); // Set up spinner event protectionPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { boolean isCustom = position == PROTECTION_PRESETS.length; if (!isCustom) { int preset = PROTECTION_PRESETS[position]; dialog.setBoxChecked(R.id.permission_filter_world_accessible, (preset & PROTECTION_WORLD_ACCESSIBLE) != 0); dialog.setBoxChecked(R.id.permission_filter_normal, (preset & PROTECTION_NORMAL) != 0); dialog.setBoxChecked(R.id.permission_filter_dangerous, (preset & PROTECTION_DANGEROUS) != 0); dialog.setBoxChecked(R.id.permission_filter_signature, (preset & PROTECTION_SIGNATURE) != 0); dialog.setBoxChecked(R.id.permission_filter_system, (preset & PROTECTION_SYSTEM) != 0); dialog.setBoxChecked(R.id.permission_filter_development, (preset & PROTECTION_DEVELOPMENT) != 0); dialog.setBoxChecked(R.id.permission_filter_unexported, (preset & PROTECTION_UNEXPORTED) != 0); dialog.setBoxChecked(R.id.permission_filter_unknown, (preset & PROTECTION_UNKNOWN) != 0); dialog.setBoxChecked(R.id.read_permission, true); } dialog.findView(R.id.permission_filter_details) .setVisibility(isCustom ? View.VISIBLE : View.GONE); } @Override public void onNothingSelected(AdapterView<?> parent) { // Spinner cannot have nothing selected } }); } // Fill form dialog.setBoxChecked(R.id.system_apps, (appType & APP_TYPE_SYSTEM) != 0); dialog.setBoxChecked(R.id.user_apps, (appType & APP_TYPE_USER) != 0); dialog.setBoxChecked(R.id.activities, (type & PackageManager.GET_ACTIVITIES) != 0); dialog.setBoxChecked(R.id.receivers, (type & PackageManager.GET_RECEIVERS) != 0); dialog.setBoxChecked(R.id.services, (type & PackageManager.GET_SERVICES) != 0); dialog.setBoxChecked(R.id.content_providers, (type & PackageManager.GET_PROVIDERS) != 0); dialog.setBoxChecked(R.id.permission_filter_world_accessible, (protection & PROTECTION_WORLD_ACCESSIBLE) != 0); dialog.setBoxChecked(R.id.permission_filter_normal, (protection & PROTECTION_NORMAL) != 0); dialog.setBoxChecked(R.id.permission_filter_dangerous, (protection & PROTECTION_DANGEROUS) != 0); dialog.setBoxChecked(R.id.permission_filter_signature, (protection & PROTECTION_SIGNATURE) != 0); dialog.setBoxChecked(R.id.permission_filter_system, (protection & PROTECTION_SYSTEM) != 0); dialog.setBoxChecked(R.id.permission_filter_development, (protection & PROTECTION_DEVELOPMENT) != 0); dialog.setBoxChecked(R.id.permission_filter_unexported, (protection & PROTECTION_UNEXPORTED) != 0); dialog.setBoxChecked(R.id.permission_filter_unknown, (protection & PROTECTION_UNKNOWN) != 0); dialog.setBoxChecked(testWritePermissionForProviders ? R.id.write_permission : R.id.read_permission, true); dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, includeOnlyProvidersAllowingPermissionGranting); dialog.setBoxChecked(R.id.metadata, requireMetaDataSubstring != null); dialog.setTextInField(R.id.metadata_substring, requireMetaDataSubstring); // Set up sections showing when their checkboxes are checked dialog.findView(R.id.content_provider_permission_type) .setVisibility(testWritePermissionForProviders ? View.VISIBLE : View.GONE); dialog.findView(R.id.content_provider_options) .setVisibility((type & PackageManager.GET_PROVIDERS) != 0 ? View.VISIBLE : View.GONE); ((CheckBox) dialog.findView(R.id.content_providers)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { dialog.findView(R.id.content_provider_permission_type) .setVisibility(isChecked ? View.VISIBLE : View.GONE); dialog.findView(R.id.content_provider_options) .setVisibility(isChecked ? View.VISIBLE : View.GONE); if (!isChecked) { dialog.setBoxChecked(R.id.read_permission, true); dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, false); } } }); dialog.findView(R.id.metadata_details) .setVisibility(requireMetaDataSubstring != null ? View.VISIBLE : View.GONE); ((CheckBox) dialog.findView(R.id.metadata)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { dialog.findView(R.id.metadata_details).setVisibility(isChecked ? View.VISIBLE : View.GONE); if (!isChecked) { dialog.setTextInField(R.id.metadata_substring, ""); } } }); }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override void updateFromConfigurationForm(FetcherOptionsDialog dialog) { appType = (dialog.isBoxChecked(R.id.system_apps) ? APP_TYPE_SYSTEM : 0) | (dialog.isBoxChecked(R.id.user_apps) ? APP_TYPE_USER : 0); type = (dialog.isBoxChecked(R.id.activities) ? PackageManager.GET_ACTIVITIES : 0) | (dialog.isBoxChecked(R.id.receivers) ? PackageManager.GET_RECEIVERS : 0) | (dialog.isBoxChecked(R.id.services) ? PackageManager.GET_SERVICES : 0) | (dialog.isBoxChecked(R.id.content_providers) ? PackageManager.GET_PROVIDERS : 0); protection = (dialog.isBoxChecked(R.id.permission_filter_world_accessible) ? PROTECTION_WORLD_ACCESSIBLE : 0) | (dialog.isBoxChecked(R.id.permission_filter_normal) ? PROTECTION_NORMAL : 0) | (dialog.isBoxChecked(R.id.permission_filter_dangerous) ? PROTECTION_DANGEROUS : 0) | (dialog.isBoxChecked(R.id.permission_filter_signature) ? PROTECTION_SIGNATURE : 0) | (dialog.isBoxChecked(R.id.permission_filter_system) ? PROTECTION_SYSTEM : 0) | (dialog.isBoxChecked(R.id.permission_filter_development) ? PROTECTION_DEVELOPMENT : 0) | (dialog.isBoxChecked(R.id.permission_filter_unexported) ? PROTECTION_UNEXPORTED : 0) | (dialog.isBoxChecked(R.id.permission_filter_unknown) ? PROTECTION_UNKNOWN : 0); includeOnlyProvidersAllowingPermissionGranting = dialog .isBoxChecked(R.id.only_providers_with_grant_uri_permission); boolean requireMetaData = dialog.isBoxChecked(R.id.metadata); requireMetaDataSubstring = requireMetaData ? dialog.getTextFromField(R.id.metadata_substring) : null; testWritePermissionForProviders = dialog.isBoxChecked(R.id.write_permission); }
From source file:android.content.pm.PackageParser.java
public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags, long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state, int userId) { if (!checkUseInstalledOrHidden(flags, state)) { return null; }/* ww w . j av a 2 s .c o m*/ PackageInfo pi = new PackageInfo(); pi.packageName = p.packageName; pi.splitNames = p.splitNames; pi.versionCode = p.mVersionCode; pi.baseRevisionCode = p.baseRevisionCode; pi.splitRevisionCodes = p.splitRevisionCodes; pi.versionName = p.mVersionName; pi.sharedUserId = p.mSharedUserId; pi.sharedUserLabel = p.mSharedUserLabel; pi.applicationInfo = generateApplicationInfo(p, flags, state, userId); pi.installLocation = p.installLocation; pi.coreApp = p.coreApp; if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { pi.requiredForAllUsers = p.mRequiredForAllUsers; } pi.restrictedAccountType = p.mRestrictedAccountType; pi.requiredAccountType = p.mRequiredAccountType; pi.overlayTarget = p.mOverlayTarget; pi.firstInstallTime = firstInstallTime; pi.lastUpdateTime = lastUpdateTime; if ((flags & PackageManager.GET_GIDS) != 0) { pi.gids = gids; } if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) { int N = p.configPreferences != null ? p.configPreferences.size() : 0; if (N > 0) { pi.configPreferences = new ConfigurationInfo[N]; p.configPreferences.toArray(pi.configPreferences); } N = p.reqFeatures != null ? p.reqFeatures.size() : 0; if (N > 0) { pi.reqFeatures = new FeatureInfo[N]; p.reqFeatures.toArray(pi.reqFeatures); } N = p.featureGroups != null ? p.featureGroups.size() : 0; if (N > 0) { pi.featureGroups = new FeatureGroupInfo[N]; p.featureGroups.toArray(pi.featureGroups); } } if ((flags & PackageManager.GET_ACTIVITIES) != 0) { int N = p.activities.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities = new ActivityInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.activities.get(i).info.enabled) num++; } pi.activities = new ActivityInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Activity activity = p.activities.get(i); if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.activities[j++] = generateActivityInfo(p.activities.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_RECEIVERS) != 0) { int N = p.receivers.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.receivers = new ActivityInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.receivers.get(i).info.enabled) num++; } pi.receivers = new ActivityInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Activity activity = p.receivers.get(i); if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.receivers[j++] = generateActivityInfo(p.receivers.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_SERVICES) != 0) { int N = p.services.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.services = new ServiceInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.services.get(i).info.enabled) num++; } pi.services = new ServiceInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Service service = p.services.get(i); if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.services[j++] = generateServiceInfo(p.services.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_PROVIDERS) != 0) { int N = p.providers.size(); if (N > 0) { if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers = new ProviderInfo[N]; } else { int num = 0; for (int i = 0; i < N; i++) { if (p.providers.get(i).info.enabled) num++; } pi.providers = new ProviderInfo[num]; } for (int i = 0, j = 0; i < N; i++) { final Provider provider = p.providers.get(i); if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) { pi.providers[j++] = generateProviderInfo(p.providers.get(i), flags, state, userId); } } } } if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) { int N = p.instrumentation.size(); if (N > 0) { pi.instrumentation = new InstrumentationInfo[N]; for (int i = 0; i < N; i++) { pi.instrumentation[i] = generateInstrumentationInfo(p.instrumentation.get(i), flags); } } } if ((flags & PackageManager.GET_PERMISSIONS) != 0) { int N = p.permissions.size(); if (N > 0) { pi.permissions = new PermissionInfo[N]; for (int i = 0; i < N; i++) { pi.permissions[i] = generatePermissionInfo(p.permissions.get(i), flags); } } N = p.requestedPermissions.size(); if (N > 0) { pi.requestedPermissions = new String[N]; pi.requestedPermissionsFlags = new int[N]; for (int i = 0; i < N; i++) { final String perm = p.requestedPermissions.get(i); pi.requestedPermissions[i] = perm; // The notion of required permissions is deprecated but for compatibility. pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_REQUIRED; if (grantedPermissions != null && grantedPermissions.contains(perm)) { pi.requestedPermissionsFlags[i] |= PackageInfo.REQUESTED_PERMISSION_GRANTED; } } } } if ((flags & PackageManager.GET_SIGNATURES) != 0) { int N = (p.mSignatures != null) ? p.mSignatures.length : 0; if (N > 0) { pi.signatures = new Signature[N]; System.arraycopy(p.mSignatures, 0, pi.signatures, 0, N); } } return pi; }