Removing static Context access using LauncherAppState

> This ensures that LauncherAppState is only accessed in the presence of
a valid context

Bug: 33032833
Change-Id: I955e5cb022f8bd6374681ae6c0720a2666d5b750
This commit is contained in:
Sunny Goyal
2017-01-11 10:48:34 -08:00
parent 4130705141
commit 87f784c285
34 changed files with 117 additions and 126 deletions

View File

@@ -99,11 +99,11 @@ public class BgDataModel {
deepShortcutMap.clear();
}
public synchronized void removeItem(ItemInfo... items) {
removeItem(Arrays.asList(items));
public synchronized void removeItem(Context context, ItemInfo... items) {
removeItem(context, Arrays.asList(items));
}
public synchronized void removeItem(Iterable<? extends ItemInfo> items) {
public synchronized void removeItem(Context context, Iterable<? extends ItemInfo> items) {
for (ItemInfo item : items) {
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
@@ -125,7 +125,6 @@ public class BgDataModel {
// Decrement pinned shortcut count
ShortcutKey pinnedShortcut = ShortcutKey.fromItemInfo(item);
MutableInt count = pinnedShortcutCounts.get(pinnedShortcut);
Context context = LauncherAppState.getInstance().getContext();
if ((count == null || --count.value == 0)
&& !InstallShortcutReceiver.getPendingShortcuts(context)
.contains(pinnedShortcut)) {
@@ -146,7 +145,7 @@ public class BgDataModel {
}
}
public synchronized void addItem(ItemInfo item, boolean newItem) {
public synchronized void addItem(Context context, ItemInfo item, boolean newItem) {
itemsIdMap.put(item.id, item);
switch (item.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
@@ -166,8 +165,7 @@ public class BgDataModel {
// Since this is a new item, pin the shortcut in the system server.
if (newItem && count.value == 1) {
DeepShortcutManager.getInstance(LauncherAppState.getInstance().getContext())
.pinShortcut(pinnedShortcut);
DeepShortcutManager.getInstance(context).pinShortcut(pinnedShortcut);
}
// Fall through
}