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