mobile/android/base/preferences/PrivateDataPreference.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko.preferences;
     8 import org.mozilla.gecko.GeckoAppShell;
     9 import org.mozilla.gecko.GeckoEvent;
    10 import org.mozilla.gecko.Telemetry;
    11 import org.mozilla.gecko.TelemetryContract;
    13 import org.json.JSONException;
    14 import org.json.JSONObject;
    16 import android.content.Context;
    17 import android.util.AttributeSet;
    18 import android.util.Log;
    20 class PrivateDataPreference extends MultiChoicePreference {
    21     private static final String LOGTAG = "GeckoPrivateDataPreference";
    22     private static final String PREF_KEY_PREFIX = "private.data.";
    24     public PrivateDataPreference(Context context, AttributeSet attrs) {
    25         super(context, attrs);
    26     }
    28     @Override
    29     protected void onDialogClosed(boolean positiveResult) {
    30         super.onDialogClosed(positiveResult);
    32         if (!positiveResult)
    33             return;
    35         Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.DIALOG);
    37         CharSequence keys[] = getEntryKeys();
    38         boolean values[] = getValues();
    39         JSONObject json = new JSONObject();
    41         for (int i = 0; i < keys.length; i++) {
    42             // Privacy pref checkbox values are stored in Android prefs to
    43             // remember their check states. The key names are private.data.X,
    44             // where X is a string from Gecko sanitization. This prefix is
    45             // removed here so we can send the values to Gecko, which then does
    46             // the sanitization for each key.
    47             String key = keys[i].toString().substring(PREF_KEY_PREFIX.length());
    48             boolean value = values[i];
    49             try {
    50                 json.put(key, value);
    51             } catch (JSONException e) {
    52                 Log.e(LOGTAG, "JSON error", e);
    53             }
    54         }
    56         // clear private data in gecko
    57         GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Sanitize:ClearData", json.toString()));
    58     }
    59 }

mercurial