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