List of usage examples for android.content Intent ACTION_GET_RESTRICTION_ENTRIES
String ACTION_GET_RESTRICTION_ENTRIES
To view the source code for android.content Intent ACTION_GET_RESTRICTION_ENTRIES.
Click Source Link
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
private void populateApps() { final Context context = getActivity(); if (context == null) return;//from w w w . jav a2 s.c o m final PackageManager pm = mPackageManager; final int userId = mUser.getIdentifier(); // Check if the user was removed in the meantime. if (getExistingUser(mUserManager, mUser) == null) { return; } mAppList.removeAll(); addLocationAppRestrictionsPreference(); Intent restrictionsIntent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES); final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(restrictionsIntent, 0); for (AppRestrictionsHelper.SelectableAppInfo app : mHelper.getVisibleApps()) { String packageName = app.packageName; if (packageName == null) continue; final boolean isSettingsApp = packageName.equals(context.getPackageName()); AppRestrictionsPreference p = new AppRestrictionsPreference(getPreferenceManager().getContext()); final boolean hasSettings = resolveInfoListHasPackage(receivers, packageName); if (isSettingsApp) { // Settings app should be available to restricted user mHelper.setPackageSelected(packageName, true); continue; } PackageInfo pi = null; try { pi = mIPm.getPackageInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_SIGNATURES, userId); } catch (RemoteException e) { // Ignore } if (pi == null) { continue; } if (mRestrictedProfile && isAppUnsupportedInRestrictedProfile(pi)) { continue; } p.setIcon(app.icon != null ? app.icon.mutate() : null); p.setChecked(false); p.setTitle(app.activityName); p.setKey(getKeyForPackage(packageName)); p.setPersistent(false); p.setOnPreferenceChangeListener(this); p.setSummary(getPackageSummary(pi, app)); if (pi.requiredForAllUsers || isPlatformSigned(pi)) { p.setChecked(true); p.setImmutable(true); // If the app is required and has no restrictions, skip showing it if (!hasSettings) continue; } else if (!mNewUser && isAppEnabledForUser(pi)) { p.setChecked(true); } if (app.masterEntry == null && hasSettings) { requestRestrictionsForApp(packageName, p); } if (app.masterEntry != null) { p.setImmutable(true); p.setChecked(mHelper.isPackageSelected(packageName)); } p.setOrder(MAX_APP_RESTRICTIONS * (mAppList.getPreferenceCount() + 2)); mHelper.setPackageSelected(packageName, p.isChecked()); mAppList.addPreference(p); } mAppListChanged = true; // If this is the first time for a new profile, install/uninstall default apps for profile // to avoid taking the hit in onPause(), which can cause race conditions on user switch. if (mNewUser && mFirstTime) { mFirstTime = false; mHelper.applyUserAppsStates(this); } }
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
/** * Send a broadcast to the app to query its restrictions * @param packageName package name of the app with restrictions * @param preference the preference item for the app toggle *///from ww w .jav a 2 s .c o m private void requestRestrictionsForApp(String packageName, AppRestrictionsPreference preference) { Bundle oldEntries = mUserManager.getApplicationRestrictions(packageName, mUser); Intent intent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES); intent.setPackage(packageName); intent.putExtra(Intent.EXTRA_RESTRICTIONS_BUNDLE, oldEntries); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); getActivity().sendOrderedBroadcast(intent, null, new RestrictionsResultReceiver(packageName, preference), null, Activity.RESULT_OK, null, null); }