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