mobile/android/base/preferences/PrivateDataPreference.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:c22159687f29
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/. */
5
6 package org.mozilla.gecko.preferences;
7
8 import org.mozilla.gecko.GeckoAppShell;
9 import org.mozilla.gecko.GeckoEvent;
10 import org.mozilla.gecko.Telemetry;
11 import org.mozilla.gecko.TelemetryContract;
12
13 import org.json.JSONException;
14 import org.json.JSONObject;
15
16 import android.content.Context;
17 import android.util.AttributeSet;
18 import android.util.Log;
19
20 class PrivateDataPreference extends MultiChoicePreference {
21 private static final String LOGTAG = "GeckoPrivateDataPreference";
22 private static final String PREF_KEY_PREFIX = "private.data.";
23
24 public PrivateDataPreference(Context context, AttributeSet attrs) {
25 super(context, attrs);
26 }
27
28 @Override
29 protected void onDialogClosed(boolean positiveResult) {
30 super.onDialogClosed(positiveResult);
31
32 if (!positiveResult)
33 return;
34
35 Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.DIALOG);
36
37 CharSequence keys[] = getEntryKeys();
38 boolean values[] = getValues();
39 JSONObject json = new JSONObject();
40
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 }
55
56 // clear private data in gecko
57 GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Sanitize:ClearData", json.toString()));
58 }
59 }

mercurial