diff options
author | Michael Jurka <mikejurka@google.com> | 2013-05-14 20:17:58 +0200 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2013-05-14 20:45:36 +0200 |
commit | c7700af21f7b1df939fce22f4ab5072b3ea29b66 (patch) | |
tree | 57dea676552b50e588ebe732947522065ff431e0 /src/com/android/launcher2/InstallShortcutReceiver.java | |
parent | 56d796a9b09725fc44714bc2216d6bc6c4746b95 (diff) | |
download | Launcher2-c7700af21f7b1df939fce22f4ab5072b3ea29b66.tar.gz |
Fix bug where apps weren't appearing on workspace after being installed
Bug: 8707110
Change-Id: Ib50e0c600a4a77450127f3947aa894346dc99a5a
Diffstat (limited to 'src/com/android/launcher2/InstallShortcutReceiver.java')
-rw-r--r-- | src/com/android/launcher2/InstallShortcutReceiver.java | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java index 20a19660..23c89641 100644 --- a/src/com/android/launcher2/InstallShortcutReceiver.java +++ b/src/com/android/launcher2/InstallShortcutReceiver.java @@ -48,10 +48,23 @@ public class InstallShortcutReceiver extends BroadcastReceiver { public static final String SHORTCUT_MIMETYPE = "com.android.launcher/shortcut"; + private static Object sLock = new Object(); + // The set of shortcuts that are pending install private static ArrayList<PendingInstallShortcutInfo> mInstallQueue = new ArrayList<PendingInstallShortcutInfo>(); + private static void addToStringSet(SharedPreferences sharedPrefs, + SharedPreferences.Editor editor, String key, String value) { + Set<String> strings = sharedPrefs.getStringSet(key, null); + if (strings == null) { + strings = new HashSet<String>(0); + } else { + strings = new HashSet<String>(strings); + } + strings.add(value); + editor.putStringSet(key, strings); + } // Determines whether to defer installing shortcuts immediately until // processAllPendingInstalls() is called. private static boolean mUseInstallQueue = false; @@ -131,6 +144,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { final int[] result = {INSTALL_SHORTCUT_SUCCESSFUL}; boolean found = false; synchronized (app) { + // Flush the LauncherModel worker thread, so that if we just did another + // processInstallShortcut, we give it time for its shortcut to get added to the + // database (getItemsInLocalCoordinates reads the database) + app.getModel().flushWorkerThread(); final ArrayList<ItemInfo> items = LauncherModel.getItemsInLocalCoordinates(context); final boolean exists = LauncherModel.shortcutExists(context, name, intent); @@ -160,7 +177,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { } private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, - String name, Intent intent, final int screen, boolean shortcutExists, + String name, final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs, int[] result) { int[] tmpCoordinates = new int[2]; if (findEmptyCell(context, items, tmpCoordinates, screen)) { @@ -178,24 +195,20 @@ public class InstallShortcutReceiver extends BroadcastReceiver { // different places) boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); if (duplicate || !shortcutExists) { - // If the new app is going to fall into the same page as before, then just - // continue adding to the current page - int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen); - Set<String> newApps = new HashSet<String>(); - if (newAppsScreen == screen) { - newApps = sharedPrefs.getStringSet(NEW_APPS_LIST_KEY, newApps); - } - synchronized (newApps) { - newApps.add(intent.toUri(0).toString()); - } - final Set<String> savedNewApps = newApps; new Thread("setNewAppsThread") { public void run() { - synchronized (savedNewApps) { - sharedPrefs.edit() - .putInt(NEW_APPS_PAGE_KEY, screen) - .putStringSet(NEW_APPS_LIST_KEY, savedNewApps) - .commit(); + synchronized (sLock) { + // If the new app is going to fall into the same page as before, + // then just continue adding to the current page + final int newAppsScreen = sharedPrefs.getInt( + NEW_APPS_PAGE_KEY, screen); + SharedPreferences.Editor editor = sharedPrefs.edit(); + if (newAppsScreen == screen) { + addToStringSet(sharedPrefs, + editor, NEW_APPS_LIST_KEY, intent.toUri(0)); + } + editor.putInt(NEW_APPS_PAGE_KEY, screen); + editor.commit(); } } }.start(); |