Files
Flexera-Launcher/src/com/android/launcher3/SecondaryDropTarget.java
T
Tracy Zhou b6af1d0efc Merging ub-launcher3-master, build 5945220
Test: Manual
Bug:123904290 P2 Remove magic constants from TAPL
Bug:130294785 P3 Can no longer long press to open settings in hotseat area
Bug:131115553 P2 Enable CacheDataUpdatedTaskTest tests
Bug:134712476 P4 Add Duo contact to home screen, icon froze and vanished while over home screen
Bug:136278866 P2 Temporary workarounds to make tests pass on Cuttlefish
Bug:136829198 P2 Scrolling Overview During Quickswitch causes switch with weird animation
Bug:137568159 P4 Refactor LauncherCallback to support multiple clients
Bug:137777105 P1 Make clearcut launcher logging feature parity with westworld logging
Bug:137851409 P4 Jank during swipe up due to inflation
Bug:138620399 P1 Quick switch flicker / artifacts
Bug:139016518 P2 [PinnedStackController] Move shelf offset into sysui
Bug:139137636 P2 Create memory tests for Launcher
Bug:139258979 P2 Switch to the screenshot mode when then system passes ThumbnailData back upon RecentsAnimation cancelation
Bug:139259253 P2 Transform multiple app surfaces during app open animation from overview
Bug:139439373 P2 Live tile should switch to screenshot before finishing recents animation
Bug:139828243 P2 Create a prototype for Overview screenshot actions with a SystemUI plugin
Bug:139888225 P2 Convert custom widget into plugins
Bug:139913027 P2 [a11y] App title in Widget list shouldn't be actionable by a11y methods. (It would cause Pixel launcher crash.)
Bug:139917483 P1 [B1C1][Dec19_QPR][CTS_Verifier_10_r1]Pixel launcher crash observed in Device owner test-> Lock Task UI
Bug:139941530 P2 Lab-only Flake: Launcher switches to All Apps after pressing Recents button
Bug:140212732 P2 [PO Cable] Strange launcher behavior after restore
Bug:140242324 P2 Cache shortcutInfo icons in Launcher
Bug:140246642 P4 Add binder tests for launcher interactions
Bug:140311911 P2 Flake in Launcher tests: java.lang.AssertionError: Stable state != state: OverviewState, LauncherState
Bug:140406263 P2 [a11y] Unable to scroll to the left of the main Home screen to Display google app by Voice access or Switch access.
Bug:140539007 P3 After apply the wallpaper on wallpaper picker, the screen will stay on wallpaper picker about 2 second
Bug:140626334 P4 Pass wallpaper SC to launcher for animation during launch and swipe up
Bug:140635319 P1 [Flaky test] testPromiseIcon_addedFromEligibleSession failing due to NPE on Launcher#getStateManager
Bug:140786694 P2 [A11y]No talkback feedback when long pressing on an app at home screen
Bug:140935140 P1 Launcher force close observed while accessing app info shortcuts.
Bug:141260670 P3 Drag and drop preview doesn't match the destination grid size
Bug:141262820 P3 [Grid] icon badge size should scale as the grid size changes
Bug:141265063 P2 Long press on homescreen in between icons doesn't bring up home settings
Bug:141275518 P2 Test WellbeingTests.testPauseAppFromOverview flakes on Cuttlefish
Bug:141315387 P1 [Failing test] 3P launchers + 2 button mode: failed goToOverviewFromHome and goToOverviewFromApp
Bug:141376165 P2 Remove static initializations in Launcher
Bug:141390432 P1 [Failing test] TaplTestsLauncher3 in 2-button mode
Bug:141517004 P1 FallbackRecentsTest.goToOverviewFromHome Failure
Bug:141522764 P1 DefaultLayoutProviderTest failures
Bug:141523101 P1 TaplTestsQuickstep#testAllAppsFromHome,testAllAppsFromOverview failures
Bug:141524555 P1 FallbackRecentsTest.testOverview flake
Bug:141576561 P2 Fix FlagOverrideSampleTest inside robolectric test
Bug:141576665 P2 AddWorkspaceItemsTaskTest broken
Bug:141577881 P2 FileLogTest broken
Bug:141579810 P1 ViewInflationDuringSwipeUp test failures
Bug:141580748 P2 FallbackRecentsTest#testOverview failure
Bug:141697444 P1 TaplTestsLauncher3#testWidgets test failure
Bug:141770616 P2 Flake: Can't find a launcher object; selector: BySelector [RES='\Qcom.google.android.apps.nexuslauncher:id/deep_shortcuts_container\E'] (visible state: AllApps),
Bug:141772190 P2 Flake: Context menu is still visible afterswiping up to home
Bug:141864547 P2 calendar-stable sometimes fails dialog dismissal on cuttlefish
Bug:141886704 P2 Use app targets to determine input consumer instead of launcher state
Bug:141934188 P2 Automation Test for adding widget automatically
Bug:141939911 P3 Clean up SwipeDetector
Bug:141986013 P2 Update all apps fade interpolators
Bug:142068081 P1 Quick Switch touch swipe dropped, flicker ensues
Bug:142120338 P2 Gmail app (work profile) icon not drawing
Bug:142148773 P2 grid size should not affect widget padding in WidgetsRecyclerView
Bug:142351228 P1 public void testSwipeUp_with_list_widgets() is failing for merge CL
Bug:79868152 P3 Fade out caret with workspace and back in when in Overview
Bug:136282913 P1 Swipe up from Assistant Fulfillment Card Jank
Bug:138473688 P4 Home settings can't be dismissed by swipe up
Bug:140252765 P2 Audit Gesture Nav tests (including Back and Quick Switch)
Bug:141568904 P1 NPE: Pixel launcher crash is observed when adding Directions widget
Bug:142514365 P1 Failing test AddWidgetTest.testDragIcon
Bug:142803200 P1 Broken binder tests

