Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0414c82 authored by Svet Ganov's avatar Svet Ganov
Browse files

Required permissions individually controlled on review

This change allows individual permission control when the
permissions review feature is enabled only for permissions
that are required to be individually controlled as opposed
to all permissions in the group.

Test: Manually interacted with each permission group that
has granularly controlled permissions. Verified from the
shell that permissions are correctly granted or revoked.
The UI also shows the correct messages based on the number
of granted granular permissions.

Change-Id: I3c79fbfd126109b5af1fdb58480ab34c3cb36b1f
parent f33338ab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@
                </Button>

                <com.android.packageinstaller.permission.ui.ButtonBarLayout
                    android:id="@+id/button_group"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
+6 −6
Original line number Diff line number Diff line
@@ -153,15 +153,12 @@ public final class AllAppPermissionsFragment extends SettingsWithHeader {
                            continue;
                        }
                        PreferenceGroup pref = findOrCreate(group, pm, prefs);
                        // We allow individual permission control in some groups if review enabled
                        final boolean mutable = Utils.areGroupPermissionsIndividuallyControlled(
                                getContext(), group.name);
                        pref.addPreference(getPreference(info, perm, group, pm, mutable));
                        pref.addPreference(getPreference(info, perm, group, pm));
                    } else if (filterGroup == null) {
                        if (perm.protectionLevel == PermissionInfo.PROTECTION_NORMAL) {
                            PermissionGroupInfo group = getGroup(perm.group, pm);
                            otherGroup.addPreference(getPreference(info,
                                    perm, group, pm, false));
                                    perm, group, pm));
                        }
                    }

@@ -218,8 +215,11 @@ public final class AllAppPermissionsFragment extends SettingsWithHeader {
    }

    private Preference getPreference(PackageInfo packageInfo, PermissionInfo perm,
            PackageItemInfo group, PackageManager pm, boolean mutable) {
            PackageItemInfo group, PackageManager pm) {
        final Preference pref;

        // We allow individual permission control for some permissions if review enabled
        final boolean mutable = Utils.isPermissionIndividuallyControlled(getContext(), perm.name);
        if (mutable) {
            pref = new MyMultiTargetSwitchPreference(getContext(), packageInfo, perm.name);
        } else {
+3 −0
Original line number Diff line number Diff line
@@ -351,6 +351,9 @@ public final class AppPermissionsFragment extends SettingsWithHeader
        final int permissionCount = permissions.size();
        for (int i = 0; i < permissionCount; i++) {
            Permission permission = permissions.get(i);
            if (!Utils.isPermissionIndividuallyControlled(getContext(), permission.getName())) {
                continue;
            }
            if (group.doesSupportRuntimePermissions()
                    ? !permission.isGranted() : !permission.isAppOpAllowed()) {
                revokedCount++;
+16 −0
Original line number Diff line number Diff line
@@ -155,4 +155,20 @@ public final class Utils {
                || Manifest.permission_group.PHONE.equals(group)
                || Manifest.permission_group.CONTACTS.equals(group);
    }

    public static boolean isPermissionIndividuallyControlled(Context context, String permission) {
        if (!context.getResources().getBoolean(
                com.android.internal.R.bool.config_permissionReviewRequired)) {
            return false;
        }
        return Manifest.permission.READ_CONTACTS.equals(permission)
                || Manifest.permission.WRITE_CONTACTS.equals(permission)
                || Manifest.permission.SEND_SMS.equals(permission)
                || Manifest.permission.RECEIVE_SMS.equals(permission)
                || Manifest.permission.READ_SMS.equals(permission)
                || Manifest.permission.RECEIVE_MMS.equals(permission)
                || Manifest.permission.CALL_PHONE.equals(permission)
                || Manifest.permission.READ_CALL_LOG.equals(permission)
                || Manifest.permission.WRITE_CALL_LOG.equals(permission);
    }
}