Bug 1357579 - Correctly copy the sparse Boolean array when clearing Site Settings. r?ahunt draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 21 Apr 2017 22:53:19 +0200
changeset 566583 b133cc7754f3126b62a26ac5a86b4fd7653bd571
parent 566475 6e3beea3294ef46e33d41a21a1599417235c08d3
child 625361 223f5f8edf9b86c02701fb31823efeaa5240d129
push id55267
push usermozilla@buttercookie.de
push dateFri, 21 Apr 2017 20:54:06 +0000
reviewersahunt
bugs1357579
milestone55.0a1
Bug 1357579 - Correctly copy the sparse Boolean array when clearing Site Settings. r?ahunt The checked items are stored in a *sparse* Boolean array, which we want to transform into an array (list) of the checked indices for transmission to Gecko. The current approach doesn't do this correctly, as it iterates over all (sparse and non-sparse) items, but uses SparseBooleanArray.size() (which only counts non-sparse items) as its iteration limit. This means that we only copy the checked state of the first n items, where n is the total count of checked items. For correctly iterating over the array to retrieve all indices that are true, we'd either have to use the largest available key (if we'd want to iterate over everything, including the sparse indices), or else use the approach chosen in this patch, namely using valueAt/keyAt in order to iterate over the internal array that's storing the values for all non-sparse indices. MozReview-Commit-ID: FRGI4Rr0uCb
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -881,21 +881,21 @@ public abstract class GeckoApp
             });
 
         builder.setPositiveButton(R.string.site_settings_clear, new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
                 ListView listView = ((AlertDialog) dialog).getListView();
                 SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
 
-                // An array of the indices of the permissions we want to clear
+                // An array of the indices of the permissions we want to clear.
                 final ArrayList<Integer> permissionsToClear = new ArrayList<>();
                 for (int i = 0; i < checkedItemPositions.size(); i++) {
-                    if (checkedItemPositions.get(i)) {
-                        permissionsToClear.add(i);
+                    if (checkedItemPositions.valueAt(i)) {
+                        permissionsToClear.add(checkedItemPositions.keyAt(i));
                     }
                 }
 
                 final GeckoBundle data = new GeckoBundle(1);
                 data.putIntArray("permissions", permissionsToClear);
                 EventDispatcher.getInstance().dispatch("Permissions:Clear", data);
             }
         });