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

Commit 52f2c51e authored by Joel Galenson's avatar Joel Galenson
Browse files

Fix crash in permission grant screen.

Ensure we properly set mRequestedPermissions before finishing the activity.

Fixes: 132824645
Test: Force code down error paths and see no crash.
Change-Id: Ieb7e309ca140c92d6e73aceefd037d59bad4cdef
parent 7a557e31
Loading
Loading
Loading
Loading
+21 −21
Original line number Diff line number Diff line
@@ -265,6 +265,19 @@ public class GrantPermissionsActivity extends Activity

        setTitle(R.string.permission_request_title);

        mRequestedPermissions = getIntent().getStringArrayExtra(
                PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES);
        if (mRequestedPermissions == null) {
            mRequestedPermissions = new String[0];
        }

        final int requestedPermCount = mRequestedPermissions.length;

        if (requestedPermCount == 0) {
            setResultAndFinish();
            return;
        }

        PackageInfo callingPackageInfo = getCallingPackageInfo();

        if (callingPackageInfo == null || callingPackageInfo.requestedPermissions == null
@@ -273,6 +286,14 @@ public class GrantPermissionsActivity extends Activity
            return;
        }

        // Don't allow legacy apps to request runtime permissions.
        if (callingPackageInfo.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
            // Returning empty arrays means a cancellation.
            mRequestedPermissions = new String[0];
            setResultAndFinish();
            return;
        }

        mCallingUid = callingPackageInfo.applicationInfo.uid;

        UserHandle userHandle = UserHandle.getUserHandleForUid(mCallingUid);
@@ -292,27 +313,6 @@ public class GrantPermissionsActivity extends Activity
                    .setResultListener(this);
        }

        mRequestedPermissions = getIntent().getStringArrayExtra(
                PackageManager.EXTRA_REQUEST_PERMISSIONS_NAMES);
        if (mRequestedPermissions == null) {
            mRequestedPermissions = new String[0];
        }

        final int requestedPermCount = mRequestedPermissions.length;

        if (requestedPermCount == 0) {
            setResultAndFinish();
            return;
        }

        // Don't allow legacy apps to request runtime permissions.
        if (callingPackageInfo.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
            // Returning empty arrays means a cancellation.
            mRequestedPermissions = new String[0];
            setResultAndFinish();
            return;
        }

        mAppPermissions = new AppPermissions(this, callingPackageInfo, false,
                new Runnable() {
                    @Override