Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 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; |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 24 | import android.util.IndentingPrintWriter; |
Eric Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 25 | import android.util.Slog; |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 26 | |
| 27 | /** Wraps a {@link LocationManager}. */ |
| 28 | public class LocationManagerProxy extends ILocationManagerProxy.Stub { |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 29 | |
Mayank Garg | 72c71d2 | 2021-02-03 23:54:45 -0800 | [diff] [blame] | 30 | private static final String TAG = CarLog.tagFor(LocationManagerProxy.class); |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 31 | private static final boolean DBG = false; |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 32 | |
| 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 Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 40 | Slog.d(TAG, "constructed."); |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 41 | } |
| 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 Jeong | bd5fb56 | 2020-12-21 13:49:40 -0800 | [diff] [blame] | 58 | Slog.d(TAG, "Getting last known location for provider " + provider); |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 59 | } |
| 60 | return mLocationManager.getLastKnownLocation(provider); |
| 61 | } |
Felipe Leme | 176a5fd | 2021-01-20 15:48:33 -0800 | [diff] [blame] | 62 | |
| 63 | void dump(IndentingPrintWriter pw) { |
| 64 | pw.printf("isLocationEnabled: %b\n", isLocationEnabled()); |
| 65 | } |
Gregory Clark | 55620c1 | 2019-06-03 17:42:58 -0700 | [diff] [blame] | 66 | } |