OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.preferences.privacy; | 5 package org.chromium.chrome.browser.preferences.privacy; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
9 import android.net.ConnectivityManager; | 9 import android.net.ConnectivityManager; |
10 import android.net.NetworkInfo; | 10 import android.net.NetworkInfo; |
11 | 11 |
12 import org.chromium.base.CommandLine; | 12 import org.chromium.base.CommandLine; |
13 import org.chromium.base.ContextUtils; | 13 import org.chromium.base.ContextUtils; |
14 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
15 import org.chromium.chrome.browser.ChromeSwitches; | 15 import org.chromium.chrome.browser.ChromeSwitches; |
16 import org.chromium.chrome.browser.device.DeviceClassManager; | 16 import org.chromium.chrome.browser.device.DeviceClassManager; |
17 import org.chromium.chrome.browser.physicalweb.PhysicalWeb; | 17 import org.chromium.chrome.browser.physicalweb.PhysicalWeb; |
18 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 18 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 19 import org.chromium.components.minidump_uploader.util.CrashReportingNetworkPermi
ssionManager; |
19 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; | 20 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
20 | 21 |
21 /** | 22 /** |
22 * Reads, writes, and migrates preferences related to network usage and privacy. | 23 * Reads, writes, and migrates preferences related to network usage and privacy. |
23 */ | 24 */ |
24 public class PrivacyPreferencesManager implements CrashReportingPermissionManage
r{ | 25 public class PrivacyPreferencesManager implements CrashReportingPermissionManage
r{ |
25 static final String DEPRECATED_PREF_CRASH_DUMP_UPLOAD = "crash_dump_upload"; | 26 static final String DEPRECATED_PREF_CRASH_DUMP_UPLOAD = "crash_dump_upload"; |
26 static final String DEPRECATED_PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR = | 27 static final String DEPRECATED_PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR = |
27 "crash_dump_upload_no_cellular"; | 28 "crash_dump_upload_no_cellular"; |
28 private static final String DEPRECATED_PREF_CELLULAR_EXPERIMENT = "cellular_
experiment"; | 29 private static final String DEPRECATED_PREF_CELLULAR_EXPERIMENT = "cellular_
experiment"; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be sto
red. Note that this | 185 // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be sto
red. Note that this |
185 // SharedPreference carries no information, because it used to be overwr
itten by | 186 // SharedPreference carries no information, because it used to be overwr
itten by |
186 // kNetworkPredictionEnabled on startup, and now it is overwritten by | 187 // kNetworkPredictionEnabled on startup, and now it is overwritten by |
187 // kNetworkPredictionOptions on startup. | 188 // kNetworkPredictionOptions on startup. |
188 if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) { | 189 if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) { |
189 sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS); | 190 sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS); |
190 } | 191 } |
191 sharedPreferencesEditor.apply(); | 192 sharedPreferencesEditor.apply(); |
192 } | 193 } |
193 | 194 |
194 private NetworkInfo getActiveNetworkInfo() { | 195 protected boolean isNetworkAvailable() { |
195 ConnectivityManager connectivityManager = | 196 ConnectivityManager connectivityManager = |
196 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); | 197 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
197 return connectivityManager.getActiveNetworkInfo(); | 198 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); |
198 } | |
199 | |
200 protected boolean isNetworkAvailable() { | |
201 NetworkInfo networkInfo = getActiveNetworkInfo(); | |
202 return (networkInfo != null && networkInfo.isConnected()); | 199 return (networkInfo != null && networkInfo.isConnected()); |
203 } | 200 } |
204 | 201 |
205 protected boolean isWiFiOrEthernetNetwork() { | |
206 NetworkInfo networkInfo = getActiveNetworkInfo(); | |
207 return networkInfo != null | |
208 && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI | |
209 || networkInfo.getType() == ConnectivityManager.TYPE_ETH
ERNET); | |
210 } | |
211 | |
212 protected boolean isMobileNetworkCapable() { | 202 protected boolean isMobileNetworkCapable() { |
213 ConnectivityManager connectivityManager = | 203 ConnectivityManager connectivityManager = |
214 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); | 204 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
215 // Android telephony team said it is OK to continue using getNetworkInfo
() for our purposes. | 205 // Android telephony team said it is OK to continue using getNetworkInfo
() for our purposes. |
216 // We cannot use ConnectivityManager#getAllNetworks() because that one o
nly reports enabled | 206 // We cannot use ConnectivityManager#getAllNetworks() because that one o
nly reports enabled |
217 // networks. See crbug.com/532455. | 207 // networks. See crbug.com/532455. |
218 @SuppressWarnings("deprecation") | 208 @SuppressWarnings("deprecation") |
219 NetworkInfo networkInfo = connectivityManager | 209 NetworkInfo networkInfo = connectivityManager |
220 .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | 210 .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); |
221 return networkInfo != null; | 211 return networkInfo != null; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return mSharedPreferences.getBoolean(PREF_METRICS_IN_SAMPLE, true); | 264 return mSharedPreferences.getBoolean(PREF_METRICS_IN_SAMPLE, true); |
275 } | 265 } |
276 | 266 |
277 /** | 267 /** |
278 * Checks whether uploading of crash dumps is permitted for the available ne
twork(s). | 268 * Checks whether uploading of crash dumps is permitted for the available ne
twork(s). |
279 * | 269 * |
280 * @return whether uploading crash dumps is permitted. | 270 * @return whether uploading crash dumps is permitted. |
281 */ | 271 */ |
282 @Override | 272 @Override |
283 public boolean isNetworkAvailableForCrashUploads() { | 273 public boolean isNetworkAvailableForCrashUploads() { |
284 return isNetworkAvailable() && isWiFiOrEthernetNetwork(); | 274 ConnectivityManager connectivityManager = |
| 275 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
| 276 return CrashReportingNetworkPermissionManager.isNetworkUnmetered(connect
ivityManager); |
285 } | 277 } |
286 | 278 |
287 /** | 279 /** |
288 * Checks whether uploading of crash dumps is permitted, based on the corres
ponding command line | 280 * Checks whether uploading of crash dumps is permitted, based on the corres
ponding command line |
289 * flag only. | 281 * flag only. |
290 * TODO(jchinlee): this is not quite a boolean. Depending on other refactori
ng, change to enum. | 282 * TODO(jchinlee): this is not quite a boolean. Depending on other refactori
ng, change to enum. |
291 * | 283 * |
292 * @return whether uploading of crash dumps is enabled or disabled by a comm
and line flag. | 284 * @return whether uploading of crash dumps is enabled or disabled by a comm
and line flag. |
293 */ | 285 */ |
294 @Override | 286 @Override |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 /** | 368 /** |
377 * Check whether Physical Web is configured to notify on nearby beacons. | 369 * Check whether Physical Web is configured to notify on nearby beacons. |
378 * | 370 * |
379 * @return boolean {@code true} if the feature is enabled. | 371 * @return boolean {@code true} if the feature is enabled. |
380 */ | 372 */ |
381 public boolean isPhysicalWebEnabled() { | 373 public boolean isPhysicalWebEnabled() { |
382 int state = mSharedPreferences.getInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON
BOARDING); | 374 int state = mSharedPreferences.getInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON
BOARDING); |
383 return (state == PHYSICAL_WEB_ON); | 375 return (state == PHYSICAL_WEB_ON); |
384 } | 376 } |
385 } | 377 } |
OLD | NEW |