OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.components.location; | 5 package org.chromium.components.location; |
6 | 6 |
7 import android.Manifest; | 7 import android.Manifest; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.os.Process; | 12 import android.os.Process; |
13 import android.provider.Settings; | 13 import android.provider.Settings; |
14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
15 | 15 |
16 import org.chromium.base.ApiCompatibilityUtils; | 16 import org.chromium.base.ApiCompatibilityUtils; |
17 import org.chromium.base.Callback; | 17 import org.chromium.base.Callback; |
18 import org.chromium.base.ContextUtils; | 18 import org.chromium.base.ContextUtils; |
19 import org.chromium.base.ThreadUtils; | 19 import org.chromium.base.ThreadUtils; |
20 import org.chromium.base.VisibleForTesting; | 20 import org.chromium.base.VisibleForTesting; |
21 import org.chromium.base.annotations.SuppressFBWarnings; | 21 import org.chromium.base.annotations.SuppressFBWarnings; |
22 import org.chromium.components.location.LocationSettingsDialogContext.LocationSe
ttingsDialogContextEnum; | |
23 import org.chromium.components.location.LocationSettingsDialogOutcome.LocationSe
ttingsDialogOutcomeEnum; | |
24 import org.chromium.ui.base.WindowAndroid; | 22 import org.chromium.ui.base.WindowAndroid; |
25 | 23 |
26 /** | 24 /** |
27 * Provides methods for querying Chrome's ability to use Android's location serv
ices. | 25 * Provides methods for querying Chrome's ability to use Android's location serv
ices. |
28 * | 26 * |
29 * This class should be used only on the UI thread. | 27 * This class should be used only on the UI thread. |
30 */ | 28 */ |
31 public class LocationUtils { | 29 public class LocationUtils { |
32 // Used to construct sInstance if that's null. | 30 // Used to construct sInstance if that's null. |
33 private static Factory sFactory; | 31 private static Factory sFactory; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 98 |
101 /** | 99 /** |
102 * Triggers a prompt to ask the user to turn on the system location setting
on their device. | 100 * Triggers a prompt to ask the user to turn on the system location setting
on their device. |
103 * | 101 * |
104 * <p>The prompt will be triggered within the specified window. | 102 * <p>The prompt will be triggered within the specified window. |
105 * | 103 * |
106 * <p>The callback is guaranteed to be called unless the user never replies
to the prompt | 104 * <p>The callback is guaranteed to be called unless the user never replies
to the prompt |
107 * dialog, which in practice happens very infrequently since the dialog is m
odal. | 105 * dialog, which in practice happens very infrequently since the dialog is m
odal. |
108 */ | 106 */ |
109 public void promptToEnableSystemLocationSetting( | 107 public void promptToEnableSystemLocationSetting( |
110 @LocationSettingsDialogContextEnum int promptContext, WindowAndroid
window, | 108 @LocationSettingsDialogContext int promptContext, WindowAndroid wind
ow, |
111 @LocationSettingsDialogOutcomeEnum Callback<Integer> callback) { | 109 @LocationSettingsDialogOutcome Callback<Integer> callback) { |
112 callback.onResult(LocationSettingsDialogOutcome.NO_PROMPT); | 110 callback.onResult(LocationSettingsDialogOutcome.NO_PROMPT); |
113 } | 111 } |
114 | 112 |
115 /** | 113 /** |
116 * Returns an intent to launch Android Location Settings. | 114 * Returns an intent to launch Android Location Settings. |
117 */ | 115 */ |
118 public Intent getSystemLocationSettingsIntent() { | 116 public Intent getSystemLocationSettingsIntent() { |
119 Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); | 117 Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); |
120 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 118 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
121 return i; | 119 return i; |
122 } | 120 } |
123 | 121 |
124 /** | 122 /** |
125 * Instantiate this to explain how to create a LocationUtils instance in | 123 * Instantiate this to explain how to create a LocationUtils instance in |
126 * LocationUtils.getInstance(). | 124 * LocationUtils.getInstance(). |
127 */ | 125 */ |
128 public interface Factory { public LocationUtils create(); } | 126 public interface Factory { public LocationUtils create(); } |
129 | 127 |
130 /** | 128 /** |
131 * Call this to use a different subclass of LocationUtils throughout the pro
gram. | 129 * Call this to use a different subclass of LocationUtils throughout the pro
gram. |
132 * This can be used by embedders in addition to tests. | 130 * This can be used by embedders in addition to tests. |
133 */ | 131 */ |
134 @VisibleForTesting | 132 @VisibleForTesting |
135 public static void setFactory(Factory factory) { | 133 public static void setFactory(Factory factory) { |
136 sFactory = factory; | 134 sFactory = factory; |
137 sInstance = null; | 135 sInstance = null; |
138 } | 136 } |
139 } | 137 } |
OLD | NEW |