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; | 5 package org.chromium.chrome.browser.preferences; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.location.LocationManager; | 9 import android.location.LocationManager; |
10 import android.provider.Settings; | 10 import android.provider.Settings; |
11 | 11 |
12 import org.chromium.base.ApplicationStatus; | 12 import org.chromium.base.ApplicationStatus; |
13 import org.chromium.base.CalledByNative; | 13 import org.chromium.base.CalledByNative; |
14 import org.chromium.base.ThreadUtils; | |
15 import org.chromium.base.VisibleForTesting; | 14 import org.chromium.base.VisibleForTesting; |
16 import org.chromium.base.annotations.SuppressFBWarnings; | 15 import org.chromium.base.annotations.SuppressFBWarnings; |
17 import org.chromium.chrome.browser.ChromiumApplication; | 16 import org.chromium.chrome.browser.ChromiumApplication; |
18 | 17 |
19 import java.util.concurrent.Callable; | |
20 import java.util.concurrent.ExecutionException; | |
21 | |
22 /** | 18 /** |
23 * Provides methods for querying Android system-wide location settings as well a s Chrome's internal | 19 * Provides methods for querying Android system-wide location settings as well a s Chrome's internal |
24 * location setting. | 20 * location setting. |
25 */ | 21 */ |
26 public class LocationSettings { | 22 public class LocationSettings { |
27 | 23 |
28 private static LocationSettings sInstance; | 24 private static LocationSettings sInstance; |
29 | 25 |
30 protected final Context mContext; | 26 protected final Context mContext; |
31 | 27 |
(...skipping 16 matching lines...) Expand all Loading... | |
48 sInstance = application.createLocationSettings(); | 44 sInstance = application.createLocationSettings(); |
49 } | 45 } |
50 return sInstance; | 46 return sInstance; |
51 } | 47 } |
52 | 48 |
53 /** | 49 /** |
54 * Returns true if location is enabled system-wide and the Chrome location s etting is enabled. | 50 * Returns true if location is enabled system-wide and the Chrome location s etting is enabled. |
55 */ | 51 */ |
56 @CalledByNative | 52 @CalledByNative |
57 public static boolean areAllLocationSettingsEnabled() { | 53 public static boolean areAllLocationSettingsEnabled() { |
58 try { | 54 LocationSettings settings = LocationSettings.getInstance(); |
Ted C
2015/01/20 17:52:18
Should we have a ThreadUtils.assertOnUiThread() he
newt (away)
2015/01/20 22:46:08
Added ThreadUtils.assertOnUiThread() to LocationSe
| |
59 return ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>(){ | 55 return settings.isChromeLocationSettingEnabled() |
60 @Override | 56 && settings.isSystemLocationSettingEnabled(); |
61 public Boolean call() throws Exception { | |
62 LocationSettings settings = LocationSettings.getInstance(); | |
63 return settings.isChromeLocationSettingEnabled() | |
64 && settings.isSystemLocationSettingEnabled(); | |
65 } | |
66 }); | |
67 } catch (ExecutionException e) { | |
68 e.printStackTrace(); | |
69 return false; | |
70 } | |
71 } | 57 } |
72 | 58 |
73 /** | 59 /** |
74 * Returns whether Chrome's user-configurable location setting is enabled. | 60 * Returns whether Chrome's user-configurable location setting is enabled. |
75 */ | 61 */ |
76 public boolean isChromeLocationSettingEnabled() { | 62 public boolean isChromeLocationSettingEnabled() { |
77 return PrefServiceBridge.getInstance().isAllowLocationEnabled(); | 63 return PrefServiceBridge.getInstance().isAllowLocationEnabled(); |
78 } | 64 } |
79 | 65 |
80 /** | 66 /** |
(...skipping 14 matching lines...) Expand all Loading... | |
95 Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | 81 Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
96 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 82 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
97 return i; | 83 return i; |
98 } | 84 } |
99 | 85 |
100 @VisibleForTesting | 86 @VisibleForTesting |
101 public static void setInstanceForTesting(LocationSettings instance) { | 87 public static void setInstanceForTesting(LocationSettings instance) { |
102 sInstance = instance; | 88 sInstance = instance; |
103 } | 89 } |
104 } | 90 } |
OLD | NEW |