From 3ec66fb33368085acc9fbb391bcdc5a88a2cf29a Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Tue, 30 Jan 2024 09:00:12 +0000 Subject: [PATCH] Preventing DragAndDrop for PS apps. This Cl restricts item dragging for PS apps from all launcher surfaces such as AllApps, AppPredictionRow, etc. Video: https://photos.app.goo.gl/PKGw8n23hJVJMyUk7 Flag: ACONFIG com.android.launcher3.Flags.private_space_restrict_item_drag DEVELOPMENT Bug: 289223923 Test: Ran Launcher3 tests Change-Id: I2c5dbaa325095ec63aedf39b6b2c269f745d58ca --- aconfig/launcher_search.aconfig | 7 +++++++ .../launcher3/allapps/PrivateProfileManager.java | 3 ++- .../android/launcher3/dragndrop/DragController.java | 10 ++++++++++ .../launcher3/dragndrop/LauncherDragController.java | 5 +++-- .../launcher3/popup/PopupContainerWithArrow.java | 13 ++++++++++--- .../secondarydisplay/SecondaryDragController.java | 6 ++++++ 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/aconfig/launcher_search.aconfig b/aconfig/launcher_search.aconfig index b84660402c..4e16e7fb2b 100644 --- a/aconfig/launcher_search.aconfig +++ b/aconfig/launcher_search.aconfig @@ -34,3 +34,10 @@ flag { description: "This flag disables accessibility drag for Private Space Apps." bug: "289223923" } + +flag { + name: "private_space_restrict_item_drag" + namespace: "launcher_search" + description: "This flag disables drag and drop for Private Space Items." + bug: "289223923" +} \ No newline at end of file diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java index 557ec486eb..6422943b07 100644 --- a/src/com/android/launcher3/allapps/PrivateProfileManager.java +++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java @@ -22,6 +22,7 @@ import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_PRIVATE import static com.android.launcher3.allapps.BaseAllAppsAdapter.VIEW_TYPE_PRIVATE_SPACE_SYS_APPS_DIVIDER; import static com.android.launcher3.allapps.SectionDecorationInfo.ROUND_NOTHING; import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_PRIVATE_PROFILE_QUIET_MODE_ENABLED; +import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_NOT_PINNABLE; import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_PRIVATE_SPACE_INSTALL_APP; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; @@ -109,7 +110,7 @@ public class PrivateProfileManager extends UserProfileManager { itemInfo.bitmap = bitmapInfo; itemInfo.contentDescription = context.getResources().getString( com.android.launcher3.R.string.ps_add_button_content_description); - itemInfo.runtimeStatusFlags |= FLAG_PRIVATE_SPACE_INSTALL_APP; + itemInfo.runtimeStatusFlags |= FLAG_PRIVATE_SPACE_INSTALL_APP | FLAG_NOT_PINNABLE; BaseAllAppsAdapter.AdapterItem item = new BaseAllAppsAdapter.AdapterItem(VIEW_TYPE_ICON); item.itemInfo = itemInfo; diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index 3ccde0ac6a..b6e5977b87 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -16,6 +16,8 @@ package com.android.launcher3.dragndrop; +import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_NOT_PINNABLE; + import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -29,8 +31,10 @@ import androidx.annotation.Nullable; import com.android.app.animation.Interpolators; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; +import com.android.launcher3.Flags; import com.android.launcher3.logging.InstanceId; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.TouchController; import com.android.launcher3.views.ActivityContext; @@ -221,6 +225,12 @@ public abstract class DragController } } + protected boolean isItemPinnable() { + return !Flags.privateSpaceRestrictItemDrag() + || !(mDragObject.dragInfo instanceof ItemInfoWithIcon itemInfoWithIcon) + || (itemInfoWithIcon.runtimeStatusFlags & FLAG_NOT_PINNABLE) == 0; + } + public Optional getLogInstanceId() { return Optional.ofNullable(mDragObject) .map(dragObject -> dragObject.logInstanceId); diff --git a/src/com/android/launcher3/dragndrop/LauncherDragController.java b/src/com/android/launcher3/dragndrop/LauncherDragController.java index da6f446725..f3708a2af6 100644 --- a/src/com/android/launcher3/dragndrop/LauncherDragController.java +++ b/src/com/android/launcher3/dragndrop/LauncherDragController.java @@ -149,9 +149,10 @@ public class LauncherDragController extends DragController { handleMoveEvent(mLastTouch.x, mLastTouch.y); - if (!mActivity.isTouchInProgress() && options.simulatedDndStartPoint == null) { + if (!isItemPinnable() + || (!mActivity.isTouchInProgress() && options.simulatedDndStartPoint == null)) { // If it is an internal drag and the touch is already complete, cancel immediately - MAIN_EXECUTOR.submit(this::cancelDrag); + MAIN_EXECUTOR.post(this::cancelDrag); } return dragView; } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index c9c5fd3d98..1c9db17822 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -19,6 +19,7 @@ package com.android.launcher3.popup; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.Utilities.squaredTouchSlop; +import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_NOT_PINNABLE; import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; @@ -44,6 +45,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; import com.android.launcher3.DropTarget.DragObject; +import com.android.launcher3.Flags; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; @@ -53,6 +55,7 @@ import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.model.data.ItemInfo; +import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; @@ -204,17 +207,21 @@ public class PopupContainerWithArrow .collect(Collectors.toList()); container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( R.layout.popup_container, launcher.getDragLayer(), false); - container.configureForLauncher(launcher); + container.configureForLauncher(launcher, item); container.populateAndShowRows(icon, deepShortcutCount, systemShortcuts); launcher.refreshAndBindWidgetsForPackageUser(PackageUserKey.fromItemInfo(item)); container.requestFocus(); return container; } - private void configureForLauncher(Launcher launcher) { + private void configureForLauncher(Launcher launcher, ItemInfo itemInfo) { addOnAttachStateChangeListener(new LauncherPopupLiveUpdateHandler( launcher, (PopupContainerWithArrow) this)); - mPopupItemDragHandler = new LauncherPopupItemDragHandler(launcher, this); + if (!Flags.privateSpaceRestrictItemDrag() + || !(itemInfo instanceof ItemInfoWithIcon itemInfoWithIcon) + || (itemInfoWithIcon.runtimeStatusFlags & FLAG_NOT_PINNABLE) == 0) { + mPopupItemDragHandler = new LauncherPopupItemDragHandler(launcher, this); + } mAccessibilityDelegate = new ShortcutMenuAccessibilityDelegate(launcher); launcher.getDragController().addDragListener(this); } diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java b/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java index 8d1d96b649..79b25a424f 100644 --- a/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java +++ b/src/com/android/launcher3/secondarydisplay/SecondaryDragController.java @@ -16,6 +16,8 @@ package com.android.launcher3.secondarydisplay; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; + import android.content.res.Resources; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -129,6 +131,10 @@ public class SecondaryDragController extends DragController