Merge "Ensuring disabled packages remove all components on the workspace. (Bug 11172454)" into jb-ub-now-jetsonic
diff --git a/res/values-sw/strings.xml b/res/values-sw/strings.xml
index 606a80d..d78b536 100644
--- a/res/values-sw/strings.xml
+++ b/res/values-sw/strings.xml
@@ -104,7 +104,7 @@
     <string name="first_run_cling_search_bar_hint" msgid="5909062802402452582"></string>
     <string name="first_run_cling_create_screens_hint" msgid="6950729526680114157">"Unda skrini zaidi za programu na folda"</string>
     <string name="workspace_cling_title" msgid="5626202359865825661">"Panga nafasi yako"</string>
-    <string name="workspace_cling_move_item" msgid="528201129978005352">"Gusa na ushikile mandharinyuma ili udhibiti mandhari, wijeti, na mipangilio."</string>
+    <string name="workspace_cling_move_item" msgid="528201129978005352">"Gusa na ushikilie mandharinyuma ili udhibiti mandhari, wijeti, na mipangilio."</string>
     <string name="all_apps_cling_title" msgid="34929250753095858">"Chagua programu kadhaa"</string>
     <string name="all_apps_cling_add_item" msgid="400866858451850784">"Ili kuongeza programu kwenye Skrini yako Kuu, iguse na uishikilie."</string>
     <string name="folder_cling_title" msgid="3894908818693254164">"Folda hii hapa"</string>
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java
index cda2e89..a9d237a 100644
--- a/src/com/android/launcher3/InstallShortcutReceiver.java
+++ b/src/com/android/launcher3/InstallShortcutReceiver.java
@@ -36,6 +36,9 @@
 import org.json.*;
 
 public class InstallShortcutReceiver extends BroadcastReceiver {
+    private static final String TAG = "InstallShortcutReceiver";
+    private static final boolean DBG = false;
+
     public static final String ACTION_INSTALL_SHORTCUT =
             "com.android.launcher.action.INSTALL_SHORTCUT";
 
@@ -94,10 +97,11 @@
                 }
                 json = json.endObject();
                 SharedPreferences.Editor editor = sharedPrefs.edit();
+                if (DBG) Log.d(TAG, "Adding to APPS_PENDING_INSTALL: " + json);
                 addToStringSet(sharedPrefs, editor, APPS_PENDING_INSTALL, json.toString());
                 editor.commit();
             } catch (org.json.JSONException e) {
-                Log.d("InstallShortcutReceiver", "Exception when adding shortcut: " + e);
+                Log.d(TAG, "Exception when adding shortcut: " + e);
             }
         }
     }
@@ -109,9 +113,15 @@
         }
         synchronized(sLock) {
             Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
+            if (DBG) {
+                Log.d(TAG, "APPS_PENDING_INSTALL: " + strings
+                        + ", removing packages: " + packageNames);
+            }
             if (strings != null) {
                 Set<String> newStrings = new HashSet<String>(strings);
-                for (String json : newStrings) {
+                Iterator<String> newStringsIter = newStrings.iterator();
+                while (newStringsIter.hasNext()) {
+                    String json = newStringsIter.next();
                     try {
                         JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                         Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
@@ -120,12 +130,12 @@
                             pn = launchIntent.getComponent().getPackageName();
                         }
                         if (packageNames.contains(pn)) {
-                            newStrings.remove(json);
+                            newStringsIter.remove();
                         }
                     } catch (org.json.JSONException e) {
-                        Log.d("InstallShortcutReceiver", "Exception reading shortcut to remove: " + e);
+                        Log.d(TAG, "Exception reading shortcut to remove: " + e);
                     } catch (java.net.URISyntaxException e) {
-                        Log.d("InstallShortcutReceiver", "Exception reading shortcut to remove: " + e);
+                        Log.d(TAG, "Exception reading shortcut to remove: " + e);
                     }
                 }
                 sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL,
@@ -138,6 +148,7 @@
             SharedPreferences sharedPrefs) {
         synchronized(sLock) {
             Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
+            if (DBG) Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
             if (strings == null) {
                 return new ArrayList<PendingInstallShortcutInfo>();
             }
@@ -170,11 +181,9 @@
                         new PendingInstallShortcutInfo(data, name, launchIntent);
                     infos.add(info);
                 } catch (org.json.JSONException e) {
-                    Log.d("InstallShortcutReceiver",
-                            "Exception reading shortcut to add: " + e);
+                    Log.d(TAG, "Exception reading shortcut to add: " + e);
                 } catch (java.net.URISyntaxException e) {
-                    Log.d("InstallShortcutReceiver",
-                            "Exception reading shortcut to add: " + e);
+                    Log.d(TAG, "Exception reading shortcut to add: " + e);
                 }
             }
             sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).commit();
@@ -206,6 +215,8 @@
             return;
         }
 
+        if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));
+
         Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
         if (intent == null) {
             return;