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
This commit is contained in:
Himanshu Gupta
2024-02-15 20:00:33 +00:00
parent 772e0127c3
commit 4499fa60f9
2 changed files with 16 additions and 4 deletions

View File

@@ -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);
}
}