blob: 521bae27547336cda97699f2a5ab893a9afd01e2 [file] [log] [blame]
Gregory Clark55620c12019-06-03 17:42:58 -07001/*
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
17package com.android.car;
18
19import android.annotation.NonNull;
20import android.car.ILocationManagerProxy;
21import android.content.Context;
22import android.location.Location;
23import android.location.LocationManager;
Felipe Leme176a5fd2021-01-20 15:48:33 -080024import android.util.IndentingPrintWriter;
Eric Jeongbd5fb562020-12-21 13:49:40 -080025import android.util.Slog;
Gregory Clark55620c12019-06-03 17:42:58 -070026
27/** Wraps a {@link LocationManager}. */
28public class LocationManagerProxy extends ILocationManagerProxy.Stub {
Felipe Leme176a5fd2021-01-20 15:48:33 -080029
Mayank Garg72c71d22021-02-03 23:54:45 -080030 private static final String TAG = CarLog.tagFor(LocationManagerProxy.class);
Felipe Leme176a5fd2021-01-20 15:48:33 -080031 private static final boolean DBG = false;
Gregory Clark55620c12019-06-03 17:42:58 -070032
33 private final LocationManager mLocationManager;
34
35 /**
36 * Create a LocationManagerProxy instance given a {@link Context}.
37 */
38 public LocationManagerProxy(Context context) {
39 if (DBG) {
Eric Jeongbd5fb562020-12-21 13:49:40 -080040 Slog.d(TAG, "constructed.");
Gregory Clark55620c12019-06-03 17:42:58 -070041 }
42 mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
43 }
44
45 @Override
46 public boolean isLocationEnabled() {
47 return mLocationManager.isLocationEnabled();
48 }
49
50 @Override
51 public boolean injectLocation(Location location) {
52 return mLocationManager.injectLocation(location);
53 }
54
55 @Override
56 public Location getLastKnownLocation(@NonNull String provider) {
57 if (DBG) {
Eric Jeongbd5fb562020-12-21 13:49:40 -080058 Slog.d(TAG, "Getting last known location for provider " + provider);
Gregory Clark55620c12019-06-03 17:42:58 -070059 }
60 return mLocationManager.getLastKnownLocation(provider);
61 }
Felipe Leme176a5fd2021-01-20 15:48:33 -080062
63 void dump(IndentingPrintWriter pw) {
64 pw.printf("isLocationEnabled: %b\n", isLocationEnabled());
65 }
Gregory Clark55620c12019-06-03 17:42:58 -070066}