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
This commit is contained in:
Louis Chang
2022-03-23 10:28:39 +08:00
parent 8cb7fb5bef
commit 544f9bb7a6

View File

@@ -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);
try {
mHandler.postDelayed(() -> mContext.startActivityAsUser(
grantPermission, options.toBundle(), user), ACTIVITY_START_DELAY_MS);
} catch (Exception e) {
Log.e(LOG_TAG, "couldn't start grant permission dialog"
+ "for other package " + pkgName, e);
}
mHandler.postDelayed(() -> {
try {
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