blob: 0b92c285fbc836e5445001cee856b503f4f7b2e6 [file] [log] [blame]
Sunny Goyalfa401a12015-04-10 13:45:42 -07001package com.android.launcher3;
2
Winson Chung1054d4e2018-03-05 19:39:21 +00003import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
4import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURABLE;
Samuel Fufacc1e1072019-09-06 16:19:11 -07005
Samuel Fufa5cf3e862020-02-03 20:22:54 -08006import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION;
Alex Chau158caf42022-05-24 17:09:32 +01007import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.INVALID;
Winson Chung1054d4e2018-03-05 19:39:21 +00008import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
9import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
Stefan Andonian510a8182022-03-30 17:46:09 +000010import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DISMISS_PREDICTION_UNDO;
thiruramff484512020-05-11 11:19:58 -070011import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST;
12import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROPPED_ON_UNINSTALL;
13import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_UNINSTALL_CANCELLED;
14import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_UNINSTALL_COMPLETED;
Sunny Goyale396abf2020-04-06 15:11:17 -070015import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_MASK;
16import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_NO;
Sunny Goyal076839c2017-10-30 13:52:20 -070017
Winson Chung1054d4e2018-03-05 19:39:21 +000018import android.appwidget.AppWidgetHostView;
Winson Chung1054d4e2018-03-05 19:39:21 +000019import android.appwidget.AppWidgetProviderInfo;
Sunny Goyalfa401a12015-04-10 13:45:42 -070020import android.content.ComponentName;
21import android.content.Context;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080022import android.content.Intent;
Sunny Goyal8e0e1d72016-10-10 10:41:41 -070023import android.content.pm.ApplicationInfo;
Sunny Goyal3e9be432017-01-05 15:22:41 -080024import android.content.pm.LauncherActivityInfo;
Sunny Goyale7b00122019-10-02 16:13:34 -070025import android.content.pm.LauncherApps;
Sunny Goyalf2db2532017-03-01 17:27:16 -080026import android.content.pm.PackageManager;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080027import android.net.Uri;
Sunny Goyalfa401a12015-04-10 13:45:42 -070028import android.os.Bundle;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080029import android.os.UserHandle;
Sunny Goyalfa401a12015-04-10 13:45:42 -070030import android.os.UserManager;
Sunny Goyal0236d0b2017-10-24 14:54:30 -070031import android.util.ArrayMap;
Sunny Goyalfa401a12015-04-10 13:45:42 -070032import android.util.AttributeSet;
Jon Mirandac56e3ff2017-08-23 12:13:24 -070033import android.util.Log;
Sunny Goyal3dce5f32017-10-05 11:40:05 -070034import android.view.View;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080035import android.widget.Toast;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070036
Samuel Fufa5cf3e862020-02-03 20:22:54 -080037import com.android.launcher3.config.FeatureFlags;
Sunny Goyal3dce5f32017-10-05 11:40:05 -070038import com.android.launcher3.dragndrop.DragOptions;
Samuel Fufacc1e1072019-09-06 16:19:11 -070039import com.android.launcher3.logging.FileLog;
Sunny Goyal384b5782021-02-09 22:50:02 -080040import com.android.launcher3.logging.InstanceId;
41import com.android.launcher3.logging.InstanceIdSequence;
thiruramff484512020-05-11 11:19:58 -070042import com.android.launcher3.logging.StatsLogManager;
Sunny Goyal852537f2020-07-15 17:02:16 -070043import com.android.launcher3.logging.StatsLogManager.StatsLogger;
Sunny Goyale396abf2020-04-06 15:11:17 -070044import com.android.launcher3.model.data.ItemInfo;
45import com.android.launcher3.model.data.ItemInfoWithIcon;
Sunny Goyale7b00122019-10-02 16:13:34 -070046import com.android.launcher3.util.PackageManagerHelper;
Yogisha Dixit741fae92021-02-22 14:03:44 +000047import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
Sunny Goyalfa401a12015-04-10 13:45:42 -070048
Jon Mirandac56e3ff2017-08-23 12:13:24 -070049import java.net.URISyntaxException;
50
Winson Chung1054d4e2018-03-05 19:39:21 +000051/**
52 * Drop target which provides a secondary option for an item.
53 * For app targets: shows as uninstall
54 * For configurable widgets: shows as setup
Samuel Fufa5cf3e862020-02-03 20:22:54 -080055 * For predicted app icons: don't suggest app
Winson Chung1054d4e2018-03-05 19:39:21 +000056 */
57public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070058
Winson Chung1054d4e2018-03-05 19:39:21 +000059 private static final String TAG = "SecondaryDropTarget";
Sunny Goyal0236d0b2017-10-24 14:54:30 -070060
61 private static final long CACHE_EXPIRE_TIMEOUT = 5000;
62 private final ArrayMap<UserHandle, Boolean> mUninstallDisabledCache = new ArrayMap<>(1);
thiruramff484512020-05-11 11:19:58 -070063 private final StatsLogManager mStatsLogManager;
Sunny Goyal0236d0b2017-10-24 14:54:30 -070064 private final Alarm mCacheExpireAlarm;
vadimt3d64ffd2020-02-27 11:28:47 -080065 private boolean mHadPendingAlarm;
Jon Mirandac56e3ff2017-08-23 12:13:24 -070066
Mehdi Alizadeh8517b692018-04-23 15:55:26 -070067 protected int mCurrentAccessibilityAction = -1;
Alex Chau158caf42022-05-24 17:09:32 +010068
Winson Chung1054d4e2018-03-05 19:39:21 +000069 public SecondaryDropTarget(Context context, AttributeSet attrs) {
Sunny Goyalfa401a12015-04-10 13:45:42 -070070 this(context, attrs, 0);
71 }
72
Winson Chung1054d4e2018-03-05 19:39:21 +000073 public SecondaryDropTarget(Context context, AttributeSet attrs, int defStyle) {
Sunny Goyalfa401a12015-04-10 13:45:42 -070074 super(context, attrs, defStyle);
Sunny Goyal0236d0b2017-10-24 14:54:30 -070075 mCacheExpireAlarm = new Alarm();
thiruramff484512020-05-11 11:19:58 -070076 mStatsLogManager = StatsLogManager.newInstance(context);
Sunny Goyalfa401a12015-04-10 13:45:42 -070077 }
78
79 @Override
vadimt3d64ffd2020-02-27 11:28:47 -080080 protected void onAttachedToWindow() {
81 super.onAttachedToWindow();
82 if (mHadPendingAlarm) {
83 mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
vadimt908e9bb2020-02-28 18:02:30 -080084 mCacheExpireAlarm.setOnAlarmListener(this);
vadimt3d64ffd2020-02-27 11:28:47 -080085 mHadPendingAlarm = false;
86 }
87 }
88
89 @Override
90 protected void onDetachedFromWindow() {
91 super.onDetachedFromWindow();
92 if (mCacheExpireAlarm.alarmPending()) {
93 mCacheExpireAlarm.cancelAlarm();
vadimt908e9bb2020-02-28 18:02:30 -080094 mCacheExpireAlarm.setOnAlarmListener(null);
vadimt3d64ffd2020-02-27 11:28:47 -080095 mHadPendingAlarm = true;
96 }
97 }
98
99 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700100 protected void onFinishInflate() {
101 super.onFinishInflate();
Winson Chung1054d4e2018-03-05 19:39:21 +0000102 setupUi(UNINSTALL);
Sunny Goyalda1dfa32017-04-26 22:34:49 -0700103 }
104
Mehdi Alizadeh8517b692018-04-23 15:55:26 -0700105 protected void setupUi(int action) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000106 if (action == mCurrentAccessibilityAction) {
107 return;
108 }
109 mCurrentAccessibilityAction = action;
110
111 if (action == UNINSTALL) {
Yogisha Dixita3a6f512021-04-28 13:45:37 +0100112 setDrawable(R.drawable.ic_uninstall_no_shadow);
Winson Chung1054d4e2018-03-05 19:39:21 +0000113 updateText(R.string.uninstall_drop_target_label);
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800114 } else if (action == DISMISS_PREDICTION) {
Yogisha Dixita3a6f512021-04-28 13:45:37 +0100115 setDrawable(R.drawable.ic_block_no_shadow);
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800116 updateText(R.string.dismiss_prediction_label);
117 } else if (action == RECONFIGURE) {
Yogisha Dixita3a6f512021-04-28 13:45:37 +0100118 setDrawable(R.drawable.ic_setting);
Winson Chung1054d4e2018-03-05 19:39:21 +0000119 updateText(R.string.gadget_setup_text);
120 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700121 }
122
123 @Override
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700124 public void onAlarm(Alarm alarm) {
125 mUninstallDisabledCache.clear();
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700126 }
127
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700128 @Override
129 public int getAccessibilityAction() {
Winson Chung1054d4e2018-03-05 19:39:21 +0000130 return mCurrentAccessibilityAction;
131 }
132
133 @Override
Alex Chau158caf42022-05-24 17:09:32 +0100134 protected void setupItemInfo(ItemInfo info) {
135 int buttonType = getButtonType(info, getViewUnderDrag(info));
136 if (buttonType != INVALID) {
137 setupUi(buttonType);
138 }
139 }
140
141 @Override
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700142 protected boolean supportsDrop(ItemInfo info) {
Alex Chau158caf42022-05-24 17:09:32 +0100143 return getButtonType(info, getViewUnderDrag(info)) != INVALID;
Winson Chung1054d4e2018-03-05 19:39:21 +0000144 }
145
146 @Override
147 public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
Alex Chau158caf42022-05-24 17:09:32 +0100148 return getButtonType(info, view) != INVALID;
149 }
150
151 private int getButtonType(ItemInfo info, View view) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000152 if (view instanceof AppWidgetHostView) {
153 if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
Alex Chau158caf42022-05-24 17:09:32 +0100154 return RECONFIGURE;
Winson Chung1054d4e2018-03-05 19:39:21 +0000155 }
Alex Chau158caf42022-05-24 17:09:32 +0100156 return INVALID;
Sunny Goyalc5c7da92022-08-02 13:36:54 -0700157 } else if (info.isPredictedItem()) {
Anushree Ganjam5e9b71e2024-01-11 14:15:54 -0800158 if (Flags.enableShortcutDontSuggestApp()) {
159 return INVALID;
160 }
Alex Chau158caf42022-05-24 17:09:32 +0100161 return DISMISS_PREDICTION;
Winson Chung1054d4e2018-03-05 19:39:21 +0000162 }
163
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700164 Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
165 if (uninstallDisabled == null) {
166 UserManager userManager =
167 (UserManager) getContext().getSystemService(Context.USER_SERVICE);
168 Bundle restrictions = userManager.getUserRestrictions(info.user);
169 uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700170 || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700171 mUninstallDisabledCache.put(info.user, uninstallDisabled);
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700172 }
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700173 // Cancel any pending alarm and set cache expiry after some time
174 mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
vadimt908e9bb2020-02-28 18:02:30 -0800175 mCacheExpireAlarm.setOnAlarmListener(this);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700176 if (uninstallDisabled) {
Alex Chau158caf42022-05-24 17:09:32 +0100177 return INVALID;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700178 }
179
Sunny Goyal076839c2017-10-30 13:52:20 -0700180 if (info instanceof ItemInfoWithIcon) {
181 ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
Alex Chau158caf42022-05-24 17:09:32 +0100182 if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0
183 && (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) == 0) {
184 return INVALID;
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700185 }
186 }
Alex Chau158caf42022-05-24 17:09:32 +0100187 if (getUninstallTarget(info) == null) {
188 return INVALID;
189 }
190 return UNINSTALL;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700191 }
192
193 /**
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700194 * @return the component name that should be uninstalled or null.
Sunny Goyalfa401a12015-04-10 13:45:42 -0700195 */
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700196 private ComponentName getUninstallTarget(ItemInfo item) {
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700197 Intent intent = null;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800198 UserHandle user = null;
Sunny Goyal1fe0c2c2017-08-15 12:54:42 -0700199 if (item != null &&
Sunny Goyalc5939392018-12-07 11:43:47 -0800200 item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
Sunny Goyal1fe0c2c2017-08-15 12:54:42 -0700201 intent = item.getIntent();
202 user = item.user;
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700203 }
204 if (intent != null) {
Andrew Cole44898c32023-04-05 13:49:32 -0700205 LauncherActivityInfo info = getContext().getSystemService(LauncherApps.class)
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700206 .resolveActivity(intent, user);
207 if (info != null
208 && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
209 return info.getComponentName();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700210 }
211 }
212 return null;
213 }
214
215 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700216 public void onDrop(DragObject d, DragOptions options) {
217 // Defer onComplete
Sunny Goyal1797af42017-10-06 13:29:57 -0700218 d.dragSource = new DeferredOnComplete(d.dragSource, getContext());
Sunny Goyal852537f2020-07-15 17:02:16 -0700219
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700220 super.onDrop(d, options);
Sunny Goyal384b5782021-02-09 22:50:02 -0800221 doLog(d.logInstanceId, d.originalDragInfo);
222 }
223
224 private void doLog(InstanceId logInstanceId, ItemInfo itemInfo) {
225 StatsLogger logger = mStatsLogManager.logger().withInstanceId(logInstanceId);
226 if (itemInfo != null) {
227 logger.withItemInfo(itemInfo);
Sunny Goyal852537f2020-07-15 17:02:16 -0700228 }
thiruramff484512020-05-11 11:19:58 -0700229 if (mCurrentAccessibilityAction == UNINSTALL) {
Sunny Goyal852537f2020-07-15 17:02:16 -0700230 logger.log(LAUNCHER_ITEM_DROPPED_ON_UNINSTALL);
thiruramff484512020-05-11 11:19:58 -0700231 } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
Sunny Goyal852537f2020-07-15 17:02:16 -0700232 logger.log(LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST);
thiruramff484512020-05-11 11:19:58 -0700233 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700234 }
235
236 @Override
Sunny Goyal0f76b562016-12-13 19:37:10 -0800237 public void completeDrop(final DragObject d) {
Stefan Andonian510a8182022-03-30 17:46:09 +0000238 ComponentName target = performDropAction(getViewUnderDrag(d.dragInfo), d.dragInfo,
239 d.logInstanceId);
Andrew Cole44898c32023-04-05 13:49:32 -0700240 mDropTargetHandler.onSecondaryTargetCompleteDrop(target, d);
Tony Wickham734dfbe2015-09-16 16:22:36 -0700241 }
242
Winson Chung1054d4e2018-03-05 19:39:21 +0000243 private View getViewUnderDrag(ItemInfo info) {
Andrew Cole44898c32023-04-05 13:49:32 -0700244 return mDropTargetHandler.getViewUnderDrag(info);
Winson Chung1054d4e2018-03-05 19:39:21 +0000245 }
246
247 /**
248 * Verifies that the view is an reconfigurable widget and returns the corresponding widget Id,
249 * otherwise return {@code INVALID_APPWIDGET_ID}
250 */
251 private int getReconfigurableWidgetId(View view) {
252 if (!(view instanceof AppWidgetHostView)) {
253 return INVALID_APPWIDGET_ID;
254 }
255 AppWidgetHostView hostView = (AppWidgetHostView) view;
256 AppWidgetProviderInfo widgetInfo = hostView.getAppWidgetInfo();
257 if (widgetInfo == null || widgetInfo.configure == null) {
258 return INVALID_APPWIDGET_ID;
259 }
260 if ( (LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(), widgetInfo)
261 .getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) == 0) {
262 return INVALID_APPWIDGET_ID;
263 }
264 return hostView.getAppWidgetId();
265 }
266
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700267 /**
268 * Performs the drop action and returns the target component for the dragObject or null if
269 * the action was not performed.
270 */
Stefan Andonian510a8182022-03-30 17:46:09 +0000271 protected ComponentName performDropAction(View view, ItemInfo info, InstanceId instanceId) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000272 if (mCurrentAccessibilityAction == RECONFIGURE) {
273 int widgetId = getReconfigurableWidgetId(view);
274 if (widgetId != INVALID_APPWIDGET_ID) {
Andrew Cole44898c32023-04-05 13:49:32 -0700275 mDropTargetHandler.reconfigureWidget(widgetId, info);
Winson Chung1054d4e2018-03-05 19:39:21 +0000276 }
277 return null;
278 }
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800279 if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
Stefan Andonian510a8182022-03-30 17:46:09 +0000280 if (FeatureFlags.ENABLE_DISMISS_PREDICTION_UNDO.get()) {
Andrew Cole44898c32023-04-05 13:49:32 -0700281 CharSequence announcement = getContext().getString(R.string.item_removed);
282 mDropTargetHandler
283 .dismissPrediction(announcement, () -> {}, () -> {
Stefan Andonian510a8182022-03-30 17:46:09 +0000284 mStatsLogManager.logger()
285 .withInstanceId(instanceId)
286 .withItemInfo(info)
287 .log(LAUNCHER_DISMISS_PREDICTION_UNDO);
288 });
289 }
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800290 return null;
291 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000292
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700293 ComponentName cn = getUninstallTarget(info);
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700294 if (cn == null) {
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800295 // System applications cannot be installed. For now, show a toast explaining that.
296 // We may give them the option of disabling apps this way.
Andrew Cole44898c32023-04-05 13:49:32 -0700297 Toast.makeText(
298 getContext(),
299 R.string.uninstall_system_app_text,
300 Toast.LENGTH_SHORT
301 ).show();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700302 return null;
303 }
304 try {
Andrew Cole44898c32023-04-05 13:49:32 -0700305 Intent i = Intent.parseUri(getContext().getString(R.string.delete_package_intent), 0)
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700306 .setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName()))
307 .putExtra(Intent.EXTRA_USER, info.user);
Andrew Cole44898c32023-04-05 13:49:32 -0700308 getContext().startActivity(i);
Samuel Fufacc1e1072019-09-06 16:19:11 -0700309 FileLog.d(TAG, "start uninstall activity " + cn.getPackageName());
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700310 return cn;
311 } catch (URISyntaxException e) {
312 Log.e(TAG, "Failed to parse intent to start uninstall activity for item=" + info);
313 return null;
314 }
315 }
316
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700317 @Override
318 public void onAccessibilityDrop(View view, ItemInfo item) {
Stefan Andonian510a8182022-03-30 17:46:09 +0000319 InstanceId instanceId = new InstanceIdSequence().newInstanceId();
320 doLog(instanceId, item);
321 performDropAction(view, item, instanceId);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700322 }
323
324 /**
325 * A wrapper around {@link DragSource} which delays the {@link #onDropCompleted} action until
326 * {@link #onLauncherResume}
327 */
Andrew Cole44898c32023-04-05 13:49:32 -0700328 protected class DeferredOnComplete implements DragSource {
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700329
330 private final DragSource mOriginal;
331 private final Context mContext;
332
Andrew Cole44898c32023-04-05 13:49:32 -0700333 protected String mPackageName;
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700334 private DragObject mDragObject;
335
336 public DeferredOnComplete(DragSource original, Context context) {
337 mOriginal = original;
338 mContext = context;
339 }
340
341 @Override
Sunny Goyal1797af42017-10-06 13:29:57 -0700342 public void onDropCompleted(View target, DragObject d,
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700343 boolean success) {
344 mDragObject = d;
345 }
346
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700347 public void onLauncherResume() {
348 // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
Sunny Goyale7b00122019-10-02 16:13:34 -0700349 if (new PackageManagerHelper(mContext).getApplicationInfo(mPackageName,
350 mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) {
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700351 mDragObject.dragSource = mOriginal;
Winson Chung1054d4e2018-03-05 19:39:21 +0000352 mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true);
thiruramc6a38ba2020-06-16 18:58:13 -0700353 mStatsLogManager.logger().withInstanceId(mDragObject.logInstanceId)
354 .log(LAUNCHER_ITEM_UNINSTALL_COMPLETED);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700355 } else {
356 sendFailure();
thiruramc6a38ba2020-06-16 18:58:13 -0700357 mStatsLogManager.logger().withInstanceId(mDragObject.logInstanceId)
358 .log(LAUNCHER_ITEM_UNINSTALL_CANCELLED);
Jon Mirandac56e3ff2017-08-23 12:13:24 -0700359 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700360 }
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700361
362 public void sendFailure() {
363 mDragObject.dragSource = mOriginal;
364 mDragObject.cancelled = true;
Winson Chung1054d4e2018-03-05 19:39:21 +0000365 mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, false);
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800366 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700367 }
368}