The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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.server; |
| 18 | |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 20 | import static android.location.LocationManager.FUSED_PROVIDER; |
| 21 | import static android.location.LocationManager.GPS_PROVIDER; |
| 22 | import static android.location.LocationManager.NETWORK_PROVIDER; |
| 23 | import static android.location.LocationManager.PASSIVE_PROVIDER; |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 24 | import static android.os.PowerManager.locationPowerSaveModeToString; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 25 | |
Wei Wang | 980b7c2 | 2018-12-06 17:53:00 -0800 | [diff] [blame] | 26 | import android.Manifest; |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 27 | import android.annotation.NonNull; |
Wyatt Riley | 49097c0 | 2018-03-15 09:14:43 -0700 | [diff] [blame] | 28 | import android.annotation.Nullable; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 29 | import android.app.ActivityManager; |
| 30 | import android.app.AppOpsManager; |
| 31 | import android.app.PendingIntent; |
| 32 | import android.content.BroadcastReceiver; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
| 35 | import android.content.IntentFilter; |
| 36 | import android.content.pm.ApplicationInfo; |
| 37 | import android.content.pm.PackageInfo; |
| 38 | import android.content.pm.PackageManager; |
| 39 | import android.content.pm.PackageManager.NameNotFoundException; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 40 | import android.content.pm.ResolveInfo; |
| 41 | import android.content.pm.Signature; |
| 42 | import android.content.res.Resources; |
Brian Duddie | cfa5b5b | 2019-01-22 18:01:40 +0000 | [diff] [blame] | 43 | import android.hardware.location.ActivityRecognitionHardware; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 44 | import android.location.Address; |
| 45 | import android.location.Criteria; |
| 46 | import android.location.GeocoderParams; |
| 47 | import android.location.Geofence; |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 48 | import android.location.GnssMeasurementCorrections; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 49 | import android.location.IBatchedLocationCallback; |
| 50 | import android.location.IGnssMeasurementsListener; |
| 51 | import android.location.IGnssNavigationMessageListener; |
| 52 | import android.location.IGnssStatusListener; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 53 | import android.location.ILocationListener; |
| 54 | import android.location.ILocationManager; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 55 | import android.location.Location; |
| 56 | import android.location.LocationManager; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 57 | import android.location.LocationRequest; |
Chad Brubaker | f113333 | 2019-03-15 14:13:59 -0700 | [diff] [blame] | 58 | import android.location.LocationTime; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 59 | import android.os.Binder; |
| 60 | import android.os.Bundle; |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 61 | import android.os.CancellationSignal; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 62 | import android.os.Handler; |
| 63 | import android.os.IBinder; |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 64 | import android.os.ICancellationSignal; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 65 | import android.os.PowerManager; |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 66 | import android.os.PowerManager.ServiceType; |
| 67 | import android.os.PowerManagerInternal; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 68 | import android.os.Process; |
| 69 | import android.os.RemoteException; |
| 70 | import android.os.SystemClock; |
| 71 | import android.os.UserHandle; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 72 | import android.os.WorkSource; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 73 | import android.os.WorkSource.WorkChain; |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 74 | import android.stats.location.LocationStatsEnums; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 75 | import android.text.TextUtils; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 76 | import android.util.EventLog; |
| 77 | import android.util.Log; |
| 78 | import android.util.Slog; |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 79 | import android.util.SparseArray; |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 80 | import android.util.TimeUtils; |
Yu-Han Yang | a4d250e | 2018-10-02 21:29:20 -0700 | [diff] [blame] | 81 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 82 | import com.android.internal.annotations.GuardedBy; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 83 | import com.android.internal.content.PackageMonitor; |
| 84 | import com.android.internal.location.ProviderProperties; |
| 85 | import com.android.internal.location.ProviderRequest; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 86 | import com.android.internal.util.DumpUtils; |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 87 | import com.android.internal.util.IndentingPrintWriter; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 88 | import com.android.internal.util.Preconditions; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 89 | import com.android.server.location.AbstractLocationProvider; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 90 | import com.android.server.location.AbstractLocationProvider.State; |
Brian Duddie | cfa5b5b | 2019-01-22 18:01:40 +0000 | [diff] [blame] | 91 | import com.android.server.location.ActivityRecognitionProxy; |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 92 | import com.android.server.location.CallerIdentity; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 93 | import com.android.server.location.GeocoderProxy; |
| 94 | import com.android.server.location.GeofenceManager; |
| 95 | import com.android.server.location.GeofenceProxy; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 96 | import com.android.server.location.LocationFudger; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 97 | import com.android.server.location.LocationProviderProxy; |
| 98 | import com.android.server.location.LocationRequestStatistics; |
| 99 | import com.android.server.location.LocationRequestStatistics.PackageProviderKey; |
| 100 | import com.android.server.location.LocationRequestStatistics.PackageStatistics; |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 101 | import com.android.server.location.LocationSettingsStore; |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 102 | import com.android.server.location.LocationUsageLogger; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 103 | import com.android.server.location.MockProvider; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 104 | import com.android.server.location.MockableLocationProvider; |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 105 | import com.android.server.location.PassiveProvider; |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 106 | import com.android.server.location.UserInfoStore; |
Todd Kennedy | 583378d | 2019-07-12 06:50:30 -0700 | [diff] [blame] | 107 | import com.android.server.pm.permission.PermissionManagerServiceInternal; |
Yu-Han Yang | a4d250e | 2018-10-02 21:29:20 -0700 | [diff] [blame] | 108 | |
Soonil Nagarkar | ae6ce77 | 2019-05-01 13:16:17 -0700 | [diff] [blame] | 109 | import java.io.ByteArrayOutputStream; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 110 | import java.io.FileDescriptor; |
Soonil Nagarkar | ae6ce77 | 2019-05-01 13:16:17 -0700 | [diff] [blame] | 111 | import java.io.PrintStream; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 112 | import java.io.PrintWriter; |
| 113 | import java.util.ArrayList; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 114 | import java.util.Arrays; |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 115 | import java.util.Collections; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 116 | import java.util.HashMap; |
| 117 | import java.util.HashSet; |
| 118 | import java.util.List; |
| 119 | import java.util.Map; |
Soonil Nagarkar | 681d711 | 2017-02-23 17:14:16 -0800 | [diff] [blame] | 120 | import java.util.Map.Entry; |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 121 | import java.util.Objects; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 122 | import java.util.Set; |
| 123 | import java.util.concurrent.CopyOnWriteArrayList; |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 124 | import java.util.concurrent.TimeUnit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * The service class that manages LocationProviders and issues location |
| 128 | * updates and alerts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | */ |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 130 | public class LocationManagerService extends ILocationManager.Stub { |
Soonil Nagarkar | 141417a | 2019-10-28 11:12:48 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Controls lifecycle of LocationManagerService. |
| 134 | */ |
| 135 | public static class Lifecycle extends SystemService { |
| 136 | |
| 137 | private LocationManagerService mService; |
| 138 | |
| 139 | public Lifecycle(Context context) { |
| 140 | super(context); |
| 141 | mService = new LocationManagerService(context); |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void onStart() { |
| 146 | publishBinderService(Context.LOCATION_SERVICE, mService); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onBootPhase(int phase) { |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 151 | if (phase == PHASE_SYSTEM_SERVICES_READY) { |
| 152 | // the location service must be functioning after this boot phase |
| 153 | mService.onSystemReady(); |
| 154 | } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { |
| 155 | // some providers rely on third party code, so we wait to initialize |
| 156 | // providers until third party code is allowed to run |
| 157 | mService.onSystemThirdPartyAppsCanStart(); |
Soonil Nagarkar | 141417a | 2019-10-28 11:12:48 -0700 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 162 | public static final String TAG = "LocationManagerService"; |
JP Abgrall | f79811e7 | 2013-02-01 18:45:05 -0800 | [diff] [blame] | 163 | public static final boolean D = Log.isLoggable(TAG, Log.DEBUG); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 164 | |
Olivier Gaillard | 7a22266 | 2017-11-20 16:07:24 +0000 | [diff] [blame] | 165 | private static final String WAKELOCK_KEY = "*location*"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 167 | private static final int RESOLUTION_LEVEL_NONE = 0; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 168 | private static final int RESOLUTION_LEVEL_COARSE = 1; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 169 | private static final int RESOLUTION_LEVEL_FINE = 2; |
| 170 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 171 | private static final String NETWORK_LOCATION_SERVICE_ACTION = |
Stan Chesnutt | 39062dd | 2013-07-22 14:33:30 -0700 | [diff] [blame] | 172 | "com.android.location.service.v3.NetworkLocationProvider"; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 173 | private static final String FUSED_LOCATION_SERVICE_ACTION = |
| 174 | "com.android.location.service.FusedLocationProvider"; |
| 175 | |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 176 | // The maximum interval a location request can have and still be considered "high power". |
| 177 | private static final long HIGH_POWER_INTERVAL_MS = 5 * 60 * 1000; |
| 178 | |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 179 | // maximum age of a location before it is no longer considered "current" |
| 180 | private static final long MAX_CURRENT_LOCATION_AGE_MS = 10 * 1000; |
| 181 | |
Soonil Nagarkar | ebda028 | 2017-04-10 14:55:37 -0700 | [diff] [blame] | 182 | private static final int FOREGROUND_IMPORTANCE_CUTOFF |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 183 | = ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE; |
Soonil Nagarkar | ebda028 | 2017-04-10 14:55:37 -0700 | [diff] [blame] | 184 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 185 | // Location Providers may sometimes deliver location updates |
| 186 | // slightly faster that requested - provide grace period so |
| 187 | // we don't unnecessarily filter events that are otherwise on |
| 188 | // time |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 189 | private static final int MAX_PROVIDER_SCHEDULING_JITTER_MS = 100; |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 190 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 191 | private static final LocationRequest DEFAULT_LOCATION_REQUEST = new LocationRequest(); |
| 192 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 193 | private final Object mLock = new Object(); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 194 | private final Context mContext; |
| 195 | private final Handler mHandler; |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 196 | private final UserInfoStore mUserInfoStore; |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 197 | private final LocationSettingsStore mSettingsStore; |
| 198 | private final LocationUsageLogger mLocationUsageLogger; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 199 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 200 | private final PassiveLocationProviderManager mPassiveManager; |
| 201 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 202 | private AppOpsManager mAppOps; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 203 | private PackageManager mPackageManager; |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 204 | private PowerManager mPowerManager; |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 205 | private ActivityManager mActivityManager; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 206 | |
| 207 | private GeofenceManager mGeofenceManager; |
| 208 | private LocationFudger mLocationFudger; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 209 | private GeocoderProxy mGeocodeProvider; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 210 | @Nullable private GnssManagerService mGnssManagerService; |
| 211 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 212 | @GuardedBy("mLock") |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 213 | private String mExtraLocationControllerPackage; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 214 | @GuardedBy("mLock") |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 215 | private boolean mExtraLocationControllerPackageEnabled; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 216 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 217 | // @GuardedBy("mLock") |
| 218 | // hold lock for write or to prevent write, no lock for read |
| 219 | private final CopyOnWriteArrayList<LocationProviderManager> mProviderManagers = |
| 220 | new CopyOnWriteArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 222 | @GuardedBy("mLock") |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 223 | private final HashMap<Object, Receiver> mReceivers = new HashMap<>(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 224 | private final HashMap<String, ArrayList<UpdateRecord>> mRecordsByProvider = |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 225 | new HashMap<>(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 226 | |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 227 | private final LocationRequestStatistics mRequestStatistics = new LocationRequestStatistics(); |
| 228 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 229 | // mapping from provider name to last known location |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 230 | @GuardedBy("mLock") |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 231 | private final HashMap<String, Location> mLastLocation = new HashMap<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 233 | // same as mLastLocation, but is not updated faster than LocationFudger.FASTEST_INTERVAL_MS. |
| 234 | // locations stored here are not fudged for coarse permissions. |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 235 | @GuardedBy("mLock") |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 236 | private final HashMap<String, Location> mLastLocationCoarseInterval = |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 237 | new HashMap<>(); |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 238 | |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 239 | @GuardedBy("mLock") |
| 240 | @PowerManager.LocationPowerSaveMode |
| 241 | private int mBatterySaverMode; |
| 242 | |
Soonil Nagarkar | 141417a | 2019-10-28 11:12:48 -0700 | [diff] [blame] | 243 | private LocationManagerService(Context context) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 244 | mContext = context; |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 245 | mHandler = FgThread.getHandler(); |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 246 | mUserInfoStore = new UserInfoStore(mContext); |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 247 | mSettingsStore = new LocationSettingsStore(mContext, mHandler); |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 248 | mLocationUsageLogger = new LocationUsageLogger(); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 249 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 250 | // set up passive provider - we do this early because it has no dependencies on system |
| 251 | // services or external code that isn't ready yet, and because this allows the variable to |
| 252 | // be final. other more complex providers are initialized later, when system services are |
| 253 | // ready |
| 254 | mPassiveManager = new PassiveLocationProviderManager(); |
| 255 | mProviderManagers.add(mPassiveManager); |
| 256 | mPassiveManager.setRealProvider(new PassiveProvider(mContext)); |
| 257 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 258 | // Let the package manager query which are the default location |
| 259 | // providers as they get certain permissions granted by default. |
Todd Kennedy | 583378d | 2019-07-12 06:50:30 -0700 | [diff] [blame] | 260 | PermissionManagerServiceInternal permissionManagerInternal = LocalServices.getService( |
| 261 | PermissionManagerServiceInternal.class); |
| 262 | permissionManagerInternal.setLocationPackagesProvider( |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 263 | userId -> mContext.getResources().getStringArray( |
| 264 | com.android.internal.R.array.config_locationProviderPackageNames)); |
Todd Kennedy | 583378d | 2019-07-12 06:50:30 -0700 | [diff] [blame] | 265 | permissionManagerInternal.setLocationExtraPackagesProvider( |
Wei Wang | ffb94e6 | 2019-01-14 00:05:45 -0800 | [diff] [blame] | 266 | userId -> mContext.getResources().getStringArray( |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 267 | com.android.internal.R.array.config_locationExtraPackageNames)); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 268 | |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 269 | // most startup is deferred until systemReady() |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 272 | private void onSystemReady() { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 273 | mUserInfoStore.onSystemReady(); |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 274 | mSettingsStore.onSystemReady(); |
| 275 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 276 | synchronized (mLock) { |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 277 | mPackageManager = mContext.getPackageManager(); |
| 278 | mAppOps = mContext.getSystemService(AppOpsManager.class); |
| 279 | mPowerManager = mContext.getSystemService(PowerManager.class); |
| 280 | mActivityManager = mContext.getSystemService(ActivityManager.class); |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 281 | |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 282 | mLocationFudger = new LocationFudger(mContext, mHandler); |
| 283 | mGeofenceManager = new GeofenceManager(mContext, mSettingsStore); |
| 284 | |
| 285 | PowerManagerInternal localPowerManager = |
| 286 | LocalServices.getService(PowerManagerInternal.class); |
| 287 | |
| 288 | // add listeners |
| 289 | mAppOps.startWatchingMode( |
| 290 | AppOpsManager.OP_COARSE_LOCATION, |
| 291 | null, |
| 292 | AppOpsManager.WATCH_FOREGROUND_CHANGES, |
| 293 | new AppOpsManager.OnOpChangedInternalListener() { |
| 294 | public void onOpChanged(int op, String packageName) { |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 295 | // onOpChanged invoked on ui thread, move to our thread to reduce risk |
| 296 | // of blocking ui thread |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 297 | mHandler.post(() -> { |
| 298 | synchronized (mLock) { |
| 299 | onAppOpChangedLocked(); |
| 300 | } |
| 301 | }); |
| 302 | } |
| 303 | }); |
| 304 | mPackageManager.addOnPermissionsChangeListener( |
| 305 | uid -> { |
| 306 | // listener invoked on ui thread, move to our thread to reduce risk of |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 307 | // blocking ui thread |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 308 | mHandler.post(() -> { |
| 309 | synchronized (mLock) { |
| 310 | onPermissionsChangedLocked(); |
| 311 | } |
| 312 | }); |
| 313 | }); |
| 314 | mActivityManager.addOnUidImportanceListener( |
| 315 | (uid, importance) -> { |
| 316 | // listener invoked on ui thread, move to our thread to reduce risk of |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 317 | // blocking ui thread |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 318 | mHandler.post(() -> { |
| 319 | synchronized (mLock) { |
| 320 | onUidImportanceChangedLocked(uid, importance); |
| 321 | } |
| 322 | }); |
| 323 | }, |
| 324 | FOREGROUND_IMPORTANCE_CUTOFF); |
| 325 | |
| 326 | localPowerManager.registerLowPowerModeObserver(ServiceType.LOCATION, |
| 327 | state -> { |
| 328 | // listener invoked on ui thread, move to our thread to reduce risk of |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 329 | // blocking ui thread |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 330 | mHandler.post(() -> { |
| 331 | synchronized (mLock) { |
| 332 | onBatterySaverModeChangedLocked(state.locationMode); |
| 333 | } |
| 334 | }); |
| 335 | }); |
| 336 | mBatterySaverMode = mPowerManager.getLocationPowerSaveMode(); |
| 337 | |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 338 | mSettingsStore.addOnLocationEnabledChangedListener((userId) -> { |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 339 | synchronized (mLock) { |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 340 | onLocationModeChangedLocked(userId); |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 341 | } |
| 342 | }); |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 343 | mSettingsStore.addOnBackgroundThrottleIntervalChangedListener(() -> { |
| 344 | synchronized (mLock) { |
| 345 | onBackgroundThrottleIntervalChangedLocked(); |
| 346 | } |
| 347 | }); |
| 348 | mSettingsStore.addOnBackgroundThrottlePackageWhitelistChangedListener(() -> { |
| 349 | synchronized (mLock) { |
| 350 | onBackgroundThrottleWhitelistChangedLocked(); |
| 351 | } |
| 352 | }); |
| 353 | mSettingsStore.addOnIgnoreSettingsPackageWhitelistChangedListener(() -> { |
| 354 | synchronized (mLock) { |
| 355 | onIgnoreSettingsWhitelistChangedLocked(); |
| 356 | } |
| 357 | }); |
| 358 | |
| 359 | new PackageMonitor() { |
| 360 | @Override |
| 361 | public void onPackageDisappeared(String packageName, int reason) { |
| 362 | synchronized (mLock) { |
| 363 | LocationManagerService.this.onPackageDisappearedLocked(packageName); |
| 364 | } |
| 365 | } |
| 366 | }.register(mContext, mHandler.getLooper(), true); |
| 367 | |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 368 | mUserInfoStore.addListener((oldUserId, newUserId) -> { |
| 369 | synchronized (mLock) { |
| 370 | onUserChangedLocked(oldUserId, newUserId); |
| 371 | } |
| 372 | }); |
| 373 | |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 374 | IntentFilter intentFilter = new IntentFilter(); |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 375 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 376 | intentFilter.addAction(Intent.ACTION_SCREEN_ON); |
| 377 | |
| 378 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 379 | @Override |
| 380 | public void onReceive(Context context, Intent intent) { |
| 381 | final String action = intent.getAction(); |
| 382 | if (action == null) { |
| 383 | return; |
| 384 | } |
| 385 | synchronized (mLock) { |
| 386 | switch (action) { |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 387 | case Intent.ACTION_SCREEN_ON: |
| 388 | case Intent.ACTION_SCREEN_OFF: |
| 389 | onScreenStateChangedLocked(); |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | }, UserHandle.ALL, intentFilter, null, mHandler); |
| 395 | |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 396 | // switching the user from null to current here performs the bulk of the initialization |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 397 | // work. the user being changed will cause a reload of all user specific settings, which |
| 398 | // causes initialization, and propagates changes until a steady state is reached |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 399 | onUserChangedLocked(UserHandle.USER_NULL, mUserInfoStore.getCurrentUserId()); |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 400 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 401 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 402 | |
Soonil Nagarkar | 3709606 | 2019-11-25 13:24:48 -0800 | [diff] [blame] | 403 | private void onSystemThirdPartyAppsCanStart() { |
| 404 | synchronized (mLock) { |
| 405 | // prepare providers |
| 406 | initializeProvidersLocked(); |
| 407 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 410 | @GuardedBy("mLock") |
| 411 | private void onAppOpChangedLocked() { |
| 412 | for (Receiver receiver : mReceivers.values()) { |
| 413 | receiver.updateMonitoring(true); |
| 414 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 415 | for (LocationProviderManager manager : mProviderManagers) { |
| 416 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
| 420 | @GuardedBy("mLock") |
| 421 | private void onPermissionsChangedLocked() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 422 | for (LocationProviderManager manager : mProviderManagers) { |
| 423 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | @GuardedBy("mLock") |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 428 | private void onBatterySaverModeChangedLocked(int newLocationMode) { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 429 | if (mBatterySaverMode == newLocationMode) { |
| 430 | return; |
| 431 | } |
| 432 | |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 433 | if (D) { |
| 434 | Slog.d(TAG, |
| 435 | "Battery Saver location mode changed from " |
| 436 | + locationPowerSaveModeToString(mBatterySaverMode) + " to " |
| 437 | + locationPowerSaveModeToString(newLocationMode)); |
| 438 | } |
| 439 | |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 440 | mBatterySaverMode = newLocationMode; |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 441 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 442 | for (LocationProviderManager manager : mProviderManagers) { |
| 443 | applyRequirementsLocked(manager); |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | @GuardedBy("mLock") |
| 448 | private void onScreenStateChangedLocked() { |
| 449 | if (mBatterySaverMode == PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 450 | for (LocationProviderManager manager : mProviderManagers) { |
| 451 | applyRequirementsLocked(manager); |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | @GuardedBy("mLock") |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 457 | private void onLocationModeChangedLocked(int userId) { |
| 458 | if (D) { |
| 459 | Log.d(TAG, "[u" + userId + "] location enabled = " + isLocationEnabledForUser(userId)); |
Soonil Nagarkar | 6bf751f | 2019-11-27 13:41:28 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 462 | Intent intent = new Intent(LocationManager.MODE_CHANGED_ACTION); |
Soonil Nagarkar | 57f4b7b | 2019-12-09 10:19:18 -0800 | [diff] [blame] | 463 | intent.putExtra(LocationManager.EXTRA_LOCATION_ENABLED, isLocationEnabledForUser(userId)); |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 464 | mContext.sendBroadcastAsUser(intent, UserHandle.of(userId)); |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 465 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 466 | for (LocationProviderManager manager : mProviderManagers) { |
| 467 | manager.onUseableChangedLocked(userId); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 468 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | @GuardedBy("mLock") |
| 472 | private void onPackageDisappearedLocked(String packageName) { |
| 473 | ArrayList<Receiver> deadReceivers = null; |
| 474 | |
| 475 | for (Receiver receiver : mReceivers.values()) { |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 476 | if (receiver.mCallerIdentity.mPackageName.equals(packageName)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 477 | if (deadReceivers == null) { |
| 478 | deadReceivers = new ArrayList<>(); |
| 479 | } |
| 480 | deadReceivers.add(receiver); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // perform removal outside of mReceivers loop |
| 485 | if (deadReceivers != null) { |
| 486 | for (Receiver receiver : deadReceivers) { |
| 487 | removeUpdatesLocked(receiver); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | @GuardedBy("mLock") |
| 493 | private void onUidImportanceChangedLocked(int uid, int importance) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 494 | boolean foreground = LocationManagerServiceUtils.isImportanceForeground(importance); |
Soonil Nagarkar | e056b0d | 2017-06-21 13:08:16 -0700 | [diff] [blame] | 495 | HashSet<String> affectedProviders = new HashSet<>(mRecordsByProvider.size()); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 496 | for (Entry<String, ArrayList<UpdateRecord>> entry : mRecordsByProvider.entrySet()) { |
| 497 | String provider = entry.getKey(); |
| 498 | for (UpdateRecord record : entry.getValue()) { |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 499 | if (record.mReceiver.mCallerIdentity.mUid == uid |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 500 | && record.mIsForegroundUid != foreground) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 501 | if (D) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 502 | Log.d(TAG, "request from uid " + uid + " is now " |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 503 | + LocationManagerServiceUtils.foregroundAsString( |
| 504 | foreground)); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 505 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 506 | record.updateForeground(foreground); |
| 507 | |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 508 | if (!isThrottlingExemptLocked(record.mReceiver.mCallerIdentity)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 509 | affectedProviders.add(provider); |
Soonil Nagarkar | e056b0d | 2017-06-21 13:08:16 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 513 | } |
| 514 | for (String provider : affectedProviders) { |
| 515 | applyRequirementsLocked(provider); |
| 516 | } |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 519 | @GuardedBy("mLock") |
| 520 | private void onBackgroundThrottleIntervalChangedLocked() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 521 | for (LocationProviderManager manager : mProviderManagers) { |
| 522 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 523 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 526 | @GuardedBy("mLock") |
| 527 | private void onBackgroundThrottleWhitelistChangedLocked() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 528 | for (LocationProviderManager manager : mProviderManagers) { |
| 529 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 530 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 533 | @GuardedBy("lock") |
| 534 | private void onIgnoreSettingsWhitelistChangedLocked() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 535 | for (LocationProviderManager manager : mProviderManagers) { |
| 536 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 540 | @GuardedBy("mLock") |
Soonil Nagarkar | e731ca8 | 2018-11-02 13:55:51 -0700 | [diff] [blame] | 541 | private void ensureFallbackFusedProviderPresentLocked(String[] pkgs) { |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 542 | PackageManager pm = mContext.getPackageManager(); |
| 543 | String systemPackageName = mContext.getPackageName(); |
| 544 | ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs); |
| 545 | |
| 546 | List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser( |
| 547 | new Intent(FUSED_LOCATION_SERVICE_ACTION), |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 548 | PackageManager.GET_META_DATA, mUserInfoStore.getCurrentUserId()); |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 549 | for (ResolveInfo rInfo : rInfos) { |
| 550 | String packageName = rInfo.serviceInfo.packageName; |
| 551 | |
| 552 | // Check that the signature is in the list of supported sigs. If it's not in |
| 553 | // this list the standard provider binding logic won't bind to it. |
| 554 | try { |
| 555 | PackageInfo pInfo; |
| 556 | pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); |
| 557 | if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) { |
| 558 | Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION + |
| 559 | ", but has wrong signature, ignoring"); |
| 560 | continue; |
| 561 | } |
| 562 | } catch (NameNotFoundException e) { |
| 563 | Log.e(TAG, "missing package: " + packageName); |
| 564 | continue; |
| 565 | } |
| 566 | |
| 567 | // Get the version info |
| 568 | if (rInfo.serviceInfo.metaData == null) { |
| 569 | Log.w(TAG, "Found fused provider without metadata: " + packageName); |
| 570 | continue; |
| 571 | } |
| 572 | |
| 573 | int version = rInfo.serviceInfo.metaData.getInt( |
| 574 | ServiceWatcher.EXTRA_SERVICE_VERSION, -1); |
| 575 | if (version == 0) { |
| 576 | // This should be the fallback fused location provider. |
| 577 | |
| 578 | // Make sure it's in the system partition. |
| 579 | if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 580 | if (D) Log.d(TAG, "Fallback candidate not in /system: " + packageName); |
| 581 | continue; |
| 582 | } |
| 583 | |
| 584 | // Check that the fallback is signed the same as the OS |
| 585 | // as a proxy for coreApp="true" |
| 586 | if (pm.checkSignatures(systemPackageName, packageName) |
| 587 | != PackageManager.SIGNATURE_MATCH) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 588 | if (D) { |
| 589 | Log.d(TAG, "Fallback candidate not signed the same as system: " |
| 590 | + packageName); |
| 591 | } |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 592 | continue; |
| 593 | } |
| 594 | |
| 595 | // Found a valid fallback. |
| 596 | if (D) Log.d(TAG, "Found fallback provider: " + packageName); |
| 597 | return; |
| 598 | } else { |
| 599 | if (D) Log.d(TAG, "Fallback candidate not version 0: " + packageName); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | throw new IllegalStateException("Unable to find a fused location provider that is in the " |
| 604 | + "system partition with version 0 and signed with the platform certificate. " |
| 605 | + "Such a package is needed to provide a default fused location provider in the " |
| 606 | + "event that no other fused location provider has been installed or is currently " |
| 607 | + "available. For example, coreOnly boot mode when decrypting the data " |
| 608 | + "partition. The fallback must also be marked coreApp=\"true\" in the manifest"); |
| 609 | } |
| 610 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 611 | @GuardedBy("mLock") |
| 612 | private void initializeProvidersLocked() { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 613 | if (GnssManagerService.isGnssSupported()) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 614 | mGnssManagerService = new GnssManagerService(this, mContext, mLocationUsageLogger); |
| 615 | LocationProviderManager gnssManager = new LocationProviderManager(GPS_PROVIDER); |
| 616 | mProviderManagers.add(gnssManager); |
| 617 | gnssManager.setRealProvider(mGnssManagerService.getGnssLocationProvider()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 620 | /* |
| 621 | Load package name(s) containing location provider support. |
| 622 | These packages can contain services implementing location providers: |
| 623 | Geocoder Provider, Network Location Provider, and |
| 624 | Fused Location Provider. They will each be searched for |
| 625 | service components implementing these providers. |
| 626 | The location framework also has support for installation |
| 627 | of new location providers at run-time. The new package does not |
| 628 | have to be explicitly listed here, however it must have a signature |
| 629 | that matches the signature of at least one package on this list. |
| 630 | */ |
| 631 | Resources resources = mContext.getResources(); |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 632 | String[] pkgs = resources.getStringArray( |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 633 | com.android.internal.R.array.config_locationProviderPackageNames); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 634 | if (D) { |
| 635 | Log.d(TAG, "certificates for location providers pulled from: " + |
| 636 | Arrays.toString(pkgs)); |
| 637 | } |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 638 | |
Soonil Nagarkar | e731ca8 | 2018-11-02 13:55:51 -0700 | [diff] [blame] | 639 | ensureFallbackFusedProviderPresentLocked(pkgs); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 640 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 641 | LocationProviderProxy networkProvider = LocationProviderProxy.createAndBind( |
| 642 | mContext, |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 643 | NETWORK_LOCATION_SERVICE_ACTION, |
Zhentao Sun | c5fc998 | 2013-04-17 17:47:53 -0700 | [diff] [blame] | 644 | com.android.internal.R.bool.config_enableNetworkLocationOverlay, |
| 645 | com.android.internal.R.string.config_networkLocationProviderPackageName, |
Soonil Nagarkar | e731ca8 | 2018-11-02 13:55:51 -0700 | [diff] [blame] | 646 | com.android.internal.R.array.config_locationProviderPackageNames); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 647 | if (networkProvider != null) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 648 | LocationProviderManager networkManager = new LocationProviderManager(NETWORK_PROVIDER); |
| 649 | mProviderManagers.add(networkManager); |
| 650 | networkManager.setRealProvider(networkProvider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 651 | } else { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 652 | Slog.w(TAG, "no network location provider found"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | // bind to fused provider |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 656 | LocationProviderProxy fusedProvider = LocationProviderProxy.createAndBind( |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 657 | mContext, |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 658 | FUSED_LOCATION_SERVICE_ACTION, |
Zhentao Sun | c5fc998 | 2013-04-17 17:47:53 -0700 | [diff] [blame] | 659 | com.android.internal.R.bool.config_enableFusedLocationOverlay, |
| 660 | com.android.internal.R.string.config_fusedLocationProviderPackageName, |
Soonil Nagarkar | e731ca8 | 2018-11-02 13:55:51 -0700 | [diff] [blame] | 661 | com.android.internal.R.array.config_locationProviderPackageNames); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 662 | if (fusedProvider != null) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 663 | LocationProviderManager fusedManager = new LocationProviderManager(FUSED_PROVIDER); |
| 664 | mProviderManagers.add(fusedManager); |
| 665 | fusedManager.setRealProvider(fusedProvider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 666 | } else { |
| 667 | Slog.e(TAG, "no fused location provider found", |
| 668 | new IllegalStateException("Location service needs a fused location provider")); |
| 669 | } |
| 670 | |
| 671 | // bind to geocoder provider |
Zhentao Sun | c5fc998 | 2013-04-17 17:47:53 -0700 | [diff] [blame] | 672 | mGeocodeProvider = GeocoderProxy.createAndBind(mContext, |
| 673 | com.android.internal.R.bool.config_enableGeocoderOverlay, |
| 674 | com.android.internal.R.string.config_geocoderProviderPackageName, |
Soonil Nagarkar | e731ca8 | 2018-11-02 13:55:51 -0700 | [diff] [blame] | 675 | com.android.internal.R.array.config_locationProviderPackageNames); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 676 | if (mGeocodeProvider == null) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 677 | Slog.e(TAG, "no geocoder provider found"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 678 | } |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame] | 679 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 680 | if (mGnssManagerService != null) { |
| 681 | // bind to geofence provider |
| 682 | GeofenceProxy provider = GeofenceProxy.createAndBind( |
| 683 | mContext, com.android.internal.R.bool.config_enableGeofenceOverlay, |
| 684 | com.android.internal.R.string.config_geofenceProviderPackageName, |
| 685 | com.android.internal.R.array.config_locationProviderPackageNames, |
| 686 | mGnssManagerService.getGpsGeofenceProxy(), |
| 687 | null); |
| 688 | if (provider == null) { |
| 689 | Slog.d(TAG, "Unable to bind FLP Geofence proxy."); |
| 690 | } |
destradaa | 0682809a | 2013-08-12 18:50:30 -0700 | [diff] [blame] | 691 | } |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 692 | |
Brian Duddie | cfa5b5b | 2019-01-22 18:01:40 +0000 | [diff] [blame] | 693 | // bind to hardware activity recognition |
| 694 | boolean activityRecognitionHardwareIsSupported = ActivityRecognitionHardware.isSupported(); |
| 695 | ActivityRecognitionHardware activityRecognitionHardware = null; |
| 696 | if (activityRecognitionHardwareIsSupported) { |
| 697 | activityRecognitionHardware = ActivityRecognitionHardware.getInstance(mContext); |
| 698 | } else { |
| 699 | Slog.d(TAG, "Hardware Activity-Recognition not supported."); |
| 700 | } |
| 701 | ActivityRecognitionProxy proxy = ActivityRecognitionProxy.createAndBind( |
| 702 | mContext, |
| 703 | activityRecognitionHardwareIsSupported, |
| 704 | activityRecognitionHardware, |
| 705 | com.android.internal.R.bool.config_enableActivityRecognitionHardwareOverlay, |
| 706 | com.android.internal.R.string.config_activityRecognitionHardwarePackageName, |
| 707 | com.android.internal.R.array.config_locationProviderPackageNames); |
| 708 | if (proxy == null) { |
| 709 | Slog.d(TAG, "Unable to bind ActivityRecognitionProxy."); |
| 710 | } |
| 711 | |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 712 | String[] testProviderStrings = resources.getStringArray( |
| 713 | com.android.internal.R.array.config_testLocationProviders); |
| 714 | for (String testProviderString : testProviderStrings) { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 715 | String[] fragments = testProviderString.split(","); |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 716 | String name = fragments[0].trim(); |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 717 | ProviderProperties properties = new ProviderProperties( |
| 718 | Boolean.parseBoolean(fragments[1]) /* requiresNetwork */, |
| 719 | Boolean.parseBoolean(fragments[2]) /* requiresSatellite */, |
| 720 | Boolean.parseBoolean(fragments[3]) /* requiresCell */, |
| 721 | Boolean.parseBoolean(fragments[4]) /* hasMonetaryCost */, |
| 722 | Boolean.parseBoolean(fragments[5]) /* supportsAltitude */, |
| 723 | Boolean.parseBoolean(fragments[6]) /* supportsSpeed */, |
| 724 | Boolean.parseBoolean(fragments[7]) /* supportsBearing */, |
| 725 | Integer.parseInt(fragments[8]) /* powerRequirement */, |
| 726 | Integer.parseInt(fragments[9]) /* accuracy */); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 727 | addTestProvider(name, properties, mContext.getOpPackageName()); |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 728 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 729 | } |
Mike Lockwood | 9637d47 | 2009-04-02 21:41:57 -0700 | [diff] [blame] | 730 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 731 | @GuardedBy("mLock") |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 732 | private void onUserChangedLocked(int oldUserId, int newUserId) { |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 733 | if (D) { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 734 | Log.d(TAG, "foreground user is changing to " + newUserId); |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 737 | for (LocationProviderManager manager : mProviderManagers) { |
| 738 | // update LOCATION_PROVIDERS_ALLOWED for best effort backwards compatibility |
| 739 | mSettingsStore.setLocationProviderAllowed(manager.getName(), |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 740 | manager.isUseable(newUserId), newUserId); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 741 | |
| 742 | manager.onUseableChangedLocked(oldUserId); |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 743 | manager.onUseableChangedLocked(newUserId); |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 744 | } |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 747 | /** |
| 748 | * Location provider manager, manages a LocationProvider. |
| 749 | */ |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 750 | class LocationProviderManager implements MockableLocationProvider.Listener { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 751 | |
| 752 | private final String mName; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 753 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 754 | // acquiring mLock makes operations on mProvider atomic, but is otherwise unnecessary |
| 755 | protected final MockableLocationProvider mProvider; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 756 | |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 757 | // useable state for parent user ids, no entry implies false. location state is only kept |
| 758 | // for parent user ids, the location state for a profile user id is assumed to be the same |
| 759 | // as for the parent. if querying this structure, ensure that the user id being used is a |
| 760 | // parent id or the results may be incorrect. |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 761 | @GuardedBy("mLock") |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 762 | private final SparseArray<Boolean> mUseable; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 763 | |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 764 | private LocationProviderManager(String name) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 765 | mName = name; |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 766 | mUseable = new SparseArray<>(1); |
Soonil Nagarkar | 42da1b1 | 2019-01-22 11:29:27 -0800 | [diff] [blame] | 767 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 768 | // initialize last since this lets our reference escape |
| 769 | mProvider = new MockableLocationProvider(mContext, mLock, this); |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 770 | |
| 771 | // we can assume all users start with unuseable location state since the initial state |
| 772 | // of all providers is disabled. no need to initialize mUseable further. |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 775 | public String getName() { |
| 776 | return mName; |
| 777 | } |
| 778 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 779 | public boolean hasProvider() { |
| 780 | return mProvider.getProvider() != null; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 783 | public void setRealProvider(AbstractLocationProvider provider) { |
| 784 | mProvider.setRealProvider(provider); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 787 | public void setMockProvider(@Nullable MockProvider provider) { |
| 788 | mProvider.setMockProvider(provider); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 789 | } |
| 790 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 791 | public Set<String> getPackages() { |
| 792 | return mProvider.getState().providerPackageNames; |
| 793 | } |
| 794 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 795 | @Nullable |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 796 | public ProviderProperties getProperties() { |
| 797 | return mProvider.getState().properties; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 800 | public void setMockProviderEnabled(boolean enabled) { |
| 801 | synchronized (mLock) { |
| 802 | if (!mProvider.isMock()) { |
| 803 | throw new IllegalArgumentException(mName + " provider is not a test provider"); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 804 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 805 | |
| 806 | mProvider.setMockProviderEnabled(enabled); |
| 807 | } |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 810 | public void setMockProviderLocation(Location location) { |
| 811 | synchronized (mLock) { |
| 812 | if (!mProvider.isMock()) { |
| 813 | throw new IllegalArgumentException(mName + " provider is not a test provider"); |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 814 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 815 | |
| 816 | String locationProvider = location.getProvider(); |
| 817 | if (!TextUtils.isEmpty(locationProvider) && !mName.equals(locationProvider)) { |
| 818 | // The location has an explicit provider that is different from the mock |
| 819 | // provider name. The caller may be trying to fool us via b/33091107. |
| 820 | EventLog.writeEvent(0x534e4554, "33091107", Binder.getCallingUid(), |
| 821 | mName + "!=" + locationProvider); |
| 822 | } |
| 823 | |
| 824 | mProvider.setMockProviderLocation(location); |
| 825 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 828 | public List<LocationRequest> getMockProviderRequests() { |
| 829 | synchronized (mLock) { |
| 830 | if (!mProvider.isMock()) { |
| 831 | throw new IllegalArgumentException(mName + " provider is not a test provider"); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 832 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 833 | |
| 834 | return mProvider.getCurrentRequest().locationRequests; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 835 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | public void setRequest(ProviderRequest request) { |
| 839 | mProvider.setRequest(request); |
| 840 | } |
| 841 | |
| 842 | public void sendExtraCommand(int uid, int pid, String command, Bundle extras) { |
| 843 | mProvider.sendExtraCommand(uid, pid, command, extras); |
| 844 | } |
| 845 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 846 | @GuardedBy("mLock") |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 847 | @Override |
| 848 | public void onReportLocation(Location location) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 849 | // don't validate mock locations |
| 850 | if (!location.isFromMockProvider()) { |
| 851 | if (location.getLatitude() == 0 && location.getLongitude() == 0) { |
| 852 | Slog.w(TAG, "blocking 0,0 location from " + mName + " provider"); |
| 853 | return; |
| 854 | } |
Soonil Nagarkar | 7fc24c6 | 2019-10-18 17:32:38 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 857 | handleLocationChangedLocked(location, this); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 860 | @GuardedBy("mLock") |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 861 | @Override |
| 862 | public void onReportLocation(List<Location> locations) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 863 | if (mGnssManagerService == null) { |
| 864 | return; |
| 865 | } |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 866 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 867 | if (!GPS_PROVIDER.equals(mName) || !isUseable()) { |
| 868 | Slog.w(TAG, "reportLocationBatch() called without user permission"); |
| 869 | return; |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 870 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 871 | |
| 872 | mGnssManagerService.onReportLocation(locations); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 875 | @GuardedBy("mLock") |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 876 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 877 | public void onStateChanged(State oldState, State newState) { |
| 878 | if (oldState.enabled != newState.enabled) { |
| 879 | // it would be more correct to call this for all users, but we know this can |
| 880 | // only affect the current user since providers are disabled for non-current |
| 881 | // users |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 882 | onUseableChangedLocked(mUserInfoStore.getCurrentUserId()); |
Soonil Nagarkar | d334f7b | 2019-07-08 16:16:19 -0700 | [diff] [blame] | 883 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 886 | public boolean isUseable() { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 887 | return isUseable(mUserInfoStore.getCurrentUserId()); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 888 | } |
| 889 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 890 | public boolean isUseable(int userId) { |
Soonil Nagarkar | 66c0bac | 2019-01-15 13:36:44 -0800 | [diff] [blame] | 891 | synchronized (mLock) { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 892 | // normalize user id to always refer to parent since profile state is always the |
| 893 | // same as parent state |
| 894 | userId = mUserInfoStore.getParentUserId(userId); |
| 895 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 896 | return mUseable.get(userId, Boolean.FALSE); |
Soonil Nagarkar | 66c0bac | 2019-01-15 13:36:44 -0800 | [diff] [blame] | 897 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 898 | } |
| 899 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 900 | @GuardedBy("mLock") |
Soonil Nagarkar | 57f4b7b | 2019-12-09 10:19:18 -0800 | [diff] [blame] | 901 | public void onUseableChangedLocked(int userId) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 902 | if (userId == UserHandle.USER_NULL) { |
| 903 | // only used during initialization - we don't care about the null user |
| 904 | return; |
| 905 | } |
| 906 | |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 907 | // normalize user id to always refer to parent since profile state is always the same |
| 908 | // as parent state |
| 909 | userId = mUserInfoStore.getParentUserId(userId); |
| 910 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 911 | // if any property that contributes to "useability" here changes state, it MUST result |
| 912 | // in a direct or indrect call to onUseableChangedLocked. this allows the provider to |
| 913 | // guarantee that it will always eventually reach the correct state. |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 914 | boolean useable = (userId == mUserInfoStore.getCurrentUserId()) |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 915 | && mSettingsStore.isLocationEnabled(userId) && mProvider.getState().enabled; |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 916 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 917 | if (useable == isUseable(userId)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 918 | return; |
| 919 | } |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 920 | |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 921 | mUseable.put(userId, useable); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 922 | |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 923 | if (D) { |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 924 | Log.d(TAG, "[u" + userId + "] " + mName + " provider useable = " + useable); |
Soonil Nagarkar | 4ee3ac2 | 2019-02-08 19:19:24 -0800 | [diff] [blame] | 925 | } |
| 926 | |
Soonil Nagarkar | 57f4b7b | 2019-12-09 10:19:18 -0800 | [diff] [blame] | 927 | // fused and passive provider never get public updates for legacy reasons |
| 928 | if (!FUSED_PROVIDER.equals(mName) && !PASSIVE_PROVIDER.equals(mName)) { |
| 929 | // update LOCATION_PROVIDERS_ALLOWED for best effort backwards compatibility |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 930 | mSettingsStore.setLocationProviderAllowed(mName, useable, userId); |
Soonil Nagarkar | 57f4b7b | 2019-12-09 10:19:18 -0800 | [diff] [blame] | 931 | |
| 932 | Intent intent = new Intent(LocationManager.PROVIDERS_CHANGED_ACTION); |
| 933 | intent.putExtra(LocationManager.EXTRA_PROVIDER_NAME, mName); |
| 934 | intent.putExtra(LocationManager.EXTRA_PROVIDER_ENABLED, useable); |
| 935 | mContext.sendBroadcastAsUser(intent, UserHandle.of(userId)); |
| 936 | } |
| 937 | |
Soonil Nagarkar | 06e37f6 | 2019-12-04 16:05:08 -0800 | [diff] [blame] | 938 | if (!useable) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 939 | // If any provider has been disabled, clear all last locations for all |
| 940 | // providers. This is to be on the safe side in case a provider has location |
| 941 | // derived from this disabled provider. |
| 942 | mLastLocation.clear(); |
| 943 | mLastLocationCoarseInterval.clear(); |
| 944 | } |
| 945 | |
| 946 | updateProviderUseableLocked(this); |
| 947 | } |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 948 | |
| 949 | public void dump(FileDescriptor fd, IndentingPrintWriter pw, String[] args) { |
| 950 | synchronized (mLock) { |
| 951 | pw.print(mName + " provider"); |
| 952 | if (mProvider.isMock()) { |
| 953 | pw.print(" [mock]"); |
| 954 | } |
| 955 | pw.println(":"); |
| 956 | |
| 957 | pw.increaseIndent(); |
| 958 | |
| 959 | boolean useable = isUseable(); |
| 960 | pw.println("useable=" + useable); |
| 961 | if (!useable) { |
| 962 | pw.println("enabled=" + mProvider.getState().enabled); |
| 963 | } |
| 964 | |
| 965 | pw.println("properties=" + mProvider.getState().properties); |
| 966 | } |
| 967 | |
| 968 | mProvider.dump(fd, pw, args); |
| 969 | |
| 970 | pw.decreaseIndent(); |
| 971 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 972 | } |
| 973 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 974 | class PassiveLocationProviderManager extends LocationProviderManager { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 975 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 976 | private PassiveLocationProviderManager() { |
| 977 | super(PASSIVE_PROVIDER); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 981 | public void setRealProvider(AbstractLocationProvider provider) { |
| 982 | Preconditions.checkArgument(provider instanceof PassiveProvider); |
| 983 | super.setRealProvider(provider); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 984 | } |
| 985 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 986 | @Override |
| 987 | public void setMockProvider(@Nullable MockProvider provider) { |
| 988 | if (provider != null) { |
| 989 | throw new IllegalArgumentException("Cannot mock the passive provider"); |
| 990 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 993 | public void updateLocation(Location location) { |
| 994 | synchronized (mLock) { |
| 995 | PassiveProvider passiveProvider = (PassiveProvider) mProvider.getProvider(); |
| 996 | Preconditions.checkState(passiveProvider != null); |
| 997 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 998 | long identity = Binder.clearCallingIdentity(); |
| 999 | try { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1000 | passiveProvider.updateLocation(location); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1001 | } finally { |
| 1002 | Binder.restoreCallingIdentity(identity); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 1008 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | * A wrapper class holding either an ILocationListener or a PendingIntent to receive |
| 1010 | * location updates. |
| 1011 | */ |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1012 | private final class Receiver extends LocationManagerServiceUtils.LinkedListenerBase implements |
| 1013 | PendingIntent.OnFinished { |
Yu-Han Yang | 2418982 | 2018-07-11 15:24:11 -0700 | [diff] [blame] | 1014 | private static final long WAKELOCK_TIMEOUT_MILLIS = 60 * 1000; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1015 | private final int mAllowedResolutionLevel; // resolution level allowed to receiver |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1016 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1017 | private final ILocationListener mListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | final PendingIntent mPendingIntent; |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1019 | final WorkSource mWorkSource; // WorkSource for battery blame, or null to assign to caller. |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1020 | private final boolean mHideFromAppOps; // True if AppOps should not monitor this receiver. |
| 1021 | private final Object mKey; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1022 | |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1023 | final HashMap<String, UpdateRecord> mUpdateRecords = new HashMap<>(); |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 1024 | |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1025 | // True if app ops has started monitoring this receiver for locations. |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1026 | private boolean mOpMonitoring; |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1027 | // True if app ops has started monitoring this receiver for high power (gps) locations. |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1028 | private boolean mOpHighPowerMonitoring; |
| 1029 | private int mPendingBroadcasts; |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 1030 | PowerManager.WakeLock mWakeLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1032 | private Receiver(ILocationListener listener, PendingIntent intent, int pid, int uid, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1033 | String packageName, @Nullable String featureId, WorkSource workSource, |
| 1034 | boolean hideFromAppOps, @NonNull String listenerIdentifier) { |
| 1035 | super(new CallerIdentity(uid, pid, packageName, featureId, listenerIdentifier), |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1036 | "LocationListener"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | mListener = listener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | mPendingIntent = intent; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1039 | if (listener != null) { |
| 1040 | mKey = listener.asBinder(); |
| 1041 | } else { |
| 1042 | mKey = intent; |
| 1043 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1044 | mAllowedResolutionLevel = getAllowedResolutionLevel(pid, uid); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1045 | if (workSource != null && workSource.isEmpty()) { |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1046 | workSource = null; |
| 1047 | } |
| 1048 | mWorkSource = workSource; |
David Christie | 40e5782 | 2013-07-30 11:36:48 -0700 | [diff] [blame] | 1049 | mHideFromAppOps = hideFromAppOps; |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 1050 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1051 | updateMonitoring(true); |
| 1052 | |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 1053 | // construct/configure wakelock |
| 1054 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1055 | if (workSource == null) { |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1056 | workSource = new WorkSource(mCallerIdentity.mUid, mCallerIdentity.mPackageName); |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1057 | } |
| 1058 | mWakeLock.setWorkSource(workSource); |
Yu-Han Yang | 2418982 | 2018-07-11 15:24:11 -0700 | [diff] [blame] | 1059 | |
| 1060 | // For a non-reference counted wakelock, each acquire will reset the timeout, and we |
| 1061 | // only need to release it once. |
| 1062 | mWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | @Override |
| 1066 | public boolean equals(Object otherObj) { |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1067 | return (otherObj instanceof Receiver) && mKey.equals(((Receiver) otherObj).mKey); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | @Override |
| 1071 | public int hashCode() { |
| 1072 | return mKey.hashCode(); |
| 1073 | } |
Mike Lockwood | 3681f26 | 2009-05-12 10:52:03 -0400 | [diff] [blame] | 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | @Override |
| 1076 | public String toString() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1077 | StringBuilder s = new StringBuilder(); |
| 1078 | s.append("Reciever["); |
| 1079 | s.append(Integer.toHexString(System.identityHashCode(this))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | if (mListener != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1081 | s.append(" listener"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | } else { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1083 | s.append(" intent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1085 | for (String p : mUpdateRecords.keySet()) { |
| 1086 | s.append(" ").append(mUpdateRecords.get(p).toString()); |
| 1087 | } |
Wei Wang | dd070f2 | 2018-06-21 11:29:40 -0700 | [diff] [blame] | 1088 | s.append(" monitoring location: ").append(mOpMonitoring); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1089 | s.append("]"); |
| 1090 | return s.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | } |
| 1092 | |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1093 | /** |
| 1094 | * Update AppOp monitoring for this receiver. |
| 1095 | * |
| 1096 | * @param allow If true receiver is currently active, if false it's been removed. |
| 1097 | */ |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1098 | public void updateMonitoring(boolean allow) { |
David Christie | 40e5782 | 2013-07-30 11:36:48 -0700 | [diff] [blame] | 1099 | if (mHideFromAppOps) { |
| 1100 | return; |
| 1101 | } |
| 1102 | |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1103 | boolean requestingLocation = false; |
| 1104 | boolean requestingHighPowerLocation = false; |
| 1105 | if (allow) { |
| 1106 | // See if receiver has any enabled update records. Also note if any update records |
| 1107 | // are high power (has a high power provider with an interval under a threshold). |
| 1108 | for (UpdateRecord updateRecord : mUpdateRecords.values()) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1109 | LocationProviderManager manager = getLocationProviderManager( |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 1110 | updateRecord.mProvider); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1111 | if (manager == null) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1112 | continue; |
| 1113 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1114 | if (!manager.isUseable() && !isSettingsExemptLocked(updateRecord)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1115 | continue; |
| 1116 | } |
| 1117 | |
| 1118 | requestingLocation = true; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1119 | ProviderProperties properties = manager.getProperties(); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1120 | if (properties != null |
| 1121 | && properties.mPowerRequirement == Criteria.POWER_HIGH |
| 1122 | && updateRecord.mRequest.getInterval() < HIGH_POWER_INTERVAL_MS) { |
| 1123 | requestingHighPowerLocation = true; |
| 1124 | break; |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | } |
| 1128 | |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1129 | // First update monitoring of any location request (including high power). |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1130 | mOpMonitoring = updateMonitoring( |
| 1131 | requestingLocation, |
| 1132 | mOpMonitoring, |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1133 | AppOpsManager.OP_MONITOR_LOCATION); |
| 1134 | |
| 1135 | // Now update monitoring of high power requests only. |
David Christie | c750c1f | 2013-08-08 12:56:57 -0700 | [diff] [blame] | 1136 | boolean wasHighPowerMonitoring = mOpHighPowerMonitoring; |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1137 | mOpHighPowerMonitoring = updateMonitoring( |
| 1138 | requestingHighPowerLocation, |
| 1139 | mOpHighPowerMonitoring, |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1140 | AppOpsManager.OP_MONITOR_HIGH_POWER_LOCATION); |
David Christie | c750c1f | 2013-08-08 12:56:57 -0700 | [diff] [blame] | 1141 | if (mOpHighPowerMonitoring != wasHighPowerMonitoring) { |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1142 | // Send an intent to notify that a high power request has been added/removed. |
David Christie | c750c1f | 2013-08-08 12:56:57 -0700 | [diff] [blame] | 1143 | Intent intent = new Intent(LocationManager.HIGH_POWER_REQUEST_CHANGE_ACTION); |
| 1144 | mContext.sendBroadcastAsUser(intent, UserHandle.ALL); |
| 1145 | } |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | /** |
| 1149 | * Update AppOps monitoring for a single location request and op type. |
| 1150 | * |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1151 | * @param allowMonitoring True if monitoring is allowed for this request/op. |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1152 | * @param currentlyMonitoring True if AppOps is currently monitoring this request/op. |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1153 | * @param op AppOps code for the op to update. |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1154 | * @return True if monitoring is on for this request/op after updating. |
| 1155 | */ |
| 1156 | private boolean updateMonitoring(boolean allowMonitoring, boolean currentlyMonitoring, |
| 1157 | int op) { |
| 1158 | if (!currentlyMonitoring) { |
| 1159 | if (allowMonitoring) { |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1160 | return mAppOps.startOpNoThrow(op, mCallerIdentity.mUid, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1161 | mCallerIdentity.mPackageName, false, mCallerIdentity.mFeatureId, null) |
| 1162 | == AppOpsManager.MODE_ALLOWED; |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1163 | } |
| 1164 | } else { |
Soonil Nagarkar | 681d711 | 2017-02-23 17:14:16 -0800 | [diff] [blame] | 1165 | if (!allowMonitoring |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 1166 | || mAppOps.checkOpNoThrow(op, mCallerIdentity.mUid, |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1167 | mCallerIdentity.mPackageName) != AppOpsManager.MODE_ALLOWED) { |
| 1168 | mAppOps.finishOp(op, mCallerIdentity.mUid, mCallerIdentity.mPackageName); |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 1169 | return false; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | return currentlyMonitoring; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | public boolean isListener() { |
| 1177 | return mListener != null; |
| 1178 | } |
| 1179 | |
| 1180 | public boolean isPendingIntent() { |
| 1181 | return mPendingIntent != null; |
| 1182 | } |
| 1183 | |
| 1184 | public ILocationListener getListener() { |
| 1185 | if (mListener != null) { |
| 1186 | return mListener; |
| 1187 | } |
| 1188 | throw new IllegalStateException("Request for non-existent listener"); |
| 1189 | } |
| 1190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | public boolean callLocationChangedLocked(Location location) { |
| 1192 | if (mListener != null) { |
| 1193 | try { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1194 | mListener.onLocationChanged(new Location(location)); |
| 1195 | // call this after broadcasting so we do not increment |
| 1196 | // if we throw an exception. |
| 1197 | incrementPendingBroadcastsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | } catch (RemoteException e) { |
| 1199 | return false; |
| 1200 | } |
| 1201 | } else { |
| 1202 | Intent locationChanged = new Intent(); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1203 | locationChanged.putExtra(LocationManager.KEY_LOCATION_CHANGED, |
| 1204 | new Location(location)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | try { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1206 | mPendingIntent.send(mContext, 0, locationChanged, this, mHandler, |
| 1207 | getResolutionPermission(mAllowedResolutionLevel), |
| 1208 | PendingIntentUtils.createDontSendToRestrictedAppsBundle(null)); |
| 1209 | // call this after broadcasting so we do not increment |
| 1210 | // if we throw an exception. |
| 1211 | incrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1212 | } catch (PendingIntent.CanceledException e) { |
| 1213 | return false; |
| 1214 | } |
| 1215 | } |
| 1216 | return true; |
| 1217 | } |
| 1218 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1219 | private boolean callProviderEnabledLocked(String provider, boolean enabled) { |
David Christie | 15b3191 | 2013-08-13 15:54:32 -0700 | [diff] [blame] | 1220 | // First update AppOp monitoring. |
| 1221 | // An app may get/lose location access as providers are enabled/disabled. |
| 1222 | updateMonitoring(true); |
| 1223 | |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1224 | if (mListener != null) { |
| 1225 | try { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1226 | if (enabled) { |
| 1227 | mListener.onProviderEnabled(provider); |
| 1228 | } else { |
| 1229 | mListener.onProviderDisabled(provider); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1230 | } |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1231 | // call this after broadcasting so we do not increment |
| 1232 | // if we throw an exception. |
| 1233 | incrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1234 | } catch (RemoteException e) { |
| 1235 | return false; |
| 1236 | } |
| 1237 | } else { |
| 1238 | Intent providerIntent = new Intent(); |
| 1239 | providerIntent.putExtra(LocationManager.KEY_PROVIDER_ENABLED, enabled); |
| 1240 | try { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1241 | mPendingIntent.send(mContext, 0, providerIntent, this, mHandler, |
| 1242 | getResolutionPermission(mAllowedResolutionLevel), |
| 1243 | PendingIntentUtils.createDontSendToRestrictedAppsBundle(null)); |
| 1244 | // call this after broadcasting so we do not increment |
| 1245 | // if we throw an exception. |
| 1246 | incrementPendingBroadcastsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | } catch (PendingIntent.CanceledException e) { |
| 1248 | return false; |
| 1249 | } |
| 1250 | } |
| 1251 | return true; |
| 1252 | } |
| 1253 | |
Soonil Nagarkar | 39d614a | 2019-10-31 12:10:31 -0700 | [diff] [blame] | 1254 | public void callRemovedLocked() { |
| 1255 | if (mListener != null) { |
| 1256 | try { |
| 1257 | mListener.onRemoved(); |
| 1258 | } catch (RemoteException e) { |
| 1259 | // doesn't matter |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 1264 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | public void binderDied() { |
Anil Admal | 98d49b7 | 2019-02-06 15:26:33 -0800 | [diff] [blame] | 1266 | if (D) Log.d(TAG, "Remote " + mListenerName + " died."); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1267 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1268 | synchronized (mLock) { |
| 1269 | removeUpdatesLocked(this); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1270 | clearPendingBroadcastsLocked(); |
| 1271 | } |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1274 | @Override |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1275 | public void onSendFinished(PendingIntent pendingIntent, Intent intent, |
| 1276 | int resultCode, String resultData, Bundle resultExtras) { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1277 | synchronized (mLock) { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1278 | decrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1282 | // this must be called while synchronized by caller in a synchronized block |
| 1283 | // containing the sending of the broadcaset |
| 1284 | private void incrementPendingBroadcastsLocked() { |
Yu-Han Yang | 2418982 | 2018-07-11 15:24:11 -0700 | [diff] [blame] | 1285 | mPendingBroadcasts++; |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1286 | // so wakelock calls will succeed |
| 1287 | long identity = Binder.clearCallingIdentity(); |
| 1288 | try { |
| 1289 | mWakeLock.acquire(WAKELOCK_TIMEOUT_MILLIS); |
| 1290 | } finally { |
| 1291 | Binder.restoreCallingIdentity(identity); |
| 1292 | } |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | private void decrementPendingBroadcastsLocked() { |
| 1296 | if (--mPendingBroadcasts == 0) { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1297 | // so wakelock calls will succeed |
| 1298 | long identity = Binder.clearCallingIdentity(); |
| 1299 | try { |
| 1300 | if (mWakeLock.isHeld()) { |
| 1301 | mWakeLock.release(); |
| 1302 | } |
| 1303 | } finally { |
| 1304 | Binder.restoreCallingIdentity(identity); |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | public void clearPendingBroadcastsLocked() { |
| 1310 | if (mPendingBroadcasts > 0) { |
| 1311 | mPendingBroadcasts = 0; |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1312 | // so wakelock calls will succeed |
| 1313 | long identity = Binder.clearCallingIdentity(); |
| 1314 | try { |
| 1315 | if (mWakeLock.isHeld()) { |
| 1316 | mWakeLock.release(); |
| 1317 | } |
| 1318 | } finally { |
| 1319 | Binder.restoreCallingIdentity(identity); |
Victoria Lease | 0aa2860 | 2013-05-29 15:28:26 -0700 | [diff] [blame] | 1320 | } |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1325 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1326 | public void locationCallbackFinished(ILocationListener listener) { |
Dianne Hackborn | f5fdca9 | 2013-06-05 14:53:33 -0700 | [diff] [blame] | 1327 | //Do not use getReceiverLocked here as that will add the ILocationListener to |
Joshua Bartel | 080b61b | 2009-10-05 12:44:46 -0400 | [diff] [blame] | 1328 | //the receiver list if it is not found. If it is not found then the |
| 1329 | //LocationListener was removed when it had a pending broadcast and should |
| 1330 | //not be added back. |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1331 | synchronized (mLock) { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1332 | Receiver receiver = mReceivers.get(listener.asBinder()); |
Dianne Hackborn | f5fdca9 | 2013-06-05 14:53:33 -0700 | [diff] [blame] | 1333 | if (receiver != null) { |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1334 | receiver.decrementPendingBroadcastsLocked(); |
Dianne Hackborn | f5fdca9 | 2013-06-05 14:53:33 -0700 | [diff] [blame] | 1335 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1336 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | } |
| 1338 | |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1339 | @Override |
Lifu Tang | 9363b94 | 2016-02-16 18:07:00 -0800 | [diff] [blame] | 1340 | public int getGnssYearOfHardware() { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1341 | return mGnssManagerService == null ? 0 : mGnssManagerService.getGnssYearOfHardware(); |
Lifu Tang | 82f893d | 2016-01-21 18:15:33 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1344 | @Override |
Wyatt Riley | 49097c0 | 2018-03-15 09:14:43 -0700 | [diff] [blame] | 1345 | @Nullable |
Wyatt Riley | d87cf91 | 2017-12-05 09:31:52 -0800 | [diff] [blame] | 1346 | public String getGnssHardwareModelName() { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1347 | return mGnssManagerService == null ? "" : mGnssManagerService.getGnssHardwareModelName(); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1350 | @Override |
| 1351 | public int getGnssBatchSize(String packageName) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1352 | return mGnssManagerService == null ? 0 : mGnssManagerService.getGnssBatchSize(packageName); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1355 | @Override |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1356 | public boolean addGnssBatchingCallback(IBatchedLocationCallback callback, String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1357 | String featureId, String listenerIdentifier) { |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 1358 | Objects.requireNonNull(listenerIdentifier); |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1359 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1360 | return mGnssManagerService != null && mGnssManagerService.addGnssBatchingCallback( |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1361 | callback, packageName, featureId, listenerIdentifier); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1364 | @Override |
| 1365 | public void removeGnssBatchingCallback() { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1366 | if (mGnssManagerService != null) mGnssManagerService.removeGnssBatchingCallback(); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1367 | } |
| 1368 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1369 | @Override |
| 1370 | public boolean startGnssBatch(long periodNanos, boolean wakeOnFifoFull, String packageName) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1371 | return mGnssManagerService != null && mGnssManagerService.startGnssBatch(periodNanos, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1372 | wakeOnFifoFull, packageName); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1373 | } |
| 1374 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1375 | @Override |
| 1376 | public void flushGnssBatch(String packageName) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1377 | if (mGnssManagerService != null) mGnssManagerService.flushGnssBatch(packageName); |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Wyatt Riley | cf879db | 2017-01-12 13:57:38 -0800 | [diff] [blame] | 1380 | @Override |
| 1381 | public boolean stopGnssBatch() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1382 | return mGnssManagerService != null && mGnssManagerService.stopGnssBatch(); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1383 | } |
| 1384 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1385 | @Nullable |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1386 | private LocationProviderManager getLocationProviderManager(String providerName) { |
| 1387 | for (LocationProviderManager manager : mProviderManagers) { |
| 1388 | if (providerName.equals(manager.getName())) { |
| 1389 | return manager; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1390 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1393 | return null; |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1396 | private String getResolutionPermission(int resolutionLevel) { |
| 1397 | switch (resolutionLevel) { |
| 1398 | case RESOLUTION_LEVEL_FINE: |
| 1399 | return android.Manifest.permission.ACCESS_FINE_LOCATION; |
| 1400 | case RESOLUTION_LEVEL_COARSE: |
| 1401 | return android.Manifest.permission.ACCESS_COARSE_LOCATION; |
| 1402 | default: |
| 1403 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | } |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 1405 | } |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1406 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1407 | private int getAllowedResolutionLevel(int pid, int uid) { |
| 1408 | if (mContext.checkPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 1409 | pid, uid) == PERMISSION_GRANTED) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1410 | return RESOLUTION_LEVEL_FINE; |
| 1411 | } else if (mContext.checkPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION, |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 1412 | pid, uid) == PERMISSION_GRANTED) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1413 | return RESOLUTION_LEVEL_COARSE; |
| 1414 | } else { |
| 1415 | return RESOLUTION_LEVEL_NONE; |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 1416 | } |
Victoria Lease | 4fab68b | 2012-09-13 13:20:59 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1419 | private int getCallerAllowedResolutionLevel() { |
| 1420 | return getAllowedResolutionLevel(Binder.getCallingPid(), Binder.getCallingUid()); |
| 1421 | } |
| 1422 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1423 | private void checkResolutionLevelIsSufficientForGeofenceUse(int allowedResolutionLevel) { |
| 1424 | if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
Victoria Lease | 4fab68b | 2012-09-13 13:20:59 -0700 | [diff] [blame] | 1425 | throw new SecurityException("Geofence usage requires ACCESS_FINE_LOCATION permission"); |
| 1426 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | } |
| 1428 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1429 | @GuardedBy("mLock") |
| 1430 | private int getMinimumResolutionLevelForProviderUseLocked(String provider) { |
| 1431 | if (GPS_PROVIDER.equals(provider) || PASSIVE_PROVIDER.equals(provider)) { |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 1432 | // gps and passive providers require FINE permission |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1433 | return RESOLUTION_LEVEL_FINE; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1434 | } else if (NETWORK_PROVIDER.equals(provider) || FUSED_PROVIDER.equals(provider)) { |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 1435 | // network and fused providers are ok with COARSE or FINE |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1436 | return RESOLUTION_LEVEL_COARSE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 1437 | } else { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1438 | for (LocationProviderManager lp : mProviderManagers) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1439 | if (!lp.getName().equals(provider)) { |
| 1440 | continue; |
| 1441 | } |
| 1442 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1443 | ProviderProperties properties = lp.getProperties(); |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 1444 | if (properties != null) { |
| 1445 | if (properties.mRequiresSatellite) { |
| 1446 | // provider requiring satellites require FINE permission |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1447 | return RESOLUTION_LEVEL_FINE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 1448 | } else if (properties.mRequiresNetwork || properties.mRequiresCell) { |
| 1449 | // provider requiring network and or cell require COARSE or FINE |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1450 | return RESOLUTION_LEVEL_COARSE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | } |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 1454 | } |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1455 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1456 | return RESOLUTION_LEVEL_FINE; // if in doubt, require FINE |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1459 | @GuardedBy("mLock") |
| 1460 | private void checkResolutionLevelIsSufficientForProviderUseLocked(int allowedResolutionLevel, |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1461 | String providerName) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1462 | int requiredResolutionLevel = getMinimumResolutionLevelForProviderUseLocked(providerName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1463 | if (allowedResolutionLevel < requiredResolutionLevel) { |
| 1464 | switch (requiredResolutionLevel) { |
| 1465 | case RESOLUTION_LEVEL_FINE: |
| 1466 | throw new SecurityException("\"" + providerName + "\" location provider " + |
| 1467 | "requires ACCESS_FINE_LOCATION permission."); |
| 1468 | case RESOLUTION_LEVEL_COARSE: |
| 1469 | throw new SecurityException("\"" + providerName + "\" location provider " + |
| 1470 | "requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission."); |
| 1471 | default: |
| 1472 | throw new SecurityException("Insufficient permission for \"" + providerName + |
| 1473 | "\" location provider."); |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 1474 | } |
| 1475 | } |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1478 | public static int resolutionLevelToOp(int allowedResolutionLevel) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1479 | if (allowedResolutionLevel != RESOLUTION_LEVEL_NONE) { |
| 1480 | if (allowedResolutionLevel == RESOLUTION_LEVEL_COARSE) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1481 | return AppOpsManager.OP_COARSE_LOCATION; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1482 | } else { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1483 | return AppOpsManager.OP_FINE_LOCATION; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1484 | } |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1485 | } |
| 1486 | return -1; |
| 1487 | } |
| 1488 | |
Wei Wang | b86334f | 2018-07-03 16:33:24 -0700 | [diff] [blame] | 1489 | private static String resolutionLevelToOpStr(int allowedResolutionLevel) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1490 | switch (allowedResolutionLevel) { |
Wei Wang | b86334f | 2018-07-03 16:33:24 -0700 | [diff] [blame] | 1491 | case RESOLUTION_LEVEL_COARSE: |
| 1492 | return AppOpsManager.OPSTR_COARSE_LOCATION; |
| 1493 | case RESOLUTION_LEVEL_FINE: |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1494 | // fall through |
Wei Wang | b86334f | 2018-07-03 16:33:24 -0700 | [diff] [blame] | 1495 | case RESOLUTION_LEVEL_NONE: |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1496 | // fall through |
Wei Wang | b86334f | 2018-07-03 16:33:24 -0700 | [diff] [blame] | 1497 | default: |
| 1498 | // Use the most restrictive ops if not sure. |
| 1499 | return AppOpsManager.OPSTR_FINE_LOCATION; |
| 1500 | } |
| 1501 | } |
| 1502 | |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1503 | private boolean reportLocationAccessNoThrow(int pid, int uid, String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1504 | @Nullable String featureId, int allowedResolutionLevel, @Nullable String message) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1505 | int op = resolutionLevelToOp(allowedResolutionLevel); |
| 1506 | if (op >= 0) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1507 | if (mAppOps.noteOpNoThrow(op, uid, packageName, featureId, message) |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1508 | != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1509 | return false; |
| 1510 | } |
| 1511 | } |
David Christie | b870dbf | 2015-06-22 12:42:53 -0700 | [diff] [blame] | 1512 | |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1513 | return getAllowedResolutionLevel(pid, uid) >= allowedResolutionLevel; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1514 | } |
| 1515 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1516 | private boolean checkLocationAccess(int pid, int uid, String packageName, |
| 1517 | int allowedResolutionLevel) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1518 | int op = resolutionLevelToOp(allowedResolutionLevel); |
| 1519 | if (op >= 0) { |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 1520 | if (mAppOps.checkOp(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1521 | return false; |
| 1522 | } |
| 1523 | } |
David Christie | b870dbf | 2015-06-22 12:42:53 -0700 | [diff] [blame] | 1524 | |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1525 | return getAllowedResolutionLevel(pid, uid) >= allowedResolutionLevel; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1528 | /** |
Maggie | 91e630c | 2018-01-24 17:31:46 -0800 | [diff] [blame] | 1529 | * Returns all providers by name, including passive and the ones that are not permitted to |
| 1530 | * be accessed by the calling activity or are currently disabled, but excluding fused. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1531 | */ |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1532 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | public List<String> getAllProviders() { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1534 | ArrayList<String> providers = new ArrayList<>(mProviderManagers.size()); |
| 1535 | for (LocationProviderManager manager : mProviderManagers) { |
| 1536 | if (FUSED_PROVIDER.equals(manager.getName())) { |
| 1537 | continue; |
Maggie | 91e630c | 2018-01-24 17:31:46 -0800 | [diff] [blame] | 1538 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1539 | providers.add(manager.getName()); |
Maggie | 91e630c | 2018-01-24 17:31:46 -0800 | [diff] [blame] | 1540 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1541 | return providers; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | } |
| 1543 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1544 | /** |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1545 | * Return all providers by name, that match criteria and are optionally |
| 1546 | * enabled. |
| 1547 | * Can return passive provider, but never returns fused provider. |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1548 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1549 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1550 | public List<String> getProviders(Criteria criteria, boolean enabledOnly) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1551 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1552 | synchronized (mLock) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1553 | ArrayList<String> providers = new ArrayList<>(mProviderManagers.size()); |
| 1554 | for (LocationProviderManager manager : mProviderManagers) { |
| 1555 | String name = manager.getName(); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1556 | if (FUSED_PROVIDER.equals(name)) { |
| 1557 | continue; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1558 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1559 | if (allowedResolutionLevel < getMinimumResolutionLevelForProviderUseLocked(name)) { |
| 1560 | continue; |
| 1561 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1562 | if (enabledOnly && !manager.isUseable()) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1563 | continue; |
| 1564 | } |
| 1565 | if (criteria != null |
| 1566 | && !android.location.LocationProvider.propertiesMeetCriteria( |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1567 | name, manager.getProperties(), criteria)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1568 | continue; |
| 1569 | } |
| 1570 | providers.add(name); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1571 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1572 | return providers; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1573 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /** |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1577 | * Return the name of the best provider given a Criteria object. |
| 1578 | * This method has been deprecated from the public API, |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 1579 | * and the whole LocationProvider (including #meetsCriteria) |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1580 | * has been deprecated as well. So this method now uses |
| 1581 | * some simplified logic. |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1582 | */ |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1583 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1584 | public String getBestProvider(Criteria criteria, boolean enabledOnly) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1585 | List<String> providers = getProviders(criteria, enabledOnly); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1586 | if (providers.isEmpty()) { |
| 1587 | providers = getProviders(null, enabledOnly); |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 1588 | } |
| 1589 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1590 | if (!providers.isEmpty()) { |
| 1591 | if (providers.contains(GPS_PROVIDER)) { |
| 1592 | return GPS_PROVIDER; |
| 1593 | } else if (providers.contains(NETWORK_PROVIDER)) { |
| 1594 | return NETWORK_PROVIDER; |
| 1595 | } else { |
| 1596 | return providers.get(0); |
| 1597 | } |
| 1598 | } |
| 1599 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1600 | return null; |
| 1601 | } |
| 1602 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1603 | @GuardedBy("mLock") |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1604 | private void updateProviderUseableLocked(LocationProviderManager manager) { |
| 1605 | boolean useable = manager.isUseable(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | ArrayList<Receiver> deadReceivers = null; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1608 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1609 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(manager.getName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1610 | if (records != null) { |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1611 | for (UpdateRecord record : records) { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 1612 | if (!mUserInfoStore.isCurrentUserOrProfile( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1613 | UserHandle.getUserId(record.mReceiver.mCallerIdentity.mUid))) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1614 | continue; |
| 1615 | } |
| 1616 | |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1617 | // requests that ignore location settings will never provide notifications |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 1618 | if (isSettingsExemptLocked(record)) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1619 | continue; |
| 1620 | } |
| 1621 | |
| 1622 | // Sends a notification message to the receiver |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1623 | if (!record.mReceiver.callProviderEnabledLocked(manager.getName(), useable)) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1624 | if (deadReceivers == null) { |
| 1625 | deadReceivers = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | } |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1627 | deadReceivers.add(record.mReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | if (deadReceivers != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1633 | for (int i = deadReceivers.size() - 1; i >= 0; i--) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1634 | removeUpdatesLocked(deadReceivers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | } |
| 1636 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1637 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1638 | applyRequirementsLocked(manager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1641 | @GuardedBy("mLock") |
| 1642 | private void applyRequirementsLocked(String providerName) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1643 | LocationProviderManager manager = getLocationProviderManager(providerName); |
| 1644 | if (manager != null) { |
| 1645 | applyRequirementsLocked(manager); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1646 | } |
| 1647 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1648 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1649 | @GuardedBy("mLock") |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1650 | private void applyRequirementsLocked(LocationProviderManager manager) { |
| 1651 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(manager.getName()); |
| 1652 | ProviderRequest.Builder providerRequest = new ProviderRequest.Builder(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1653 | |
Soonil Nagarkar | 04cff6c | 2019-03-19 11:29:52 -0700 | [diff] [blame] | 1654 | // if provider is not active, it should not respond to requests |
| 1655 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1656 | if (mProviderManagers.contains(manager) && records != null && !records.isEmpty()) { |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1657 | long backgroundThrottleInterval; |
| 1658 | |
| 1659 | long identity = Binder.clearCallingIdentity(); |
| 1660 | try { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 1661 | backgroundThrottleInterval = mSettingsStore.getBackgroundThrottleIntervalMs(); |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1662 | } finally { |
| 1663 | Binder.restoreCallingIdentity(identity); |
| 1664 | } |
| 1665 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1666 | ArrayList<LocationRequest> requests = new ArrayList<>(records.size()); |
| 1667 | |
Kweku Adams | 5e0052b | 2019-02-22 15:17:52 -0800 | [diff] [blame] | 1668 | final boolean isForegroundOnlyMode = |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 1669 | mBatterySaverMode == PowerManager.LOCATION_MODE_FOREGROUND_ONLY; |
| 1670 | final boolean shouldThrottleRequests = |
| 1671 | mBatterySaverMode |
| 1672 | == PowerManager.LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF |
| 1673 | && !mPowerManager.isInteractive(); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1674 | // initialize the low power mode to true and set to false if any of the records requires |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1675 | providerRequest.setLowPowerMode(true); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1676 | for (UpdateRecord record : records) { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 1677 | if (!mUserInfoStore.isCurrentUserOrProfile( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1678 | UserHandle.getUserId(record.mReceiver.mCallerIdentity.mUid))) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1679 | continue; |
| 1680 | } |
| 1681 | if (!checkLocationAccess( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1682 | record.mReceiver.mCallerIdentity.mPid, |
| 1683 | record.mReceiver.mCallerIdentity.mUid, |
| 1684 | record.mReceiver.mCallerIdentity.mPackageName, |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1685 | record.mReceiver.mAllowedResolutionLevel)) { |
| 1686 | continue; |
| 1687 | } |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 1688 | final boolean isBatterySaverDisablingLocation = shouldThrottleRequests |
| 1689 | || (isForegroundOnlyMode && !record.mIsForegroundUid); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1690 | if (!manager.isUseable() || isBatterySaverDisablingLocation) { |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1691 | if (isSettingsExemptLocked(record)) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1692 | providerRequest.setLocationSettingsIgnored(true); |
| 1693 | providerRequest.setLowPowerMode(false); |
Soonil Nagarkar | 35c3b91 | 2019-01-31 10:31:24 -0800 | [diff] [blame] | 1694 | } else { |
| 1695 | continue; |
| 1696 | } |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1697 | } |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1698 | |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1699 | LocationRequest locationRequest = record.mRealRequest; |
| 1700 | long interval = locationRequest.getInterval(); |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1701 | |
Soonil Nagarkar | 509580f | 2019-02-06 15:57:26 -0800 | [diff] [blame] | 1702 | |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1703 | // if we're forcing location, don't apply any throttling |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1704 | if (!providerRequest.isLocationSettingsIgnored() && !isThrottlingExemptLocked( |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1705 | record.mReceiver.mCallerIdentity)) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1706 | if (!record.mIsForegroundUid) { |
| 1707 | interval = Math.max(interval, backgroundThrottleInterval); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1708 | } |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1709 | if (interval != locationRequest.getInterval()) { |
| 1710 | locationRequest = new LocationRequest(locationRequest); |
| 1711 | locationRequest.setInterval(interval); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | record.mRequest = locationRequest; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1716 | requests.add(locationRequest); |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1717 | if (!locationRequest.isLowPowerMode()) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1718 | providerRequest.setLowPowerMode(false); |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 1719 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1720 | if (interval < providerRequest.getInterval()) { |
| 1721 | providerRequest.setInterval(interval); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1722 | } |
| 1723 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1724 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1725 | providerRequest.setLocationRequests(requests); |
| 1726 | |
| 1727 | if (providerRequest.getInterval() < Long.MAX_VALUE) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1728 | // calculate who to blame for power |
| 1729 | // This is somewhat arbitrary. We pick a threshold interval |
| 1730 | // that is slightly higher that the minimum interval, and |
| 1731 | // spread the blame across all applications with a request |
| 1732 | // under that threshold. |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1733 | // TODO: overflow |
| 1734 | long thresholdInterval = (providerRequest.getInterval() + 1000) * 3 / 2; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1735 | for (UpdateRecord record : records) { |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 1736 | if (mUserInfoStore.isCurrentUserOrProfile( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1737 | UserHandle.getUserId(record.mReceiver.mCallerIdentity.mUid))) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1738 | LocationRequest locationRequest = record.mRequest; |
Svet Ganov | e998c73 | 2016-06-10 00:12:38 -0700 | [diff] [blame] | 1739 | |
| 1740 | // Don't assign battery blame for update records whose |
| 1741 | // client has no permission to receive location data. |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1742 | if (!providerRequest.getLocationRequests().contains(locationRequest)) { |
Svet Ganov | e998c73 | 2016-06-10 00:12:38 -0700 | [diff] [blame] | 1743 | continue; |
| 1744 | } |
| 1745 | |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1746 | if (locationRequest.getInterval() <= thresholdInterval) { |
David Christie | e55c968 | 2013-08-22 10:10:34 -0700 | [diff] [blame] | 1747 | if (record.mReceiver.mWorkSource != null |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1748 | && isValidWorkSource(record.mReceiver.mWorkSource)) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1749 | providerRequest.getWorkSource().add(record.mReceiver.mWorkSource); |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1750 | } else { |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1751 | // Assign blame to caller if there's no WorkSource associated with |
| 1752 | // the request or if it's invalid. |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1753 | providerRequest.getWorkSource().add( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1754 | record.mReceiver.mCallerIdentity.mUid, |
| 1755 | record.mReceiver.mCallerIdentity.mPackageName); |
David Christie | 82edc9b | 2013-07-19 11:31:42 -0700 | [diff] [blame] | 1756 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1757 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1758 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1759 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1760 | } |
| 1761 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1762 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 1763 | manager.setRequest(providerRequest.build()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1764 | } |
| 1765 | |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1766 | /** |
| 1767 | * Whether a given {@code WorkSource} associated with a Location request is valid. |
| 1768 | */ |
| 1769 | private static boolean isValidWorkSource(WorkSource workSource) { |
| 1770 | if (workSource.size() > 0) { |
| 1771 | // If the WorkSource has one or more non-chained UIDs, make sure they're accompanied |
| 1772 | // by tags. |
Suprabh Shukla | f7cffa7 | 2019-11-08 17:03:03 -0800 | [diff] [blame] | 1773 | return workSource.getPackageName(0) != null; |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1774 | } else { |
| 1775 | // For now, make sure callers have supplied an attribution tag for use with |
| 1776 | // AppOpsManager. This might be relaxed in the future. |
Suprabh Shukla | f7cffa7 | 2019-11-08 17:03:03 -0800 | [diff] [blame] | 1777 | final List<WorkChain> workChains = workSource.getWorkChains(); |
Narayan Kamath | 32684dd | 2018-01-08 17:32:51 +0000 | [diff] [blame] | 1778 | return workChains != null && !workChains.isEmpty() && |
| 1779 | workChains.get(0).getAttributionTag() != null; |
| 1780 | } |
| 1781 | } |
| 1782 | |
Soonil Nagarkar | 681d711 | 2017-02-23 17:14:16 -0800 | [diff] [blame] | 1783 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1784 | public String[] getBackgroundThrottlingWhitelist() { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 1785 | return mSettingsStore.getBackgroundThrottlePackageWhitelist().toArray(new String[0]); |
Soonil Nagarkar | 681d711 | 2017-02-23 17:14:16 -0800 | [diff] [blame] | 1786 | } |
| 1787 | |
Soonil Nagarkar | 5140e4f | 2019-02-14 17:21:33 -0800 | [diff] [blame] | 1788 | @Override |
| 1789 | public String[] getIgnoreSettingsWhitelist() { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 1790 | return mSettingsStore.getIgnoreSettingsPackageWhitelist().toArray(new String[0]); |
Soonil Nagarkar | 5140e4f | 2019-02-14 17:21:33 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1793 | @GuardedBy("mLock") |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1794 | public boolean isThrottlingExemptLocked(CallerIdentity callerIdentity) { |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1795 | if (callerIdentity.mUid == Process.SYSTEM_UID) { |
Soonil Nagarkar | 2f1f7e8 | 2017-01-24 12:52:10 -0800 | [diff] [blame] | 1796 | return true; |
| 1797 | } |
| 1798 | |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 1799 | if (mSettingsStore.getBackgroundThrottlePackageWhitelist().contains( |
| 1800 | callerIdentity.mPackageName)) { |
Soonil Nagarkar | 2f1f7e8 | 2017-01-24 12:52:10 -0800 | [diff] [blame] | 1801 | return true; |
| 1802 | } |
| 1803 | |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1804 | return isProviderPackage(callerIdentity.mPackageName); |
Soonil Nagarkar | 2f1f7e8 | 2017-01-24 12:52:10 -0800 | [diff] [blame] | 1805 | |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 1808 | @GuardedBy("mLock") |
| 1809 | private boolean isSettingsExemptLocked(UpdateRecord record) { |
| 1810 | if (!record.mRealRequest.isLocationSettingsIgnored()) { |
| 1811 | return false; |
| 1812 | } |
| 1813 | |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 1814 | if (mSettingsStore.getIgnoreSettingsPackageWhitelist().contains( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1815 | record.mReceiver.mCallerIdentity.mPackageName)) { |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 1816 | return true; |
| 1817 | } |
| 1818 | |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 1819 | return isProviderPackage(record.mReceiver.mCallerIdentity.mPackageName); |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 1820 | |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1823 | private class UpdateRecord { |
| 1824 | final String mProvider; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1825 | private final LocationRequest mRealRequest; // original request from client |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 1826 | LocationRequest mRequest; // possibly throttled version of the request |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1827 | private final Receiver mReceiver; |
| 1828 | private boolean mIsForegroundUid; |
| 1829 | private Location mLastFixBroadcast; |
Soonil Nagarkar | ae6ce77 | 2019-05-01 13:16:17 -0700 | [diff] [blame] | 1830 | private Throwable mStackTrace; // for debugging only |
Soonil Nagarkar | 95768ce | 2019-11-05 15:22:44 -0800 | [diff] [blame] | 1831 | private long mExpirationRealtimeMs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1832 | |
| 1833 | /** |
| 1834 | * Note: must be constructed with lock held. |
| 1835 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1836 | private UpdateRecord(String provider, LocationRequest request, Receiver receiver) { |
Soonil Nagarkar | 95768ce | 2019-11-05 15:22:44 -0800 | [diff] [blame] | 1837 | mExpirationRealtimeMs = request.getExpirationRealtimeMs(SystemClock.elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | mProvider = provider; |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 1839 | mRealRequest = request; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1840 | mRequest = request; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | mReceiver = receiver; |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1842 | mIsForegroundUid = |
| 1843 | LocationManagerServiceUtils.isImportanceForeground( |
| 1844 | mActivityManager.getPackageImportance( |
| 1845 | mReceiver.mCallerIdentity.mPackageName)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | |
Soonil Nagarkar | ae6ce77 | 2019-05-01 13:16:17 -0700 | [diff] [blame] | 1847 | if (D && receiver.mCallerIdentity.mPid == Process.myPid()) { |
| 1848 | mStackTrace = new Throwable(); |
| 1849 | } |
| 1850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); |
| 1852 | if (records == null) { |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 1853 | records = new ArrayList<>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | mRecordsByProvider.put(provider, records); |
| 1855 | } |
| 1856 | if (!records.contains(this)) { |
| 1857 | records.add(this); |
| 1858 | } |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 1859 | |
| 1860 | // Update statistics for historical location requests by package/provider |
| 1861 | mRequestStatistics.startRequesting( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1862 | mReceiver.mCallerIdentity.mPackageName, provider, request.getInterval(), |
Wyatt Riley | f7075e0 | 2018-04-12 17:54:26 -0700 | [diff] [blame] | 1863 | mIsForegroundUid); |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * Method to be called when record changes foreground/background |
| 1868 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1869 | private void updateForeground(boolean isForeground) { |
Wyatt Riley | f7075e0 | 2018-04-12 17:54:26 -0700 | [diff] [blame] | 1870 | mIsForegroundUid = isForeground; |
| 1871 | mRequestStatistics.updateForeground( |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 1872 | mReceiver.mCallerIdentity.mPackageName, mProvider, isForeground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | /** |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 1876 | * Method to be called when a record will no longer be used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | */ |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1878 | private void disposeLocked(boolean removeReceiver) { |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 1879 | String packageName = mReceiver.mCallerIdentity.mPackageName; |
| 1880 | mRequestStatistics.stopRequesting(packageName, mProvider); |
| 1881 | |
| 1882 | mLocationUsageLogger.logLocationApiUsage( |
| 1883 | LocationStatsEnums.USAGE_ENDED, |
| 1884 | LocationStatsEnums.API_REQUEST_LOCATION_UPDATES, |
| 1885 | packageName, |
| 1886 | mRealRequest, |
| 1887 | mReceiver.isListener(), |
| 1888 | mReceiver.isPendingIntent(), |
Hongyi Zhang | 0e9ea75 | 2019-06-09 22:49:25 -0700 | [diff] [blame] | 1889 | /* geofence= */ null, |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 1890 | mActivityManager.getPackageImportance(packageName)); |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 1891 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1892 | // remove from mRecordsByProvider |
| 1893 | ArrayList<UpdateRecord> globalRecords = mRecordsByProvider.get(this.mProvider); |
| 1894 | if (globalRecords != null) { |
| 1895 | globalRecords.remove(this); |
| 1896 | } |
| 1897 | |
| 1898 | if (!removeReceiver) return; // the caller will handle the rest |
| 1899 | |
| 1900 | // remove from Receiver#mUpdateRecords |
| 1901 | HashMap<String, UpdateRecord> receiverRecords = mReceiver.mUpdateRecords; |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1902 | receiverRecords.remove(this.mProvider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1903 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 1904 | // and also remove the Receiver if it has no more update records |
| 1905 | if (receiverRecords.size() == 0) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1906 | removeUpdatesLocked(mReceiver); |
Mike Lockwood | 3a76fd6 | 2009-09-01 07:26:56 -0400 | [diff] [blame] | 1907 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | @Override |
| 1911 | public String toString() { |
Soonil Nagarkar | ae6ce77 | 2019-05-01 13:16:17 -0700 | [diff] [blame] | 1912 | StringBuilder b = new StringBuilder("UpdateRecord["); |
| 1913 | b.append(mProvider).append(" "); |
| 1914 | b.append(mReceiver.mCallerIdentity.mPackageName); |
| 1915 | b.append("(").append(mReceiver.mCallerIdentity.mUid); |
| 1916 | if (mIsForegroundUid) { |
| 1917 | b.append(" foreground"); |
| 1918 | } else { |
| 1919 | b.append(" background"); |
| 1920 | } |
| 1921 | b.append(") "); |
| 1922 | b.append(mRealRequest).append(" ").append(mReceiver.mWorkSource); |
| 1923 | |
| 1924 | if (mStackTrace != null) { |
| 1925 | ByteArrayOutputStream tmp = new ByteArrayOutputStream(); |
| 1926 | mStackTrace.printStackTrace(new PrintStream(tmp)); |
| 1927 | b.append("\n\n").append(tmp.toString()).append("\n"); |
| 1928 | } |
| 1929 | |
| 1930 | b.append("]"); |
| 1931 | return b.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1935 | @GuardedBy("mLock") |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1936 | private Receiver getReceiverLocked(ILocationListener listener, int pid, int uid, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1937 | String packageName, @Nullable String featureId, WorkSource workSource, |
| 1938 | boolean hideFromAppOps, @NonNull String listenerIdentifier) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1939 | IBinder binder = listener.asBinder(); |
| 1940 | Receiver receiver = mReceivers.get(binder); |
| 1941 | if (receiver == null) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1942 | receiver = new Receiver(listener, null, pid, uid, packageName, featureId, workSource, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1943 | hideFromAppOps, listenerIdentifier); |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 1944 | if (!receiver.linkToListenerDeathNotificationLocked( |
| 1945 | receiver.getListener().asBinder())) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1946 | return null; |
| 1947 | } |
Wen Jing | cb3ab22 | 2014-03-27 13:42:59 +0800 | [diff] [blame] | 1948 | mReceivers.put(binder, receiver); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1949 | } |
| 1950 | return receiver; |
| 1951 | } |
| 1952 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 1953 | @GuardedBy("mLock") |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 1954 | private Receiver getReceiverLocked(PendingIntent intent, int pid, int uid, String packageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1955 | @Nullable String featureId, WorkSource workSource, boolean hideFromAppOps, |
| 1956 | @NonNull String listenerIdentifier) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1957 | Receiver receiver = mReceivers.get(intent); |
| 1958 | if (receiver == null) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1959 | receiver = new Receiver(null, intent, pid, uid, packageName, featureId, workSource, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 1960 | hideFromAppOps, listenerIdentifier); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1961 | mReceivers.put(intent, receiver); |
| 1962 | } |
| 1963 | return receiver; |
| 1964 | } |
| 1965 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1966 | /** |
| 1967 | * Creates a LocationRequest based upon the supplied LocationRequest that to meets resolution |
| 1968 | * and consistency requirements. |
| 1969 | * |
| 1970 | * @param request the LocationRequest from which to create a sanitized version |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1971 | * @return a version of request that meets the given resolution and consistency requirements |
| 1972 | * @hide |
| 1973 | */ |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1974 | private LocationRequest createSanitizedRequest(LocationRequest request, int resolutionLevel, |
| 1975 | boolean callerHasLocationHardwarePermission) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1976 | LocationRequest sanitizedRequest = new LocationRequest(request); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 1977 | if (!callerHasLocationHardwarePermission) { |
| 1978 | // allow setting low power mode only for callers with location hardware permission |
| 1979 | sanitizedRequest.setLowPowerMode(false); |
| 1980 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1981 | if (resolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 1982 | switch (sanitizedRequest.getQuality()) { |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1983 | case LocationRequest.ACCURACY_FINE: |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1984 | sanitizedRequest.setQuality(LocationRequest.ACCURACY_BLOCK); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1985 | break; |
| 1986 | case LocationRequest.POWER_HIGH: |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1987 | sanitizedRequest.setQuality(LocationRequest.POWER_LOW); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1988 | break; |
| 1989 | } |
| 1990 | // throttle |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1991 | if (sanitizedRequest.getInterval() < LocationFudger.FASTEST_INTERVAL_MS) { |
| 1992 | sanitizedRequest.setInterval(LocationFudger.FASTEST_INTERVAL_MS); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1993 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1994 | if (sanitizedRequest.getFastestInterval() < LocationFudger.FASTEST_INTERVAL_MS) { |
| 1995 | sanitizedRequest.setFastestInterval(LocationFudger.FASTEST_INTERVAL_MS); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1996 | } |
Nick Pelly | 74fa7ea | 2012-08-13 19:36:38 -0700 | [diff] [blame] | 1997 | } |
Nick Pelly | 4e31c4f | 2012-08-13 19:35:39 -0700 | [diff] [blame] | 1998 | // make getFastestInterval() the minimum of interval and fastest interval |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1999 | if (sanitizedRequest.getFastestInterval() > sanitizedRequest.getInterval()) { |
Soonil Nagarkar | 397ad58 | 2019-01-23 22:47:57 -0800 | [diff] [blame] | 2000 | sanitizedRequest.setFastestInterval(request.getInterval()); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2001 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 2002 | return sanitizedRequest; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2003 | } |
| 2004 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2005 | private void checkPackageName(String packageName) { |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2006 | if (packageName == null) { |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2007 | throw new SecurityException("invalid package name: " + null); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2008 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2009 | int uid = Binder.getCallingUid(); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2010 | String[] packages = mPackageManager.getPackagesForUid(uid); |
| 2011 | if (packages == null) { |
| 2012 | throw new SecurityException("invalid UID " + uid); |
| 2013 | } |
| 2014 | for (String pkg : packages) { |
| 2015 | if (packageName.equals(pkg)) return; |
| 2016 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2017 | throw new SecurityException("invalid package name: " + packageName); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2020 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2021 | public void requestLocationUpdates(LocationRequest request, ILocationListener listener, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2022 | PendingIntent intent, String packageName, String featureId, |
| 2023 | String listenerIdentifier) { |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 2024 | Objects.requireNonNull(listenerIdentifier); |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2025 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2026 | synchronized (mLock) { |
| 2027 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
| 2028 | checkPackageName(packageName); |
| 2029 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 2030 | checkResolutionLevelIsSufficientForProviderUseLocked(allowedResolutionLevel, |
| 2031 | request.getProvider()); |
| 2032 | WorkSource workSource = request.getWorkSource(); |
| 2033 | if (workSource != null && !workSource.isEmpty()) { |
| 2034 | mContext.enforceCallingOrSelfPermission( |
| 2035 | Manifest.permission.UPDATE_DEVICE_STATS, null); |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2036 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2037 | boolean hideFromAppOps = request.getHideFromAppOps(); |
| 2038 | if (hideFromAppOps) { |
| 2039 | mContext.enforceCallingOrSelfPermission( |
| 2040 | Manifest.permission.UPDATE_APP_OPS_STATS, null); |
| 2041 | } |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2042 | if (request.isLocationSettingsIgnored()) { |
| 2043 | mContext.enforceCallingOrSelfPermission( |
| 2044 | Manifest.permission.WRITE_SECURE_SETTINGS, null); |
| 2045 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2046 | boolean callerHasLocationHardwarePermission = |
| 2047 | mContext.checkCallingPermission(android.Manifest.permission.LOCATION_HARDWARE) |
| 2048 | == PERMISSION_GRANTED; |
| 2049 | LocationRequest sanitizedRequest = createSanitizedRequest(request, |
| 2050 | allowedResolutionLevel, |
| 2051 | callerHasLocationHardwarePermission); |
| 2052 | |
| 2053 | final int pid = Binder.getCallingPid(); |
| 2054 | final int uid = Binder.getCallingUid(); |
| 2055 | |
| 2056 | long identity = Binder.clearCallingIdentity(); |
| 2057 | try { |
| 2058 | |
| 2059 | // We don't check for MODE_IGNORED here; we will do that when we go to deliver |
| 2060 | // a location. |
| 2061 | checkLocationAccess(pid, uid, packageName, allowedResolutionLevel); |
| 2062 | |
| 2063 | if (intent == null && listener == null) { |
| 2064 | throw new IllegalArgumentException("need either listener or intent"); |
| 2065 | } else if (intent != null && listener != null) { |
| 2066 | throw new IllegalArgumentException( |
| 2067 | "cannot register both listener and intent"); |
| 2068 | } |
| 2069 | |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2070 | mLocationUsageLogger.logLocationApiUsage( |
| 2071 | LocationStatsEnums.USAGE_STARTED, |
| 2072 | LocationStatsEnums.API_REQUEST_LOCATION_UPDATES, |
| 2073 | packageName, request, listener != null, intent != null, |
Hongyi Zhang | 0e9ea75 | 2019-06-09 22:49:25 -0700 | [diff] [blame] | 2074 | /* geofence= */ null, |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2075 | mActivityManager.getPackageImportance(packageName)); |
| 2076 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2077 | Receiver receiver; |
| 2078 | if (intent != null) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2079 | receiver = getReceiverLocked(intent, pid, uid, packageName, featureId, |
| 2080 | workSource, hideFromAppOps, listenerIdentifier); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2081 | } else { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2082 | receiver = getReceiverLocked(listener, pid, uid, packageName, featureId, |
| 2083 | workSource, hideFromAppOps, listenerIdentifier); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2084 | } |
| 2085 | requestLocationUpdatesLocked(sanitizedRequest, receiver, uid, packageName); |
| 2086 | } finally { |
| 2087 | Binder.restoreCallingIdentity(identity); |
| 2088 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2092 | @GuardedBy("mLock") |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2093 | private void requestLocationUpdatesLocked(LocationRequest request, Receiver receiver, |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2094 | int uid, String packageName) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2095 | // Figure out the provider. Either its explicitly request (legacy use cases), or |
| 2096 | // use the fused provider |
| 2097 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
| 2098 | String name = request.getProvider(); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2099 | if (name == null) { |
| 2100 | throw new IllegalArgumentException("provider name must not be null"); |
| 2101 | } |
Zhentao Sun | c5fc998 | 2013-04-17 17:47:53 -0700 | [diff] [blame] | 2102 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2103 | LocationProviderManager manager = getLocationProviderManager(name); |
| 2104 | if (manager == null) { |
Victoria Lease | b30f383 | 2013-10-13 12:15:40 -0700 | [diff] [blame] | 2105 | throw new IllegalArgumentException("provider doesn't exist: " + name); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2108 | UpdateRecord record = new UpdateRecord(name, request, receiver); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2109 | if (D) { |
| 2110 | Log.d(TAG, "request " + Integer.toHexString(System.identityHashCode(receiver)) |
| 2111 | + " " + name + " " + request + " from " + packageName + "(" + uid + " " |
| 2112 | + (record.mIsForegroundUid ? "foreground" : "background") |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 2113 | + (isThrottlingExemptLocked(receiver.mCallerIdentity) |
Soonil Nagarkar | 681d711 | 2017-02-23 17:14:16 -0800 | [diff] [blame] | 2114 | ? " [whitelisted]" : "") + ")"); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2115 | } |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 2116 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2117 | UpdateRecord oldRecord = receiver.mUpdateRecords.put(name, record); |
| 2118 | if (oldRecord != null) { |
| 2119 | oldRecord.disposeLocked(false); |
| 2120 | } |
| 2121 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2122 | if (!manager.isUseable() && !isSettingsExemptLocked(record)) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2123 | // Notify the listener that updates are currently disabled - but only if the request |
| 2124 | // does not ignore location settings |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2125 | receiver.callProviderEnabledLocked(name, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2127 | |
| 2128 | applyRequirementsLocked(name); |
| 2129 | |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 2130 | // Update the monitoring here just in case multiple location requests were added to the |
| 2131 | // same receiver (this request may be high power and the initial might not have been). |
| 2132 | receiver.updateMonitoring(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | } |
| 2134 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2135 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2136 | public void removeUpdates(ILocationListener listener, PendingIntent intent, |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2137 | String packageName) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2138 | checkPackageName(packageName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 2139 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2140 | int pid = Binder.getCallingPid(); |
| 2141 | int uid = Binder.getCallingUid(); |
| 2142 | |
| 2143 | if (intent == null && listener == null) { |
| 2144 | throw new IllegalArgumentException("need either listener or intent"); |
| 2145 | } else if (intent != null && listener != null) { |
| 2146 | throw new IllegalArgumentException("cannot register both listener and intent"); |
| 2147 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2148 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2149 | synchronized (mLock) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2150 | Receiver receiver; |
| 2151 | if (intent != null) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2152 | receiver = getReceiverLocked(intent, pid, uid, packageName, null, null, false, ""); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2153 | } else { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2154 | receiver = getReceiverLocked(listener, pid, uid, packageName, null, null, false, |
| 2155 | ""); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2156 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2157 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2158 | long identity = Binder.clearCallingIdentity(); |
| 2159 | try { |
| 2160 | removeUpdatesLocked(receiver); |
| 2161 | } finally { |
| 2162 | Binder.restoreCallingIdentity(identity); |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2163 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2164 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | } |
| 2166 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2167 | @GuardedBy("mLock") |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2168 | private void removeUpdatesLocked(Receiver receiver) { |
Dianne Hackborn | 7ff3011 | 2012-11-08 11:12:09 -0800 | [diff] [blame] | 2169 | if (D) Log.i(TAG, "remove " + Integer.toHexString(System.identityHashCode(receiver))); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2170 | |
| 2171 | if (mReceivers.remove(receiver.mKey) != null && receiver.isListener()) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2172 | receiver.unlinkFromListenerDeathNotificationLocked( |
| 2173 | receiver.getListener().asBinder()); |
Soonil Nagarkar | b46c167 | 2019-02-06 12:49:10 -0800 | [diff] [blame] | 2174 | receiver.clearPendingBroadcastsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 2177 | receiver.updateMonitoring(false); |
| 2178 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2179 | // Record which providers were associated with this listener |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 2180 | HashSet<String> providers = new HashSet<>(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2181 | HashMap<String, UpdateRecord> oldRecords = receiver.mUpdateRecords; |
| 2182 | if (oldRecords != null) { |
| 2183 | // Call dispose() on the obsolete update records. |
| 2184 | for (UpdateRecord record : oldRecords.values()) { |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 2185 | // Update statistics for historical location requests by package/provider |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2186 | record.disposeLocked(false); |
| 2187 | } |
| 2188 | // Accumulate providers |
| 2189 | providers.addAll(oldRecords.keySet()); |
| 2190 | } |
| 2191 | |
| 2192 | // update provider |
| 2193 | for (String provider : providers) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2194 | applyRequirementsLocked(provider); |
| 2195 | } |
| 2196 | } |
| 2197 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2198 | @Override |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2199 | public Location getLastLocation(LocationRequest r, String packageName, String featureId) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2200 | synchronized (mLock) { |
| 2201 | LocationRequest request = r != null ? r : DEFAULT_LOCATION_REQUEST; |
| 2202 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 2203 | checkPackageName(packageName); |
| 2204 | checkResolutionLevelIsSufficientForProviderUseLocked(allowedResolutionLevel, |
| 2205 | request.getProvider()); |
| 2206 | // no need to sanitize this request, as only the provider name is used |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 2207 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2208 | final int pid = Binder.getCallingPid(); |
| 2209 | final int uid = Binder.getCallingUid(); |
| 2210 | final long identity = Binder.clearCallingIdentity(); |
| 2211 | try { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 2212 | if (mSettingsStore.isLocationPackageBlacklisted(UserHandle.getUserId(uid), |
| 2213 | packageName)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2214 | if (D) { |
| 2215 | Log.d(TAG, "not returning last loc for blacklisted app: " |
| 2216 | + packageName); |
| 2217 | } |
| 2218 | return null; |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2219 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 2220 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2221 | // Figure out the provider. Either its explicitly request (deprecated API's), |
| 2222 | // or use the fused provider |
| 2223 | String name = request.getProvider(); |
| 2224 | if (name == null) name = LocationManager.FUSED_PROVIDER; |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2225 | LocationProviderManager manager = getLocationProviderManager(name); |
| 2226 | if (manager == null) return null; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2227 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2228 | // only the current user or location providers may get location this way |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 2229 | if (!mUserInfoStore.isCurrentUserOrProfile(UserHandle.getUserId(uid)) |
| 2230 | && !isProviderPackage(packageName)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2231 | return null; |
| 2232 | } |
| 2233 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2234 | if (!manager.isUseable()) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2235 | return null; |
| 2236 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2237 | |
| 2238 | Location location; |
| 2239 | if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 2240 | // Make sure that an app with coarse permissions can't get frequent location |
| 2241 | // updates by calling LocationManager.getLastKnownLocation repeatedly. |
| 2242 | location = mLastLocationCoarseInterval.get(name); |
| 2243 | } else { |
| 2244 | location = mLastLocation.get(name); |
| 2245 | } |
| 2246 | if (location == null) { |
| 2247 | return null; |
| 2248 | } |
| 2249 | |
| 2250 | // Don't return stale location to apps with foreground-only location permission. |
| 2251 | String op = resolutionLevelToOpStr(allowedResolutionLevel); |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2252 | long locationAgeMs = TimeUnit.NANOSECONDS.toMillis( |
| 2253 | SystemClock.elapsedRealtime() - location.getElapsedRealtimeNanos()); |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 2254 | if (locationAgeMs > mSettingsStore.getMaxLastLocationAgeMs() |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2255 | && (mAppOps.unsafeCheckOp(op, uid, packageName) |
| 2256 | == AppOpsManager.MODE_FOREGROUND)) { |
| 2257 | return null; |
| 2258 | } |
| 2259 | |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2260 | Location lastLocation = null; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2261 | if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 2262 | Location noGPSLocation = location.getExtraLocation( |
| 2263 | Location.EXTRA_NO_GPS_LOCATION); |
| 2264 | if (noGPSLocation != null) { |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2265 | lastLocation = new Location(mLocationFudger.getOrCreate(noGPSLocation)); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2266 | } |
| 2267 | } else { |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2268 | lastLocation = new Location(location); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2269 | } |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2270 | // Don't report location access if there is no last location to deliver. |
| 2271 | if (lastLocation != null) { |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2272 | if (!reportLocationAccessNoThrow(pid, uid, packageName, featureId, |
| 2273 | allowedResolutionLevel, null)) { |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2274 | if (D) { |
| 2275 | Log.d(TAG, "not returning last loc for no op app: " + packageName); |
| 2276 | } |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2277 | lastLocation = null; |
Wei Wang | 16276a4 | 2019-02-04 18:23:31 -0800 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | return lastLocation; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2281 | } finally { |
| 2282 | Binder.restoreCallingIdentity(identity); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2283 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2287 | @Override |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2288 | public boolean getCurrentLocation(LocationRequest locationRequest, |
| 2289 | ICancellationSignal remoteCancellationSignal, ILocationListener listener, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2290 | String packageName, String featureId, String listenerIdentifier) { |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2291 | // side effect of validating locationRequest and packageName |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2292 | Location lastLocation = getLastLocation(locationRequest, packageName, featureId); |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2293 | if (lastLocation != null) { |
| 2294 | long locationAgeMs = TimeUnit.NANOSECONDS.toMillis( |
| 2295 | SystemClock.elapsedRealtimeNanos() - lastLocation.getElapsedRealtimeNanos()); |
| 2296 | |
| 2297 | long identity = Binder.clearCallingIdentity(); |
| 2298 | try { |
| 2299 | if (locationAgeMs < MAX_CURRENT_LOCATION_AGE_MS) { |
| 2300 | try { |
| 2301 | listener.onLocationChanged(lastLocation); |
| 2302 | return true; |
| 2303 | } catch (RemoteException e) { |
| 2304 | Log.w(TAG, e); |
| 2305 | return false; |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | // packageName already validated by getLastLocation() call above |
| 2310 | boolean foreground = LocationManagerServiceUtils.isImportanceForeground( |
| 2311 | mActivityManager.getPackageImportance(packageName)); |
| 2312 | if (!foreground) { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 2313 | if (locationAgeMs < mSettingsStore.getBackgroundThrottleIntervalMs()) { |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2314 | // not allowed to request new locations, so we can't return anything |
| 2315 | return false; |
| 2316 | } |
| 2317 | } |
| 2318 | } finally { |
| 2319 | Binder.restoreCallingIdentity(identity); |
| 2320 | } |
| 2321 | } |
| 2322 | |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2323 | requestLocationUpdates(locationRequest, listener, null, packageName, featureId, |
| 2324 | listenerIdentifier); |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2325 | CancellationSignal cancellationSignal = CancellationSignal.fromTransport( |
| 2326 | remoteCancellationSignal); |
| 2327 | if (cancellationSignal != null) { |
| 2328 | cancellationSignal.setOnCancelListener( |
| 2329 | () -> removeUpdates(listener, null, packageName)); |
| 2330 | } |
| 2331 | return true; |
| 2332 | } |
| 2333 | |
| 2334 | @Override |
Chad Brubaker | f113333 | 2019-03-15 14:13:59 -0700 | [diff] [blame] | 2335 | public LocationTime getGnssTimeMillis() { |
| 2336 | synchronized (mLock) { |
| 2337 | Location location = mLastLocation.get(LocationManager.GPS_PROVIDER); |
| 2338 | if (location == null) { |
| 2339 | return null; |
| 2340 | } |
| 2341 | long currentNanos = SystemClock.elapsedRealtimeNanos(); |
| 2342 | long deltaMs = (currentNanos - location.getElapsedRealtimeNanos()) / 1000000L; |
| 2343 | return new LocationTime(location.getTime() + deltaMs, currentNanos); |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2348 | public boolean injectLocation(Location location) { |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2349 | mContext.enforceCallingPermission(android.Manifest.permission.LOCATION_HARDWARE, |
| 2350 | "Location Hardware permission not granted to inject location"); |
| 2351 | mContext.enforceCallingPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 2352 | "Access Fine Location permission not granted to inject Location"); |
| 2353 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2354 | synchronized (mLock) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2355 | LocationProviderManager manager = getLocationProviderManager(location.getProvider()); |
| 2356 | if (manager == null || !manager.isUseable()) { |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2357 | return false; |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2358 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2359 | |
| 2360 | // NOTE: If last location is already available, location is not injected. If |
| 2361 | // provider's normal source (like a GPS chipset) have already provided an output |
| 2362 | // there is no need to inject this location. |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2363 | if (mLastLocation.get(manager.getName()) != null) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2364 | return false; |
| 2365 | } |
| 2366 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2367 | updateLastLocationLocked(location, manager.getName()); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2368 | return true; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2369 | } |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2372 | @Override |
| 2373 | public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2374 | String packageName, String featureId, String listenerIdentifier) { |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 2375 | Objects.requireNonNull(listenerIdentifier); |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2376 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2377 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 2378 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 2379 | checkResolutionLevelIsSufficientForGeofenceUse(allowedResolutionLevel); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2380 | if (intent == null) { |
| 2381 | throw new IllegalArgumentException("invalid pending intent: " + null); |
Victoria Lease | 56e675b | 2012-11-05 19:25:06 -0800 | [diff] [blame] | 2382 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2383 | checkPackageName(packageName); |
| 2384 | synchronized (mLock) { |
| 2385 | checkResolutionLevelIsSufficientForProviderUseLocked(allowedResolutionLevel, |
| 2386 | request.getProvider()); |
Soonil Nagarkar | 8c4655e | 2019-02-27 13:00:56 -0800 | [diff] [blame] | 2387 | } |
| 2388 | // Require that caller can manage given document |
| 2389 | boolean callerHasLocationHardwarePermission = |
| 2390 | mContext.checkCallingPermission(android.Manifest.permission.LOCATION_HARDWARE) |
| 2391 | == PERMISSION_GRANTED; |
| 2392 | LocationRequest sanitizedRequest = createSanitizedRequest(request, |
| 2393 | allowedResolutionLevel, |
| 2394 | callerHasLocationHardwarePermission); |
| 2395 | |
| 2396 | if (D) { |
| 2397 | Log.d(TAG, "requestGeofence: " + sanitizedRequest + " " + geofence + " " + intent); |
| 2398 | } |
| 2399 | |
| 2400 | // geo-fence manager uses the public location API, need to clear identity |
| 2401 | int uid = Binder.getCallingUid(); |
| 2402 | if (UserHandle.getUserId(uid) != UserHandle.USER_SYSTEM) { |
| 2403 | // temporary measure until geofences work for secondary users |
| 2404 | Log.w(TAG, "proximity alerts are currently available only to the primary user"); |
| 2405 | return; |
| 2406 | } |
| 2407 | long identity = Binder.clearCallingIdentity(); |
| 2408 | try { |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2409 | synchronized (mLock) { |
| 2410 | mLocationUsageLogger.logLocationApiUsage( |
| 2411 | LocationStatsEnums.USAGE_STARTED, |
| 2412 | LocationStatsEnums.API_REQUEST_GEOFENCE, |
| 2413 | packageName, |
| 2414 | request, |
| 2415 | /* hasListener= */ false, |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2416 | true, |
Hongyi Zhang | 0e9ea75 | 2019-06-09 22:49:25 -0700 | [diff] [blame] | 2417 | geofence, |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2418 | mActivityManager.getPackageImportance(packageName)); |
| 2419 | } |
| 2420 | |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2421 | mGeofenceManager.addFence(sanitizedRequest, geofence, intent, allowedResolutionLevel, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2422 | uid, packageName, featureId, listenerIdentifier); |
Soonil Nagarkar | 8c4655e | 2019-02-27 13:00:56 -0800 | [diff] [blame] | 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(identity); |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 2425 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | @Override |
| 2429 | public void removeGeofence(Geofence geofence, PendingIntent intent, String packageName) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2430 | if (intent == null) { |
| 2431 | throw new IllegalArgumentException("invalid pending intent: " + null); |
| 2432 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2433 | checkPackageName(packageName); |
| 2434 | |
| 2435 | if (D) Log.d(TAG, "removeGeofence: " + geofence + " " + intent); |
| 2436 | |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 2437 | // geo-fence manager uses the public location API, need to clear identity |
| 2438 | long identity = Binder.clearCallingIdentity(); |
| 2439 | try { |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2440 | synchronized (mLock) { |
| 2441 | mLocationUsageLogger.logLocationApiUsage( |
| 2442 | LocationStatsEnums.USAGE_ENDED, |
| 2443 | LocationStatsEnums.API_REQUEST_GEOFENCE, |
| 2444 | packageName, |
| 2445 | /* LocationRequest= */ null, |
| 2446 | /* hasListener= */ false, |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2447 | true, |
Hongyi Zhang | 0e9ea75 | 2019-06-09 22:49:25 -0700 | [diff] [blame] | 2448 | geofence, |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2449 | mActivityManager.getPackageImportance(packageName)); |
| 2450 | } |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 2451 | mGeofenceManager.removeFence(geofence, intent); |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
| 2454 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2457 | @Override |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2458 | public boolean registerGnssStatusCallback(IGnssStatusListener listener, String packageName, |
| 2459 | String featureId) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2460 | return mGnssManagerService != null && mGnssManagerService.registerGnssStatusCallback( |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2461 | listener, packageName, featureId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | } |
| 2463 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2464 | @Override |
Anil Admal | 98d49b7 | 2019-02-06 15:26:33 -0800 | [diff] [blame] | 2465 | public void unregisterGnssStatusCallback(IGnssStatusListener listener) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2466 | if (mGnssManagerService != null) mGnssManagerService.unregisterGnssStatusCallback(listener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2469 | @Override |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2470 | public boolean addGnssMeasurementsListener(IGnssMeasurementsListener listener, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2471 | String packageName, String featureId, String listenerIdentifier) { |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 2472 | Objects.requireNonNull(listenerIdentifier); |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2473 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2474 | return mGnssManagerService != null && mGnssManagerService.addGnssMeasurementsListener( |
| 2475 | listener, packageName, featureId, listenerIdentifier); |
Anil Admal | 52686f8 | 2019-02-13 19:04:10 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | @Override |
| 2479 | public void removeGnssMeasurementsListener(IGnssMeasurementsListener listener) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2480 | if (mGnssManagerService != null) { |
| 2481 | mGnssManagerService.removeGnssMeasurementsListener( |
| 2482 | listener); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2483 | } |
destradaa | ea8a8a6 | 2014-06-23 18:19:03 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | @Override |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2487 | public void injectGnssMeasurementCorrections( |
| 2488 | GnssMeasurementCorrections measurementCorrections, String packageName) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2489 | if (mGnssManagerService != null) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2490 | mGnssManagerService.injectGnssMeasurementCorrections(measurementCorrections, |
| 2491 | packageName); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | @Override |
Anil Admal | 9934978 | 2019-03-19 18:58:42 -0700 | [diff] [blame] | 2496 | public long getGnssCapabilities(String packageName) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2497 | return mGnssManagerService == null ? 0L : mGnssManagerService.getGnssCapabilities( |
| 2498 | packageName); |
gomo | 226b7b7 | 2018-12-12 16:49:39 -0800 | [diff] [blame] | 2499 | } |
| 2500 | |
| 2501 | @Override |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2502 | public boolean addGnssNavigationMessageListener(IGnssNavigationMessageListener listener, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2503 | String packageName, String featureId, String listenerIdentifier) { |
Daulet Zhanguzin | ea1a7ca | 2020-01-03 09:46:50 +0000 | [diff] [blame] | 2504 | Objects.requireNonNull(listenerIdentifier); |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2505 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2506 | return mGnssManagerService != null && mGnssManagerService.addGnssNavigationMessageListener( |
| 2507 | listener, packageName, featureId, listenerIdentifier); |
destradaa | 4b3e393 | 2014-07-21 18:01:47 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2511 | public void removeGnssNavigationMessageListener(IGnssNavigationMessageListener listener) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2512 | if (mGnssManagerService != null) { |
| 2513 | mGnssManagerService.removeGnssNavigationMessageListener( |
| 2514 | listener); |
| 2515 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | @Override |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2519 | public boolean sendExtraCommand(String providerName, String command, Bundle extras) { |
| 2520 | if (providerName == null) { |
Mike Lockwood | c6cc836 | 2009-08-17 13:16:08 -0400 | [diff] [blame] | 2521 | // throw NullPointerException to remain compatible with previous implementation |
| 2522 | throw new NullPointerException(); |
| 2523 | } |
Soonil Nagarkar | 3f12840 | 2019-12-12 08:31:27 -0800 | [diff] [blame] | 2524 | |
| 2525 | mContext.enforceCallingOrSelfPermission( |
| 2526 | Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS, null); |
| 2527 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2528 | synchronized (mLock) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2529 | checkResolutionLevelIsSufficientForProviderUseLocked(getCallerAllowedResolutionLevel(), |
| 2530 | providerName); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2531 | |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2532 | mLocationUsageLogger.logLocationApiUsage( |
| 2533 | LocationStatsEnums.USAGE_STARTED, |
| 2534 | LocationStatsEnums.API_SEND_EXTRA_COMMAND, |
| 2535 | providerName); |
| 2536 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2537 | LocationProviderManager manager = getLocationProviderManager(providerName); |
| 2538 | if (manager != null) { |
| 2539 | manager.sendExtraCommand(Binder.getCallingUid(), Binder.getCallingPid(), command, |
| 2540 | extras); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2541 | } |
| 2542 | |
Hongyi Zhang | 700137e | 2019-05-23 21:19:36 -0700 | [diff] [blame] | 2543 | mLocationUsageLogger.logLocationApiUsage( |
| 2544 | LocationStatsEnums.USAGE_ENDED, |
| 2545 | LocationStatsEnums.API_SEND_EXTRA_COMMAND, |
| 2546 | providerName); |
| 2547 | |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2548 | return true; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2549 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2552 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2553 | public boolean sendNiResponse(int notifId, int userResponse) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2554 | return mGnssManagerService != null && mGnssManagerService.sendNiResponse(notifId, |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 2555 | userResponse); |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 2556 | } |
| 2557 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2558 | @Override |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2559 | public ProviderProperties getProviderProperties(String providerName) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2560 | LocationProviderManager manager = getLocationProviderManager(providerName); |
| 2561 | if (manager == null) { |
| 2562 | return null; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2563 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2564 | return manager.getProperties(); |
Jason Monk | b71218a | 2015-06-17 14:44:39 -0400 | [diff] [blame] | 2565 | } |
| 2566 | |
Wei Wang | 980b7c2 | 2018-12-06 17:53:00 -0800 | [diff] [blame] | 2567 | @Override |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 2568 | public boolean isProviderPackage(String packageName) { |
Soonil Nagarkar | 514dff4 | 2019-04-30 12:04:28 -0700 | [diff] [blame] | 2569 | mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_DEVICE_CONFIG, |
| 2570 | Manifest.permission.READ_DEVICE_CONFIG + " permission required"); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2571 | for (LocationProviderManager manager : mProviderManagers) { |
| 2572 | if (manager.getPackages().contains(packageName)) { |
| 2573 | return true; |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 2574 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2575 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2576 | return false; |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2579 | @Override |
Wei Wang | 9f52d55 | 2019-10-02 14:49:02 -0700 | [diff] [blame] | 2580 | public List<String> getProviderPackages(String providerName) { |
| 2581 | mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_DEVICE_CONFIG, |
| 2582 | Manifest.permission.READ_DEVICE_CONFIG + " permission required"); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2583 | LocationProviderManager manager = getLocationProviderManager(providerName); |
| 2584 | return manager == null ? Collections.emptyList() : new ArrayList<>(manager.getPackages()); |
Wei Wang | 9f52d55 | 2019-10-02 14:49:02 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | @Override |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2588 | public void setExtraLocationControllerPackage(String packageName) { |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2589 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, |
| 2590 | Manifest.permission.LOCATION_HARDWARE + " permission required"); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2591 | synchronized (mLock) { |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2592 | mExtraLocationControllerPackage = packageName; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2593 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | @Override |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2597 | public String getExtraLocationControllerPackage() { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2598 | synchronized (mLock) { |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2599 | return mExtraLocationControllerPackage; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2600 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | @Override |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2604 | public void setExtraLocationControllerPackageEnabled(boolean enabled) { |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2605 | mContext.enforceCallingPermission(Manifest.permission.LOCATION_HARDWARE, |
| 2606 | Manifest.permission.LOCATION_HARDWARE + " permission required"); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2607 | synchronized (mLock) { |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2608 | mExtraLocationControllerPackageEnabled = enabled; |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2609 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | @Override |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2613 | public boolean isExtraLocationControllerPackageEnabled() { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2614 | synchronized (mLock) { |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 2615 | return mExtraLocationControllerPackageEnabled |
| 2616 | && (mExtraLocationControllerPackage != null); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2617 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2621 | public boolean isLocationEnabledForUser(int userId) { |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2622 | // Check INTERACT_ACROSS_USERS permission if userId is not current user id. |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2623 | if (UserHandle.getCallingUserId() != userId) { |
| 2624 | mContext.enforceCallingOrSelfPermission( |
| 2625 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 2626 | "Requires INTERACT_ACROSS_USERS permission"); |
| 2627 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2628 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2629 | long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 2631 | return mSettingsStore.isLocationEnabled(userId); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2632 | } finally { |
| 2633 | Binder.restoreCallingIdentity(identity); |
| 2634 | } |
Soonil Nagarkar | b2fcddd | 2019-01-03 15:20:06 -0800 | [diff] [blame] | 2635 | } |
| 2636 | |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2637 | @Override |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2638 | public boolean isProviderEnabledForUser(String providerName, int userId) { |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2639 | // Check INTERACT_ACROSS_USERS permission if userId is not current user id. |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2640 | if (UserHandle.getCallingUserId() != userId) { |
| 2641 | mContext.enforceCallingOrSelfPermission( |
| 2642 | Manifest.permission.INTERACT_ACROSS_USERS, |
| 2643 | "Requires INTERACT_ACROSS_USERS permission"); |
Soonil Nagarkar | 1575a04 | 2018-10-24 17:54:54 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2646 | // Fused provider is accessed indirectly via criteria rather than the provider-based APIs, |
| 2647 | // so we discourage its use |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2648 | if (FUSED_PROVIDER.equals(providerName)) return false; |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2649 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2650 | synchronized (mLock) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2651 | LocationProviderManager manager = getLocationProviderManager(providerName); |
| 2652 | return manager != null && manager.isUseable(userId); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2653 | } |
Maggie | 2a9409e | 2018-03-21 11:47:28 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2656 | @GuardedBy("mLock") |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2657 | private static boolean shouldBroadcastSafeLocked( |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 2658 | Location loc, Location lastLoc, UpdateRecord record, long now) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | // Always broadcast the first update |
| 2660 | if (lastLoc == null) { |
| 2661 | return true; |
| 2662 | } |
| 2663 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 2664 | // Check whether sufficient time has passed |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 2665 | long minTime = record.mRealRequest.getFastestInterval(); |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2666 | long deltaMs = TimeUnit.NANOSECONDS.toMillis( |
| 2667 | loc.getElapsedRealtimeNanos() - lastLoc.getElapsedRealtimeNanos()); |
| 2668 | if (deltaMs < minTime - MAX_PROVIDER_SCHEDULING_JITTER_MS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | return false; |
| 2670 | } |
| 2671 | |
| 2672 | // Check whether sufficient distance has been traveled |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 2673 | double minDistance = record.mRealRequest.getSmallestDisplacement(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | if (minDistance > 0.0) { |
| 2675 | if (loc.distanceTo(lastLoc) <= minDistance) { |
| 2676 | return false; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 2680 | // Check whether sufficient number of udpates is left |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 2681 | if (record.mRealRequest.getNumUpdates() <= 0) { |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 2682 | return false; |
| 2683 | } |
| 2684 | |
| 2685 | // Check whether the expiry date has passed |
Soonil Nagarkar | 95768ce | 2019-11-05 15:22:44 -0800 | [diff] [blame] | 2686 | return record.mExpirationRealtimeMs >= now; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | } |
| 2688 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2689 | @GuardedBy("mLock") |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2690 | private void handleLocationChangedLocked(Location location, LocationProviderManager manager) { |
| 2691 | if (!mProviderManagers.contains(manager)) { |
| 2692 | Log.w(TAG, "received location from unknown provider: " + manager.getName()); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2693 | return; |
| 2694 | } |
| 2695 | if (!location.isComplete()) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2696 | Log.w(TAG, "dropping incomplete location from " + manager.getName() + " provider: " |
| 2697 | + location); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2698 | return; |
| 2699 | } |
| 2700 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2701 | // notify passive provider |
| 2702 | if (manager != mPassiveManager) { |
| 2703 | mPassiveManager.updateLocation(new Location(location)); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2704 | } |
| 2705 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2706 | if (D) Log.d(TAG, "incoming location: " + location); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2707 | long now = SystemClock.elapsedRealtime(); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2708 | |
| 2709 | |
| 2710 | // only update last location for locations that come from useable providers |
| 2711 | if (manager.isUseable()) { |
| 2712 | updateLastLocationLocked(location, manager.getName()); |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 2713 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2715 | // Update last known coarse interval location if enough time has passed. |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2716 | Location lastLocationCoarseInterval = mLastLocationCoarseInterval.get( |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2717 | manager.getName()); |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2718 | if (lastLocationCoarseInterval == null) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2719 | lastLocationCoarseInterval = new Location(location); |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2720 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2721 | if (manager.isUseable()) { |
| 2722 | mLastLocationCoarseInterval.put(manager.getName(), lastLocationCoarseInterval); |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2723 | } |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2724 | } |
Soonil Nagarkar | 905e722 | 2019-10-01 12:03:29 -0700 | [diff] [blame] | 2725 | long timeDeltaMs = TimeUnit.NANOSECONDS.toMillis(location.getElapsedRealtimeNanos() |
| 2726 | - lastLocationCoarseInterval.getElapsedRealtimeNanos()); |
| 2727 | if (timeDeltaMs > LocationFudger.FASTEST_INTERVAL_MS) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2728 | lastLocationCoarseInterval.set(location); |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2729 | } |
| 2730 | // Don't ever return a coarse location that is more recent than the allowed update |
| 2731 | // interval (i.e. don't allow an app to keep registering and unregistering for |
| 2732 | // location updates to overcome the minimum interval). |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2733 | Location noGPSLocation = |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2734 | lastLocationCoarseInterval.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 2735 | |
Laurent Tu | 60ec50a | 2012-10-04 17:00:10 -0700 | [diff] [blame] | 2736 | // Skip if there are no UpdateRecords for this provider. |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2737 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(manager.getName()); |
Laurent Tu | 60ec50a | 2012-10-04 17:00:10 -0700 | [diff] [blame] | 2738 | if (records == null || records.size() == 0) return; |
| 2739 | |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2740 | // Fetch coarse location |
| 2741 | Location coarseLocation = null; |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 2742 | if (noGPSLocation != null) { |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2743 | coarseLocation = mLocationFudger.getOrCreate(noGPSLocation); |
| 2744 | } |
| 2745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | ArrayList<Receiver> deadReceivers = null; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2747 | ArrayList<UpdateRecord> deadUpdateRecords = null; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2748 | |
Soonil Nagarkar | 94749f7 | 2018-11-08 11:46:43 -0800 | [diff] [blame] | 2749 | // Broadcast location to all listeners |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2750 | for (UpdateRecord r : records) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | Receiver receiver = r.mReceiver; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2752 | boolean receiverDead = false; |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 2753 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2754 | if (!manager.isUseable() && !isSettingsExemptLocked(r)) { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2755 | continue; |
| 2756 | } |
| 2757 | |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 2758 | int receiverUserId = UserHandle.getUserId(receiver.mCallerIdentity.mUid); |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 2759 | if (!mUserInfoStore.isCurrentUserOrProfile(receiverUserId) |
Soonil Nagarkar | 0d77ea6 | 2019-01-31 14:36:56 -0800 | [diff] [blame] | 2760 | && !isProviderPackage(receiver.mCallerIdentity.mPackageName)) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 2761 | if (D) { |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 2762 | Log.d(TAG, "skipping loc update for background user " + receiverUserId + |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 2763 | " (app: " + receiver.mCallerIdentity.mPackageName + ")"); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 2764 | } |
| 2765 | continue; |
| 2766 | } |
| 2767 | |
Soonil Nagarkar | b8466b7 | 2019-10-25 14:10:30 -0700 | [diff] [blame] | 2768 | if (mSettingsStore.isLocationPackageBlacklisted(receiverUserId, |
| 2769 | receiver.mCallerIdentity.mPackageName)) { |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2770 | if (D) { |
| 2771 | Log.d(TAG, "skipping loc update for blacklisted app: " + |
Anil Admal | 08b9612 | 2019-01-30 16:55:05 -0800 | [diff] [blame] | 2772 | receiver.mCallerIdentity.mPackageName); |
gomo | 48f1a64 | 2017-11-10 20:35:46 -0800 | [diff] [blame] | 2773 | } |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 2774 | continue; |
| 2775 | } |
| 2776 | |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 2777 | Location notifyLocation; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 2778 | if (receiver.mAllowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 2779 | notifyLocation = coarseLocation; // use coarse location |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2780 | } else { |
Soonil Nagarkar | be93e9c | 2019-01-08 13:05:03 -0800 | [diff] [blame] | 2781 | notifyLocation = location; // use fine location |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2782 | } |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2783 | if (notifyLocation != null) { |
| 2784 | Location lastLoc = r.mLastFixBroadcast; |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2785 | if ((lastLoc == null) |
| 2786 | || shouldBroadcastSafeLocked(notifyLocation, lastLoc, r, now)) { |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2787 | if (lastLoc == null) { |
| 2788 | lastLoc = new Location(notifyLocation); |
| 2789 | r.mLastFixBroadcast = lastLoc; |
| 2790 | } else { |
| 2791 | lastLoc.set(notifyLocation); |
| 2792 | } |
Wei Wang | 8486fc7 | 2019-03-07 18:49:21 -0800 | [diff] [blame] | 2793 | // Report location access before delivering location to the client. This will |
| 2794 | // note location delivery to appOps, so it should be called only when a |
| 2795 | // location is really being delivered to the client. |
| 2796 | if (!reportLocationAccessNoThrow( |
| 2797 | receiver.mCallerIdentity.mPid, |
| 2798 | receiver.mCallerIdentity.mUid, |
| 2799 | receiver.mCallerIdentity.mPackageName, |
Philip P. Moltmann | 6c7377c | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2800 | receiver.mCallerIdentity.mFeatureId, |
Philip P. Moltmann | bc8b48a | 2019-09-27 17:06:25 -0700 | [diff] [blame] | 2801 | receiver.mAllowedResolutionLevel, |
| 2802 | "Location sent to " + receiver.mCallerIdentity.mListenerIdentifier)) { |
Wei Wang | 8486fc7 | 2019-03-07 18:49:21 -0800 | [diff] [blame] | 2803 | if (D) { |
| 2804 | Log.d(TAG, "skipping loc update for no op app: " |
| 2805 | + receiver.mCallerIdentity.mPackageName); |
| 2806 | } |
| 2807 | continue; |
| 2808 | } |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2809 | if (!receiver.callLocationChangedLocked(notifyLocation)) { |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2810 | Slog.w(TAG, "RemoteException calling onLocationChanged on " |
| 2811 | + receiver); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 2812 | receiverDead = true; |
| 2813 | } |
Soonil Nagarkar | d4def0c | 2017-05-23 15:54:55 -0700 | [diff] [blame] | 2814 | r.mRealRequest.decrementNumUpdates(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | } |
| 2816 | } |
| 2817 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2818 | // track expired records |
Soonil Nagarkar | 95768ce | 2019-11-05 15:22:44 -0800 | [diff] [blame] | 2819 | if (r.mRealRequest.getNumUpdates() <= 0 || r.mExpirationRealtimeMs < now) { |
Soonil Nagarkar | 39d614a | 2019-10-31 12:10:31 -0700 | [diff] [blame] | 2820 | // notify the client it can remove this listener |
| 2821 | r.mReceiver.callRemovedLocked(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2822 | if (deadUpdateRecords == null) { |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 2823 | deadUpdateRecords = new ArrayList<>(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2824 | } |
| 2825 | deadUpdateRecords.add(r); |
| 2826 | } |
| 2827 | // track dead receivers |
| 2828 | if (receiverDead) { |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2829 | if (deadReceivers == null) { |
Soonil Nagarkar | 7decfb6 | 2017-01-18 12:18:49 -0800 | [diff] [blame] | 2830 | deadReceivers = new ArrayList<>(); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 2831 | } |
| 2832 | if (!deadReceivers.contains(receiver)) { |
| 2833 | deadReceivers.add(receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2834 | } |
| 2835 | } |
| 2836 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2837 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2838 | // remove dead records and receivers outside the loop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | if (deadReceivers != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2840 | for (Receiver receiver : deadReceivers) { |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2841 | removeUpdatesLocked(receiver); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2842 | } |
| 2843 | } |
| 2844 | if (deadUpdateRecords != null) { |
| 2845 | for (UpdateRecord r : deadUpdateRecords) { |
| 2846 | r.disposeLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2848 | applyRequirementsLocked(manager); |
Victoria Lease | 8b38b29 | 2012-12-04 15:04:43 -0800 | [diff] [blame] | 2849 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | } |
| 2851 | |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2852 | @GuardedBy("mLock") |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2853 | private void updateLastLocationLocked(Location location, String provider) { |
Ram Periathiruvadi | 8671fea | 2017-12-08 18:35:10 -0800 | [diff] [blame] | 2854 | Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 2855 | Location lastNoGPSLocation; |
| 2856 | Location lastLocation = mLastLocation.get(provider); |
| 2857 | if (lastLocation == null) { |
| 2858 | lastLocation = new Location(provider); |
| 2859 | mLastLocation.put(provider, lastLocation); |
| 2860 | } else { |
| 2861 | lastNoGPSLocation = lastLocation.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 2862 | if (noGPSLocation == null && lastNoGPSLocation != null) { |
| 2863 | // New location has no no-GPS location: adopt last no-GPS location. This is set |
| 2864 | // directly into location because we do not want to notify COARSE clients. |
| 2865 | location.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, lastNoGPSLocation); |
| 2866 | } |
| 2867 | } |
| 2868 | lastLocation.set(location); |
| 2869 | } |
| 2870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | // Geocoder |
| 2872 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2873 | @Override |
Mike Lockwood | e15735a | 2010-09-20 17:48:47 -0400 | [diff] [blame] | 2874 | public boolean geocoderIsPresent() { |
Mark Vandevoorde | 01ac80b | 2010-05-21 15:43:26 -0700 | [diff] [blame] | 2875 | return mGeocodeProvider != null; |
| 2876 | } |
| 2877 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2878 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | public String getFromLocation(double latitude, double longitude, int maxResults, |
Mike Lockwood | 3490140 | 2010-01-04 12:14:21 -0500 | [diff] [blame] | 2880 | GeocoderParams params, List<Address> addrs) { |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2881 | if (mGeocodeProvider != null) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 2882 | return mGeocodeProvider.getFromLocation(latitude, longitude, maxResults, |
| 2883 | params, addrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | } |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2885 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | } |
| 2887 | |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2888 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2889 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | public String getFromLocationName(String locationName, |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2891 | double lowerLeftLatitude, double lowerLeftLongitude, |
| 2892 | double upperRightLatitude, double upperRightLongitude, int maxResults, |
Mike Lockwood | 3490140 | 2010-01-04 12:14:21 -0500 | [diff] [blame] | 2893 | GeocoderParams params, List<Address> addrs) { |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2894 | |
| 2895 | if (mGeocodeProvider != null) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 2896 | return mGeocodeProvider.getFromLocationName(locationName, lowerLeftLatitude, |
| 2897 | lowerLeftLongitude, upperRightLatitude, upperRightLongitude, |
| 2898 | maxResults, params, addrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | } |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 2900 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | // Mock Providers |
| 2904 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2905 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2906 | public void addTestProvider(String provider, ProviderProperties properties, |
| 2907 | String packageName) { |
| 2908 | if (mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(), packageName) |
| 2909 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 2910 | return; |
| 2911 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2913 | synchronized (mLock) { |
| 2914 | LocationProviderManager manager = getLocationProviderManager(provider); |
| 2915 | if (manager == null) { |
| 2916 | manager = new LocationProviderManager(provider); |
| 2917 | mProviderManagers.add(manager); |
| 2918 | } |
| 2919 | |
| 2920 | manager.setMockProvider(new MockProvider(mContext, properties)); |
| 2921 | } |
| 2922 | } |
| 2923 | |
| 2924 | @Override |
| 2925 | public void removeTestProvider(String provider, String packageName) { |
| 2926 | if (mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(), packageName) |
| 2927 | != AppOpsManager.MODE_ALLOWED) { |
| 2928 | return; |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 2929 | } |
| 2930 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2931 | synchronized (mLock) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2932 | LocationProviderManager manager = getLocationProviderManager(provider); |
| 2933 | if (manager == null) { |
| 2934 | return; |
| 2935 | } |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2936 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2937 | manager.setMockProvider(null); |
| 2938 | if (!manager.hasProvider()) { |
| 2939 | mProviderManagers.remove(manager); |
| 2940 | mLastLocation.remove(manager.getName()); |
| 2941 | mLastLocationCoarseInterval.remove(manager.getName()); |
Mike Lockwood | 7566c1d | 2009-08-25 10:05:18 -0700 | [diff] [blame] | 2942 | } |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2943 | } |
Ji-Hwan Lee | 26bdb8f | 2014-04-21 20:48:19 +0900 | [diff] [blame] | 2944 | } |
| 2945 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2946 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2947 | public void setTestProviderLocation(String provider, Location location, String packageName) { |
| 2948 | if (mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(), packageName) |
| 2949 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 2950 | return; |
| 2951 | } |
| 2952 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2953 | LocationProviderManager manager = getLocationProviderManager(provider); |
| 2954 | if (manager == null) { |
| 2955 | throw new IllegalArgumentException("provider doesn't exist: " + provider); |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 2956 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2957 | |
| 2958 | manager.setMockProviderLocation(location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | } |
| 2960 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2961 | @Override |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2962 | public void setTestProviderEnabled(String provider, boolean enabled, String packageName) { |
| 2963 | if (mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(), packageName) |
| 2964 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 2965 | return; |
| 2966 | } |
| 2967 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2968 | LocationProviderManager manager = getLocationProviderManager(provider); |
| 2969 | if (manager == null) { |
| 2970 | throw new IllegalArgumentException("provider doesn't exist: " + provider); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2971 | } |
| 2972 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2973 | manager.setMockProviderEnabled(enabled); |
Soonil Nagarkar | 90da1ab | 2019-01-04 16:26:59 -0800 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | @Override |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 2977 | @NonNull |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2978 | public List<LocationRequest> getTestProviderCurrentRequests(String provider, |
| 2979 | String packageName) { |
| 2980 | if (mAppOps.checkOp(AppOpsManager.OP_MOCK_LOCATION, Binder.getCallingUid(), packageName) |
| 2981 | != AppOpsManager.MODE_ALLOWED) { |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 2982 | return Collections.emptyList(); |
| 2983 | } |
| 2984 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2985 | LocationProviderManager manager = getLocationProviderManager(provider); |
| 2986 | if (manager == null) { |
| 2987 | throw new IllegalArgumentException("provider doesn't exist: " + provider); |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 2988 | } |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2989 | |
| 2990 | return manager.getMockProviderRequests(); |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 2995 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) { |
| 2996 | return; |
| 2997 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2998 | |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 2999 | IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); |
| 3000 | |
Soonil Nagarkar | 6825774 | 2019-01-09 19:42:34 +0000 | [diff] [blame] | 3001 | synchronized (mLock) { |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 3002 | if (mGnssManagerService != null && args.length > 0 && args[0].equals("--gnssmetrics")) { |
| 3003 | mGnssManagerService.dump(fd, pw, args); |
Blake Kragten | 47014d2 | 2019-12-06 14:18:38 -0800 | [diff] [blame] | 3004 | return; |
Siddharth Ray | bb608c8 | 2017-03-16 11:33:34 -0700 | [diff] [blame] | 3005 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3006 | |
| 3007 | ipw.println("Location Manager State:"); |
| 3008 | ipw.increaseIndent(); |
| 3009 | ipw.print("Current System Time: " |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 3010 | + TimeUtils.logTimeOfDay(System.currentTimeMillis())); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3011 | ipw.println(", Current Elapsed Time: " |
WyattRiley | ba6072f | 2019-04-18 07:37:52 -0700 | [diff] [blame] | 3012 | + TimeUtils.formatDuration(SystemClock.elapsedRealtime())); |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 3013 | |
| 3014 | ipw.println("User Info:"); |
| 3015 | ipw.increaseIndent(); |
| 3016 | mUserInfoStore.dump(fd, ipw, args); |
| 3017 | ipw.decreaseIndent(); |
| 3018 | |
| 3019 | ipw.println("Location Settings:"); |
| 3020 | ipw.increaseIndent(); |
| 3021 | mSettingsStore.dump(fd, ipw, args); |
| 3022 | ipw.decreaseIndent(); |
| 3023 | |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3024 | ipw.println("Battery Saver Location Mode: " |
Kweku Adams | 4fb074e | 2019-02-01 16:03:27 -0800 | [diff] [blame] | 3025 | + locationPowerSaveModeToString(mBatterySaverMode)); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3026 | |
| 3027 | ipw.println("Location Listeners:"); |
| 3028 | ipw.increaseIndent(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 3029 | for (Receiver receiver : mReceivers.values()) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3030 | ipw.println(receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3031 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3032 | ipw.decreaseIndent(); |
| 3033 | |
| 3034 | ipw.println("Active Records by Provider:"); |
| 3035 | ipw.increaseIndent(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 3036 | for (Map.Entry<String, ArrayList<UpdateRecord>> entry : mRecordsByProvider.entrySet()) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3037 | ipw.println(entry.getKey() + ":"); |
| 3038 | ipw.increaseIndent(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 3039 | for (UpdateRecord record : entry.getValue()) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3040 | ipw.println(record); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3042 | ipw.decreaseIndent(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3043 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3044 | ipw.decreaseIndent(); |
Anil Admal | 98d49b7 | 2019-02-06 15:26:33 -0800 | [diff] [blame] | 3045 | |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3046 | ipw.println("Historical Records by Provider:"); |
| 3047 | ipw.increaseIndent(); |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 3048 | for (Map.Entry<PackageProviderKey, PackageStatistics> entry |
| 3049 | : mRequestStatistics.statistics.entrySet()) { |
| 3050 | PackageProviderKey key = entry.getKey(); |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3051 | ipw.println(key.packageName + ": " + key.providerName + ": " + entry.getValue()); |
David Christie | 2ff96af | 2014-01-30 16:09:37 -0800 | [diff] [blame] | 3052 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3053 | ipw.decreaseIndent(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 3054 | |
WyattRiley | fa1ef8d3 | 2019-12-30 17:19:55 -0800 | [diff] [blame] | 3055 | mRequestStatistics.history.dump(ipw); |
| 3056 | |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3057 | ipw.println("Last Known Locations:"); |
| 3058 | ipw.increaseIndent(); |
| 3059 | for (Map.Entry<String, Location> entry : mLastLocation.entrySet()) { |
| 3060 | ipw.println(entry.getKey() + ": " + entry.getValue()); |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 3061 | } |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3062 | ipw.decreaseIndent(); |
| 3063 | |
| 3064 | ipw.println("Last Known Coarse Locations:"); |
| 3065 | ipw.increaseIndent(); |
| 3066 | for (Map.Entry<String, Location> entry : mLastLocationCoarseInterval.entrySet()) { |
| 3067 | ipw.println(entry.getKey() + ": " + entry.getValue()); |
| 3068 | } |
| 3069 | ipw.decreaseIndent(); |
David Christie | 1b9b7b1 | 2013-04-15 15:31:11 -0700 | [diff] [blame] | 3070 | |
Tyler Trephan | 2f3ee9a | 2019-03-21 10:54:22 -0700 | [diff] [blame] | 3071 | if (mGeofenceManager != null) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3072 | ipw.println("Geofences:"); |
| 3073 | ipw.increaseIndent(); |
| 3074 | mGeofenceManager.dump(ipw); |
| 3075 | ipw.decreaseIndent(); |
Tyler Trephan | 2f3ee9a | 2019-03-21 10:54:22 -0700 | [diff] [blame] | 3076 | } |
Sasha Kuznetsov | a8ace3c | 2019-09-13 14:14:40 -0700 | [diff] [blame] | 3077 | |
Wei Wang | 114922a | 2019-01-30 18:19:35 -0800 | [diff] [blame] | 3078 | if (mExtraLocationControllerPackage != null) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3079 | ipw.println("Location Controller Extra Package: " + mExtraLocationControllerPackage |
| 3080 | + (mExtraLocationControllerPackageEnabled ? " [enabled]" : "[disabled]")); |
Wei Wang | 980b7c2 | 2018-12-06 17:53:00 -0800 | [diff] [blame] | 3081 | } |
| 3082 | |
Tyler Trephan | 2f3ee9a | 2019-03-21 10:54:22 -0700 | [diff] [blame] | 3083 | if (mLocationFudger != null) { |
Soonil Nagarkar | 1c57255 | 2019-07-10 13:31:47 -0700 | [diff] [blame] | 3084 | ipw.println("Location Fudger:"); |
| 3085 | ipw.increaseIndent(); |
| 3086 | mLocationFudger.dump(fd, ipw, args); |
| 3087 | ipw.decreaseIndent(); |
Tyler Trephan | 2f3ee9a | 2019-03-21 10:54:22 -0700 | [diff] [blame] | 3088 | } |
Anil Admal | 98d49b7 | 2019-02-06 15:26:33 -0800 | [diff] [blame] | 3089 | |
Soonil Nagarkar | 9ec0185 | 2020-01-10 13:42:38 -0800 | [diff] [blame] | 3090 | ipw.println("Location Providers:"); |
| 3091 | ipw.increaseIndent(); |
| 3092 | for (LocationProviderManager manager : mProviderManagers) { |
| 3093 | manager.dump(fd, ipw, args); |
| 3094 | } |
| 3095 | ipw.decreaseIndent(); |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 3096 | |
Soonil Nagarkar | 8df02f4 | 2020-01-08 13:23:26 -0800 | [diff] [blame] | 3097 | if (mGnssManagerService != null) { |
| 3098 | ipw.println("GNSS:"); |
| 3099 | ipw.increaseIndent(); |
| 3100 | mGnssManagerService.dump(fd, ipw, args); |
| 3101 | ipw.decreaseIndent(); |
| 3102 | } |
Anil Admal | 98d49b7 | 2019-02-06 15:26:33 -0800 | [diff] [blame] | 3103 | } |
| 3104 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3105 | } |