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

Commit 544f9bb7 authored by Louis Chang's avatar Louis Chang
Browse files

Prevent the front-most activity entering pip

... when the permission prompt started on top.

Also catch the exception if start failed.

Bug: 225268867
Test: locally test via the test steps
Change-Id: Iaf3ceda746edabf98e99985817b9bf1d7c4c1f9d
parent 8cb7fb5b
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_FOREGROUND;
import static android.app.AppOpsManager.MODE_IGNORED;
import static android.app.AppOpsManager.OP_NONE;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NO_USER_ACTION;
import static android.content.pm.PackageManager.ACTION_REQUEST_PERMISSIONS;
import static android.content.pm.PackageManager.ACTION_REQUEST_PERMISSIONS_FOR_OTHER;
import static android.content.pm.PackageManager.FLAG_PERMISSION_APPLY_RESTRICTION;
@@ -1181,6 +1183,8 @@ public final class PermissionPolicyService extends SystemService {
                int taskId) {
            Intent grantPermission = mPackageManager
                    .buildRequestPermissionsIntent(new String[] { POST_NOTIFICATIONS });
            // Prevent the front-most activity entering pip due to overlay activity started on top.
            grantPermission.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NO_USER_ACTION);
            grantPermission.setAction(
                    ACTION_REQUEST_PERMISSIONS_FOR_OTHER);
            grantPermission.putExtra(Intent.EXTRA_PACKAGE_NAME, pkgName);
@@ -1188,13 +1192,15 @@ public final class PermissionPolicyService extends SystemService {
            ActivityOptions options = new ActivityOptions(new Bundle());
            options.setTaskOverlay(true, false);
            options.setLaunchTaskId(taskId);
            mHandler.postDelayed(() -> {
                try {
                mHandler.postDelayed(() -> mContext.startActivityAsUser(
                        grantPermission, options.toBundle(), user), ACTIVITY_START_DELAY_MS);
                    mContext.startActivityAsUser(
                            grantPermission, options.toBundle(), user);
                } catch (Exception e) {
                    Log.e(LOG_TAG, "couldn't start grant permission dialog"
                            + "for other package " + pkgName, e);
                }
            }, ACTIVITY_START_DELAY_MS);
        }

        @Override