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

Commit 4499fa60 authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

Preventing installed PS apps from moving to home screen

During app install in PS, promise app icons and the
installed app icons are added automatically on home screen.
In this change we restrict the same.
Also, checked that enabling `PROMISE_APP_IN_ALL_APPS` still
works for PS apps after this change.

Bug: 325057835
Test: Launcher3 tests
Flag: ACONFIG com.android.launcher3.Flags.private_space_restrict_item_drag TEAMFOOD
Change-Id: Iecff850bcc1cd17a123553a4258943da1ee61fcc
parent 772e0127
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.annotation.WorkerThread;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.util.Executors;

import java.util.Locale;
@@ -51,13 +52,13 @@ public class SessionCommitReceiver extends BroadcastReceiver {

    @WorkerThread
    private static void processIntent(Context context, Intent intent) {
        if (!isEnabled(context)) {
        UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
        if (!isEnabled(context, user)) {
            // User has decided to not add icons on homescreen.
            return;
        }

        SessionInfo info = intent.getParcelableExtra(PackageInstaller.EXTRA_SESSION);
        UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
        if (!PackageInstaller.ACTION_SESSION_COMMITTED.equals(intent.getAction())
                || info == null || user == null) {
            // Invalid intent.
@@ -92,7 +93,17 @@ public class SessionCommitReceiver extends BroadcastReceiver {
                .queueItem(info.getAppPackageName(), user);
    }

    public static boolean isEnabled(Context context) {
    /**
     * Returns whether adding Installed App Icons to home screen is allowed or not.
     * Not allowed when:
     * - User belongs to {@link com.android.launcher3.util.UserIconInfo.TYPE_PRIVATE} or
     * - Home Settings preference to add App Icons on Home Screen is set as disabled
     */
    public static boolean isEnabled(Context context, UserHandle user) {
        if (Flags.privateSpaceRestrictItemDrag() && user != null
                && UserCache.getInstance(context).getUserInfo(user).isPrivate()) {
            return false;
        }
        return LauncherPrefs.getPrefs(context).getBoolean(ADD_ICON_PREFERENCE_KEY, true);
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -211,7 +211,8 @@ public class InstallSessionHelper {
     */
    @WorkerThread
    void tryQueuePromiseAppIcon(@Nullable final PackageInstaller.SessionInfo sessionInfo) {
        if (SessionCommitReceiver.isEnabled(mAppContext)
        if (sessionInfo != null
                && SessionCommitReceiver.isEnabled(mAppContext, getUserHandle(sessionInfo))
                && verifySessionInfo(sessionInfo)
                && !promiseIconAddedForId(sessionInfo.getSessionId())) {
            FileLog.d(LOG, "Adding package name to install queue: "