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

Commit c3e66d0d authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Do not ask NEW_TASK flag

When starting a app targeting pre-M for the first time we show the permission
review dialog before going to the actual activity.

I had to add the FLAG_ACTIVITY_MULTIPLE_TASK as otherwise other
permisison controller activities might get reused which is not
desireable.

I did add NEW_TASK, but this was wrong. Forcing a NEW_TASK means that
the result of the opened activity will not be given to the original
caller. This is an API break.

Now I add the FLAG_ACTIVITY_MULTIPLE_TASK only when needed.

There are deeper underlying issues with adding
FLAG_ACTIVITY_MULTIPLE_TASK which will be addressed later in 123541623.

Change-Id: I79564a38fdbc884ea735da6f7899972df83adedb
Fixes: 123707909
Test: - atest CtsAppSecurityHostTestCases:android.appsecurity.cts.PermissionsHostTest
parent 8c83a07c
Loading
Loading
Loading
Loading
+18 −5
Original line number Original line Diff line number Diff line
@@ -830,12 +830,25 @@ class ActivityStarter {
                        new String[]{resolvedType}, PendingIntent.FLAG_CANCEL_CURRENT
                        new String[]{resolvedType}, PendingIntent.FLAG_CANCEL_CURRENT
                                | PendingIntent.FLAG_ONE_SHOT, null);
                                | PendingIntent.FLAG_ONE_SHOT, null);


                final int flags = intent.getFlags();
                Intent newIntent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS);
                Intent newIntent = new Intent(Intent.ACTION_REVIEW_PERMISSIONS);
                newIntent.setFlags(flags

                        | FLAG_ACTIVITY_NEW_TASK
                int flags = intent.getFlags();
                        | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
                flags |= Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
                        | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

                /*
                 * Prevent reuse of review activity: Each app needs their own review activity. By
                 * default activities launched with NEW_TASK or NEW_DOCUMENT try to reuse activities
                 * with the same launch parameters (extras are ignored). Hence to avoid possible
                 * reuse force a new activity via the MULTIPLE_TASK flag.
                 *
                 * Activities that are not launched with NEW_TASK or NEW_DOCUMENT are not re-used,
                 * hence no need to add the flag in this case.
                 */
                if ((flags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_NEW_DOCUMENT)) != 0) {
                    flags |= Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
                }
                newIntent.setFlags(flags);

                newIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, aInfo.packageName);
                newIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, aInfo.packageName);
                newIntent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
                newIntent.putExtra(Intent.EXTRA_INTENT, new IntentSender(target));
                if (resultRecord != null) {
                if (resultRecord != null) {