Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1 | /* |
Soonil Nagarkar | f20d10e | 2020-01-27 11:05:40 -0800 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 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 | |
Soonil Nagarkar | f20d10e | 2020-01-27 11:05:40 -0800 | [diff] [blame] | 17 | package com.android.server.location.gnss; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 18 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 19 | import static android.app.AppOpsManager.OP_FINE_LOCATION; |
| 20 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 21 | import android.Manifest; |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 24 | import android.app.AppOpsManager; |
| 25 | import android.content.Context; |
| 26 | import android.location.GnssCapabilities; |
| 27 | import android.location.GnssMeasurementCorrections; |
| 28 | import android.location.IBatchedLocationCallback; |
| 29 | import android.location.IGnssMeasurementsListener; |
| 30 | import android.location.IGnssNavigationMessageListener; |
| 31 | import android.location.IGnssStatusListener; |
| 32 | import android.location.IGpsGeofenceHardware; |
| 33 | import android.location.INetInitiatedListener; |
| 34 | import android.location.Location; |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 35 | import android.location.LocationManagerInternal; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 36 | import android.os.Binder; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 37 | import android.os.IBinder; |
| 38 | import android.os.IInterface; |
| 39 | import android.os.Process; |
| 40 | import android.os.RemoteException; |
| 41 | import android.stats.location.LocationStatsEnums; |
| 42 | import android.util.ArrayMap; |
| 43 | import android.util.Log; |
| 44 | |
| 45 | import com.android.internal.annotations.GuardedBy; |
| 46 | import com.android.internal.annotations.VisibleForTesting; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 47 | import com.android.internal.util.IndentingPrintWriter; |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 48 | import com.android.internal.util.Preconditions; |
| 49 | import com.android.server.LocalServices; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 50 | import com.android.server.LocationManagerServiceUtils.LinkedListener; |
| 51 | import com.android.server.LocationManagerServiceUtils.LinkedListenerBase; |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 52 | import com.android.server.location.AppForegroundHelper; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 53 | import com.android.server.location.CallerIdentity; |
| 54 | import com.android.server.location.GnssBatchingProvider; |
| 55 | import com.android.server.location.GnssCapabilitiesProvider; |
| 56 | import com.android.server.location.GnssLocationProvider; |
| 57 | import com.android.server.location.GnssMeasurementCorrectionsProvider; |
| 58 | import com.android.server.location.GnssMeasurementsProvider; |
| 59 | import com.android.server.location.GnssNavigationMessageProvider; |
| 60 | import com.android.server.location.GnssStatusListenerHelper; |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 61 | import com.android.server.location.LocationUsageLogger; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 62 | import com.android.server.location.RemoteListenerHelper; |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 63 | import com.android.server.location.SettingsHelper; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 64 | |
| 65 | import java.io.FileDescriptor; |
| 66 | import java.io.PrintWriter; |
| 67 | import java.util.List; |
| 68 | import java.util.Map; |
| 69 | import java.util.function.Consumer; |
| 70 | import java.util.function.Function; |
| 71 | |
| 72 | /** Manages Gnss providers and related Gnss functions for LocationManagerService. */ |
| 73 | public class GnssManagerService { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 74 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 75 | private static final String TAG = "GnssManagerService"; |
| 76 | |
| 77 | public static boolean isGnssSupported() { |
| 78 | return GnssLocationProvider.isSupported(); |
| 79 | } |
| 80 | |
| 81 | private final Context mContext; |
| 82 | private final SettingsHelper mSettingsHelper; |
| 83 | private final AppForegroundHelper mAppForegroundHelper; |
| 84 | private final LocationUsageLogger mLocationUsageLogger; |
| 85 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 86 | private final GnssLocationProvider mGnssLocationProvider; |
| 87 | private final GnssStatusListenerHelper mGnssStatusProvider; |
| 88 | private final GnssMeasurementsProvider mGnssMeasurementsProvider; |
| 89 | private final GnssMeasurementCorrectionsProvider mGnssMeasurementCorrectionsProvider; |
| 90 | private final GnssNavigationMessageProvider mGnssNavigationMessageProvider; |
| 91 | private final GnssLocationProvider.GnssSystemInfoProvider mGnssSystemInfoProvider; |
| 92 | private final GnssLocationProvider.GnssMetricsProvider mGnssMetricsProvider; |
| 93 | private final GnssCapabilitiesProvider mGnssCapabilitiesProvider; |
| 94 | private final GnssBatchingProvider mGnssBatchingProvider; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 95 | private final INetInitiatedListener mNetInitiatedListener; |
| 96 | private final IGpsGeofenceHardware mGpsGeofenceProxy; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 97 | |
| 98 | @GuardedBy("mGnssMeasurementsListeners") |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 99 | private final ArrayMap<IBinder, LinkedListener<IGnssMeasurementsListener>> |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 100 | mGnssMeasurementsListeners = new ArrayMap<>(); |
| 101 | |
| 102 | @GuardedBy("mGnssNavigationMessageListeners") |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 103 | private final ArrayMap<IBinder, LinkedListener<IGnssNavigationMessageListener>> |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 104 | mGnssNavigationMessageListeners = new ArrayMap<>(); |
| 105 | |
| 106 | @GuardedBy("mGnssStatusListeners") |
| 107 | private final ArrayMap<IBinder, LinkedListener<IGnssStatusListener>> |
| 108 | mGnssStatusListeners = new ArrayMap<>(); |
| 109 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 110 | @GuardedBy("this") |
| 111 | @Nullable private LocationManagerInternal mLocationManagerInternal; |
| 112 | @GuardedBy("this") |
| 113 | @Nullable private AppOpsManager mAppOpsManager; |
| 114 | |
| 115 | private final Object mGnssBatchingLock = new Object(); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 116 | |
| 117 | @GuardedBy("mGnssBatchingLock") |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 118 | @Nullable private IBatchedLocationCallback mGnssBatchingCallback; |
| 119 | |
| 120 | @GuardedBy("mGnssBatchingLock") |
| 121 | @Nullable private LinkedListener<IBatchedLocationCallback> mGnssBatchingDeathCallback; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 122 | |
| 123 | @GuardedBy("mGnssBatchingLock") |
| 124 | private boolean mGnssBatchingInProgress = false; |
| 125 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 126 | public GnssManagerService(Context context, SettingsHelper settingsHelper, |
| 127 | AppForegroundHelper appForegroundHelper, LocationUsageLogger locationUsageLogger) { |
| 128 | this(context, settingsHelper, appForegroundHelper, locationUsageLogger, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | // Can use this constructor to inject GnssLocationProvider for testing |
| 132 | @VisibleForTesting |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 133 | GnssManagerService(Context context, SettingsHelper settingsHelper, |
| 134 | AppForegroundHelper appForegroundHelper, LocationUsageLogger locationUsageLogger, |
| 135 | GnssLocationProvider gnssLocationProvider) { |
| 136 | Preconditions.checkState(isGnssSupported()); |
| 137 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 138 | mContext = context; |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 139 | mSettingsHelper = settingsHelper; |
| 140 | mAppForegroundHelper = appForegroundHelper; |
| 141 | mLocationUsageLogger = locationUsageLogger; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 142 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 143 | if (gnssLocationProvider == null) { |
| 144 | gnssLocationProvider = new GnssLocationProvider(mContext); |
| 145 | } |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 146 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 147 | mGnssLocationProvider = gnssLocationProvider; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 148 | mGnssStatusProvider = mGnssLocationProvider.getGnssStatusProvider(); |
| 149 | mGnssMeasurementsProvider = mGnssLocationProvider.getGnssMeasurementsProvider(); |
| 150 | mGnssMeasurementCorrectionsProvider = |
| 151 | mGnssLocationProvider.getGnssMeasurementCorrectionsProvider(); |
| 152 | mGnssNavigationMessageProvider = mGnssLocationProvider.getGnssNavigationMessageProvider(); |
| 153 | mGnssSystemInfoProvider = mGnssLocationProvider.getGnssSystemInfoProvider(); |
| 154 | mGnssMetricsProvider = mGnssLocationProvider.getGnssMetricsProvider(); |
| 155 | mGnssCapabilitiesProvider = mGnssLocationProvider.getGnssCapabilitiesProvider(); |
| 156 | mGnssBatchingProvider = mGnssLocationProvider.getGnssBatchingProvider(); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 157 | mNetInitiatedListener = mGnssLocationProvider.getNetInitiatedListener(); |
| 158 | mGpsGeofenceProxy = mGnssLocationProvider.getGpsGeofenceProxy(); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 161 | /** Called when system is ready. */ |
| 162 | public synchronized void onSystemReady() { |
| 163 | if (mLocationManagerInternal != null) { |
| 164 | return; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 165 | } |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 166 | |
| 167 | mSettingsHelper.onSystemReady(); |
| 168 | mAppForegroundHelper.onSystemReady(); |
| 169 | |
| 170 | mLocationManagerInternal = LocalServices.getService(LocationManagerInternal.class); |
| 171 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
| 172 | |
| 173 | mAppForegroundHelper.addListener(this::onAppForegroundChanged); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 176 | /** Retrieve the GnssLocationProvider. */ |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 177 | public GnssLocationProvider getGnssLocationProvider() { |
| 178 | return mGnssLocationProvider; |
| 179 | } |
| 180 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 181 | /** Retrieve the IGpsGeofenceHardware. */ |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 182 | public IGpsGeofenceHardware getGpsGeofenceProxy() { |
| 183 | return mGpsGeofenceProxy; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Get year of GNSS hardware. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 188 | */ |
| 189 | public int getGnssYearOfHardware() { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 190 | return mGnssSystemInfoProvider.getGnssYearOfHardware(); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Get model name of GNSS hardware. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 195 | */ |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 196 | @Nullable |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 197 | public String getGnssHardwareModelName() { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 198 | return mGnssSystemInfoProvider.getGnssHardwareModelName(); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 202 | * Get GNSS hardware capabilities. The capabilities returned are a bitfield as described in |
| 203 | * {@link android.location.GnssCapabilities}. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 204 | */ |
| 205 | public long getGnssCapabilities(String packageName) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 206 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 207 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 208 | |
| 209 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 210 | return GnssCapabilities.INVALID_CAPABILITIES; |
| 211 | } |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 212 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 213 | return mGnssCapabilitiesProvider.getGnssCapabilities(); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Get size of GNSS batch (GNSS location results are batched together for power savings). |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 218 | */ |
| 219 | public int getGnssBatchSize(String packageName) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 220 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 221 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 222 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 223 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | synchronized (mGnssBatchingLock) { |
| 228 | return mGnssBatchingProvider.getBatchSize(); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Starts GNSS batch collection. GNSS positions are collected in a batch before being delivered |
| 234 | * as a collection. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 235 | */ |
| 236 | public boolean startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 237 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 238 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 239 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 240 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 241 | return false; |
| 242 | } |
| 243 | |
| 244 | synchronized (mGnssBatchingLock) { |
| 245 | if (mGnssBatchingInProgress) { |
| 246 | // Current design does not expect multiple starts to be called repeatedly |
| 247 | Log.e(TAG, "startGnssBatch unexpectedly called w/o stopping prior batch"); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 248 | stopGnssBatch(); |
| 249 | } |
| 250 | |
| 251 | mGnssBatchingInProgress = true; |
| 252 | return mGnssBatchingProvider.start(periodNanos, wakeOnFifoFull); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Adds a GNSS batching callback for delivering GNSS location batch results. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 258 | */ |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 259 | public boolean addGnssBatchingCallback(IBatchedLocationCallback callback, String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 260 | @Nullable String featureId, @NonNull String listenerIdentity) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 261 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 262 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 263 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 264 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 265 | return false; |
| 266 | } |
| 267 | |
| 268 | CallerIdentity callerIdentity = |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 269 | new CallerIdentity(Binder.getCallingUid(), Binder.getCallingPid(), packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 270 | featureId, listenerIdentity); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 271 | synchronized (mGnssBatchingLock) { |
| 272 | mGnssBatchingCallback = callback; |
| 273 | mGnssBatchingDeathCallback = |
Soonil Nagarkar | f20d10e | 2020-01-27 11:05:40 -0800 | [diff] [blame] | 274 | new LinkedListener<>( |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 275 | callback, |
| 276 | "BatchedLocationCallback", |
| 277 | callerIdentity, |
| 278 | (IBatchedLocationCallback listener) -> { |
| 279 | stopGnssBatch(); |
| 280 | removeGnssBatchingCallback(); |
| 281 | }); |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 282 | |
| 283 | return mGnssBatchingDeathCallback.linkToListenerDeathNotificationLocked( |
| 284 | callback.asBinder()); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Force flush GNSS location results from batch. |
| 290 | * |
| 291 | * @param packageName name of requesting package |
| 292 | */ |
| 293 | public void flushGnssBatch(String packageName) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 294 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 295 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 296 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 297 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | |
| 301 | synchronized (mGnssBatchingLock) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 302 | mGnssBatchingProvider.flush(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Removes GNSS batching callback. |
| 308 | */ |
| 309 | public void removeGnssBatchingCallback() { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 310 | mContext.enforceCallingPermission(android.Manifest.permission.LOCATION_HARDWARE, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 311 | |
| 312 | synchronized (mGnssBatchingLock) { |
| 313 | mGnssBatchingDeathCallback.unlinkFromListenerDeathNotificationLocked( |
| 314 | mGnssBatchingCallback.asBinder()); |
| 315 | mGnssBatchingCallback = null; |
| 316 | mGnssBatchingDeathCallback = null; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Stop GNSS batch collection. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 322 | */ |
| 323 | public boolean stopGnssBatch() { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 324 | mContext.enforceCallingPermission(android.Manifest.permission.LOCATION_HARDWARE, null); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 325 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 326 | synchronized (mGnssBatchingLock) { |
| 327 | mGnssBatchingInProgress = false; |
| 328 | return mGnssBatchingProvider.stop(); |
| 329 | } |
| 330 | } |
| 331 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 332 | private void onAppForegroundChanged(int uid, boolean foreground) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 333 | synchronized (mGnssMeasurementsListeners) { |
| 334 | updateListenersOnForegroundChangedLocked( |
| 335 | mGnssMeasurementsListeners, |
| 336 | mGnssMeasurementsProvider, |
| 337 | IGnssMeasurementsListener.Stub::asInterface, |
| 338 | uid, |
| 339 | foreground); |
| 340 | } |
| 341 | synchronized (mGnssNavigationMessageListeners) { |
| 342 | updateListenersOnForegroundChangedLocked( |
| 343 | mGnssNavigationMessageListeners, |
| 344 | mGnssNavigationMessageProvider, |
| 345 | IGnssNavigationMessageListener.Stub::asInterface, |
| 346 | uid, |
| 347 | foreground); |
| 348 | } |
| 349 | synchronized (mGnssStatusListeners) { |
| 350 | updateListenersOnForegroundChangedLocked( |
| 351 | mGnssStatusListeners, |
| 352 | mGnssStatusProvider, |
| 353 | IGnssStatusListener.Stub::asInterface, |
| 354 | uid, |
| 355 | foreground); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | private <TListener extends IInterface> void updateListenersOnForegroundChangedLocked( |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 360 | Map<IBinder, ? extends LinkedListenerBase> gnssDataListeners, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 361 | RemoteListenerHelper<TListener> gnssDataProvider, |
| 362 | Function<IBinder, TListener> mapBinderToListener, |
| 363 | int uid, |
| 364 | boolean foreground) { |
| 365 | for (Map.Entry<IBinder, ? extends LinkedListenerBase> entry : |
| 366 | gnssDataListeners.entrySet()) { |
| 367 | LinkedListenerBase linkedListener = entry.getValue(); |
| 368 | CallerIdentity callerIdentity = linkedListener.getCallerIdentity(); |
| 369 | if (callerIdentity.mUid != uid) { |
| 370 | continue; |
| 371 | } |
| 372 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 373 | TListener listener = mapBinderToListener.apply(entry.getKey()); |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 374 | if (foreground || isThrottlingExempt(callerIdentity)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 375 | gnssDataProvider.addListener(listener, callerIdentity); |
| 376 | } else { |
| 377 | gnssDataProvider.removeListener(listener); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | private <TListener extends IInterface> boolean addGnssDataListenerLocked( |
| 383 | TListener listener, |
| 384 | String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 385 | @Nullable String featureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 386 | @NonNull String listenerIdentifier, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 387 | RemoteListenerHelper<TListener> gnssDataProvider, |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 388 | ArrayMap<IBinder, LinkedListener<TListener>> gnssDataListeners, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 389 | Consumer<TListener> binderDeathCallback) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 390 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 391 | |
| 392 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 393 | return false; |
| 394 | } |
| 395 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 396 | CallerIdentity callerIdentity = new CallerIdentity(Binder.getCallingUid(), |
| 397 | Binder.getCallingPid(), packageName, featureId, listenerIdentifier); |
| 398 | LinkedListener<TListener> linkedListener = new LinkedListener<>(listener, |
| 399 | listenerIdentifier, callerIdentity, binderDeathCallback); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 400 | IBinder binder = listener.asBinder(); |
| 401 | if (!linkedListener.linkToListenerDeathNotificationLocked(binder)) { |
| 402 | return false; |
| 403 | } |
| 404 | |
| 405 | gnssDataListeners.put(binder, linkedListener); |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 406 | if (gnssDataProvider == mGnssMeasurementsProvider |
| 407 | || gnssDataProvider == mGnssStatusProvider) { |
| 408 | mLocationUsageLogger.logLocationApiUsage( |
| 409 | LocationStatsEnums.USAGE_STARTED, |
| 410 | gnssDataProvider == mGnssMeasurementsProvider |
| 411 | ? LocationStatsEnums.API_ADD_GNSS_MEASUREMENTS_LISTENER |
| 412 | : LocationStatsEnums.API_REGISTER_GNSS_STATUS_CALLBACK, |
| 413 | packageName, |
| 414 | /* LocationRequest= */ null, |
| 415 | /* hasListener= */ true, |
| 416 | /* hasIntent= */ false, |
| 417 | /* geofence= */ null, |
| 418 | mAppForegroundHelper.getImportance(callerIdentity.mUid)); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 419 | } |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 420 | if (mAppForegroundHelper.isAppForeground(callerIdentity.mUid) |
| 421 | || isThrottlingExempt(callerIdentity)) { |
| 422 | gnssDataProvider.addListener(listener, callerIdentity); |
| 423 | } |
| 424 | return true; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 427 | private <TListener extends IInterface> void removeGnssDataListenerLocked( |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 428 | TListener listener, |
| 429 | RemoteListenerHelper<TListener> gnssDataProvider, |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 430 | ArrayMap<IBinder, LinkedListener<TListener>> gnssDataListeners) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 431 | if (gnssDataProvider == null) { |
| 432 | Log.e( |
| 433 | TAG, |
| 434 | "Can not remove GNSS data listener. GNSS data provider " |
| 435 | + "not available."); |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | IBinder binder = listener.asBinder(); |
| 440 | LinkedListener<TListener> linkedListener = |
| 441 | gnssDataListeners.remove(binder); |
| 442 | if (linkedListener == null) { |
| 443 | return; |
| 444 | } |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 445 | if (gnssDataProvider == mGnssMeasurementsProvider |
| 446 | || gnssDataProvider == mGnssStatusProvider) { |
| 447 | mLocationUsageLogger.logLocationApiUsage( |
| 448 | LocationStatsEnums.USAGE_ENDED, |
| 449 | gnssDataProvider == mGnssMeasurementsProvider |
| 450 | ? LocationStatsEnums.API_ADD_GNSS_MEASUREMENTS_LISTENER |
| 451 | : LocationStatsEnums.API_REGISTER_GNSS_STATUS_CALLBACK, |
| 452 | linkedListener.getCallerIdentity().mPackageName, |
| 453 | /* LocationRequest= */ null, |
| 454 | /* hasListener= */ true, |
| 455 | /* hasIntent= */ false, |
| 456 | /* geofence= */ null, |
| 457 | mAppForegroundHelper.getImportance(Binder.getCallingUid())); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 458 | } |
| 459 | linkedListener.unlinkFromListenerDeathNotificationLocked(binder); |
| 460 | gnssDataProvider.removeListener(listener); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Registers listener for GNSS status changes. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 465 | */ |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 466 | public boolean registerGnssStatusCallback(IGnssStatusListener listener, String packageName, |
| 467 | @Nullable String featureId) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 468 | synchronized (mGnssStatusListeners) { |
| 469 | return addGnssDataListenerLocked( |
| 470 | listener, |
| 471 | packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 472 | featureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 473 | "Gnss status", |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 474 | mGnssStatusProvider, |
| 475 | mGnssStatusListeners, |
| 476 | this::unregisterGnssStatusCallback); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Unregisters listener for GNSS status changes. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 482 | */ |
| 483 | public void unregisterGnssStatusCallback(IGnssStatusListener listener) { |
| 484 | synchronized (mGnssStatusListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 485 | removeGnssDataListenerLocked(listener, mGnssStatusProvider, mGnssStatusListeners); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Adds a GNSS measurements listener. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 491 | */ |
| 492 | public boolean addGnssMeasurementsListener( |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 493 | IGnssMeasurementsListener listener, String packageName, @Nullable String featureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 494 | @NonNull String listenerIdentifier) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 495 | synchronized (mGnssMeasurementsListeners) { |
| 496 | return addGnssDataListenerLocked( |
| 497 | listener, |
| 498 | packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 499 | featureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 500 | listenerIdentifier, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 501 | mGnssMeasurementsProvider, |
| 502 | mGnssMeasurementsListeners, |
| 503 | this::removeGnssMeasurementsListener); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Injects GNSS measurement corrections. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 509 | */ |
| 510 | public void injectGnssMeasurementCorrections( |
| 511 | GnssMeasurementCorrections measurementCorrections, String packageName) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 512 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, null); |
| 513 | mContext.enforceCallingPermission(Manifest.permission.ACCESS_FINE_LOCATION, null); |
| 514 | |
| 515 | if (!checkLocationAppOp(packageName)) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 516 | return; |
| 517 | } |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 518 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 519 | mGnssMeasurementCorrectionsProvider.injectGnssMeasurementCorrections( |
| 520 | measurementCorrections); |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Removes a GNSS measurements listener. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 525 | */ |
| 526 | public void removeGnssMeasurementsListener(IGnssMeasurementsListener listener) { |
| 527 | synchronized (mGnssMeasurementsListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 528 | removeGnssDataListenerLocked(listener, mGnssMeasurementsProvider, |
| 529 | mGnssMeasurementsListeners); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Adds a GNSS navigation message listener. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 535 | */ |
| 536 | public boolean addGnssNavigationMessageListener( |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 537 | IGnssNavigationMessageListener listener, String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 538 | @Nullable String featureId, @NonNull String listenerIdentifier) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 539 | synchronized (mGnssNavigationMessageListeners) { |
| 540 | return addGnssDataListenerLocked( |
| 541 | listener, |
| 542 | packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 543 | featureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 544 | listenerIdentifier, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 545 | mGnssNavigationMessageProvider, |
| 546 | mGnssNavigationMessageListeners, |
| 547 | this::removeGnssNavigationMessageListener); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Removes a GNSS navigation message listener. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 553 | */ |
| 554 | public void removeGnssNavigationMessageListener(IGnssNavigationMessageListener listener) { |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 555 | synchronized (mGnssNavigationMessageListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 556 | removeGnssDataListenerLocked( |
Sasha Kuznetsov | b9f26b4 | 2019-10-03 17:30:46 -0700 | [diff] [blame] | 557 | listener, mGnssNavigationMessageProvider, mGnssNavigationMessageListeners); |
| 558 | } |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /** |
| 562 | * Send Ni Response, indicating a location request initiated by a network carrier. |
| 563 | */ |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 564 | public void sendNiResponse(int notifId, int userResponse) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 565 | try { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 566 | mNetInitiatedListener.sendNiResponse(notifId, userResponse); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 567 | } catch (RemoteException e) { |
| 568 | Log.e(TAG, "RemoteException in LocationManagerService.sendNiResponse"); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Report location results to GNSS batching listener. |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 574 | */ |
| 575 | public void onReportLocation(List<Location> locations) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 576 | IBatchedLocationCallback gnssBatchingCallback; |
| 577 | synchronized (mGnssBatchingLock) { |
| 578 | gnssBatchingCallback = mGnssBatchingCallback; |
| 579 | } |
| 580 | |
| 581 | if (gnssBatchingCallback == null) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | |
| 585 | try { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 586 | gnssBatchingCallback.onLocationBatch(locations); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 587 | } catch (RemoteException e) { |
| 588 | Log.e(TAG, "mGnssBatchingCallback.onLocationBatch failed", e); |
| 589 | } |
| 590 | } |
| 591 | |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 592 | private boolean isThrottlingExempt(CallerIdentity callerIdentity) { |
| 593 | if (callerIdentity.mUid == Process.SYSTEM_UID) { |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | if (mSettingsHelper.getBackgroundThrottlePackageWhitelist().contains( |
| 598 | callerIdentity.mPackageName)) { |
| 599 | return true; |
| 600 | } |
| 601 | |
| 602 | synchronized (this) { |
| 603 | Preconditions.checkState(mLocationManagerInternal != null); |
| 604 | } |
| 605 | return mLocationManagerInternal.isProviderPackage(callerIdentity.mPackageName); |
| 606 | } |
| 607 | |
| 608 | private boolean checkLocationAppOp(String packageName) { |
| 609 | synchronized (this) { |
| 610 | Preconditions.checkState(mAppOpsManager != null); |
| 611 | } |
| 612 | return mAppOpsManager.checkOp(OP_FINE_LOCATION, Binder.getCallingUid(), packageName) |
| 613 | == AppOpsManager.MODE_ALLOWED; |
| 614 | } |
| 615 | |
Soonil Nagarkar | f20d10e | 2020-01-27 11:05:40 -0800 | [diff] [blame] | 616 | /** |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 617 | * Dump info for debugging. |
Soonil Nagarkar | f20d10e | 2020-01-27 11:05:40 -0800 | [diff] [blame] | 618 | */ |
| 619 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 620 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 621 | |
| 622 | if (args.length > 0 && args[0].equals("--gnssmetrics")) { |
| 623 | if (mGnssMetricsProvider != null) { |
| 624 | pw.append(mGnssMetricsProvider.getGnssMetricsAsProtoString()); |
| 625 | } |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | ipw.println("GnssMeasurement Listeners:"); |
| 630 | ipw.increaseIndent(); |
| 631 | synchronized (mGnssMeasurementsListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 632 | for (LinkedListenerBase listener : mGnssMeasurementsListeners.values()) { |
| 633 | ipw.println(listener); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | ipw.decreaseIndent(); |
| 637 | |
| 638 | ipw.println("GnssNavigationMessage Listeners:"); |
| 639 | ipw.increaseIndent(); |
| 640 | synchronized (mGnssNavigationMessageListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 641 | for (LinkedListenerBase listener : mGnssNavigationMessageListeners.values()) { |
| 642 | ipw.println(listener); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | ipw.decreaseIndent(); |
| 646 | |
| 647 | ipw.println("GnssStatus Listeners:"); |
| 648 | ipw.increaseIndent(); |
| 649 | synchronized (mGnssStatusListeners) { |
Soonil Nagarkar | b6375a4 | 2020-01-29 15:23:06 -0800 | [diff] [blame] | 650 | for (LinkedListenerBase listener : mGnssStatusListeners.values()) { |
| 651 | ipw.println(listener); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | ipw.decreaseIndent(); |
| 655 | |
| 656 | synchronized (mGnssBatchingLock) { |
| 657 | if (mGnssBatchingInProgress) { |
| 658 | ipw.println("GNSS batching in progress"); |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | } |