• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settingslib.wrapper;
18 
19 import android.location.LocationManager;
20 import android.os.UserHandle;
21 
22 /**
23  * This class replicates some methods of android.location.LocationManager that are new and not
24  * yet available in our current version of Robolectric. It provides a thin wrapper to call the real
25  * methods in production and a mock in tests.
26  */
27 public class LocationManagerWrapper {
28 
29     private LocationManager mLocationManager;
30 
LocationManagerWrapper(LocationManager locationManager)31     public LocationManagerWrapper(LocationManager locationManager) {
32         mLocationManager = locationManager;
33     }
34 
35     /** Returns the real {@code LocationManager} object */
getLocationManager()36     public LocationManager getLocationManager() {
37         return mLocationManager;
38     }
39 
40     /** Wraps {@code LocationManager.isProviderEnabled} method */
isProviderEnabled(String provider)41     public boolean isProviderEnabled(String provider) {
42         return mLocationManager.isProviderEnabled(provider);
43     }
44 
45     /** Wraps {@code LocationManager.setProviderEnabledForUser} method */
setProviderEnabledForUser(String provider, boolean enabled, UserHandle userHandle)46     public void setProviderEnabledForUser(String provider, boolean enabled, UserHandle userHandle) {
47         mLocationManager.setProviderEnabledForUser(provider, enabled, userHandle);
48     }
49 
50     /** Wraps {@code LocationManager.isLocationEnabled} method */
isLocationEnabled()51     public boolean isLocationEnabled() {
52         return mLocationManager.isLocationEnabled();
53     }
54 
55     /** Wraps {@code LocationManager.isLocationEnabledForUser} method */
isLocationEnabledForUser(UserHandle userHandle)56     public boolean isLocationEnabledForUser(UserHandle userHandle) {
57         return mLocationManager.isLocationEnabledForUser(userHandle);
58     }
59 
60     /** Wraps {@code LocationManager.setLocationEnabledForUser} method */
setLocationEnabledForUser(boolean enabled, UserHandle userHandle)61     public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
62         mLocationManager.setLocationEnabledForUser(enabled, userHandle);
63     }
64 }
65