Example usage for android.content Intent EXTRA_PERMISSION_NAME

List of usage examples for android.content Intent EXTRA_PERMISSION_NAME

Introduction

In this page you can find the example usage for android.content Intent EXTRA_PERMISSION_NAME.

Prototype

String EXTRA_PERMISSION_NAME

To view the source code for android.content Intent EXTRA_PERMISSION_NAME.

Click Source Link

Document

Intent extra: The name of a permission.

Usage

From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java

private static <T extends Fragment> T setPermissionName(T fragment, String permissionName) {
    Bundle arguments = new Bundle();
    arguments.putString(Intent.EXTRA_PERMISSION_NAME, permissionName);
    fragment.setArguments(arguments);/*  www.  j a v  a2s  .c  o m*/
    return fragment;
}

From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setLoading(true /* loading */, false /* animate */);
    setHasOptionsMenu(true);//from  w w  w  .j  a  va2  s .  c o  m
    final ActionBar ab = getActivity().getActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }
    mLauncherPkgs = Utils.getLauncherPackages(getContext());

    String groupName = getArguments().getString(Intent.EXTRA_PERMISSION_NAME);
    mPermissionApps = new PermissionApps(getActivity(), groupName, this);
    mPermissionApps.refresh(true);
}

From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java

@Override
public void onPermissionsLoaded(PermissionApps permissionApps) {
    Context context = getPreferenceManager().getContext();

    if (context == null) {
        return;//from w ww.  j  ava  2  s  . c  o  m
    }

    boolean isTelevision = DeviceUtils.isTelevision(context);
    PreferenceScreen screen = getPreferenceScreen();

    ArraySet<String> preferencesToRemove = new ArraySet<>();
    for (int i = 0, n = screen.getPreferenceCount(); i < n; i++) {
        preferencesToRemove.add(screen.getPreference(i).getKey());
    }
    if (mExtraScreen != null) {
        for (int i = 0, n = mExtraScreen.getPreferenceCount(); i < n; i++) {
            preferencesToRemove.add(mExtraScreen.getPreference(i).getKey());
        }
    }

    for (PermissionApp app : permissionApps.getApps()) {
        if (!Utils.shouldShowPermission(app)) {
            continue;
        }

        String key = app.getKey();
        preferencesToRemove.remove(key);
        Preference existingPref = screen.findPreference(key);
        if (existingPref == null && mExtraScreen != null) {
            existingPref = mExtraScreen.findPreference(key);
        }

        boolean isSystemApp = Utils.isSystem(app, mLauncherPkgs);
        if (isSystemApp && !isTelevision && !mShowSystem) {
            if (existingPref != null) {
                screen.removePreference(existingPref);
            }
            continue;
        }

        if (existingPref != null) {
            // If existing preference - only update its state.
            if (app.isPolicyFixed()) {
                existingPref.setSummary(getString(R.string.permission_summary_enforced_by_policy));
            }
            existingPref.setPersistent(false);
            existingPref.setEnabled(!app.isPolicyFixed());
            if (existingPref instanceof SwitchPreference) {
                ((SwitchPreference) existingPref).setChecked(app.areRuntimePermissionsGranted());
            }
            continue;
        }

        SwitchPreference pref = new SwitchPreference(context);
        pref.setOnPreferenceChangeListener(this);
        pref.setKey(app.getKey());
        pref.setIcon(app.getIcon());
        pref.setTitle(app.getLabel());
        if (app.isPolicyFixed()) {
            pref.setSummary(getString(R.string.permission_summary_enforced_by_policy));
        }
        pref.setPersistent(false);
        pref.setEnabled(!app.isPolicyFixed());
        pref.setChecked(app.areRuntimePermissionsGranted());

        if (isSystemApp && isTelevision) {
            if (mExtraScreen == null) {
                mExtraScreen = getPreferenceManager().createPreferenceScreen(context);
            }
            mExtraScreen.addPreference(pref);
        } else {
            screen.addPreference(pref);
        }
    }

    if (mExtraScreen != null) {
        preferencesToRemove.remove(KEY_SHOW_SYSTEM_PREFS);
        Preference pref = screen.findPreference(KEY_SHOW_SYSTEM_PREFS);

        if (pref == null) {
            pref = new Preference(context);
            pref.setKey(KEY_SHOW_SYSTEM_PREFS);
            pref.setIcon(Utils.applyTint(context, R.drawable.ic_toc, android.R.attr.colorControlNormal));
            pref.setTitle(R.string.preference_show_system_apps);
            pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    SystemAppsFragment frag = new SystemAppsFragment();
                    setPermissionName(frag, getArguments().getString(Intent.EXTRA_PERMISSION_NAME));
                    frag.setTargetFragment(PermissionAppsFragment.this, 0);
                    getFragmentManager().beginTransaction().replace(android.R.id.content, frag)
                            .addToBackStack("SystemApps").commit();
                    return true;
                }
            });
            screen.addPreference(pref);
        }

        int grantedCount = 0;
        for (int i = 0, n = mExtraScreen.getPreferenceCount(); i < n; i++) {
            if (((SwitchPreference) mExtraScreen.getPreference(i)).isChecked()) {
                grantedCount++;
            }
        }
        pref.setSummary(getString(R.string.app_permissions_group_summary, grantedCount,
                mExtraScreen.getPreferenceCount()));
    }

    for (String key : preferencesToRemove) {
        Preference pref = screen.findPreference(key);
        if (pref != null) {
            screen.removePreference(pref);
        } else if (mExtraScreen != null) {
            pref = mExtraScreen.findPreference(key);
            if (pref != null) {
                mExtraScreen.removePreference(pref);
            }
        }
    }

    setLoading(false /* loading */, true /* animate */);

    if (mOnPermissionsLoadedListener != null) {
        mOnPermissionsLoadedListener.onPermissionsLoaded(permissionApps);
    }
}