Merge "Changing DeepShortcutManager to have a singleton contructor instead of getting it from LauncherAppState" into ub-launcher3-master

This commit is contained in:
Sunny Goyal
2016-11-21 17:07:05 +00:00
committed by Android (Google) Code Review
9 changed files with 36 additions and 31 deletions

View File

@@ -2594,7 +2594,7 @@ public class Launcher extends Activity
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
String id = ((ShortcutInfo) info).getDeepShortcutId();
String packageName = intent.getPackage();
LauncherAppState.getInstance().getShortcutManager().startShortcut(
DeepShortcutManager.getInstance(this).startShortcut(
packageName, id, intent.getSourceBounds(), optsBundle, info.user);
} else {
// Could be launching some bookkeeping activity

View File

@@ -28,8 +28,6 @@ import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutCache;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
@@ -44,7 +42,6 @@ public class LauncherAppState {
@Thunk final LauncherModel mModel;
private final IconCache mIconCache;
private final WidgetPreviewLoader mWidgetCache;
private final DeepShortcutManager mDeepShortcutManager;
@Thunk boolean mWallpaperChangedSinceLastCheck;
@@ -98,10 +95,9 @@ public class LauncherAppState {
mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);
mDeepShortcutManager = new DeepShortcutManager(sContext, new ShortcutCache());
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
mModel = new LauncherModel(this, mIconCache, mAppFilter, mDeepShortcutManager);
mModel = new LauncherModel(this, mIconCache, mAppFilter);
LauncherAppsCompat.getInstance(sContext).addOnAppsChangedCallback(mModel);
@@ -173,10 +169,6 @@ public class LauncherAppState {
return mWidgetCache;
}
public DeepShortcutManager getShortcutManager() {
return mDeepShortcutManager;
}
public boolean hasWallpaperChangedSinceLastCheck() {
boolean result = mWallpaperChangedSinceLastCheck;
mWallpaperChangedSinceLastCheck = false;

View File

@@ -156,7 +156,8 @@ public class LauncherModel extends BroadcastReceiver
@Override
public void run() {
if (mDeepShortcutsLoaded) {
boolean hasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
boolean hasShortcutHostPermission =
DeepShortcutManager.getInstance(mApp.getContext()).hasHostPermission();
if (hasShortcutHostPermission != mHasShortcutHostPermission) {
mApp.reloadWorkspace();
}
@@ -173,7 +174,6 @@ public class LauncherModel extends BroadcastReceiver
// </ only access in worker thread >
private final IconCache mIconCache;
private final DeepShortcutManager mDeepShortcutManager;
private final LauncherAppsCompat mLauncherApps;
private final UserManagerCompat mUserManager;
@@ -210,14 +210,12 @@ public class LauncherModel extends BroadcastReceiver
public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMap);
}
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter,
DeepShortcutManager deepShortcutManager) {
LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) {
Context context = app.getContext();
mApp = app;
mBgAllAppsList = new AllAppsList(iconCache, appFilter);
mBgWidgetsModel = new WidgetsModel(iconCache, appFilter);
mIconCache = iconCache;
mDeepShortcutManager = deepShortcutManager;
mLauncherApps = LauncherAppsCompat.getInstance(context);
mUserManager = UserManagerCompat.getInstance(context);
@@ -1191,6 +1189,7 @@ public class LauncherModel extends BroadcastReceiver
final PackageManager manager = context.getPackageManager();
final boolean isSafeMode = manager.isSafeMode();
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
final DeepShortcutManager shortcutManager = DeepShortcutManager.getInstance(context);
final boolean isSdCardReady = Utilities.isBootCompleted();
final MultiHashMap<UserHandleCompat, String> pendingPackages = new MultiHashMap<>();
@@ -1288,8 +1287,8 @@ public class LauncherModel extends BroadcastReceiver
// We can only query for shortcuts when the user is unlocked.
if (userUnlocked) {
List<ShortcutInfoCompat> pinnedShortcuts =
mDeepShortcutManager.queryForPinnedShortcuts(null, user);
if (mDeepShortcutManager.wasLastCallSuccess()) {
shortcutManager.queryForPinnedShortcuts(null, user);
if (shortcutManager.wasLastCallSuccess()) {
for (ShortcutInfoCompat shortcut : pinnedShortcuts) {
shortcutKeyToPinnedShortcuts.put(ShortcutKey.fromInfo(shortcut),
shortcut);
@@ -1773,7 +1772,7 @@ public class LauncherModel extends BroadcastReceiver
MutableInt numTimesPinned = sBgDataModel.pinnedShortcutCounts.get(key);
if (numTimesPinned == null || numTimesPinned.value == 0) {
// Shortcut is pinned but doesn't exist on the workspace; unpin it.
mDeepShortcutManager.unpinShortcut(key);
shortcutManager.unpinShortcut(key);
}
}
@@ -2326,12 +2325,13 @@ public class LauncherModel extends BroadcastReceiver
}
if (!mDeepShortcutsLoaded) {
sBgDataModel.deepShortcutMap.clear();
mHasShortcutHostPermission = mDeepShortcutManager.hasHostPermission();
DeepShortcutManager shortcutManager = DeepShortcutManager.getInstance(mContext);
mHasShortcutHostPermission = shortcutManager.hasHostPermission();
if (mHasShortcutHostPermission) {
for (UserHandleCompat user : mUserManager.getUserProfiles()) {
if (mUserManager.isUserUnlocked(user)) {
List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager
.queryForAllShortcuts(user);
List<ShortcutInfoCompat> shortcuts =
shortcutManager.queryForAllShortcuts(user);
sBgDataModel.updateDeepShortcutMap(null, user, shortcuts);
}
}

View File

@@ -31,6 +31,7 @@ import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.ContentWriter;
@@ -295,7 +296,7 @@ public class ShortcutInfo extends ItemInfo {
// TODO: Use cache for this
LauncherAppState launcherAppState = LauncherAppState.getInstance();
Drawable unbadgedDrawable = launcherAppState.getShortcutManager()
Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context)
.getShortcutIconDrawable(shortcutInfo,
launcherAppState.getInvariantDeviceProfile().fillResIconDpi);

View File

@@ -26,6 +26,7 @@ import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.ComponentKey;
@@ -123,8 +124,8 @@ public class BgDataModel {
ShortcutKey pinnedShortcut = ShortcutKey.fromShortcutInfo((ShortcutInfo) item);
MutableInt count = pinnedShortcutCounts.get(pinnedShortcut);
if (count == null || --count.value == 0) {
LauncherAppState.getInstance()
.getShortcutManager().unpinShortcut(pinnedShortcut);
DeepShortcutManager.getInstance(LauncherAppState.getInstance().getContext())
.unpinShortcut(pinnedShortcut);
}
// Fall through.
}
@@ -161,7 +162,7 @@ public class BgDataModel {
// Since this is a new item, pin the shortcut in the system server.
if (newItem && count.value == 1) {
LauncherAppState.getInstance().getShortcutManager()
DeepShortcutManager.getInstance(LauncherAppState.getInstance().getContext())
.pinShortcut(pinnedShortcut);
}
// Fall through

View File

@@ -51,7 +51,8 @@ public class ShortcutsChangedTask extends ExtendedModelTask {
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
DeepShortcutManager deepShortcutManager = app.getShortcutManager();
final Context context = app.getContext();
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
deepShortcutManager.onShortcutsChanged(mShortcuts);
// Find ShortcutInfo's that have changed on the workspace.
@@ -67,7 +68,6 @@ public class ShortcutsChangedTask extends ExtendedModelTask {
}
}
final Context context = LauncherAppState.getInstance().getContext();
final ArrayList<ShortcutInfo> updatedShortcutInfos = new ArrayList<>();
if (!idsToWorkspaceShortcutInfos.isEmpty()) {
// Update the workspace to reflect the changes to updated shortcuts residing on it.

View File

@@ -50,7 +50,7 @@ public class UserLockStateChangedTask extends ExtendedModelTask {
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
Context context = app.getContext();
boolean isUserUnlocked = UserManagerCompat.getInstance(context).isUserUnlocked(mUser);
DeepShortcutManager deepShortcutManager = app.getShortcutManager();
DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context);
HashMap<ShortcutKey, ShortcutInfoCompat> pinnedShortcuts = new HashMap<>();
if (isUserUnlocked) {

View File

@@ -45,10 +45,22 @@ public class DeepShortcutManager {
private static final int FLAG_GET_ALL = ShortcutQuery.FLAG_MATCH_DYNAMIC
| ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_PINNED;
private static DeepShortcutManager sInstance;
private static final Object sInstanceLock = new Object();
public static DeepShortcutManager getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
sInstance = new DeepShortcutManager(context.getApplicationContext());
}
return sInstance;
}
}
private final LauncherApps mLauncherApps;
private boolean mWasLastCallSuccess;
public DeepShortcutManager(Context context, ShortcutCache shortcutCache) {
private DeepShortcutManager(Context context) {
mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
}

View File

@@ -52,7 +52,6 @@ import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherViewPropertyAnimator;
@@ -103,7 +102,7 @@ public class DeepShortcutsContainer extends AbstractFloatingView
public DeepShortcutsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mLauncher = Launcher.getLauncher(context);
mDeepShortcutsManager = LauncherAppState.getInstance().getShortcutManager();
mDeepShortcutsManager = DeepShortcutManager.getInstance(context);
mStartDragThreshold = getResources().getDimensionPixelSize(
R.dimen.deep_shortcuts_start_drag_threshold);