Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1376)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java

Issue 2621223002: Change the method of getting Location Mode for Geolocation histograms. (Closed)
Patch Set: Use ContextUtils.getApplicationContext() instead of 'context' Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java
index 1c0c709c4c905d985e943f9c37fe7be33b1aca0c..e1520073618a88212054f5066624c6e1fecf4bca 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/geo/GeolocationHeader.java
@@ -5,7 +5,6 @@
package org.chromium.chrome.browser.omnibox.geo;
import android.Manifest;
-import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
@@ -13,6 +12,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
+import android.provider.Settings;
import android.support.annotation.IntDef;
import android.util.Base64;
@@ -31,7 +31,6 @@ import org.chromium.chrome.browser.util.UrlUtilities;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@@ -403,21 +402,40 @@ public class GeolocationHeader {
/** Returns the location source. */
@LocationSource
private static int getLocationSource() {
- LocationManager locationManager = (LocationManager) ContextUtils.getApplicationContext()
- .getSystemService(Context.LOCATION_SERVICE);
- List<String> providers = locationManager.getProviders(true);
- boolean hasNetworkProvider = false;
- boolean hasGpsProvider = false;
- for (String provider : providers) {
- if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
- hasNetworkProvider = true;
- } else if (LocationManager.GPS_PROVIDER.equals(provider)) {
- hasGpsProvider = true;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ int locationMode;
+ try {
+ locationMode = Settings.Secure.getInt(
+ ContextUtils.getApplicationContext().getContentResolver(),
+ Settings.Secure.LOCATION_MODE);
+ } catch (Settings.SettingNotFoundException e) {
+ Log.e(TAG, "Error getting the LOCATION_MODE");
+ return LOCATION_SOURCE_MASTER_OFF;
+ }
+ if (locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY) {
+ return LOCATION_SOURCE_HIGH_ACCURACY;
+ } else if (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY) {
+ return LOCATION_SOURCE_GPS_ONLY;
+ } else if (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING) {
+ return LOCATION_SOURCE_BATTERY_SAVING;
+ } else {
+ return LOCATION_SOURCE_MASTER_OFF;
+ }
+ } else {
+ String locationProviders = Settings.Secure.getString(
+ ContextUtils.getApplicationContext().getContentResolver(),
+ Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
+ if (locationProviders.contains(LocationManager.GPS_PROVIDER)
+ && locationProviders.contains(LocationManager.NETWORK_PROVIDER)) {
+ return LOCATION_SOURCE_HIGH_ACCURACY;
+ } else if (locationProviders.contains(LocationManager.GPS_PROVIDER)) {
+ return LOCATION_SOURCE_GPS_ONLY;
+ } else if (locationProviders.contains(LocationManager.NETWORK_PROVIDER)) {
+ return LOCATION_SOURCE_BATTERY_SAVING;
+ } else {
+ return LOCATION_SOURCE_MASTER_OFF;
}
}
- return hasNetworkProvider
- ? (hasGpsProvider ? LOCATION_SOURCE_HIGH_ACCURACY : LOCATION_SOURCE_BATTERY_SAVING)
- : (hasGpsProvider ? LOCATION_SOURCE_GPS_ONLY : LOCATION_SOURCE_MASTER_OFF);
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698