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

Commit efe0ef47 authored by Achim Thesmann's avatar Achim Thesmann
Browse files

Do not require BAL opt-in for Launchers

Launchers can be assumed to have the user's consent and need to launch
activities, so we grant their privileges by default without requiring the
launcher to opt in every single time.
This fixes multiple test that start when BAL priviliges by sender are restricted,

Test: atest android.content.pm.cts.shortcutmanager.ShortcutManagerStartShortcutTest
Bug: 265916225
Change-Id: I6c49cf5ec6af3c609f517f51836507dfca7aec50
parent 0b2ee80a
Loading
Loading
Loading
Loading
+26 −5
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.pm;
package com.android.server.pm;


import static android.app.ActivityOptions.KEY_SPLASH_SCREEN_THEME;
import static android.app.ActivityOptions.KEY_SPLASH_SCREEN_THEME;
import static android.app.ComponentOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED;
import static android.app.ComponentOptions.MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.app.PendingIntent.FLAG_MUTABLE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
@@ -1143,7 +1145,8 @@ public class LauncherAppsService extends SystemService {
            final int code;
            final int code;
            try {
            try {
                code = mActivityTaskManagerInternal.startActivitiesAsPackage(publisherPackage,
                code = mActivityTaskManagerInternal.startActivitiesAsPackage(publisherPackage,
                        publishedFeatureId, userId, intents, startActivityOptions);
                        publishedFeatureId, userId, intents,
                        getActivityOptionsForLauncher(startActivityOptions));
                if (ActivityManager.isStartResultSuccessful(code)) {
                if (ActivityManager.isStartResultSuccessful(code)) {
                    return true; // Success
                    return true; // Success
                } else {
                } else {
@@ -1158,6 +1161,23 @@ public class LauncherAppsService extends SystemService {
            }
            }
        }
        }


        private Bundle getActivityOptionsForLauncher(Bundle startActivityOptions) {
            // starting a shortcut implies the user's consent, so grant the launchers/senders BAL
            // privileges (unless the caller explicitly defined the behavior)
            if (startActivityOptions == null) {
                return ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode(
                                MODE_BACKGROUND_ACTIVITY_START_ALLOWED).toBundle();
            }
            ActivityOptions activityOptions = ActivityOptions.fromBundle(startActivityOptions);
            if (activityOptions.getPendingIntentBackgroundActivityStartMode()
                    == MODE_BACKGROUND_ACTIVITY_START_SYSTEM_DEFINED) {
                // only override if the property was not explicitly set
                return activityOptions.setPendingIntentBackgroundActivityStartMode(
                        MODE_BACKGROUND_ACTIVITY_START_ALLOWED).toBundle();
            }
            return startActivityOptions;
        }

        @Override
        @Override
        public boolean isActivityEnabled(
        public boolean isActivityEnabled(
                String callingPackage, ComponentName component, UserHandle user)
                String callingPackage, ComponentName component, UserHandle user)
@@ -1216,8 +1236,8 @@ public class LauncherAppsService extends SystemService {
            i.setSourceBounds(sourceBounds);
            i.setSourceBounds(sourceBounds);


            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, i, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK, opts,
                    callingFeatureId, i, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK,
                    userId);
                    getActivityOptionsForLauncher(opts), userId);
        }
        }


        @Override
        @Override
@@ -1264,7 +1284,8 @@ public class LauncherAppsService extends SystemService {


            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, launchIntent, /* resultTo= */ null,
                    callingFeatureId, launchIntent, /* resultTo= */ null,
                    Intent.FLAG_ACTIVITY_NEW_TASK, opts, user.getIdentifier());
                    Intent.FLAG_ACTIVITY_NEW_TASK, getActivityOptionsForLauncher(opts),
                    user.getIdentifier());
        }
        }


        /**
        /**
@@ -1347,7 +1368,7 @@ public class LauncherAppsService extends SystemService {
            }
            }
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
            mActivityTaskManagerInternal.startActivityAsUser(caller, callingPackage,
                    callingFeatureId, intent, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK,
                    callingFeatureId, intent, /* resultTo= */ null, Intent.FLAG_ACTIVITY_NEW_TASK,
                    opts, user.getIdentifier());
                    getActivityOptionsForLauncher(opts), user.getIdentifier());
        }
        }


        /** Checks if user is a profile of or same as listeningUser.
        /** Checks if user is a profile of or same as listeningUser.