blob: 499b54f6d227409e469e01d5adc18bb7566de069 [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
Winson Chung1054d4e2018-03-05 19:39:21 +00006import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
Samuel Fufa5cf3e862020-02-03 20:22:54 -08007import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION;
Winson Chung1054d4e2018-03-05 19:39:21 +00008import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
9import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
thiruramff484512020-05-11 11:19:58 -070010import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST;
11import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROPPED_ON_UNINSTALL;
12import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_UNINSTALL_CANCELLED;
13import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_UNINSTALL_COMPLETED;
Sunny Goyale396abf2020-04-06 15:11:17 -070014import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_MASK;
15import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_NO;
Sunny Goyal076839c2017-10-30 13:52:20 -070016
Winson Chung1054d4e2018-03-05 19:39:21 +000017import android.appwidget.AppWidgetHostView;
Winson Chung1054d4e2018-03-05 19:39:21 +000018import android.appwidget.AppWidgetProviderInfo;
Sunny Goyalfa401a12015-04-10 13:45:42 -070019import android.content.ComponentName;
20import android.content.Context;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080021import android.content.Intent;
Sunny Goyal8e0e1d72016-10-10 10:41:41 -070022import android.content.pm.ApplicationInfo;
Sunny Goyal3e9be432017-01-05 15:22:41 -080023import android.content.pm.LauncherActivityInfo;
Sunny Goyale7b00122019-10-02 16:13:34 -070024import android.content.pm.LauncherApps;
Sunny Goyalf2db2532017-03-01 17:27:16 -080025import android.content.pm.PackageManager;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080026import android.net.Uri;
Sunny Goyalfa401a12015-04-10 13:45:42 -070027import android.os.Bundle;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -080028import android.os.UserHandle;
Sunny Goyalfa401a12015-04-10 13:45:42 -070029import android.os.UserManager;
Sunny Goyal0236d0b2017-10-24 14:54:30 -070030import android.util.ArrayMap;
Sunny Goyalfa401a12015-04-10 13:45:42 -070031import android.util.AttributeSet;
Jon Mirandac56e3ff2017-08-23 12:13:24 -070032import android.util.Log;
Sunny Goyal3dce5f32017-10-05 11:40:05 -070033import android.view.View;
Sunny Goyald5bd67d2016-03-11 01:10:19 -080034import android.widget.Toast;
Sunny Goyalaa8ef112015-06-12 20:04:41 -070035
Sunny Goyal3dce5f32017-10-05 11:40:05 -070036import com.android.launcher3.Launcher.OnResumeCallback;
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;
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -070040import com.android.launcher3.logging.LoggerUtils;
thiruramff484512020-05-11 11:19:58 -070041import com.android.launcher3.logging.StatsLogManager;
Samuel Fufa5cf3e862020-02-03 20:22:54 -080042import com.android.launcher3.model.AppLaunchTracker;
Sunny Goyale396abf2020-04-06 15:11:17 -070043import com.android.launcher3.model.data.ItemInfo;
44import com.android.launcher3.model.data.ItemInfoWithIcon;
45import com.android.launcher3.model.data.LauncherAppWidgetInfo;
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -070046import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
Sunny Goyal3dce5f32017-10-05 11:40:05 -070047import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
Sunny Goyale7b00122019-10-02 16:13:34 -070048import com.android.launcher3.util.PackageManagerHelper;
Winson Chung1054d4e2018-03-05 19:39:21 +000049import com.android.launcher3.util.Themes;
Sunny Goyalfa401a12015-04-10 13:45:42 -070050
Jon Mirandac56e3ff2017-08-23 12:13:24 -070051import java.net.URISyntaxException;
Samuel Fufaa579ddc2020-02-27 16:59:19 -080052import java.util.ArrayList;
Jon Mirandac56e3ff2017-08-23 12:13:24 -070053
Winson Chung1054d4e2018-03-05 19:39:21 +000054/**
55 * Drop target which provides a secondary option for an item.
56 * For app targets: shows as uninstall
57 * For configurable widgets: shows as setup
Samuel Fufa5cf3e862020-02-03 20:22:54 -080058 * For predicted app icons: don't suggest app
Winson Chung1054d4e2018-03-05 19:39:21 +000059 */
60public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener {
Sunny Goyalfa401a12015-04-10 13:45:42 -070061
Winson Chung1054d4e2018-03-05 19:39:21 +000062 private static final String TAG = "SecondaryDropTarget";
Sunny Goyal0236d0b2017-10-24 14:54:30 -070063
64 private static final long CACHE_EXPIRE_TIMEOUT = 5000;
65 private final ArrayMap<UserHandle, Boolean> mUninstallDisabledCache = new ArrayMap<>(1);
thiruramff484512020-05-11 11:19:58 -070066 private final StatsLogManager mStatsLogManager;
Sunny Goyal0236d0b2017-10-24 14:54:30 -070067 private final Alarm mCacheExpireAlarm;
vadimt3d64ffd2020-02-27 11:28:47 -080068 private boolean mHadPendingAlarm;
Jon Mirandac56e3ff2017-08-23 12:13:24 -070069
Mehdi Alizadeh8517b692018-04-23 15:55:26 -070070 protected int mCurrentAccessibilityAction = -1;
Winson Chung1054d4e2018-03-05 19:39:21 +000071 public SecondaryDropTarget(Context context, AttributeSet attrs) {
Sunny Goyalfa401a12015-04-10 13:45:42 -070072 this(context, attrs, 0);
73 }
74
Winson Chung1054d4e2018-03-05 19:39:21 +000075 public SecondaryDropTarget(Context context, AttributeSet attrs, int defStyle) {
Sunny Goyalfa401a12015-04-10 13:45:42 -070076 super(context, attrs, defStyle);
Sunny Goyal0236d0b2017-10-24 14:54:30 -070077 mCacheExpireAlarm = new Alarm();
thiruramff484512020-05-11 11:19:58 -070078 mStatsLogManager = StatsLogManager.newInstance(context);
Sunny Goyalfa401a12015-04-10 13:45:42 -070079 }
80
81 @Override
vadimt3d64ffd2020-02-27 11:28:47 -080082 protected void onAttachedToWindow() {
83 super.onAttachedToWindow();
84 if (mHadPendingAlarm) {
85 mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
vadimt908e9bb2020-02-28 18:02:30 -080086 mCacheExpireAlarm.setOnAlarmListener(this);
vadimt3d64ffd2020-02-27 11:28:47 -080087 mHadPendingAlarm = false;
88 }
89 }
90
91 @Override
92 protected void onDetachedFromWindow() {
93 super.onDetachedFromWindow();
94 if (mCacheExpireAlarm.alarmPending()) {
95 mCacheExpireAlarm.cancelAlarm();
vadimt908e9bb2020-02-28 18:02:30 -080096 mCacheExpireAlarm.setOnAlarmListener(null);
vadimt3d64ffd2020-02-27 11:28:47 -080097 mHadPendingAlarm = true;
98 }
99 }
100
101 @Override
Sunny Goyalfa401a12015-04-10 13:45:42 -0700102 protected void onFinishInflate() {
103 super.onFinishInflate();
Winson Chung1054d4e2018-03-05 19:39:21 +0000104 setupUi(UNINSTALL);
Sunny Goyalda1dfa32017-04-26 22:34:49 -0700105 }
106
Mehdi Alizadeh8517b692018-04-23 15:55:26 -0700107 protected void setupUi(int action) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000108 if (action == mCurrentAccessibilityAction) {
109 return;
110 }
111 mCurrentAccessibilityAction = action;
112
113 if (action == UNINSTALL) {
114 mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint);
115 setDrawable(R.drawable.ic_uninstall_shadow);
116 updateText(R.string.uninstall_drop_target_label);
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800117 } else if (action == DISMISS_PREDICTION) {
118 mHoverColor = Themes.getColorAccent(getContext());
Tony Wickhambd9754d2020-03-27 20:11:16 -0700119 setDrawable(R.drawable.ic_block_shadow);
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800120 updateText(R.string.dismiss_prediction_label);
121 } else if (action == RECONFIGURE) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000122 mHoverColor = Themes.getColorAccent(getContext());
123 setDrawable(R.drawable.ic_setup_shadow);
124 updateText(R.string.gadget_setup_text);
125 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700126 }
127
128 @Override
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700129 public void onAlarm(Alarm alarm) {
130 mUninstallDisabledCache.clear();
Sunny Goyal1a70cef2015-04-22 11:29:51 -0700131 }
132
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700133 @Override
134 public int getAccessibilityAction() {
Winson Chung1054d4e2018-03-05 19:39:21 +0000135 return mCurrentAccessibilityAction;
136 }
137
138 @Override
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -0700139 public Target getDropTargetForLogging() {
140 Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800141 if (mCurrentAccessibilityAction == UNINSTALL) {
142 t.controlType = ControlType.UNINSTALL_TARGET;
143 } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
144 t.controlType = ControlType.DISMISS_PREDICTION;
145 } else {
146 t.controlType = ControlType.SETTINGS_BUTTON;
147 }
Mehdi Alizadehbda47cf2018-05-01 19:26:05 -0700148 return t;
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700149 }
150
151 @Override
152 protected boolean supportsDrop(ItemInfo info) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000153 return supportsAccessibilityDrop(info, getViewUnderDrag(info));
154 }
155
156 @Override
157 public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
158 if (view instanceof AppWidgetHostView) {
159 if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
160 setupUi(RECONFIGURE);
161 return true;
162 }
163 return false;
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800164 } else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
165 setupUi(DISMISS_PREDICTION);
166 return true;
Winson Chung1054d4e2018-03-05 19:39:21 +0000167 }
168
169 setupUi(UNINSTALL);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700170 Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
171 if (uninstallDisabled == null) {
172 UserManager userManager =
173 (UserManager) getContext().getSystemService(Context.USER_SERVICE);
174 Bundle restrictions = userManager.getUserRestrictions(info.user);
175 uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700176 || restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700177 mUninstallDisabledCache.put(info.user, uninstallDisabled);
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700178 }
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700179 // Cancel any pending alarm and set cache expiry after some time
180 mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
vadimt908e9bb2020-02-28 18:02:30 -0800181 mCacheExpireAlarm.setOnAlarmListener(this);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700182 if (uninstallDisabled) {
Sunny Goyala52ecb02016-12-16 15:04:51 -0800183 return false;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700184 }
185
Sunny Goyal076839c2017-10-30 13:52:20 -0700186 if (info instanceof ItemInfoWithIcon) {
187 ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
188 if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
189 return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
Sunny Goyal6b0aa872017-09-29 07:54:37 -0700190 }
191 }
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700192 return getUninstallTarget(info) != null;
Sunny Goyalfa401a12015-04-10 13:45:42 -0700193 }
194
195 /**
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700196 * @return the component name that should be uninstalled or null.
Sunny Goyalfa401a12015-04-10 13:45:42 -0700197 */
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700198 private ComponentName getUninstallTarget(ItemInfo item) {
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700199 Intent intent = null;
Sunny Goyal7c74e4a2016-12-15 15:53:17 -0800200 UserHandle user = null;
Sunny Goyal1fe0c2c2017-08-15 12:54:42 -0700201 if (item != null &&
Sunny Goyalc5939392018-12-07 11:43:47 -0800202 item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
Sunny Goyal1fe0c2c2017-08-15 12:54:42 -0700203 intent = item.getIntent();
204 user = item.user;
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700205 }
206 if (intent != null) {
Sunny Goyale7b00122019-10-02 16:13:34 -0700207 LauncherActivityInfo info = mLauncher.getSystemService(LauncherApps.class)
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700208 .resolveActivity(intent, user);
209 if (info != null
210 && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
211 return info.getComponentName();
Sunny Goyalfa401a12015-04-10 13:45:42 -0700212 }
213 }
214 return null;
215 }
216
217 @Override
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700218 public void onDrop(DragObject d, DragOptions options) {
219 // Defer onComplete
Sunny Goyal1797af42017-10-06 13:29:57 -0700220 d.dragSource = new DeferredOnComplete(d.dragSource, getContext());
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700221 super.onDrop(d, options);
thiruramff484512020-05-11 11:19:58 -0700222 if (mCurrentAccessibilityAction == UNINSTALL) {
thiruramc6a38ba2020-06-16 18:58:13 -0700223 mStatsLogManager.logger().withInstanceId(d.logInstanceId)
224 .log(LAUNCHER_ITEM_DROPPED_ON_UNINSTALL);
thiruramff484512020-05-11 11:19:58 -0700225 } else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
thiruramc6a38ba2020-06-16 18:58:13 -0700226 mStatsLogManager.logger().withInstanceId(d.logInstanceId)
227 .log(LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST);
thiruramff484512020-05-11 11:19:58 -0700228 }
Sunny Goyalfa401a12015-04-10 13:45:42 -0700229 }
230
231 @Override
Sunny Goyal0f76b562016-12-13 19:37:10 -0800232 public void completeDrop(final DragObject d) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000233 ComponentName target = performDropAction(getViewUnderDrag(d.dragInfo), d.dragInfo);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700234 if (d.dragSource instanceof DeferredOnComplete) {
235 DeferredOnComplete deferred = (DeferredOnComplete) d.dragSource;
236 if (target != null) {
237 deferred.mPackageName = target.getPackageName();
Winson Chung0b70cd42019-06-17 22:34:33 -0700238 mLauncher.addOnResumeCallback(deferred);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700239 } else {
240 deferred.sendFailure();
241 }
242 }
Tony Wickham734dfbe2015-09-16 16:22:36 -0700243 }
244
Winson Chung1054d4e2018-03-05 19:39:21 +0000245 private View getViewUnderDrag(ItemInfo info) {
246 if (info instanceof LauncherAppWidgetInfo && info.container == CONTAINER_DESKTOP &&
247 mLauncher.getWorkspace().getDragInfo() != null) {
248 return mLauncher.getWorkspace().getDragInfo().cell;
249 }
250 return null;
251 }
252
253 /**
254 * Verifies that the view is an reconfigurable widget and returns the corresponding widget Id,
255 * otherwise return {@code INVALID_APPWIDGET_ID}
256 */
257 private int getReconfigurableWidgetId(View view) {
258 if (!(view instanceof AppWidgetHostView)) {
259 return INVALID_APPWIDGET_ID;
260 }
261 AppWidgetHostView hostView = (AppWidgetHostView) view;
262 AppWidgetProviderInfo widgetInfo = hostView.getAppWidgetInfo();
263 if (widgetInfo == null || widgetInfo.configure == null) {
264 return INVALID_APPWIDGET_ID;
265 }
266 if ( (LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(), widgetInfo)
267 .getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) == 0) {
268 return INVALID_APPWIDGET_ID;
269 }
270 return hostView.getAppWidgetId();
271 }
272
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700273 /**
274 * Performs the drop action and returns the target component for the dragObject or null if
275 * the action was not performed.
276 */
Winson Chung1054d4e2018-03-05 19:39:21 +0000277 protected ComponentName performDropAction(View view, ItemInfo info) {
278 if (mCurrentAccessibilityAction == RECONFIGURE) {
279 int widgetId = getReconfigurableWidgetId(view);
280 if (widgetId != INVALID_APPWIDGET_ID) {
281 mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, widgetId, -1);
282 }
283 return null;
284 }
Samuel Fufa5cf3e862020-02-03 20:22:54 -0800285 if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
286 AppLaunchTracker.INSTANCE.get(getContext()).onDismissApp(info.getTargetComponent(),
287 info.user, AppLaunchTracker.CONTAINER_PREDICTIONS);
288 return null;
289 }
Winson Chung1054d4e2018-03-05 19:39:21 +0000290 // else: mCurrentAccessibilityAction == UNINSTALL
291
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700292 ComponentName cn = getUninstallTarget(info);
Sunny Goyal8e0e1d72016-10-10 10:41:41 -0700293 if (cn == null) {
Sunny Goyald5bd67d2016-03-11 01:10:19 -0800294 // System applications cannot be installed. For now, show a toast explaining that.
295 // We may give them the option of disabling apps this way.
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700296 Toast.makeText(mLauncher, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show();
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700297 return null;
298 }
299 try {
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700300 Intent i = Intent.parseUri(mLauncher.getString(R.string.delete_package_intent), 0)
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700301 .setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName()))
302 .putExtra(Intent.EXTRA_USER, info.user);
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700303 mLauncher.startActivity(i);
Samuel Fufacc1e1072019-09-06 16:19:11 -0700304 FileLog.d(TAG, "start uninstall activity " + cn.getPackageName());
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700305 return cn;
306 } catch (URISyntaxException e) {
307 Log.e(TAG, "Failed to parse intent to start uninstall activity for item=" + info);
308 return null;
309 }
310 }
311
Sunny Goyal0236d0b2017-10-24 14:54:30 -0700312 @Override
313 public void onAccessibilityDrop(View view, ItemInfo item) {
Winson Chung1054d4e2018-03-05 19:39:21 +0000314 performDropAction(view, item);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700315 }
316
317 /**
318 * A wrapper around {@link DragSource} which delays the {@link #onDropCompleted} action until
319 * {@link #onLauncherResume}
320 */
321 private class DeferredOnComplete implements DragSource, OnResumeCallback {
322
323 private final DragSource mOriginal;
324 private final Context mContext;
325
326 private String mPackageName;
327 private DragObject mDragObject;
328
329 public DeferredOnComplete(DragSource original, Context context) {
330 mOriginal = original;
331 mContext = context;
332 }
333
334 @Override
Sunny Goyal1797af42017-10-06 13:29:57 -0700335 public void onDropCompleted(View target, DragObject d,
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700336 boolean success) {
337 mDragObject = d;
338 }
339
340 @Override
Samuel Fufaa579ddc2020-02-27 16:59:19 -0800341 public void fillInLogContainerData(ItemInfo childInfo, Target child,
342 ArrayList<Target> parents) {
343 mOriginal.fillInLogContainerData(childInfo, child, parents);
Sunny Goyal3dce5f32017-10-05 11:40:05 -0700344 }
345
346 @Override
347 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}