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