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

Commit 6ca90168 authored by Eugene Susla's avatar Eugene Susla
Browse files

Avoid aborting sms kill switch cleanup on unexpected exception

There was a report of a kill switch not working as intended, which seems
to be related to an unexpected exception happening during the cleanup:
https://paste.googleplex.com/6587646319001600

It's difficult to pinpoint the exact root cause, as it's only reproducible
on a userdebug device that is used as a personal one, so for now we should
at least take a precaution to ensure any such failure's effect is localized
to the problematic package/permission pair instead of bringing down the entire
process.

Bug: 124789865
Test: presubmit
Change-Id: I9f31954623fc22ac363d6fb8b1ceea3f6407214c
parent 200dc55b
Loading
Loading
Loading
Loading
+32 −24
Original line number Diff line number Diff line
@@ -182,12 +182,14 @@ public class RoleControllerServiceImpl extends RoleControllerService {
    void onSmsKillSwitchToggled(boolean smsRestrictionEnabled, PackageInfo pkg,
            List<PermissionInfo> permissions) {
        PackageManager pm = getPackageManager();
        int uid = pkg.applicationInfo.uid; //TODO multiuser support?
        int uid = pkg.applicationInfo.uid;

        for (int i = 0, permissionsSize = permissions.size(); i < permissionsSize; i++) {
            PermissionInfo permission = permissions.get(i);
            try {
                int permFlags =
                    pm.getPermissionFlags(permission.name, pkg.packageName, Process.myUserHandle());
                        pm.getPermissionFlags(permission.name, pkg.packageName,
                                Process.myUserHandle());

                if ((permFlags
                        & (PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT
@@ -209,10 +211,16 @@ public class RoleControllerServiceImpl extends RoleControllerService {
                }

                if (!smsRestrictionEnabled
                    && pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
                        && pkg.applicationInfo.targetSdkVersion
                        > Build.VERSION_CODES.LOLLIPOP_MR1) {
                    pm.revokeRuntimePermission(
                            pkg.packageName, permission.name, Process.myUserHandle());
                }
            } catch (Exception e) {
                Log.e(LOG_TAG, "Unexpected exception while cleaning up state for package "
                        + pkg.packageName + " & " + permission.name, e);
                continue;
            }
        }
    }