2015-04-10 13:45:42 -07:00
|
|
|
package com.android.launcher3;
|
|
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
import static android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
|
|
|
import static android.appwidget.AppWidgetProviderInfo.WIDGET_FEATURE_RECONFIGURABLE;
|
2019-09-06 16:19:11 -07:00
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
|
2020-02-03 20:22:54 -08:00
|
|
|
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.DISMISS_PREDICTION;
|
2018-03-05 19:39:21 +00:00
|
|
|
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.RECONFIGURE;
|
|
|
|
|
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.UNINSTALL;
|
2020-04-06 15:11:17 -07:00
|
|
|
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_MASK;
|
|
|
|
|
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_SYSTEM_NO;
|
2017-10-30 13:52:20 -07:00
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
import android.appwidget.AppWidgetHostView;
|
|
|
|
|
import android.appwidget.AppWidgetProviderInfo;
|
2015-04-10 13:45:42 -07:00
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Context;
|
2016-03-11 01:10:19 -08:00
|
|
|
import android.content.Intent;
|
2016-10-10 10:41:41 -07:00
|
|
|
import android.content.pm.ApplicationInfo;
|
2017-01-05 15:22:41 -08:00
|
|
|
import android.content.pm.LauncherActivityInfo;
|
2019-10-02 16:13:34 -07:00
|
|
|
import android.content.pm.LauncherApps;
|
2017-03-01 17:27:16 -08:00
|
|
|
import android.content.pm.PackageManager;
|
2016-03-11 01:10:19 -08:00
|
|
|
import android.net.Uri;
|
2015-04-10 13:45:42 -07:00
|
|
|
import android.os.Bundle;
|
2016-12-15 15:53:17 -08:00
|
|
|
import android.os.UserHandle;
|
2015-04-10 13:45:42 -07:00
|
|
|
import android.os.UserManager;
|
2017-10-24 14:54:30 -07:00
|
|
|
import android.util.ArrayMap;
|
2015-04-10 13:45:42 -07:00
|
|
|
import android.util.AttributeSet;
|
2017-08-23 12:13:24 -07:00
|
|
|
import android.util.Log;
|
2017-10-05 11:40:05 -07:00
|
|
|
import android.view.View;
|
2016-03-11 01:10:19 -08:00
|
|
|
import android.widget.Toast;
|
2015-06-12 20:04:41 -07:00
|
|
|
|
2017-10-05 11:40:05 -07:00
|
|
|
import com.android.launcher3.Launcher.OnResumeCallback;
|
2020-02-03 20:22:54 -08:00
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
2017-10-05 11:40:05 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragOptions;
|
2019-09-06 16:19:11 -07:00
|
|
|
import com.android.launcher3.logging.FileLog;
|
2018-05-01 19:26:05 -07:00
|
|
|
import com.android.launcher3.logging.LoggerUtils;
|
2020-02-03 20:22:54 -08:00
|
|
|
import com.android.launcher3.model.AppLaunchTracker;
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
|
|
|
|
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
|
|
|
|
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
|
2018-05-01 19:26:05 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
|
2017-10-05 11:40:05 -07:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
|
2019-10-02 16:13:34 -07:00
|
|
|
import com.android.launcher3.util.PackageManagerHelper;
|
2018-03-05 19:39:21 +00:00
|
|
|
import com.android.launcher3.util.Themes;
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2017-08-23 12:13:24 -07:00
|
|
|
import java.net.URISyntaxException;
|
2020-02-27 16:59:19 -08:00
|
|
|
import java.util.ArrayList;
|
2017-08-23 12:13:24 -07:00
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
/**
|
|
|
|
|
* Drop target which provides a secondary option for an item.
|
|
|
|
|
* For app targets: shows as uninstall
|
|
|
|
|
* For configurable widgets: shows as setup
|
2020-02-03 20:22:54 -08:00
|
|
|
* For predicted app icons: don't suggest app
|
2018-03-05 19:39:21 +00:00
|
|
|
*/
|
|
|
|
|
public class SecondaryDropTarget extends ButtonDropTarget implements OnAlarmListener {
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
private static final String TAG = "SecondaryDropTarget";
|
2017-10-24 14:54:30 -07:00
|
|
|
|
|
|
|
|
private static final long CACHE_EXPIRE_TIMEOUT = 5000;
|
|
|
|
|
private final ArrayMap<UserHandle, Boolean> mUninstallDisabledCache = new ArrayMap<>(1);
|
|
|
|
|
|
|
|
|
|
private final Alarm mCacheExpireAlarm;
|
2020-02-27 11:28:47 -08:00
|
|
|
private boolean mHadPendingAlarm;
|
2017-08-23 12:13:24 -07:00
|
|
|
|
2018-04-23 15:55:26 -07:00
|
|
|
protected int mCurrentAccessibilityAction = -1;
|
2018-03-05 19:39:21 +00:00
|
|
|
public SecondaryDropTarget(Context context, AttributeSet attrs) {
|
2015-04-10 13:45:42 -07:00
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
public SecondaryDropTarget(Context context, AttributeSet attrs, int defStyle) {
|
2015-04-10 13:45:42 -07:00
|
|
|
super(context, attrs, defStyle);
|
2017-10-24 14:54:30 -07:00
|
|
|
|
|
|
|
|
mCacheExpireAlarm = new Alarm();
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
2020-02-27 11:28:47 -08:00
|
|
|
@Override
|
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
if (mHadPendingAlarm) {
|
|
|
|
|
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
|
2020-02-28 18:02:30 -08:00
|
|
|
mCacheExpireAlarm.setOnAlarmListener(this);
|
2020-02-27 11:28:47 -08:00
|
|
|
mHadPendingAlarm = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
if (mCacheExpireAlarm.alarmPending()) {
|
|
|
|
|
mCacheExpireAlarm.cancelAlarm();
|
2020-02-28 18:02:30 -08:00
|
|
|
mCacheExpireAlarm.setOnAlarmListener(null);
|
2020-02-27 11:28:47 -08:00
|
|
|
mHadPendingAlarm = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-10 13:45:42 -07:00
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
2018-03-05 19:39:21 +00:00
|
|
|
setupUi(UNINSTALL);
|
2017-04-26 22:34:49 -07:00
|
|
|
}
|
|
|
|
|
|
2018-04-23 15:55:26 -07:00
|
|
|
protected void setupUi(int action) {
|
2018-03-05 19:39:21 +00:00
|
|
|
if (action == mCurrentAccessibilityAction) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mCurrentAccessibilityAction = action;
|
|
|
|
|
|
|
|
|
|
if (action == UNINSTALL) {
|
|
|
|
|
mHoverColor = getResources().getColor(R.color.uninstall_target_hover_tint);
|
|
|
|
|
setDrawable(R.drawable.ic_uninstall_shadow);
|
|
|
|
|
updateText(R.string.uninstall_drop_target_label);
|
2020-02-03 20:22:54 -08:00
|
|
|
} else if (action == DISMISS_PREDICTION) {
|
|
|
|
|
mHoverColor = Themes.getColorAccent(getContext());
|
2020-03-27 20:11:16 -07:00
|
|
|
setDrawable(R.drawable.ic_block_shadow);
|
2020-02-03 20:22:54 -08:00
|
|
|
updateText(R.string.dismiss_prediction_label);
|
|
|
|
|
} else if (action == RECONFIGURE) {
|
2018-03-05 19:39:21 +00:00
|
|
|
mHoverColor = Themes.getColorAccent(getContext());
|
|
|
|
|
setDrawable(R.drawable.ic_setup_shadow);
|
|
|
|
|
updateText(R.string.gadget_setup_text);
|
|
|
|
|
}
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-10-24 14:54:30 -07:00
|
|
|
public void onAlarm(Alarm alarm) {
|
|
|
|
|
mUninstallDisabledCache.clear();
|
2015-04-22 11:29:51 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
@Override
|
|
|
|
|
public int getAccessibilityAction() {
|
2018-03-05 19:39:21 +00:00
|
|
|
return mCurrentAccessibilityAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2018-05-01 19:26:05 -07:00
|
|
|
public Target getDropTargetForLogging() {
|
|
|
|
|
Target t = LoggerUtils.newTarget(Target.Type.CONTROL);
|
2020-02-03 20:22:54 -08:00
|
|
|
if (mCurrentAccessibilityAction == UNINSTALL) {
|
|
|
|
|
t.controlType = ControlType.UNINSTALL_TARGET;
|
|
|
|
|
} else if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
|
|
|
|
|
t.controlType = ControlType.DISMISS_PREDICTION;
|
|
|
|
|
} else {
|
|
|
|
|
t.controlType = ControlType.SETTINGS_BUTTON;
|
|
|
|
|
}
|
2018-05-01 19:26:05 -07:00
|
|
|
return t;
|
2017-10-24 14:54:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean supportsDrop(ItemInfo info) {
|
2018-03-05 19:39:21 +00:00
|
|
|
return supportsAccessibilityDrop(info, getViewUnderDrag(info));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
|
|
|
|
|
if (view instanceof AppWidgetHostView) {
|
|
|
|
|
if (getReconfigurableWidgetId(view) != INVALID_APPWIDGET_ID) {
|
|
|
|
|
setupUi(RECONFIGURE);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2020-02-03 20:22:54 -08:00
|
|
|
} else if (FeatureFlags.ENABLE_PREDICTION_DISMISS.get() && info.isPredictedItem()) {
|
|
|
|
|
setupUi(DISMISS_PREDICTION);
|
|
|
|
|
return true;
|
2018-03-05 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupUi(UNINSTALL);
|
2017-10-24 14:54:30 -07:00
|
|
|
Boolean uninstallDisabled = mUninstallDisabledCache.get(info.user);
|
|
|
|
|
if (uninstallDisabled == null) {
|
|
|
|
|
UserManager userManager =
|
|
|
|
|
(UserManager) getContext().getSystemService(Context.USER_SERVICE);
|
|
|
|
|
Bundle restrictions = userManager.getUserRestrictions(info.user);
|
|
|
|
|
uninstallDisabled = restrictions.getBoolean(UserManager.DISALLOW_APPS_CONTROL, false)
|
2017-09-29 07:54:37 -07:00
|
|
|
|| restrictions.getBoolean(UserManager.DISALLOW_UNINSTALL_APPS, false);
|
2017-10-24 14:54:30 -07:00
|
|
|
mUninstallDisabledCache.put(info.user, uninstallDisabled);
|
2017-09-29 07:54:37 -07:00
|
|
|
}
|
2017-10-24 14:54:30 -07:00
|
|
|
// Cancel any pending alarm and set cache expiry after some time
|
|
|
|
|
mCacheExpireAlarm.setAlarm(CACHE_EXPIRE_TIMEOUT);
|
2020-02-28 18:02:30 -08:00
|
|
|
mCacheExpireAlarm.setOnAlarmListener(this);
|
2017-10-24 14:54:30 -07:00
|
|
|
if (uninstallDisabled) {
|
2016-12-16 15:04:51 -08:00
|
|
|
return false;
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-30 13:52:20 -07:00
|
|
|
if (info instanceof ItemInfoWithIcon) {
|
|
|
|
|
ItemInfoWithIcon iconInfo = (ItemInfoWithIcon) info;
|
|
|
|
|
if ((iconInfo.runtimeStatusFlags & FLAG_SYSTEM_MASK) != 0) {
|
|
|
|
|
return (iconInfo.runtimeStatusFlags & FLAG_SYSTEM_NO) != 0;
|
2017-09-29 07:54:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
2017-10-24 14:54:30 -07:00
|
|
|
return getUninstallTarget(info) != null;
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-10-10 10:41:41 -07:00
|
|
|
* @return the component name that should be uninstalled or null.
|
2015-04-10 13:45:42 -07:00
|
|
|
*/
|
2017-10-24 14:54:30 -07:00
|
|
|
private ComponentName getUninstallTarget(ItemInfo item) {
|
2016-10-10 10:41:41 -07:00
|
|
|
Intent intent = null;
|
2016-12-15 15:53:17 -08:00
|
|
|
UserHandle user = null;
|
2017-08-15 12:54:42 -07:00
|
|
|
if (item != null &&
|
2018-12-07 11:43:47 -08:00
|
|
|
item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
|
2017-08-15 12:54:42 -07:00
|
|
|
intent = item.getIntent();
|
|
|
|
|
user = item.user;
|
2016-10-10 10:41:41 -07:00
|
|
|
}
|
|
|
|
|
if (intent != null) {
|
2019-10-02 16:13:34 -07:00
|
|
|
LauncherActivityInfo info = mLauncher.getSystemService(LauncherApps.class)
|
2016-10-10 10:41:41 -07:00
|
|
|
.resolveActivity(intent, user);
|
|
|
|
|
if (info != null
|
|
|
|
|
&& (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
|
|
|
|
|
return info.getComponentName();
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-10-05 11:40:05 -07:00
|
|
|
public void onDrop(DragObject d, DragOptions options) {
|
|
|
|
|
// Defer onComplete
|
2017-10-06 13:29:57 -07:00
|
|
|
d.dragSource = new DeferredOnComplete(d.dragSource, getContext());
|
2017-10-05 11:40:05 -07:00
|
|
|
super.onDrop(d, options);
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-13 19:37:10 -08:00
|
|
|
public void completeDrop(final DragObject d) {
|
2018-03-05 19:39:21 +00:00
|
|
|
ComponentName target = performDropAction(getViewUnderDrag(d.dragInfo), d.dragInfo);
|
2017-10-05 11:40:05 -07:00
|
|
|
if (d.dragSource instanceof DeferredOnComplete) {
|
|
|
|
|
DeferredOnComplete deferred = (DeferredOnComplete) d.dragSource;
|
|
|
|
|
if (target != null) {
|
|
|
|
|
deferred.mPackageName = target.getPackageName();
|
2019-06-17 22:34:33 -07:00
|
|
|
mLauncher.addOnResumeCallback(deferred);
|
2017-10-05 11:40:05 -07:00
|
|
|
} else {
|
|
|
|
|
deferred.sendFailure();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-11 01:10:19 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-05 19:39:21 +00:00
|
|
|
private View getViewUnderDrag(ItemInfo info) {
|
|
|
|
|
if (info instanceof LauncherAppWidgetInfo && info.container == CONTAINER_DESKTOP &&
|
|
|
|
|
mLauncher.getWorkspace().getDragInfo() != null) {
|
|
|
|
|
return mLauncher.getWorkspace().getDragInfo().cell;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verifies that the view is an reconfigurable widget and returns the corresponding widget Id,
|
|
|
|
|
* otherwise return {@code INVALID_APPWIDGET_ID}
|
|
|
|
|
*/
|
|
|
|
|
private int getReconfigurableWidgetId(View view) {
|
|
|
|
|
if (!(view instanceof AppWidgetHostView)) {
|
|
|
|
|
return INVALID_APPWIDGET_ID;
|
|
|
|
|
}
|
|
|
|
|
AppWidgetHostView hostView = (AppWidgetHostView) view;
|
|
|
|
|
AppWidgetProviderInfo widgetInfo = hostView.getAppWidgetInfo();
|
|
|
|
|
if (widgetInfo == null || widgetInfo.configure == null) {
|
|
|
|
|
return INVALID_APPWIDGET_ID;
|
|
|
|
|
}
|
|
|
|
|
if ( (LauncherAppWidgetProviderInfo.fromProviderInfo(getContext(), widgetInfo)
|
|
|
|
|
.getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) == 0) {
|
|
|
|
|
return INVALID_APPWIDGET_ID;
|
|
|
|
|
}
|
|
|
|
|
return hostView.getAppWidgetId();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 11:40:05 -07:00
|
|
|
/**
|
|
|
|
|
* Performs the drop action and returns the target component for the dragObject or null if
|
|
|
|
|
* the action was not performed.
|
|
|
|
|
*/
|
2018-03-05 19:39:21 +00:00
|
|
|
protected ComponentName performDropAction(View view, ItemInfo info) {
|
|
|
|
|
if (mCurrentAccessibilityAction == RECONFIGURE) {
|
|
|
|
|
int widgetId = getReconfigurableWidgetId(view);
|
|
|
|
|
if (widgetId != INVALID_APPWIDGET_ID) {
|
|
|
|
|
mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, widgetId, -1);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-02-03 20:22:54 -08:00
|
|
|
if (mCurrentAccessibilityAction == DISMISS_PREDICTION) {
|
|
|
|
|
AppLaunchTracker.INSTANCE.get(getContext()).onDismissApp(info.getTargetComponent(),
|
|
|
|
|
info.user, AppLaunchTracker.CONTAINER_PREDICTIONS);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-03-05 19:39:21 +00:00
|
|
|
// else: mCurrentAccessibilityAction == UNINSTALL
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
ComponentName cn = getUninstallTarget(info);
|
2016-10-10 10:41:41 -07:00
|
|
|
if (cn == null) {
|
2016-03-11 01:10:19 -08:00
|
|
|
// System applications cannot be installed. For now, show a toast explaining that.
|
|
|
|
|
// We may give them the option of disabling apps this way.
|
2017-10-24 14:54:30 -07:00
|
|
|
Toast.makeText(mLauncher, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show();
|
2017-10-05 11:40:05 -07:00
|
|
|
return null;
|
2016-03-11 01:10:19 -08:00
|
|
|
}
|
2017-10-05 11:40:05 -07:00
|
|
|
try {
|
2017-10-24 14:54:30 -07:00
|
|
|
Intent i = Intent.parseUri(mLauncher.getString(R.string.delete_package_intent), 0)
|
2017-10-05 11:40:05 -07:00
|
|
|
.setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName()))
|
|
|
|
|
.putExtra(Intent.EXTRA_USER, info.user);
|
2017-10-24 14:54:30 -07:00
|
|
|
mLauncher.startActivity(i);
|
2019-09-06 16:19:11 -07:00
|
|
|
FileLog.d(TAG, "start uninstall activity " + cn.getPackageName());
|
2017-10-05 11:40:05 -07:00
|
|
|
return cn;
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
Log.e(TAG, "Failed to parse intent to start uninstall activity for item=" + info);
|
|
|
|
|
return null;
|
2016-03-11 01:10:19 -08:00
|
|
|
}
|
2017-10-05 11:40:05 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAccessibilityDrop(View view, ItemInfo item) {
|
2018-03-05 19:39:21 +00:00
|
|
|
performDropAction(view, item);
|
2016-03-11 01:10:19 -08:00
|
|
|
}
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2016-03-11 01:10:19 -08:00
|
|
|
/**
|
2017-10-05 11:40:05 -07:00
|
|
|
* A wrapper around {@link DragSource} which delays the {@link #onDropCompleted} action until
|
|
|
|
|
* {@link #onLauncherResume}
|
2016-03-11 01:10:19 -08:00
|
|
|
*/
|
2017-10-05 11:40:05 -07:00
|
|
|
private class DeferredOnComplete implements DragSource, OnResumeCallback {
|
|
|
|
|
|
|
|
|
|
private final DragSource mOriginal;
|
|
|
|
|
private final Context mContext;
|
|
|
|
|
|
|
|
|
|
private String mPackageName;
|
|
|
|
|
private DragObject mDragObject;
|
|
|
|
|
|
|
|
|
|
public DeferredOnComplete(DragSource original, Context context) {
|
|
|
|
|
mOriginal = original;
|
|
|
|
|
mContext = context;
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-05 11:40:05 -07:00
|
|
|
@Override
|
2017-10-06 13:29:57 -07:00
|
|
|
public void onDropCompleted(View target, DragObject d,
|
2017-10-05 11:40:05 -07:00
|
|
|
boolean success) {
|
|
|
|
|
mDragObject = d;
|
|
|
|
|
}
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2017-10-05 11:40:05 -07:00
|
|
|
@Override
|
2020-02-27 16:59:19 -08:00
|
|
|
public void fillInLogContainerData(ItemInfo childInfo, Target child,
|
|
|
|
|
ArrayList<Target> parents) {
|
|
|
|
|
mOriginal.fillInLogContainerData(childInfo, child, parents);
|
2017-10-05 11:40:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLauncherResume() {
|
|
|
|
|
// We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
|
2019-10-02 16:13:34 -07:00
|
|
|
if (new PackageManagerHelper(mContext).getApplicationInfo(mPackageName,
|
|
|
|
|
mDragObject.dragInfo.user, PackageManager.MATCH_UNINSTALLED_PACKAGES) == null) {
|
2017-10-05 11:40:05 -07:00
|
|
|
mDragObject.dragSource = mOriginal;
|
2018-03-05 19:39:21 +00:00
|
|
|
mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, true);
|
2017-10-05 11:40:05 -07:00
|
|
|
} else {
|
|
|
|
|
sendFailure();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2017-10-05 11:40:05 -07:00
|
|
|
public void sendFailure() {
|
|
|
|
|
mDragObject.dragSource = mOriginal;
|
|
|
|
|
mDragObject.cancelled = true;
|
2018-03-05 19:39:21 +00:00
|
|
|
mOriginal.onDropCompleted(SecondaryDropTarget.this, mDragObject, false);
|
2017-10-05 11:40:05 -07:00
|
|
|
}
|
2015-04-10 13:45:42 -07:00
|
|
|
}
|
|
|
|
|
}
|