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