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

Commit 2ac97ce7 authored by Shijian Li's avatar Shijian Li
Browse files

DO NOT MERGE: Reset USER_FIXED if all permissions are revoked in a

group.

This is a functionality backport from ag/1823384.

Test: manually test with a local build.
Bug: 35621664
Change-Id: Id1d6ae875c7eedcd79b81ed9bbd5da6c5cc27513
parent 4f2e2ff4
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -450,12 +450,14 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
                                mUserHandle);
                    }
                } else {
                    if (!permission.isUserSet()) {
                    if (!permission.isUserSet() || permission.isUserFixed()) {
                        permission.setUserSet(true);
                        permission.setUserFixed(false);
                        // Take a note that the user already chose once.
                        mPackageManager.updatePermissionFlags(permission.getName(),
                                mPackageInfo.packageName,
                                PackageManager.FLAG_PERMISSION_USER_SET,
                                PackageManager.FLAG_PERMISSION_USER_SET
                                        | PackageManager.FLAG_PERMISSION_USER_FIXED,
                                PackageManager.FLAG_PERMISSION_USER_SET,
                                mUserHandle);
                    }
+32 −19
Original line number Diff line number Diff line
@@ -210,16 +210,15 @@ public final class AppPermissionsFragmentWear extends PreferenceFragment {
        pref.setOnPreferenceChangeListener((p, newVal) -> {
            if((Boolean) newVal) {
                group.grantRuntimePermissions(false, new String[]{ perm.name });
            } else {
                group.revokeRuntimePermissions(true, new String[]{ perm.name });
            }

                if (Utils.areGroupPermissionsIndividuallyControlled(getContext(), group.getName())
                        && group.doesSupportRuntimePermissions()) {
                // As long as one permission is changed in individually controlled group
                // permissions, we will set user_fixed for non-granted permissions in that group.
                // This avoids the system to automatically grant runtime permissions based on the
                // fact that one of dangerous permission in that group is already granted.
                    // We are granting a permission from a group but since this is an
                    // individual permission control other permissions in the group may
                    // be revoked, hence we need to mark them user fixed to prevent the
                    // app from requesting a non-granted permission and it being granted
                    // because another permission in the group is granted. This applies
                    // only to apps that support runtime permissions.
                    String[] revokedPermissionsToFix = null;
                    final int permissionCount = group.getPermissions().size();

@@ -232,9 +231,23 @@ public final class AppPermissionsFragmentWear extends PreferenceFragment {
                    }

                    if (revokedPermissionsToFix != null) {
                        // If some permissions were not granted then they should be fixed.
                        group.revokeRuntimePermissions(true, revokedPermissionsToFix);
                    }
                }
            } else {
                group.revokeRuntimePermissions(true, new String[]{ perm.name });

                if (Utils.areGroupPermissionsIndividuallyControlled(getContext(), group.getName())
                        && group.doesSupportRuntimePermissions()
                        && !group.areRuntimePermissionsGranted()) {
                    // If we just revoked the last permission we need to clear
                    // the user fixed state as now the app should be able to
                    // request them at runtime if supported.
                    group.revokeRuntimePermissions(false);
                }
            }

            return true;
        });
        return pref;