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
This commit is contained in:
Himanshu Gupta
2024-01-30 09:00:12 +00:00
parent ea73bf5d77
commit 3ec66fb333
6 changed files with 38 additions and 6 deletions

View File

@@ -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"
}

View File

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

View File

@@ -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<T extends ActivityContext>
}
}
protected boolean isItemPinnable() {
return !Flags.privateSpaceRestrictItemDrag()
|| !(mDragObject.dragInfo instanceof ItemInfoWithIcon itemInfoWithIcon)
|| (itemInfoWithIcon.runtimeStatusFlags & FLAG_NOT_PINNABLE) == 0;
}
public Optional<InstanceId> getLogInstanceId() {
return Optional.ofNullable(mDragObject)
.map(dragObject -> dragObject.logInstanceId);

View File

@@ -149,9 +149,10 @@ public class LauncherDragController extends DragController<Launcher> {
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;
}

View File

@@ -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<T extends Context & ActivityContext>
.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<Launcher>) 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);
}

View File

@@ -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<SecondaryDisplayLaun
dragView.show(mLastTouch.x, mLastTouch.y);
mDistanceSinceScroll = 0;
if (!isItemPinnable()) {
MAIN_EXECUTOR.post(this:: cancelDrag);
}
if (!mIsInPreDrag) {
callOnDragStart();
} else if (mOptions.preDragCondition != null) {