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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/LocationSettings.java

Issue 850813002: Upstream Site Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@location_settings_singleton
Patch Set: Created 5 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
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/LocationSettings.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/LocationSettings.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/LocationSettings.java
new file mode 100644
index 0000000000000000000000000000000000000000..7eb283e17174b49ed68cda2e3608c9b46d1b54f1
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/LocationSettings.java
@@ -0,0 +1,102 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.preferences;
+
+import android.content.Context;
+import android.content.Intent;
+import android.location.LocationManager;
+import android.provider.Settings;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.CalledByNative;
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.VisibleForTesting;
+import org.chromium.chrome.browser.ChromiumApplication;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Provides methods for querying Android system-wide location settings as well as Chrome's internal
+ * location setting.
+ */
+public class LocationSettings {
+
+ private static LocationSettings sInstance;
+
+ protected final Context mContext;
+
+ /**
+ * Don't use this; use getInstance() instead. This should be used only by the Application inside
+ * of createLocationSettings().
+ */
+ public LocationSettings(Context context) {
+ mContext = context;
+ }
+
+ /**
+ * Returns the singleton instance of LocationSettings, creating it if needed.
+ */
+ public static LocationSettings getInstance() {
+ if (sInstance == null) {
+ ChromiumApplication application =
+ (ChromiumApplication) ApplicationStatus.getApplicationContext();
+ sInstance = application.createLocationSettings();
+ }
+ return sInstance;
+ }
+
+ /**
+ * Returns true if location is enabled system-wide and the Chrome location setting is enabled.
+ */
+ @CalledByNative
+ public static boolean areAllLocationSettingsEnabled() {
+ try {
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>(){
+ @Override
+ public Boolean call() throws Exception {
+ LocationSettings settings = LocationSettings.getInstance();
+ return settings.isChromeLocationSettingEnabled()
+ && settings.isSystemLocationSettingEnabled();
+ }
+ });
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * Returns whether Chrome's user-configurable location setting is enabled.
+ */
+ public boolean isChromeLocationSettingEnabled() {
+ return PrefServiceBridge.getInstance().isAllowLocationEnabled();
+ }
+
+ /**
+ * Returns whether location is enabled system-wide, i.e. whether Chrome itself is able to access
+ * location.
+ */
+ public boolean isSystemLocationSettingEnabled() {
+ LocationManager locationManager =
+ (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
+ return (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
+ || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
+ }
+
+ /**
+ * Returns an intent to launch Android Location Settings.
+ */
+ public Intent getSystemLocationSettingsIntent() {
+ Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ return i;
+ }
+
+ @VisibleForTesting
+ public static void setInstanceForTesting(LocationSettings instance) {
+ sInstance = instance;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698