1 /*
2  * Copyright (C) 2019 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.car;
18 
19 import android.annotation.NonNull;
20 import android.car.ILocationManagerProxy;
21 import android.content.Context;
22 import android.location.Location;
23 import android.location.LocationManager;
24 import android.util.IndentingPrintWriter;
25 import android.util.Slog;
26 
27 /** Wraps a {@link LocationManager}. */
28 public class LocationManagerProxy extends ILocationManagerProxy.Stub {
29 
30     private static final String TAG = CarLog.tagFor(LocationManagerProxy.class);
31     private static final boolean DBG = false;
32 
33     private final LocationManager mLocationManager;
34 
35     /**
36      * Create a LocationManagerProxy instance given a {@link Context}.
37      */
LocationManagerProxy(Context context)38     public LocationManagerProxy(Context context) {
39         if (DBG) {
40             Slog.d(TAG, "constructed.");
41         }
42         mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
43     }
44 
45     @Override
isLocationEnabled()46     public boolean isLocationEnabled() {
47         return mLocationManager.isLocationEnabled();
48     }
49 
50     @Override
injectLocation(Location location)51     public boolean injectLocation(Location location) {
52         return mLocationManager.injectLocation(location);
53     }
54 
55     @Override
getLastKnownLocation(@onNull String provider)56     public Location getLastKnownLocation(@NonNull String provider) {
57         if (DBG) {
58             Slog.d(TAG, "Getting last known location for provider " + provider);
59         }
60         return mLocationManager.getLastKnownLocation(provider);
61     }
62 
dump(IndentingPrintWriter pw)63     void dump(IndentingPrintWriter pw) {
64         pw.printf("isLocationEnabled: %b\n", isLocationEnabled());
65     }
66 }
67