Change-Id: I811537cc8d406f0acd9fa45daddae4da79ffff12
2019-10-16 22:46:01 -07:00

307 lines
11 KiB
Java

package com.android.launcher3;
import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURABLE;
import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_MASK;
import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_NO;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.logging.LoggerUtils;
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Themes;
import java.net.URISyntaxException;
/**
* Drop target which provides a secondary option for an item.
* For app targets: shows as uninstall
* For configurable widgets: shows as setup
*/
public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener {
private static final String TAG = "SecondaryDropTarget";
private static final long CACHE_EXPIRE_TIMEOUT = 5000;
private final ArrayMap<UserHandle, Boolean> mUninstallDisabledCache = new ArrayMap<>(1);
private final Alarm mCacheExpireAlarm;
protected int mCurrentAccessibilityAction = -1;
public SecondaryDropTarget(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SecondaryDropTarget(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mCacheExpireAlarm = new Alarm();
mCacheExpireAlarm.setOnAlarmListener(this);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
setupUi(UNINSTALL);
}
protected void setupUi(int action) {
if (action == mCurrentAccessibilityAction) {
return;
}
mCurrentAccessibilityAction = action;
if (action == UNINSTALL) {
mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint);
setDrawable(R.drawable.ic_uninstall_shadow);
updateText(R.string.uninstall_drop_target_label);
} else {
mHoverColor = Themes.getColorAccent(getContext());
setDrawable(R.drawable.ic_setup_shadow);
updateText(R.string.gadget_setup_text);
}
}
@Override
public void onAlarm(Alarm alarm) {
mUninstallDisabledCache.clear();
}
@Override
public int getAccessibilityAction() {
return mCurrentAccessibilityAction;
}
@Override
public Target getDropTargetForLogging() {
Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
t.controlType = mCurrentAccessibilityAction == UNINSTALL ? ControlType.UNINSTALL_TARGET
: ControlType.SETTINGS_BUTTON;
return t;
}
@Override
protected boolean supportsDrop(ItemInfo info) {
return supportsAccessibilityDrop(info, getViewUnderDrag(info));
}
@Override
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
if (view instanceof AppWidgetHostView) {
if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
setupUi(RECONFIGURE);
return true;
}
return false;
}
setupUi(UNINSTALL);
Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
if (uninstallDisabled == null) {
UserManager userManager =
(UserManager) getContext().getSystemService(Context.USER_SERVICE);
Bundle restrictions = userManager.getUserRestrictions(info.user);
uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
|| restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
mUninstallDisabledCache.put(info.user, uninstallDisabled);
}
// Cancel any pending alarm and set cache expiry after some time
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
if (uninstallDisabled) {
return false;
}
if (info instanceof ItemInfoWithIcon) {
ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
}
}
return getUninstallTarget(info) != null;
}
/**
* @return the component name that should be uninstalled or null.
*/
private ComponentName getUninstallTarget(ItemInfo item) {
Intent intent = null;
UserHandle user = null;
if (item != null &&
item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
intent = item.getIntent();
user = item.user;
}
if (intent != null) {
LauncherActivityInfo info = mLauncher.getSystemService(LauncherApps.class)
.resolveActivity(intent, user);
if (info != null
&& (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
return info.getComponentName();
}
}
return null;
}
@Override
public void onDrop(DragObject d, DragOptions options) {
// Defer onComplete
d.dragSource = new DeferredOnComplete(d.dragSource, getContext());
super.onDrop(d, options);
}
@Override
public void completeDrop(final DragObject d) {
ComponentName target = performDropAction(getViewUnderDrag(d.dragInfo), d.dragInfo);
if (d.dragSource instanceof DeferredOnComplete) {
DeferredOnComplete deferred = (DeferredOnComplete) d.dragSource;
if (target != null) {
deferred.mPackageName = target.getPackageName();
mLauncher.addOnResumeCallback(deferred);
} else {
deferred.sendFailure();
}
}
}
private View getViewUnderDrag(ItemInfo info) {
if (info instanceof LauncherAppWidgetInfo && info.container == CONTAINER_DESKTOP &&
mLauncher.getWorkspace().getDragInfo() != null) {
return mLauncher.getWorkspace().getDragInfo().cell;
}
return null;
}
/**
* Verifies that the view is an reconfigurable widget and returns the corresponding widget Id,
* otherwise return {@code INVALID_APPWIDGET_ID}
*/
private int getReconfigurableWidgetId(View view) {
if (!(view instanceof AppWidgetHostView)) {
return INVALID_APPWIDGET_ID;
}
AppWidgetHostView hostView = (AppWidgetHostView) view;
AppWidgetProviderInfo widgetInfo = hostView.getAppWidgetInfo();
if (widgetInfo == null || widgetInfo.configure == null) {
return INVALID_APPWIDGET_ID;
}
if ( (LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(), widgetInfo)
.getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) == 0) {
return INVALID_APPWIDGET_ID;
}
return hostView.getAppWidgetId();
}
/**
* Performs the drop action and returns the target component for the dragObject or null if
* the action was not performed.
*/
protected ComponentName performDropAction(View view, ItemInfo info) {
if (mCurrentAccessibilityAction == RECONFIGURE) {
int widgetId = getReconfigurableWidgetId(view);
if (widgetId != INVALID_APPWIDGET_ID) {
mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, widgetId, -1);
}
return null;
}
// else: mCurrentAccessibilityAction == UNINSTALL
ComponentName cn = getUninstallTarget(info);
if (cn == null) {
// System applications cannot be installed. For now, show a toast explaining that.
// We may give them the option of disabling apps this way.
Toast.makeText(mLauncher, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show();
return null;
}
try {
Intent i = Intent.parseUri(mLauncher.getString(R.string.delete_package_intent), 0)
.setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName()))
.putExtra(Intent.EXTRA_USER, info.user);
mLauncher.startActivity(i);
FileLog.d(TAG, "start uninstall activity " + cn.getPackageName());
return cn;
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to parse intent to start uninstall activity for item=" + info);
return null;
}
}
@Override
public void onAccessibilityDrop(View view, ItemInfo item) {
performDropAction(view, item);
}
/**
* A wrapper around {@link DragSource} which delays the {@link #onDropCompleted} action until
* {@link #onLauncherResume}
*/
private class DeferredOnComplete implements DragSource, OnResumeCallback {
private final DragSource mOriginal;
private final Context mContext;
private String mPackageName;
private DragObject mDragObject;
public DeferredOnComplete(DragSource original, Context context) {
mOriginal = original;
mContext = context;
}
@Override
public void onDropCompleted(View target, DragObject d,
boolean success) {
mDragObject = d;
}
@Override
public void fillInLogContainerData(View v, ItemInfo info, Target target,
Target targetParent) {
mOriginal.fillInLogContainerData(v, info, target, targetParent);
}
@Override
public void onLauncherResume() {
// We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
if (new PackageManagerHelper(mContext).getApplicationInfo(mPackageName,
mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) {
mDragObject.dragSource = mOriginal;
mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true);
} else {
sendFailure();
}
}
public void sendFailure() {
mDragObject.dragSource = mOriginal;
mDragObject.cancelled = true;
mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, false);
}
}
}