Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 3 | import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID; |
| 4 | import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURABLE; |
Samuel Fufa | cc1e107 | 2019-09-06 16:19:11 -0700 | [diff] [blame] | 5 | |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 6 | import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_MASK; |
| 7 | import static com.android.launcher3.ItemInfoWithIcon.FLAG_SYSTEM_NO; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 8 | import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 9 | import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 10 | import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE; |
| 11 | import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL; |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 12 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 13 | import android.appwidget.AppWidgetHostView; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 14 | import android.appwidget.AppWidgetProviderInfo; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 15 | import android.content.ComponentName; |
| 16 | import android.content.Context; |
Sunny Goyal | d5bd67d | 2016-03-11 01:10:19 -0800 | [diff] [blame] | 17 | import android.content.Intent; |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 18 | import android.content.pm.ApplicationInfo; |
Sunny Goyal | 3e9be43 | 2017-01-05 15:22:41 -0800 | [diff] [blame] | 19 | import android.content.pm.LauncherActivityInfo; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 20 | import android.content.pm.LauncherApps; |
Sunny Goyal | f2db253 | 2017-03-01 17:27:16 -0800 | [diff] [blame] | 21 | import android.content.pm.PackageManager; |
Sunny Goyal | d5bd67d | 2016-03-11 01:10:19 -0800 | [diff] [blame] | 22 | import android.net.Uri; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 23 | import android.os.Bundle; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 24 | import android.os.UserHandle; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 25 | import android.os.UserManager; |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 26 | import android.util.ArrayMap; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Jon Miranda | c56e3ff | 2017-08-23 12:13:24 -0700 | [diff] [blame] | 28 | import android.util.Log; |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 29 | import android.view.View; |
Sunny Goyal | d5bd67d | 2016-03-11 01:10:19 -0800 | [diff] [blame] | 30 | import android.widget.Toast; |
Sunny Goyal | aa8ef11 | 2015-06-12 20:04:41 -0700 | [diff] [blame] | 31 | |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 32 | import com.android.launcher3.Launcher.OnResumeCallback; |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 33 | import com.android.launcher3.config.FeatureFlags; |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 34 | import com.android.launcher3.dragndrop.DragOptions; |
Samuel Fufa | cc1e107 | 2019-09-06 16:19:11 -0700 | [diff] [blame] | 35 | import com.android.launcher3.logging.FileLog; |
Mehdi Alizadeh | bda47cf | 2018-05-01 19:26:05 -0700 | [diff] [blame] | 36 | import com.android.launcher3.logging.LoggerUtils; |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 37 | import com.android.launcher3.model.AppLaunchTracker; |
Mehdi Alizadeh | bda47cf | 2018-05-01 19:26:05 -0700 | [diff] [blame] | 38 | import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 39 | import com.android.launcher3.userevent.nano.LauncherLogProto.Target; |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 40 | import com.android.launcher3.util.PackageManagerHelper; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 41 | import com.android.launcher3.util.Themes; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 42 | |
Jon Miranda | c56e3ff | 2017-08-23 12:13:24 -0700 | [diff] [blame] | 43 | import java.net.URISyntaxException; |
| 44 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 45 | /** |
| 46 | * Drop target which provides a secondary option for an item. |
| 47 | * For app targets: shows as uninstall |
| 48 | * For configurable widgets: shows as setup |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 49 | * For predicted app icons: don't suggest app |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 50 | */ |
| 51 | public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 52 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 53 | private static final String TAG = "SecondaryDropTarget"; |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 54 | |
| 55 | private static final long CACHE_EXPIRE_TIMEOUT = 5000; |
| 56 | private final ArrayMap<UserHandle, Boolean> mUninstallDisabledCache = new ArrayMap<>(1); |
| 57 | |
| 58 | private final Alarm mCacheExpireAlarm; |
Jon Miranda | c56e3ff | 2017-08-23 12:13:24 -0700 | [diff] [blame] | 59 | |
Mehdi Alizadeh | 8517b69 | 2018-04-23 15:55:26 -0700 | [diff] [blame] | 60 | protected int mCurrentAccessibilityAction = -1; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 61 | public SecondaryDropTarget(Context context, AttributeSet attrs) { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 62 | this(context, attrs, 0); |
| 63 | } |
| 64 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 65 | public SecondaryDropTarget(Context context, AttributeSet attrs, int defStyle) { |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 66 | super(context, attrs, defStyle); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 67 | |
| 68 | mCacheExpireAlarm = new Alarm(); |
| 69 | mCacheExpireAlarm.setOnAlarmListener(this); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | protected void onFinishInflate() { |
| 74 | super.onFinishInflate(); |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 75 | setupUi(UNINSTALL); |
Sunny Goyal | da1dfa3 | 2017-04-26 22:34:49 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Mehdi Alizadeh | 8517b69 | 2018-04-23 15:55:26 -0700 | [diff] [blame] | 78 | protected void setupUi(int action) { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 79 | if (action == mCurrentAccessibilityAction) { |
| 80 | return; |
| 81 | } |
| 82 | mCurrentAccessibilityAction = action; |
| 83 | |
| 84 | if (action == UNINSTALL) { |
| 85 | mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint); |
| 86 | setDrawable(R.drawable.ic_uninstall_shadow); |
| 87 | updateText(R.string.uninstall_drop_target_label); |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 88 | } else if (action == DISMISS_PREDICTION) { |
| 89 | mHoverColor = Themes.getColorAccent(getContext()); |
| 90 | setDrawable(R.drawable.ic_block); |
| 91 | updateText(R.string.dismiss_prediction_label); |
| 92 | } else if (action == RECONFIGURE) { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 93 | mHoverColor = Themes.getColorAccent(getContext()); |
| 94 | setDrawable(R.drawable.ic_setup_shadow); |
| 95 | updateText(R.string.gadget_setup_text); |
| 96 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 100 | public void onAlarm(Alarm alarm) { |
| 101 | mUninstallDisabledCache.clear(); |
Sunny Goyal | 1a70cef | 2015-04-22 11:29:51 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 104 | @Override |
| 105 | public int getAccessibilityAction() { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 106 | return mCurrentAccessibilityAction; |
| 107 | } |
| 108 | |
| 109 | @Override |
Mehdi Alizadeh | bda47cf | 2018-05-01 19:26:05 -0700 | [diff] [blame] | 110 | public Target getDropTargetForLogging() { |
| 111 | Target t = LoggerUtils.newTarget(Target.Type.CONTROL); |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 112 | if (mCurrentAccessibilityAction == UNINSTALL) { |
| 113 | t.controlType = ControlType.UNINSTALL_TARGET; |
| 114 | } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) { |
| 115 | t.controlType = ControlType.DISMISS_PREDICTION; |
| 116 | } else { |
| 117 | t.controlType = ControlType.SETTINGS_BUTTON; |
| 118 | } |
Mehdi Alizadeh | bda47cf | 2018-05-01 19:26:05 -0700 | [diff] [blame] | 119 | return t; |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
| 123 | protected boolean supportsDrop(ItemInfo info) { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 124 | return supportsAccessibilityDrop(info, getViewUnderDrag(info)); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public boolean supportsAccessibilityDrop(ItemInfo info, View view) { |
| 129 | if (view instanceof AppWidgetHostView) { |
| 130 | if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) { |
| 131 | setupUi(RECONFIGURE); |
| 132 | return true; |
| 133 | } |
| 134 | return false; |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 135 | } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) { |
| 136 | setupUi(DISMISS_PREDICTION); |
| 137 | return true; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | setupUi(UNINSTALL); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 141 | Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user); |
| 142 | if (uninstallDisabled == null) { |
| 143 | UserManager userManager = |
| 144 | (UserManager) getContext().getSystemService(Context.USER_SERVICE); |
| 145 | Bundle restrictions = userManager.getUserRestrictions(info.user); |
| 146 | uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false) |
Sunny Goyal | 6b0aa87 | 2017-09-29 07:54:37 -0700 | [diff] [blame] | 147 | || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 148 | mUninstallDisabledCache.put(info.user, uninstallDisabled); |
Sunny Goyal | 6b0aa87 | 2017-09-29 07:54:37 -0700 | [diff] [blame] | 149 | } |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 150 | // Cancel any pending alarm and set cache expiry after some time |
| 151 | mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT); |
| 152 | if (uninstallDisabled) { |
Sunny Goyal | a52ecb0 | 2016-12-16 15:04:51 -0800 | [diff] [blame] | 153 | return false; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 156 | if (info instanceof ItemInfoWithIcon) { |
| 157 | ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info; |
| 158 | if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) { |
| 159 | return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0; |
Sunny Goyal | 6b0aa87 | 2017-09-29 07:54:37 -0700 | [diff] [blame] | 160 | } |
| 161 | } |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 162 | return getUninstallTarget(info) != null; |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 166 | * @return the component name that should be uninstalled or null. |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 167 | */ |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 168 | private ComponentName getUninstallTarget(ItemInfo item) { |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 169 | Intent intent = null; |
Sunny Goyal | 7c74e4a | 2016-12-15 15:53:17 -0800 | [diff] [blame] | 170 | UserHandle user = null; |
Sunny Goyal | 1fe0c2c | 2017-08-15 12:54:42 -0700 | [diff] [blame] | 171 | if (item != null && |
Sunny Goyal | c593939 | 2018-12-07 11:43:47 -0800 | [diff] [blame] | 172 | item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { |
Sunny Goyal | 1fe0c2c | 2017-08-15 12:54:42 -0700 | [diff] [blame] | 173 | intent = item.getIntent(); |
| 174 | user = item.user; |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 175 | } |
| 176 | if (intent != null) { |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 177 | LauncherActivityInfo info = mLauncher.getSystemService(LauncherApps.class) |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 178 | .resolveActivity(intent, user); |
| 179 | if (info != null |
| 180 | && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 181 | return info.getComponentName(); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | return null; |
| 185 | } |
| 186 | |
| 187 | @Override |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 188 | public void onDrop(DragObject d, DragOptions options) { |
| 189 | // Defer onComplete |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 190 | d.dragSource = new DeferredOnComplete(d.dragSource, getContext()); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 191 | super.onDrop(d, options); |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Override |
Sunny Goyal | 0f76b56 | 2016-12-13 19:37:10 -0800 | [diff] [blame] | 195 | public void completeDrop(final DragObject d) { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 196 | ComponentName target = performDropAction(getViewUnderDrag(d.dragInfo), d.dragInfo); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 197 | if (d.dragSource instanceof DeferredOnComplete) { |
| 198 | DeferredOnComplete deferred = (DeferredOnComplete) d.dragSource; |
| 199 | if (target != null) { |
| 200 | deferred.mPackageName = target.getPackageName(); |
Winson Chung | 0b70cd4 | 2019-06-17 22:34:33 -0700 | [diff] [blame] | 201 | mLauncher.addOnResumeCallback(deferred); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 202 | } else { |
| 203 | deferred.sendFailure(); |
| 204 | } |
| 205 | } |
Tony Wickham | 734dfbe | 2015-09-16 16:22:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 208 | private View getViewUnderDrag(ItemInfo info) { |
| 209 | if (info instanceof LauncherAppWidgetInfo && info.container == CONTAINER_DESKTOP && |
| 210 | mLauncher.getWorkspace().getDragInfo() != null) { |
| 211 | return mLauncher.getWorkspace().getDragInfo().cell; |
| 212 | } |
| 213 | return null; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Verifies that the view is an reconfigurable widget and returns the corresponding widget Id, |
| 218 | * otherwise return {@code INVALID_APPWIDGET_ID} |
| 219 | */ |
| 220 | private int getReconfigurableWidgetId(View view) { |
| 221 | if (!(view instanceof AppWidgetHostView)) { |
| 222 | return INVALID_APPWIDGET_ID; |
| 223 | } |
| 224 | AppWidgetHostView hostView = (AppWidgetHostView) view; |
| 225 | AppWidgetProviderInfo widgetInfo = hostView.getAppWidgetInfo(); |
| 226 | if (widgetInfo == null || widgetInfo.configure == null) { |
| 227 | return INVALID_APPWIDGET_ID; |
| 228 | } |
| 229 | if ( (LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(), widgetInfo) |
| 230 | .getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) == 0) { |
| 231 | return INVALID_APPWIDGET_ID; |
| 232 | } |
| 233 | return hostView.getAppWidgetId(); |
| 234 | } |
| 235 | |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 236 | /** |
| 237 | * Performs the drop action and returns the target component for the dragObject or null if |
| 238 | * the action was not performed. |
| 239 | */ |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 240 | protected ComponentName performDropAction(View view, ItemInfo info) { |
| 241 | if (mCurrentAccessibilityAction == RECONFIGURE) { |
| 242 | int widgetId = getReconfigurableWidgetId(view); |
| 243 | if (widgetId != INVALID_APPWIDGET_ID) { |
| 244 | mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, widgetId, -1); |
| 245 | } |
| 246 | return null; |
| 247 | } |
Samuel Fufa | 5cf3e86 | 2020-02-03 20:22:54 -0800 | [diff] [blame^] | 248 | if (mCurrentAccessibilityAction == DISMISS_PREDICTION) { |
| 249 | AppLaunchTracker.INSTANCE.get(getContext()).onDismissApp(info.getTargetComponent(), |
| 250 | info.user, AppLaunchTracker.CONTAINER_PREDICTIONS); |
| 251 | return null; |
| 252 | } |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 253 | // else: mCurrentAccessibilityAction == UNINSTALL |
| 254 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 255 | ComponentName cn = getUninstallTarget(info); |
Sunny Goyal | 8e0e1d7 | 2016-10-10 10:41:41 -0700 | [diff] [blame] | 256 | if (cn == null) { |
Sunny Goyal | d5bd67d | 2016-03-11 01:10:19 -0800 | [diff] [blame] | 257 | // System applications cannot be installed. For now, show a toast explaining that. |
| 258 | // We may give them the option of disabling apps this way. |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 259 | Toast.makeText(mLauncher, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show(); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 260 | return null; |
| 261 | } |
| 262 | try { |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 263 | Intent i = Intent.parseUri(mLauncher.getString(R.string.delete_package_intent), 0) |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 264 | .setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName())) |
| 265 | .putExtra(Intent.EXTRA_USER, info.user); |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 266 | mLauncher.startActivity(i); |
Samuel Fufa | cc1e107 | 2019-09-06 16:19:11 -0700 | [diff] [blame] | 267 | FileLog.d(TAG, "start uninstall activity " + cn.getPackageName()); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 268 | return cn; |
| 269 | } catch (URISyntaxException e) { |
| 270 | Log.e(TAG, "Failed to parse intent to start uninstall activity for item=" + info); |
| 271 | return null; |
| 272 | } |
| 273 | } |
| 274 | |
Sunny Goyal | 0236d0b | 2017-10-24 14:54:30 -0700 | [diff] [blame] | 275 | @Override |
| 276 | public void onAccessibilityDrop(View view, ItemInfo item) { |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 277 | performDropAction(view, item); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
| 281 | * A wrapper around {@link DragSource} which delays the {@link #onDropCompleted} action until |
| 282 | * {@link #onLauncherResume} |
| 283 | */ |
| 284 | private class DeferredOnComplete implements DragSource, OnResumeCallback { |
| 285 | |
| 286 | private final DragSource mOriginal; |
| 287 | private final Context mContext; |
| 288 | |
| 289 | private String mPackageName; |
| 290 | private DragObject mDragObject; |
| 291 | |
| 292 | public DeferredOnComplete(DragSource original, Context context) { |
| 293 | mOriginal = original; |
| 294 | mContext = context; |
| 295 | } |
| 296 | |
| 297 | @Override |
Sunny Goyal | 1797af4 | 2017-10-06 13:29:57 -0700 | [diff] [blame] | 298 | public void onDropCompleted(View target, DragObject d, |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 299 | boolean success) { |
| 300 | mDragObject = d; |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public void fillInLogContainerData(View v, ItemInfo info, Target target, |
| 305 | Target targetParent) { |
| 306 | mOriginal.fillInLogContainerData(v, info, target, targetParent); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onLauncherResume() { |
| 311 | // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well. |
Sunny Goyal | e7b0012 | 2019-10-02 16:13:34 -0700 | [diff] [blame] | 312 | if (new PackageManagerHelper(mContext).getApplicationInfo(mPackageName, |
| 313 | mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) { |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 314 | mDragObject.dragSource = mOriginal; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 315 | mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true); |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 316 | } else { |
| 317 | sendFailure(); |
Jon Miranda | c56e3ff | 2017-08-23 12:13:24 -0700 | [diff] [blame] | 318 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 319 | } |
Sunny Goyal | 3dce5f3 | 2017-10-05 11:40:05 -0700 | [diff] [blame] | 320 | |
| 321 | public void sendFailure() { |
| 322 | mDragObject.dragSource = mOriginal; |
| 323 | mDragObject.cancelled = true; |
Winson Chung | 1054d4e | 2018-03-05 19:39:21 +0000 | [diff] [blame] | 324 | mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, false); |
Sunny Goyal | d5bd67d | 2016-03-11 01:10:19 -0800 | [diff] [blame] | 325 | } |
Sunny Goyal | fa401a1 | 2015-04-10 13:45:42 -0700 | [diff] [blame] | 326 | } |
| 327 | } |