import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.ManagedProfileHeuristic;
+import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.StringFilter;
-import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.ViewOnDrawExecutor;
List<ShortcutInfoCompat> fullDetails = mDeepShortcutManager
.queryForFullDetails(packageName,
Collections.singletonList(shortcutId), user);
- if (fullDetails != null && !fullDetails.isEmpty()) {
+ if (fullDetails == null || fullDetails.isEmpty()) {
+ // There are no details for the shortcut. If this is due
+ // to a SecurityException, keep it in the database so
+ // we can restore the icon when the launcher regains
+ // permission. Otherwise remove the icon from the db.
+ if (!mDeepShortcutManager.wasLastCallSuccess()) {
+ itemsToRemove.add(id);
+ continue;
+ }
+ } else {
pinnedShortcut = fullDetails.get(0);
shouldPin = true;
}
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.os.UserHandle;
import android.util.Log;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.UserHandleCompat;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED | FLAG_MATCH_MANIFEST;
private final LauncherApps mLauncherApps;
+ private boolean mWasLastCallSuccess;
public DeepShortcutManager(Context context, ShortcutCache shortcutCache) {
mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
|| info.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
}
+ public boolean wasLastCallSuccess() {
+ return mWasLastCallSuccess;
+ }
+
public void onShortcutsChanged(List<ShortcutInfoCompat> shortcuts) {
// mShortcutCache.removeShortcuts(shortcuts);
}
pinnedIds.remove(id);
try {
mLauncherApps.pinShortcuts(packageName, pinnedIds, user.getUser());
+ mWasLastCallSuccess = true;
} catch (SecurityException e) {
- Log.e(TAG, Log.getStackTraceString(e));
+ Log.w(TAG, "Failed to unpin shortcut", e);
+ mWasLastCallSuccess = false;
}
}
}
pinnedIds.add(id);
try {
mLauncherApps.pinShortcuts(packageName, pinnedIds, user.getUser());
+ mWasLastCallSuccess = true;
} catch (SecurityException e) {
- Log.e(TAG, Log.getStackTraceString(e));
+ Log.w(TAG, "Failed to pin shortcut", e);
+ mWasLastCallSuccess = false;
}
}
}
Bundle startActivityOptions, UserHandleCompat user) {
if (Utilities.isNycMR1OrAbove()) {
try {
- // TODO: remove reflection once updated SDK is ready.
- // mLauncherApps.startShortcut(packageName, id, sourceBounds,
- // startActivityOptions, user.getUser());
- mLauncherApps.getClass().getMethod("startShortcut", String.class, String.class,
- Rect.class, Bundle.class, UserHandle.class).invoke(mLauncherApps,
- packageName, id, sourceBounds, startActivityOptions, user.getUser());
+ mLauncherApps.startShortcut(packageName, id, sourceBounds,
+ startActivityOptions, user.getUser());
+ mWasLastCallSuccess = true;
} catch (SecurityException e) {
- Log.e(TAG, Log.getStackTraceString(e));
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
+ Log.e(TAG, "Failed to start shortcut", e);
+ mWasLastCallSuccess = false;
}
}
}
public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) {
if (Utilities.isNycMR1OrAbove()) {
try {
- return mLauncherApps.getShortcutIconDrawable(shortcutInfo.getShortcutInfo(),
- density);
+ Drawable icon = mLauncherApps.getShortcutIconDrawable(
+ shortcutInfo.getShortcutInfo(), density);
+ mWasLastCallSuccess = true;
+ return icon;
} catch (SecurityException e) {
- Log.e(TAG, Log.getStackTraceString(e));
+ Log.e(TAG, "Failed to get shortcut icon", e);
+ mWasLastCallSuccess = false;
}
}
return null;
List<ShortcutInfo> shortcutInfos = null;
try {
shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser());
+ mWasLastCallSuccess = true;
} catch (SecurityException e) {
- Log.e(TAG, Log.getStackTraceString(e));
+ Log.e(TAG, "Failed to query for shortcuts", e);
+ mWasLastCallSuccess = false;
}
if (shortcutInfos == null) {
return Collections.EMPTY_LIST;