| 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.CrashReportingPermissionMa
nager; | 19 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa
nager; |
| 20 import org.chromium.components.minidump_uploader.util.NetworkPermissionUtil; |
| 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"; |
| 29 | 30 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be sto
red. Note that this | 178 // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be sto
red. Note that this |
| 178 // SharedPreference carries no information, because it used to be overwr
itten by | 179 // SharedPreference carries no information, because it used to be overwr
itten by |
| 179 // kNetworkPredictionEnabled on startup, and now it is overwritten by | 180 // kNetworkPredictionEnabled on startup, and now it is overwritten by |
| 180 // kNetworkPredictionOptions on startup. | 181 // kNetworkPredictionOptions on startup. |
| 181 if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) { | 182 if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) { |
| 182 sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS); | 183 sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS); |
| 183 } | 184 } |
| 184 sharedPreferencesEditor.apply(); | 185 sharedPreferencesEditor.apply(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 private NetworkInfo getActiveNetworkInfo() { | 188 protected boolean isNetworkAvailable() { |
| 188 ConnectivityManager connectivityManager = | 189 ConnectivityManager connectivityManager = |
| 189 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); | 190 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
| 190 return connectivityManager.getActiveNetworkInfo(); | 191 NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); |
| 191 } | |
| 192 | |
| 193 protected boolean isNetworkAvailable() { | |
| 194 NetworkInfo networkInfo = getActiveNetworkInfo(); | |
| 195 return (networkInfo != null && networkInfo.isConnected()); | 192 return (networkInfo != null && networkInfo.isConnected()); |
| 196 } | 193 } |
| 197 | 194 |
| 198 protected boolean isWiFiOrEthernetNetwork() { | |
| 199 NetworkInfo networkInfo = getActiveNetworkInfo(); | |
| 200 return networkInfo != null | |
| 201 && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI | |
| 202 || networkInfo.getType() == ConnectivityManager.TYPE_ETH
ERNET); | |
| 203 } | |
| 204 | |
| 205 protected boolean isMobileNetworkCapable() { | 195 protected boolean isMobileNetworkCapable() { |
| 206 ConnectivityManager connectivityManager = | 196 ConnectivityManager connectivityManager = |
| 207 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); | 197 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
| 208 // Android telephony team said it is OK to continue using getNetworkInfo
() for our purposes. | 198 // Android telephony team said it is OK to continue using getNetworkInfo
() for our purposes. |
| 209 // We cannot use ConnectivityManager#getAllNetworks() because that one o
nly reports enabled | 199 // We cannot use ConnectivityManager#getAllNetworks() because that one o
nly reports enabled |
| 210 // networks. See crbug.com/532455. | 200 // networks. See crbug.com/532455. |
| 211 @SuppressWarnings("deprecation") | 201 @SuppressWarnings("deprecation") |
| 212 NetworkInfo networkInfo = connectivityManager | 202 NetworkInfo networkInfo = connectivityManager |
| 213 .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | 203 .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); |
| 214 return networkInfo != null; | 204 return networkInfo != null; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 return mSharedPreferences.getBoolean(PREF_METRICS_IN_SAMPLE, true); | 257 return mSharedPreferences.getBoolean(PREF_METRICS_IN_SAMPLE, true); |
| 268 } | 258 } |
| 269 | 259 |
| 270 /** | 260 /** |
| 271 * Checks whether uploading of crash dumps is permitted for the available ne
twork(s). | 261 * Checks whether uploading of crash dumps is permitted for the available ne
twork(s). |
| 272 * | 262 * |
| 273 * @return whether uploading crash dumps is permitted. | 263 * @return whether uploading crash dumps is permitted. |
| 274 */ | 264 */ |
| 275 @Override | 265 @Override |
| 276 public boolean isNetworkAvailableForCrashUploads() { | 266 public boolean isNetworkAvailableForCrashUploads() { |
| 277 return isNetworkAvailable() && isWiFiOrEthernetNetwork(); | 267 ConnectivityManager connectivityManager = |
| 268 (ConnectivityManager) mContext.getSystemService(Context.CONNECTI
VITY_SERVICE); |
| 269 return NetworkPermissionUtil.isNetworkUnmetered(connectivityManager); |
| 278 } | 270 } |
| 279 | 271 |
| 280 /** | 272 /** |
| 281 * Checks whether uploading of usage metrics and crash dumps is currently pe
rmitted, based on | 273 * Checks whether uploading of usage metrics and crash dumps is currently pe
rmitted, based on |
| 282 * user consent only. This doesn't take network condition or experimental st
ate (i.e. disabling | 274 * user consent only. This doesn't take network condition or experimental st
ate (i.e. disabling |
| 283 * upload) into consideration. A crash dump may be retried if this check pas
ses. | 275 * upload) into consideration. A crash dump may be retried if this check pas
ses. |
| 284 * | 276 * |
| 285 * @return whether the user has consented to reporting usage metrics and cra
sh dumps. | 277 * @return whether the user has consented to reporting usage metrics and cra
sh dumps. |
| 286 */ | 278 */ |
| 287 @Override | 279 @Override |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 /** | 332 /** |
| 341 * Check whether Physical Web is configured to notify on nearby beacons. | 333 * Check whether Physical Web is configured to notify on nearby beacons. |
| 342 * | 334 * |
| 343 * @return boolean {@code true} if the feature is enabled. | 335 * @return boolean {@code true} if the feature is enabled. |
| 344 */ | 336 */ |
| 345 public boolean isPhysicalWebEnabled() { | 337 public boolean isPhysicalWebEnabled() { |
| 346 int state = mSharedPreferences.getInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON
BOARDING); | 338 int state = mSharedPreferences.getInt(PREF_PHYSICAL_WEB, PHYSICAL_WEB_ON
BOARDING); |
| 347 return (state == PHYSICAL_WEB_ON); | 339 return (state == PHYSICAL_WEB_ON); |
| 348 } | 340 } |
| 349 } | 341 } |
| OLD | NEW |