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