Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 235a50e0 authored by Bjorn Bringert's avatar Bjorn Bringert Committed by Android (Google) Code Review
Browse files

Merge "Fix ConcurrentModificationException in InstallShortcutReceiver" into jb-ub-now-indigo-rose

parents b178a362 4e871a21
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ import java.util.Set;
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 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                }
                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);
            }
        }
    }
@@ -106,9 +110,15 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                                              ArrayList<String> packageNames) {
        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);
@@ -117,12 +127,12 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                            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,
@@ -135,6 +145,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
            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>();
            }
@@ -167,11 +178,9 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
                        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();
@@ -203,6 +212,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
            return;
        }

        if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

        Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        if (intent == null) {
            return;