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