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 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 19 | import android.app.AppOpsManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.app.PendingIntent; |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.ContentResolver; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 25 | import android.content.IntentFilter; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 27 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageManager.NameNotFoundException; |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 30 | import android.content.pm.ResolveInfo; |
| 31 | import android.content.pm.Signature; |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 32 | import android.content.res.Resources; |
Brian Muramatsu | bb95cb9 | 2012-08-29 10:43:21 -0700 | [diff] [blame] | 33 | import android.database.ContentObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.location.Address; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 35 | import android.location.Criteria; |
Mike Lockwood | 3490140 | 2010-01-04 12:14:21 -0500 | [diff] [blame] | 36 | import android.location.GeocoderParams; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 37 | import android.location.Geofence; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.location.IGpsStatusListener; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 39 | import android.location.IGpsStatusProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.location.ILocationListener; |
| 41 | import android.location.ILocationManager; |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 42 | import android.location.INetInitiatedListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.location.Location; |
| 44 | import android.location.LocationManager; |
| 45 | import android.location.LocationProvider; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 46 | import android.location.LocationRequest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.Binder; |
| 48 | import android.os.Bundle; |
| 49 | import android.os.Handler; |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 50 | import android.os.HandlerThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.os.IBinder; |
Mike Lockwood | 3d12b51 | 2009-04-21 23:25:35 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.Message; |
| 54 | import android.os.PowerManager; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 55 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 57 | import android.os.SystemClock; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 58 | import android.os.UserHandle; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 59 | import android.os.WorkSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 62 | import android.util.Slog; |
Mike Lockwood | e97ae40 | 2010-09-29 15:23:46 -0400 | [diff] [blame] | 63 | import com.android.internal.content.PackageMonitor; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 64 | import com.android.internal.location.ProviderProperties; |
| 65 | import com.android.internal.location.ProviderRequest; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 66 | import com.android.server.location.GeocoderProxy; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame^] | 67 | import com.android.server.location.GeofenceProxy; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 68 | import com.android.server.location.GeofenceManager; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 69 | import com.android.server.location.GpsLocationProvider; |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 70 | import com.android.server.location.LocationBlacklist; |
Nick Pelly | 74fa7ea | 2012-08-13 19:36:38 -0700 | [diff] [blame] | 71 | import com.android.server.location.LocationFudger; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 72 | import com.android.server.location.LocationProviderInterface; |
| 73 | import com.android.server.location.LocationProviderProxy; |
| 74 | import com.android.server.location.MockProvider; |
| 75 | import com.android.server.location.PassiveProvider; |
| 76 | |
| 77 | import java.io.FileDescriptor; |
| 78 | import java.io.PrintWriter; |
| 79 | import java.util.ArrayList; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 80 | import java.util.Arrays; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 81 | import java.util.HashMap; |
| 82 | import java.util.HashSet; |
| 83 | import java.util.List; |
| 84 | import java.util.Map; |
Mike Lockwood | 43e33f2 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 85 | import java.util.Set; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * The service class that manages LocationProviders and issues location |
| 89 | * updates and alerts. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | */ |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 91 | public class LocationManagerService extends ILocationManager.Stub { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | private static final String TAG = "LocationManagerService"; |
JP Abgrall | f79811e7 | 2013-02-01 18:45:05 -0800 | [diff] [blame] | 93 | public static final boolean D = Log.isLoggable(TAG, Log.DEBUG); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 94 | |
| 95 | private static final String WAKELOCK_KEY = TAG; |
| 96 | private static final String THREAD_NAME = TAG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 98 | // Location resolution level: no location data whatsoever |
| 99 | private static final int RESOLUTION_LEVEL_NONE = 0; |
| 100 | // Location resolution level: coarse location data only |
| 101 | private static final int RESOLUTION_LEVEL_COARSE = 1; |
| 102 | // Location resolution level: fine location data |
| 103 | private static final int RESOLUTION_LEVEL_FINE = 2; |
| 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | private static final String ACCESS_MOCK_LOCATION = |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 106 | android.Manifest.permission.ACCESS_MOCK_LOCATION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | private static final String ACCESS_LOCATION_EXTRA_COMMANDS = |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 108 | android.Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS; |
Mike Lockwood | 275555c | 2009-05-01 11:30:34 -0400 | [diff] [blame] | 109 | private static final String INSTALL_LOCATION_PROVIDER = |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 110 | android.Manifest.permission.INSTALL_LOCATION_PROVIDER; |
| 111 | |
| 112 | private static final String NETWORK_LOCATION_SERVICE_ACTION = |
| 113 | "com.android.location.service.v2.NetworkLocationProvider"; |
| 114 | private static final String FUSED_LOCATION_SERVICE_ACTION = |
| 115 | "com.android.location.service.FusedLocationProvider"; |
| 116 | |
| 117 | private static final int MSG_LOCATION_CHANGED = 1; |
| 118 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 119 | // Location Providers may sometimes deliver location updates |
| 120 | // slightly faster that requested - provide grace period so |
| 121 | // we don't unnecessarily filter events that are otherwise on |
| 122 | // time |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 123 | private static final int MAX_PROVIDER_SCHEDULING_JITTER_MS = 100; |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 124 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 125 | private static final LocationRequest DEFAULT_LOCATION_REQUEST = new LocationRequest(); |
| 126 | |
| 127 | private final Context mContext; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 128 | private final AppOpsManager mAppOps; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 129 | |
| 130 | // used internally for synchronization |
| 131 | private final Object mLock = new Object(); |
| 132 | |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 133 | // --- fields below are final after systemReady() --- |
Nick Pelly | 74fa7ea | 2012-08-13 19:36:38 -0700 | [diff] [blame] | 134 | private LocationFudger mLocationFudger; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 135 | private GeofenceManager mGeofenceManager; |
| 136 | private PowerManager.WakeLock mWakeLock; |
| 137 | private PackageManager mPackageManager; |
| 138 | private GeocoderProxy mGeocodeProvider; |
| 139 | private IGpsStatusProvider mGpsStatusProvider; |
| 140 | private INetInitiatedListener mNetInitiatedListener; |
| 141 | private LocationWorkerHandler mLocationHandler; |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 142 | private PassiveProvider mPassiveProvider; // track passive provider for special cases |
| 143 | private LocationBlacklist mBlacklist; |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 144 | private HandlerThread mHandlerThread; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 145 | |
| 146 | // --- fields below are protected by mWakeLock --- |
| 147 | private int mPendingBroadcasts; |
| 148 | |
| 149 | // --- fields below are protected by mLock --- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | // Set of providers that are explicitly enabled |
| 151 | private final Set<String> mEnabledProviders = new HashSet<String>(); |
| 152 | |
| 153 | // Set of providers that are explicitly disabled |
| 154 | private final Set<String> mDisabledProviders = new HashSet<String>(); |
| 155 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 156 | // Mock (test) providers |
| 157 | private final HashMap<String, MockProvider> mMockProviders = |
| 158 | new HashMap<String, MockProvider>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 160 | // all receivers |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 161 | private final HashMap<Object, Receiver> mReceivers = new HashMap<Object, Receiver>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 163 | // currently installed providers (with mocks replacing real providers) |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 164 | private final ArrayList<LocationProviderInterface> mProviders = |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 165 | new ArrayList<LocationProviderInterface>(); |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 166 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 167 | // real providers, saved here when mocked out |
| 168 | private final HashMap<String, LocationProviderInterface> mRealProviders = |
| 169 | new HashMap<String, LocationProviderInterface>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 171 | // mapping from provider name to provider |
| 172 | private final HashMap<String, LocationProviderInterface> mProvidersByName = |
| 173 | new HashMap<String, LocationProviderInterface>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 175 | // mapping from provider name to all its UpdateRecords |
| 176 | private final HashMap<String, ArrayList<UpdateRecord>> mRecordsByProvider = |
| 177 | new HashMap<String, ArrayList<UpdateRecord>>(); |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 178 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 179 | // mapping from provider name to last known location |
| 180 | private final HashMap<String, Location> mLastLocation = new HashMap<String, Location>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 182 | // all providers that operate over proxy, for authorizing incoming location |
| 183 | private final ArrayList<LocationProviderProxy> mProxyProviders = |
| 184 | new ArrayList<LocationProviderProxy>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 186 | // current active user on the device - other users are denied location data |
| 187 | private int mCurrentUserId = UserHandle.USER_OWNER; |
| 188 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 189 | public LocationManagerService(Context context) { |
| 190 | super(); |
| 191 | mContext = context; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 192 | mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 193 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 194 | if (D) Log.d(TAG, "Constructed"); |
| 195 | |
| 196 | // most startup is deferred until systemReady() |
| 197 | } |
| 198 | |
| 199 | public void systemReady() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 200 | synchronized (mLock) { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 201 | if (D) Log.d(TAG, "systemReady()"); |
Brian Muramatsu | bb95cb9 | 2012-08-29 10:43:21 -0700 | [diff] [blame] | 202 | |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 203 | // fetch package manager |
| 204 | mPackageManager = mContext.getPackageManager(); |
| 205 | |
| 206 | // prepare wake lock |
| 207 | PowerManager powerManager = |
| 208 | (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 209 | mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); |
| 210 | |
| 211 | // prepare worker thread |
| 212 | mHandlerThread = new HandlerThread(THREAD_NAME, Process.THREAD_PRIORITY_BACKGROUND); |
| 213 | mHandlerThread.start(); |
| 214 | mLocationHandler = new LocationWorkerHandler(mHandlerThread.getLooper()); |
| 215 | |
| 216 | // prepare mLocationHandler's dependents |
| 217 | mLocationFudger = new LocationFudger(mContext, mLocationHandler); |
| 218 | mBlacklist = new LocationBlacklist(mContext, mLocationHandler); |
| 219 | mBlacklist.init(); |
| 220 | mGeofenceManager = new GeofenceManager(mContext, mBlacklist); |
| 221 | |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 222 | // Monitor for app ops mode changes. |
| 223 | AppOpsManager.Callback callback = new AppOpsManager.Callback() { |
| 224 | public void opChanged(int op, String packageName) { |
| 225 | synchronized (mLock) { |
| 226 | applyAllProviderRequirementsLocked(); |
| 227 | } |
| 228 | } |
| 229 | }; |
| 230 | mAppOps.startWatchingMode(AppOpsManager.OP_COARSE_LOCATION, null, callback); |
| 231 | |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 232 | // prepare providers |
| 233 | loadProvidersLocked(); |
| 234 | updateProvidersLocked(); |
| 235 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 236 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 237 | // listen for settings changes |
Brian Muramatsu | bb95cb9 | 2012-08-29 10:43:21 -0700 | [diff] [blame] | 238 | mContext.getContentResolver().registerContentObserver( |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 239 | Settings.Secure.getUriFor(Settings.Secure.LOCATION_PROVIDERS_ALLOWED), true, |
Brian Muramatsu | bb95cb9 | 2012-08-29 10:43:21 -0700 | [diff] [blame] | 240 | new ContentObserver(mLocationHandler) { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 241 | @Override |
| 242 | public void onChange(boolean selfChange) { |
| 243 | synchronized (mLock) { |
| 244 | updateProvidersLocked(); |
| 245 | } |
| 246 | } |
| 247 | }, UserHandle.USER_ALL); |
| 248 | mPackageMonitor.register(mContext, mLocationHandler.getLooper(), true); |
Brian Muramatsu | bb95cb9 | 2012-08-29 10:43:21 -0700 | [diff] [blame] | 249 | |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 250 | // listen for user change |
| 251 | IntentFilter intentFilter = new IntentFilter(); |
| 252 | intentFilter.addAction(Intent.ACTION_USER_SWITCHED); |
| 253 | |
| 254 | mContext.registerReceiverAsUser(new BroadcastReceiver() { |
| 255 | @Override |
| 256 | public void onReceive(Context context, Intent intent) { |
| 257 | String action = intent.getAction(); |
| 258 | if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 259 | switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); |
| 260 | } |
| 261 | } |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 262 | }, UserHandle.ALL, intentFilter, null, mLocationHandler); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 265 | private void ensureFallbackFusedProviderPresentLocked(ArrayList<String> pkgs) { |
| 266 | PackageManager pm = mContext.getPackageManager(); |
| 267 | String systemPackageName = mContext.getPackageName(); |
| 268 | ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs); |
| 269 | |
| 270 | List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser( |
| 271 | new Intent(FUSED_LOCATION_SERVICE_ACTION), |
| 272 | PackageManager.GET_META_DATA, mCurrentUserId); |
| 273 | for (ResolveInfo rInfo : rInfos) { |
| 274 | String packageName = rInfo.serviceInfo.packageName; |
| 275 | |
| 276 | // Check that the signature is in the list of supported sigs. If it's not in |
| 277 | // this list the standard provider binding logic won't bind to it. |
| 278 | try { |
| 279 | PackageInfo pInfo; |
| 280 | pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); |
| 281 | if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) { |
| 282 | Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION + |
| 283 | ", but has wrong signature, ignoring"); |
| 284 | continue; |
| 285 | } |
| 286 | } catch (NameNotFoundException e) { |
| 287 | Log.e(TAG, "missing package: " + packageName); |
| 288 | continue; |
| 289 | } |
| 290 | |
| 291 | // Get the version info |
| 292 | if (rInfo.serviceInfo.metaData == null) { |
| 293 | Log.w(TAG, "Found fused provider without metadata: " + packageName); |
| 294 | continue; |
| 295 | } |
| 296 | |
| 297 | int version = rInfo.serviceInfo.metaData.getInt( |
| 298 | ServiceWatcher.EXTRA_SERVICE_VERSION, -1); |
| 299 | if (version == 0) { |
| 300 | // This should be the fallback fused location provider. |
| 301 | |
| 302 | // Make sure it's in the system partition. |
| 303 | if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { |
| 304 | if (D) Log.d(TAG, "Fallback candidate not in /system: " + packageName); |
| 305 | continue; |
| 306 | } |
| 307 | |
| 308 | // Check that the fallback is signed the same as the OS |
| 309 | // as a proxy for coreApp="true" |
| 310 | if (pm.checkSignatures(systemPackageName, packageName) |
| 311 | != PackageManager.SIGNATURE_MATCH) { |
| 312 | if (D) Log.d(TAG, "Fallback candidate not signed the same as system: " |
| 313 | + packageName); |
| 314 | continue; |
| 315 | } |
| 316 | |
| 317 | // Found a valid fallback. |
| 318 | if (D) Log.d(TAG, "Found fallback provider: " + packageName); |
| 319 | return; |
| 320 | } else { |
| 321 | if (D) Log.d(TAG, "Fallback candidate not version 0: " + packageName); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | throw new IllegalStateException("Unable to find a fused location provider that is in the " |
| 326 | + "system partition with version 0 and signed with the platform certificate. " |
| 327 | + "Such a package is needed to provide a default fused location provider in the " |
| 328 | + "event that no other fused location provider has been installed or is currently " |
| 329 | + "available. For example, coreOnly boot mode when decrypting the data " |
| 330 | + "partition. The fallback must also be marked coreApp=\"true\" in the manifest"); |
| 331 | } |
| 332 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 333 | private void loadProvidersLocked() { |
Victoria Lease | 5c24fd0 | 2012-10-01 11:00:50 -0700 | [diff] [blame] | 334 | // create a passive location provider, which is always enabled |
| 335 | PassiveProvider passiveProvider = new PassiveProvider(this); |
| 336 | addProviderLocked(passiveProvider); |
| 337 | mEnabledProviders.add(passiveProvider.getName()); |
| 338 | mPassiveProvider = passiveProvider; |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame^] | 339 | // Create a gps location provider |
| 340 | GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this, |
| 341 | mLocationHandler.getLooper()); |
Victoria Lease | 5c24fd0 | 2012-10-01 11:00:50 -0700 | [diff] [blame] | 342 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 343 | if (GpsLocationProvider.isSupported()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 344 | mGpsStatusProvider = gpsProvider.getGpsStatusProvider(); |
| 345 | mNetInitiatedListener = gpsProvider.getNetInitiatedListener(); |
| 346 | addProviderLocked(gpsProvider); |
| 347 | mRealProviders.put(LocationManager.GPS_PROVIDER, gpsProvider); |
| 348 | } |
| 349 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 350 | /* |
| 351 | Load package name(s) containing location provider support. |
| 352 | These packages can contain services implementing location providers: |
| 353 | Geocoder Provider, Network Location Provider, and |
| 354 | Fused Location Provider. They will each be searched for |
| 355 | service components implementing these providers. |
| 356 | The location framework also has support for installation |
| 357 | of new location providers at run-time. The new package does not |
| 358 | have to be explicitly listed here, however it must have a signature |
| 359 | that matches the signature of at least one package on this list. |
| 360 | */ |
| 361 | Resources resources = mContext.getResources(); |
| 362 | ArrayList<String> providerPackageNames = new ArrayList<String>(); |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 363 | String[] pkgs = resources.getStringArray( |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 364 | com.android.internal.R.array.config_locationProviderPackageNames); |
Jeff Hamilton | fbadb69 | 2012-10-05 14:21:58 -0500 | [diff] [blame] | 365 | if (D) Log.d(TAG, "certificates for location providers pulled from: " + |
| 366 | Arrays.toString(pkgs)); |
| 367 | if (pkgs != null) providerPackageNames.addAll(Arrays.asList(pkgs)); |
| 368 | |
| 369 | ensureFallbackFusedProviderPresentLocked(providerPackageNames); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 370 | |
| 371 | // bind to network provider |
| 372 | LocationProviderProxy networkProvider = LocationProviderProxy.createAndBind( |
| 373 | mContext, |
| 374 | LocationManager.NETWORK_PROVIDER, |
| 375 | NETWORK_LOCATION_SERVICE_ACTION, |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 376 | providerPackageNames, mLocationHandler); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 377 | if (networkProvider != null) { |
| 378 | mRealProviders.put(LocationManager.NETWORK_PROVIDER, networkProvider); |
| 379 | mProxyProviders.add(networkProvider); |
| 380 | addProviderLocked(networkProvider); |
| 381 | } else { |
| 382 | Slog.w(TAG, "no network location provider found"); |
| 383 | } |
| 384 | |
| 385 | // bind to fused provider |
| 386 | LocationProviderProxy fusedLocationProvider = LocationProviderProxy.createAndBind( |
| 387 | mContext, |
| 388 | LocationManager.FUSED_PROVIDER, |
| 389 | FUSED_LOCATION_SERVICE_ACTION, |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 390 | providerPackageNames, mLocationHandler); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 391 | if (fusedLocationProvider != null) { |
| 392 | addProviderLocked(fusedLocationProvider); |
| 393 | mProxyProviders.add(fusedLocationProvider); |
| 394 | mEnabledProviders.add(fusedLocationProvider.getName()); |
Kenny Root | c357518 | 2012-10-09 12:44:40 -0700 | [diff] [blame] | 395 | mRealProviders.put(LocationManager.FUSED_PROVIDER, fusedLocationProvider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 396 | } else { |
| 397 | Slog.e(TAG, "no fused location provider found", |
| 398 | new IllegalStateException("Location service needs a fused location provider")); |
| 399 | } |
| 400 | |
| 401 | // bind to geocoder provider |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 402 | mGeocodeProvider = GeocoderProxy.createAndBind(mContext, providerPackageNames, |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 403 | mLocationHandler); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 404 | if (mGeocodeProvider == null) { |
| 405 | Slog.e(TAG, "no geocoder provider found"); |
| 406 | } |
Jaikumar Ganesh | 8ce470d | 2013-04-03 12:22:18 -0700 | [diff] [blame^] | 407 | |
| 408 | // bind to geofence provider |
| 409 | GeofenceProxy provider = GeofenceProxy.createAndBind(mContext, providerPackageNames, |
| 410 | mLocationHandler, gpsProvider.getGpsGeofenceProxy()); |
| 411 | if (provider == null) { |
| 412 | Slog.e(TAG, "no geofence provider found"); |
| 413 | } |
| 414 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 415 | } |
Mike Lockwood | 9637d47 | 2009-04-02 21:41:57 -0700 | [diff] [blame] | 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | /** |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 418 | * Called when the device's active user changes. |
| 419 | * @param userId the new active user's UserId |
| 420 | */ |
| 421 | private void switchUser(int userId) { |
Victoria Lease | 83762d2 | 2012-10-03 13:51:17 -0700 | [diff] [blame] | 422 | mBlacklist.switchUser(userId); |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 423 | mLocationHandler.removeMessages(MSG_LOCATION_CHANGED); |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 424 | synchronized (mLock) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 425 | mLastLocation.clear(); |
| 426 | for (LocationProviderInterface p : mProviders) { |
| 427 | updateProviderListenersLocked(p.getName(), false, mCurrentUserId); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 428 | } |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 429 | mCurrentUserId = userId; |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 430 | updateProvidersLocked(); |
Victoria Lease | 38389b6 | 2012-09-30 11:44:22 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
| 434 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | * A wrapper class holding either an ILocationListener or a PendingIntent to receive |
| 436 | * location updates. |
| 437 | */ |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 438 | private final class Receiver implements IBinder.DeathRecipient, PendingIntent.OnFinished { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 439 | final int mUid; // uid of receiver |
| 440 | final int mPid; // pid of receiver |
| 441 | final String mPackageName; // package name of receiver |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 442 | final int mAllowedResolutionLevel; // resolution level allowed to receiver |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | final ILocationListener mListener; |
| 445 | final PendingIntent mPendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | final Object mKey; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 447 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 448 | final HashMap<String,UpdateRecord> mUpdateRecords = new HashMap<String,UpdateRecord>(); |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 449 | |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 450 | int mPendingBroadcasts; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 452 | Receiver(ILocationListener listener, PendingIntent intent, int pid, int uid, |
| 453 | String packageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | mListener = listener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | mPendingIntent = intent; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 456 | if (listener != null) { |
| 457 | mKey = listener.asBinder(); |
| 458 | } else { |
| 459 | mKey = intent; |
| 460 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 461 | mAllowedResolutionLevel = getAllowedResolutionLevel(pid, uid); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 462 | mUid = uid; |
| 463 | mPid = pid; |
| 464 | mPackageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public boolean equals(Object otherObj) { |
| 469 | if (otherObj instanceof Receiver) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 470 | return mKey.equals(((Receiver)otherObj).mKey); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | } |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public int hashCode() { |
| 477 | return mKey.hashCode(); |
| 478 | } |
Mike Lockwood | 3681f26 | 2009-05-12 10:52:03 -0400 | [diff] [blame] | 479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | @Override |
| 481 | public String toString() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 482 | StringBuilder s = new StringBuilder(); |
| 483 | s.append("Reciever["); |
| 484 | s.append(Integer.toHexString(System.identityHashCode(this))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | if (mListener != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 486 | s.append(" listener"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | } else { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 488 | s.append(" intent"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 490 | for (String p : mUpdateRecords.keySet()) { |
| 491 | s.append(" ").append(mUpdateRecords.get(p).toString()); |
| 492 | } |
| 493 | s.append("]"); |
| 494 | return s.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | public boolean isListener() { |
| 498 | return mListener != null; |
| 499 | } |
| 500 | |
| 501 | public boolean isPendingIntent() { |
| 502 | return mPendingIntent != null; |
| 503 | } |
| 504 | |
| 505 | public ILocationListener getListener() { |
| 506 | if (mListener != null) { |
| 507 | return mListener; |
| 508 | } |
| 509 | throw new IllegalStateException("Request for non-existent listener"); |
| 510 | } |
| 511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | public boolean callStatusChangedLocked(String provider, int status, Bundle extras) { |
| 513 | if (mListener != null) { |
| 514 | try { |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 515 | synchronized (this) { |
| 516 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 517 | // is called before decrementPendingBroadcasts() |
| 518 | mListener.onStatusChanged(provider, status, extras); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 519 | // call this after broadcasting so we do not increment |
| 520 | // if we throw an exeption. |
| 521 | incrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 522 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | } catch (RemoteException e) { |
| 524 | return false; |
| 525 | } |
| 526 | } else { |
| 527 | Intent statusChanged = new Intent(); |
Victoria Lease | 61ecb02 | 2012-11-13 15:12:51 -0800 | [diff] [blame] | 528 | statusChanged.putExtras(new Bundle(extras)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | statusChanged.putExtra(LocationManager.KEY_STATUS_CHANGED, status); |
| 530 | try { |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 531 | synchronized (this) { |
| 532 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 533 | // is called before decrementPendingBroadcasts() |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 534 | mPendingIntent.send(mContext, 0, statusChanged, this, mLocationHandler, |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 535 | getResolutionPermission(mAllowedResolutionLevel)); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 536 | // call this after broadcasting so we do not increment |
| 537 | // if we throw an exeption. |
| 538 | incrementPendingBroadcastsLocked(); |
| 539 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | } catch (PendingIntent.CanceledException e) { |
| 541 | return false; |
| 542 | } |
| 543 | } |
| 544 | return true; |
| 545 | } |
| 546 | |
| 547 | public boolean callLocationChangedLocked(Location location) { |
| 548 | if (mListener != null) { |
| 549 | try { |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 550 | synchronized (this) { |
| 551 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 552 | // is called before decrementPendingBroadcasts() |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 553 | mListener.onLocationChanged(new Location(location)); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 554 | // call this after broadcasting so we do not increment |
| 555 | // if we throw an exeption. |
| 556 | incrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | } catch (RemoteException e) { |
| 559 | return false; |
| 560 | } |
| 561 | } else { |
| 562 | Intent locationChanged = new Intent(); |
Victoria Lease | 61ecb02 | 2012-11-13 15:12:51 -0800 | [diff] [blame] | 563 | locationChanged.putExtra(LocationManager.KEY_LOCATION_CHANGED, new Location(location)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | try { |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 565 | synchronized (this) { |
| 566 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 567 | // is called before decrementPendingBroadcasts() |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 568 | mPendingIntent.send(mContext, 0, locationChanged, this, mLocationHandler, |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 569 | getResolutionPermission(mAllowedResolutionLevel)); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 570 | // call this after broadcasting so we do not increment |
| 571 | // if we throw an exeption. |
| 572 | incrementPendingBroadcastsLocked(); |
| 573 | } |
| 574 | } catch (PendingIntent.CanceledException e) { |
| 575 | return false; |
| 576 | } |
| 577 | } |
| 578 | return true; |
| 579 | } |
| 580 | |
| 581 | public boolean callProviderEnabledLocked(String provider, boolean enabled) { |
| 582 | if (mListener != null) { |
| 583 | try { |
| 584 | synchronized (this) { |
| 585 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 586 | // is called before decrementPendingBroadcasts() |
| 587 | if (enabled) { |
| 588 | mListener.onProviderEnabled(provider); |
| 589 | } else { |
| 590 | mListener.onProviderDisabled(provider); |
| 591 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 592 | // call this after broadcasting so we do not increment |
| 593 | // if we throw an exeption. |
| 594 | incrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 595 | } |
| 596 | } catch (RemoteException e) { |
| 597 | return false; |
| 598 | } |
| 599 | } else { |
| 600 | Intent providerIntent = new Intent(); |
| 601 | providerIntent.putExtra(LocationManager.KEY_PROVIDER_ENABLED, enabled); |
| 602 | try { |
| 603 | synchronized (this) { |
| 604 | // synchronize to ensure incrementPendingBroadcastsLocked() |
| 605 | // is called before decrementPendingBroadcasts() |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 606 | mPendingIntent.send(mContext, 0, providerIntent, this, mLocationHandler, |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 607 | getResolutionPermission(mAllowedResolutionLevel)); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 608 | // call this after broadcasting so we do not increment |
| 609 | // if we throw an exeption. |
| 610 | incrementPendingBroadcastsLocked(); |
| 611 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | } catch (PendingIntent.CanceledException e) { |
| 613 | return false; |
| 614 | } |
| 615 | } |
| 616 | return true; |
| 617 | } |
| 618 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 619 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | public void binderDied() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 621 | if (D) Log.d(TAG, "Location listener died"); |
| 622 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 623 | synchronized (mLock) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | removeUpdatesLocked(this); |
| 625 | } |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 626 | synchronized (this) { |
| 627 | if (mPendingBroadcasts > 0) { |
| 628 | LocationManagerService.this.decrementPendingBroadcasts(); |
| 629 | mPendingBroadcasts = 0; |
| 630 | } |
| 631 | } |
| 632 | } |
| 633 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 634 | @Override |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 635 | public void onSendFinished(PendingIntent pendingIntent, Intent intent, |
| 636 | int resultCode, String resultData, Bundle resultExtras) { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 637 | synchronized (this) { |
| 638 | decrementPendingBroadcastsLocked(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 642 | // this must be called while synchronized by caller in a synchronized block |
| 643 | // containing the sending of the broadcaset |
| 644 | private void incrementPendingBroadcastsLocked() { |
| 645 | if (mPendingBroadcasts++ == 0) { |
| 646 | LocationManagerService.this.incrementPendingBroadcasts(); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | private void decrementPendingBroadcastsLocked() { |
| 651 | if (--mPendingBroadcasts == 0) { |
| 652 | LocationManagerService.this.decrementPendingBroadcasts(); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 657 | @Override |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 658 | public void locationCallbackFinished(ILocationListener listener) { |
Joshua Bartel | 080b61b | 2009-10-05 12:44:46 -0400 | [diff] [blame] | 659 | //Do not use getReceiver here as that will add the ILocationListener to |
| 660 | //the receiver list if it is not found. If it is not found then the |
| 661 | //LocationListener was removed when it had a pending broadcast and should |
| 662 | //not be added back. |
| 663 | IBinder binder = listener.asBinder(); |
| 664 | Receiver receiver = mReceivers.get(binder); |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 665 | if (receiver != null) { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 666 | synchronized (receiver) { |
| 667 | // so wakelock calls will succeed |
| 668 | long identity = Binder.clearCallingIdentity(); |
| 669 | receiver.decrementPendingBroadcastsLocked(); |
| 670 | Binder.restoreCallingIdentity(identity); |
| 671 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 675 | private void addProviderLocked(LocationProviderInterface provider) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 676 | mProviders.add(provider); |
| 677 | mProvidersByName.put(provider.getName(), provider); |
| 678 | } |
| 679 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 680 | private void removeProviderLocked(LocationProviderInterface provider) { |
| 681 | provider.disable(); |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 682 | mProviders.remove(provider); |
| 683 | mProvidersByName.remove(provider.getName()); |
| 684 | } |
| 685 | |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 686 | /** |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 687 | * Returns "true" if access to the specified location provider is allowed by the current |
| 688 | * user's settings. Access to all location providers is forbidden to non-location-provider |
| 689 | * processes belonging to background users. |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 690 | * |
| 691 | * @param provider the name of the location provider |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 692 | * @return |
| 693 | */ |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 694 | private boolean isAllowedByCurrentUserSettingsLocked(String provider) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | if (mEnabledProviders.contains(provider)) { |
| 696 | return true; |
| 697 | } |
| 698 | if (mDisabledProviders.contains(provider)) { |
| 699 | return false; |
| 700 | } |
| 701 | // Use system settings |
| 702 | ContentResolver resolver = mContext.getContentResolver(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 704 | return Settings.Secure.isLocationProviderEnabledForUser(resolver, provider, mCurrentUserId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 707 | /** |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 708 | * Returns "true" if access to the specified location provider is allowed by the specified |
| 709 | * user's settings. Access to all location providers is forbidden to non-location-provider |
| 710 | * processes belonging to background users. |
| 711 | * |
| 712 | * @param provider the name of the location provider |
| 713 | * @param uid the requestor's UID |
| 714 | * @return |
| 715 | */ |
| 716 | private boolean isAllowedByUserSettingsLocked(String provider, int uid) { |
| 717 | if (UserHandle.getUserId(uid) != mCurrentUserId && !isUidALocationProvider(uid)) { |
| 718 | return false; |
| 719 | } |
| 720 | return isAllowedByCurrentUserSettingsLocked(provider); |
| 721 | } |
| 722 | |
| 723 | /** |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 724 | * Returns the permission string associated with the specified resolution level. |
| 725 | * |
| 726 | * @param resolutionLevel the resolution level |
| 727 | * @return the permission string |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 728 | */ |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 729 | private String getResolutionPermission(int resolutionLevel) { |
| 730 | switch (resolutionLevel) { |
| 731 | case RESOLUTION_LEVEL_FINE: |
| 732 | return android.Manifest.permission.ACCESS_FINE_LOCATION; |
| 733 | case RESOLUTION_LEVEL_COARSE: |
| 734 | return android.Manifest.permission.ACCESS_COARSE_LOCATION; |
| 735 | default: |
| 736 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | } |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 738 | } |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 739 | |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 740 | /** |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 741 | * Returns the resolution level allowed to the given PID/UID pair. |
| 742 | * |
| 743 | * @param pid the PID |
| 744 | * @param uid the UID |
| 745 | * @return resolution level allowed to the pid/uid pair |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 746 | */ |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 747 | private int getAllowedResolutionLevel(int pid, int uid) { |
| 748 | if (mContext.checkPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 749 | pid, uid) == PackageManager.PERMISSION_GRANTED) { |
| 750 | return RESOLUTION_LEVEL_FINE; |
| 751 | } else if (mContext.checkPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 752 | pid, uid) == PackageManager.PERMISSION_GRANTED) { |
| 753 | return RESOLUTION_LEVEL_COARSE; |
| 754 | } else { |
| 755 | return RESOLUTION_LEVEL_NONE; |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 756 | } |
Victoria Lease | 4fab68b | 2012-09-13 13:20:59 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | /** |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 760 | * Returns the resolution level allowed to the caller |
| 761 | * |
| 762 | * @return resolution level allowed to caller |
Victoria Lease | 4fab68b | 2012-09-13 13:20:59 -0700 | [diff] [blame] | 763 | */ |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 764 | private int getCallerAllowedResolutionLevel() { |
| 765 | return getAllowedResolutionLevel(Binder.getCallingPid(), Binder.getCallingUid()); |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Throw SecurityException if specified resolution level is insufficient to use geofences. |
| 770 | * |
| 771 | * @param allowedResolutionLevel resolution level allowed to caller |
| 772 | */ |
| 773 | private void checkResolutionLevelIsSufficientForGeofenceUse(int allowedResolutionLevel) { |
| 774 | if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
Victoria Lease | 4fab68b | 2012-09-13 13:20:59 -0700 | [diff] [blame] | 775 | throw new SecurityException("Geofence usage requires ACCESS_FINE_LOCATION permission"); |
| 776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 779 | /** |
| 780 | * Return the minimum resolution level required to use the specified location provider. |
| 781 | * |
| 782 | * @param provider the name of the location provider |
| 783 | * @return minimum resolution level required for provider |
| 784 | */ |
| 785 | private int getMinimumResolutionLevelForProviderUse(String provider) { |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 786 | if (LocationManager.GPS_PROVIDER.equals(provider) || |
| 787 | LocationManager.PASSIVE_PROVIDER.equals(provider)) { |
| 788 | // gps and passive providers require FINE permission |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 789 | return RESOLUTION_LEVEL_FINE; |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 790 | } else if (LocationManager.NETWORK_PROVIDER.equals(provider) || |
| 791 | LocationManager.FUSED_PROVIDER.equals(provider)) { |
| 792 | // network and fused providers are ok with COARSE or FINE |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 793 | return RESOLUTION_LEVEL_COARSE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 794 | } else { |
| 795 | // mock providers |
| 796 | LocationProviderInterface lp = mMockProviders.get(provider); |
| 797 | if (lp != null) { |
| 798 | ProviderProperties properties = lp.getProperties(); |
| 799 | if (properties != null) { |
| 800 | if (properties.mRequiresSatellite) { |
| 801 | // provider requiring satellites require FINE permission |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 802 | return RESOLUTION_LEVEL_FINE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 803 | } else if (properties.mRequiresNetwork || properties.mRequiresCell) { |
| 804 | // provider requiring network and or cell require COARSE or FINE |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 805 | return RESOLUTION_LEVEL_COARSE; |
Laurent Tu | 941221c | 2012-10-04 14:21:52 -0700 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | } |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 809 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 810 | return RESOLUTION_LEVEL_FINE; // if in doubt, require FINE |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 813 | /** |
| 814 | * Throw SecurityException if specified resolution level is insufficient to use the named |
| 815 | * location provider. |
| 816 | * |
| 817 | * @param allowedResolutionLevel resolution level allowed to caller |
| 818 | * @param providerName the name of the location provider |
| 819 | */ |
| 820 | private void checkResolutionLevelIsSufficientForProviderUse(int allowedResolutionLevel, |
| 821 | String providerName) { |
| 822 | int requiredResolutionLevel = getMinimumResolutionLevelForProviderUse(providerName); |
| 823 | if (allowedResolutionLevel < requiredResolutionLevel) { |
| 824 | switch (requiredResolutionLevel) { |
| 825 | case RESOLUTION_LEVEL_FINE: |
| 826 | throw new SecurityException("\"" + providerName + "\" location provider " + |
| 827 | "requires ACCESS_FINE_LOCATION permission."); |
| 828 | case RESOLUTION_LEVEL_COARSE: |
| 829 | throw new SecurityException("\"" + providerName + "\" location provider " + |
| 830 | "requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission."); |
| 831 | default: |
| 832 | throw new SecurityException("Insufficient permission for \"" + providerName + |
| 833 | "\" location provider."); |
Victoria Lease | da479c5 | 2012-10-15 15:24:16 -0700 | [diff] [blame] | 834 | } |
| 835 | } |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 838 | public static int resolutionLevelToOp(int allowedResolutionLevel) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 839 | if (allowedResolutionLevel != RESOLUTION_LEVEL_NONE) { |
| 840 | if (allowedResolutionLevel == RESOLUTION_LEVEL_COARSE) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 841 | return AppOpsManager.OP_COARSE_LOCATION; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 842 | } else { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 843 | return AppOpsManager.OP_FINE_LOCATION; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 844 | } |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 845 | } |
| 846 | return -1; |
| 847 | } |
| 848 | |
| 849 | boolean reportLocationAccessNoThrow(int uid, String packageName, int allowedResolutionLevel) { |
| 850 | int op = resolutionLevelToOp(allowedResolutionLevel); |
| 851 | if (op >= 0) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 852 | if (mAppOps.noteOpNoThrow(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) { |
| 853 | return false; |
| 854 | } |
| 855 | } |
| 856 | return true; |
| 857 | } |
| 858 | |
| 859 | boolean checkLocationAccess(int uid, String packageName, int allowedResolutionLevel) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 860 | int op = resolutionLevelToOp(allowedResolutionLevel); |
| 861 | if (op >= 0) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 862 | if (mAppOps.checkOp(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) { |
| 863 | return false; |
| 864 | } |
| 865 | } |
| 866 | return true; |
| 867 | } |
| 868 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 869 | /** |
| 870 | * Returns all providers by name, including passive, but excluding |
Laurent Tu | 0d21e21 | 2012-10-02 15:33:48 -0700 | [diff] [blame] | 871 | * fused, also including ones that are not permitted to |
| 872 | * be accessed by the calling activity or are currently disabled. |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 873 | */ |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 874 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | public List<String> getAllProviders() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 876 | ArrayList<String> out; |
| 877 | synchronized (mLock) { |
| 878 | out = new ArrayList<String>(mProviders.size()); |
| 879 | for (LocationProviderInterface provider : mProviders) { |
| 880 | String name = provider.getName(); |
| 881 | if (LocationManager.FUSED_PROVIDER.equals(name)) { |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 882 | continue; |
| 883 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | out.add(name); |
| 885 | } |
| 886 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 887 | |
| 888 | if (D) Log.d(TAG, "getAllProviders()=" + out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | return out; |
| 890 | } |
| 891 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 892 | /** |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 893 | * Return all providers by name, that match criteria and are optionally |
| 894 | * enabled. |
| 895 | * Can return passive provider, but never returns fused provider. |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 896 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 897 | @Override |
| 898 | public List<String> getProviders(Criteria criteria, boolean enabledOnly) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 899 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 900 | ArrayList<String> out; |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 901 | int uid = Binder.getCallingUid();; |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 902 | long identity = Binder.clearCallingIdentity(); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 903 | try { |
| 904 | synchronized (mLock) { |
| 905 | out = new ArrayList<String>(mProviders.size()); |
| 906 | for (LocationProviderInterface provider : mProviders) { |
| 907 | String name = provider.getName(); |
| 908 | if (LocationManager.FUSED_PROVIDER.equals(name)) { |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 909 | continue; |
| 910 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 911 | if (allowedResolutionLevel >= getMinimumResolutionLevelForProviderUse(name)) { |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 912 | if (enabledOnly && !isAllowedByUserSettingsLocked(name, uid)) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 913 | continue; |
| 914 | } |
| 915 | if (criteria != null && !LocationProvider.propertiesMeetCriteria( |
| 916 | name, provider.getProperties(), criteria)) { |
| 917 | continue; |
| 918 | } |
| 919 | out.add(name); |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 920 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 921 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 922 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 923 | } finally { |
| 924 | Binder.restoreCallingIdentity(identity); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 925 | } |
| 926 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 927 | if (D) Log.d(TAG, "getProviders()=" + out); |
| 928 | return out; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /** |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 932 | * Return the name of the best provider given a Criteria object. |
| 933 | * This method has been deprecated from the public API, |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 934 | * and the whole LocationProvider (including #meetsCriteria) |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 935 | * has been deprecated as well. So this method now uses |
| 936 | * some simplified logic. |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 937 | */ |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 938 | @Override |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 939 | public String getBestProvider(Criteria criteria, boolean enabledOnly) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 940 | String result = null; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 941 | |
| 942 | List<String> providers = getProviders(criteria, enabledOnly); |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 943 | if (!providers.isEmpty()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 944 | result = pickBest(providers); |
| 945 | if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); |
| 946 | return result; |
| 947 | } |
| 948 | providers = getProviders(null, enabledOnly); |
Victoria Lease | 8dbb634 | 2012-09-21 16:55:53 -0700 | [diff] [blame] | 949 | if (!providers.isEmpty()) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 950 | result = pickBest(providers); |
| 951 | if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); |
| 952 | return result; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 955 | if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 956 | return null; |
| 957 | } |
| 958 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 959 | private String pickBest(List<String> providers) { |
Victoria Lease | 1925e29 | 2012-09-24 17:00:18 -0700 | [diff] [blame] | 960 | if (providers.contains(LocationManager.GPS_PROVIDER)) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 961 | return LocationManager.GPS_PROVIDER; |
Victoria Lease | 1925e29 | 2012-09-24 17:00:18 -0700 | [diff] [blame] | 962 | } else if (providers.contains(LocationManager.NETWORK_PROVIDER)) { |
| 963 | return LocationManager.NETWORK_PROVIDER; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 964 | } else { |
| 965 | return providers.get(0); |
| 966 | } |
| 967 | } |
| 968 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 969 | @Override |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 970 | public boolean providerMeetsCriteria(String provider, Criteria criteria) { |
| 971 | LocationProviderInterface p = mProvidersByName.get(provider); |
| 972 | if (p == null) { |
| 973 | throw new IllegalArgumentException("provider=" + provider); |
| 974 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 975 | |
| 976 | boolean result = LocationProvider.propertiesMeetCriteria( |
| 977 | p.getName(), p.getProperties(), criteria); |
| 978 | if (D) Log.d(TAG, "providerMeetsCriteria(" + provider + ", " + criteria + ")=" + result); |
| 979 | return result; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 980 | } |
| 981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | private void updateProvidersLocked() { |
Brad Fitzpatrick | 0c5a040 | 2010-08-27 14:01:23 -0700 | [diff] [blame] | 983 | boolean changesMade = false; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 984 | for (int i = mProviders.size() - 1; i >= 0; i--) { |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 985 | LocationProviderInterface p = mProviders.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | boolean isEnabled = p.isEnabled(); |
| 987 | String name = p.getName(); |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 988 | boolean shouldBeEnabled = isAllowedByCurrentUserSettingsLocked(name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 989 | if (isEnabled && !shouldBeEnabled) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 990 | updateProviderListenersLocked(name, false, mCurrentUserId); |
Brad Fitzpatrick | 0c5a040 | 2010-08-27 14:01:23 -0700 | [diff] [blame] | 991 | changesMade = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | } else if (!isEnabled && shouldBeEnabled) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 993 | updateProviderListenersLocked(name, true, mCurrentUserId); |
Brad Fitzpatrick | 0c5a040 | 2010-08-27 14:01:23 -0700 | [diff] [blame] | 994 | changesMade = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | } |
Brad Fitzpatrick | 0c5a040 | 2010-08-27 14:01:23 -0700 | [diff] [blame] | 996 | } |
| 997 | if (changesMade) { |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 998 | mContext.sendBroadcastAsUser(new Intent(LocationManager.PROVIDERS_CHANGED_ACTION), |
| 999 | UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1003 | private void updateProviderListenersLocked(String provider, boolean enabled, int userId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | int listeners = 0; |
| 1005 | |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1006 | LocationProviderInterface p = mProvidersByName.get(provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1007 | if (p == null) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | |
| 1009 | ArrayList<Receiver> deadReceivers = null; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); |
| 1012 | if (records != null) { |
| 1013 | final int N = records.size(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1014 | for (int i = 0; i < N; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | UpdateRecord record = records.get(i); |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1016 | if (UserHandle.getUserId(record.mReceiver.mUid) == userId) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1017 | // Sends a notification message to the receiver |
| 1018 | if (!record.mReceiver.callProviderEnabledLocked(provider, enabled)) { |
| 1019 | if (deadReceivers == null) { |
| 1020 | deadReceivers = new ArrayList<Receiver>(); |
| 1021 | } |
| 1022 | deadReceivers.add(record.mReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1024 | listeners++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | if (deadReceivers != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1030 | for (int i = deadReceivers.size() - 1; i >= 0; i--) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | removeUpdatesLocked(deadReceivers.get(i)); |
| 1032 | } |
| 1033 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | if (enabled) { |
| 1036 | p.enable(); |
| 1037 | if (listeners > 0) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1038 | applyRequirementsLocked(provider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } |
| 1040 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | p.disable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1045 | private void applyRequirementsLocked(String provider) { |
| 1046 | LocationProviderInterface p = mProvidersByName.get(provider); |
| 1047 | if (p == null) return; |
| 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1050 | WorkSource worksource = new WorkSource(); |
| 1051 | ProviderRequest providerRequest = new ProviderRequest(); |
| 1052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | if (records != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1054 | for (UpdateRecord record : records) { |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1055 | if (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1056 | if (checkLocationAccess(record.mReceiver.mUid, record.mReceiver.mPackageName, |
| 1057 | record.mReceiver.mAllowedResolutionLevel)) { |
| 1058 | LocationRequest locationRequest = record.mRequest; |
| 1059 | providerRequest.locationRequests.add(locationRequest); |
| 1060 | if (locationRequest.getInterval() < providerRequest.interval) { |
| 1061 | providerRequest.reportLocation = true; |
| 1062 | providerRequest.interval = locationRequest.getInterval(); |
| 1063 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1064 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1065 | } |
| 1066 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1067 | |
| 1068 | if (providerRequest.reportLocation) { |
| 1069 | // calculate who to blame for power |
| 1070 | // This is somewhat arbitrary. We pick a threshold interval |
| 1071 | // that is slightly higher that the minimum interval, and |
| 1072 | // spread the blame across all applications with a request |
| 1073 | // under that threshold. |
| 1074 | long thresholdInterval = (providerRequest.interval + 1000) * 3 / 2; |
| 1075 | for (UpdateRecord record : records) { |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1076 | if (UserHandle.getUserId(record.mReceiver.mUid) == mCurrentUserId) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1077 | LocationRequest locationRequest = record.mRequest; |
| 1078 | if (locationRequest.getInterval() <= thresholdInterval) { |
Dianne Hackborn | 002a54e | 2013-01-10 17:34:55 -0800 | [diff] [blame] | 1079 | worksource.add(record.mReceiver.mUid, record.mReceiver.mPackageName); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1080 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1081 | } |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 1082 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | } |
| 1084 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1085 | |
| 1086 | if (D) Log.d(TAG, "provider request: " + provider + " " + providerRequest); |
| 1087 | p.setRequest(providerRequest, worksource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | private class UpdateRecord { |
| 1091 | final String mProvider; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1092 | final LocationRequest mRequest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | final Receiver mReceiver; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1094 | Location mLastFixBroadcast; |
| 1095 | long mLastStatusBroadcast; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | |
| 1097 | /** |
| 1098 | * Note: must be constructed with lock held. |
| 1099 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1100 | UpdateRecord(String provider, LocationRequest request, Receiver receiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | mProvider = provider; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1102 | mRequest = request; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | mReceiver = receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | |
| 1105 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); |
| 1106 | if (records == null) { |
| 1107 | records = new ArrayList<UpdateRecord>(); |
| 1108 | mRecordsByProvider.put(provider, records); |
| 1109 | } |
| 1110 | if (!records.contains(this)) { |
| 1111 | records.add(this); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * Method to be called when a record will no longer be used. Calling this multiple times |
| 1117 | * must have the same effect as calling it once. |
| 1118 | */ |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1119 | void disposeLocked(boolean removeReceiver) { |
| 1120 | // remove from mRecordsByProvider |
| 1121 | ArrayList<UpdateRecord> globalRecords = mRecordsByProvider.get(this.mProvider); |
| 1122 | if (globalRecords != null) { |
| 1123 | globalRecords.remove(this); |
| 1124 | } |
| 1125 | |
| 1126 | if (!removeReceiver) return; // the caller will handle the rest |
| 1127 | |
| 1128 | // remove from Receiver#mUpdateRecords |
| 1129 | HashMap<String, UpdateRecord> receiverRecords = mReceiver.mUpdateRecords; |
| 1130 | if (receiverRecords != null) { |
| 1131 | receiverRecords.remove(this.mProvider); |
| 1132 | |
| 1133 | // and also remove the Receiver if it has no more update records |
| 1134 | if (removeReceiver && receiverRecords.size() == 0) { |
| 1135 | removeUpdatesLocked(mReceiver); |
| 1136 | } |
Mike Lockwood | 3a76fd6 | 2009-09-01 07:26:56 -0400 | [diff] [blame] | 1137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | @Override |
| 1141 | public String toString() { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1142 | StringBuilder s = new StringBuilder(); |
| 1143 | s.append("UpdateRecord["); |
| 1144 | s.append(mProvider); |
| 1145 | s.append(' ').append(mReceiver.mPackageName).append('('); |
| 1146 | s.append(mReceiver.mUid).append(')'); |
| 1147 | s.append(' ').append(mRequest); |
| 1148 | s.append(']'); |
| 1149 | return s.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1153 | private Receiver getReceiver(ILocationListener listener, int pid, int uid, String packageName) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1154 | IBinder binder = listener.asBinder(); |
| 1155 | Receiver receiver = mReceivers.get(binder); |
| 1156 | if (receiver == null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1157 | receiver = new Receiver(listener, null, pid, uid, packageName); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1158 | mReceivers.put(binder, receiver); |
| 1159 | |
| 1160 | try { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1161 | receiver.getListener().asBinder().linkToDeath(receiver, 0); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1162 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1163 | Slog.e(TAG, "linkToDeath failed:", e); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1164 | return null; |
| 1165 | } |
| 1166 | } |
| 1167 | return receiver; |
| 1168 | } |
| 1169 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1170 | private Receiver getReceiver(PendingIntent intent, int pid, int uid, String packageName) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1171 | Receiver receiver = mReceivers.get(intent); |
| 1172 | if (receiver == null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1173 | receiver = new Receiver(null, intent, pid, uid, packageName); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1174 | mReceivers.put(intent, receiver); |
| 1175 | } |
| 1176 | return receiver; |
| 1177 | } |
| 1178 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1179 | /** |
| 1180 | * Creates a LocationRequest based upon the supplied LocationRequest that to meets resolution |
| 1181 | * and consistency requirements. |
| 1182 | * |
| 1183 | * @param request the LocationRequest from which to create a sanitized version |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1184 | * @return a version of request that meets the given resolution and consistency requirements |
| 1185 | * @hide |
| 1186 | */ |
| 1187 | private LocationRequest createSanitizedRequest(LocationRequest request, int resolutionLevel) { |
| 1188 | LocationRequest sanitizedRequest = new LocationRequest(request); |
| 1189 | if (resolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 1190 | switch (sanitizedRequest.getQuality()) { |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1191 | case LocationRequest.ACCURACY_FINE: |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1192 | sanitizedRequest.setQuality(LocationRequest.ACCURACY_BLOCK); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1193 | break; |
| 1194 | case LocationRequest.POWER_HIGH: |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1195 | sanitizedRequest.setQuality(LocationRequest.POWER_LOW); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1196 | break; |
| 1197 | } |
| 1198 | // throttle |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1199 | if (sanitizedRequest.getInterval() < LocationFudger.FASTEST_INTERVAL_MS) { |
| 1200 | sanitizedRequest.setInterval(LocationFudger.FASTEST_INTERVAL_MS); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1201 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1202 | if (sanitizedRequest.getFastestInterval() < LocationFudger.FASTEST_INTERVAL_MS) { |
| 1203 | sanitizedRequest.setFastestInterval(LocationFudger.FASTEST_INTERVAL_MS); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1204 | } |
Nick Pelly | 74fa7ea | 2012-08-13 19:36:38 -0700 | [diff] [blame] | 1205 | } |
Nick Pelly | 4e31c4f | 2012-08-13 19:35:39 -0700 | [diff] [blame] | 1206 | // make getFastestInterval() the minimum of interval and fastest interval |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1207 | if (sanitizedRequest.getFastestInterval() > sanitizedRequest.getInterval()) { |
Nick Pelly | 4e31c4f | 2012-08-13 19:35:39 -0700 | [diff] [blame] | 1208 | request.setFastestInterval(request.getInterval()); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1209 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1210 | return sanitizedRequest; |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1211 | } |
| 1212 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1213 | private void checkPackageName(String packageName) { |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1214 | if (packageName == null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1215 | throw new SecurityException("invalid package name: " + packageName); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1216 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1217 | int uid = Binder.getCallingUid(); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1218 | String[] packages = mPackageManager.getPackagesForUid(uid); |
| 1219 | if (packages == null) { |
| 1220 | throw new SecurityException("invalid UID " + uid); |
| 1221 | } |
| 1222 | for (String pkg : packages) { |
| 1223 | if (packageName.equals(pkg)) return; |
| 1224 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1225 | throw new SecurityException("invalid package name: " + packageName); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1228 | private void checkPendingIntent(PendingIntent intent) { |
| 1229 | if (intent == null) { |
| 1230 | throw new IllegalArgumentException("invalid pending intent: " + intent); |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1231 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | private Receiver checkListenerOrIntent(ILocationListener listener, PendingIntent intent, |
| 1235 | int pid, int uid, String packageName) { |
| 1236 | if (intent == null && listener == null) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1237 | throw new IllegalArgumentException("need either listener or intent"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1238 | } else if (intent != null && listener != null) { |
| 1239 | throw new IllegalArgumentException("cannot register both listener and intent"); |
| 1240 | } else if (intent != null) { |
| 1241 | checkPendingIntent(intent); |
| 1242 | return getReceiver(intent, pid, uid, packageName); |
| 1243 | } else { |
| 1244 | return getReceiver(listener, pid, uid, packageName); |
| 1245 | } |
Dianne Hackborn | 6c418d5 | 2011-06-29 14:05:33 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1248 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1249 | public void requestLocationUpdates(LocationRequest request, ILocationListener listener, |
| 1250 | PendingIntent intent, String packageName) { |
| 1251 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
| 1252 | checkPackageName(packageName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1253 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 1254 | checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, |
| 1255 | request.getProvider()); |
| 1256 | LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1258 | final int pid = Binder.getCallingPid(); |
| 1259 | final int uid = Binder.getCallingUid(); |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1260 | // 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] | 1261 | long identity = Binder.clearCallingIdentity(); |
| 1262 | try { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1263 | // We don't check for MODE_IGNORED here; we will do that when we go to deliver |
| 1264 | // a location. |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1265 | checkLocationAccess(uid, packageName, allowedResolutionLevel); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1266 | Receiver recevier = checkListenerOrIntent(listener, intent, pid, uid, packageName); |
| 1267 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1268 | synchronized (mLock) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1269 | requestLocationUpdatesLocked(sanitizedRequest, recevier, pid, uid, packageName); |
Mike Lockwood | 2d4d1bf | 2010-10-18 17:06:26 -0400 | [diff] [blame] | 1270 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | } finally { |
| 1272 | Binder.restoreCallingIdentity(identity); |
| 1273 | } |
| 1274 | } |
| 1275 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1276 | private void requestLocationUpdatesLocked(LocationRequest request, Receiver receiver, |
| 1277 | int pid, int uid, String packageName) { |
| 1278 | // Figure out the provider. Either its explicitly request (legacy use cases), or |
| 1279 | // use the fused provider |
| 1280 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
| 1281 | String name = request.getProvider(); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1282 | if (name == null) { |
| 1283 | throw new IllegalArgumentException("provider name must not be null"); |
| 1284 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1285 | LocationProviderInterface provider = mProvidersByName.get(name); |
| 1286 | if (provider == null) { |
| 1287 | throw new IllegalArgumentException("provider doesn't exisit: " + provider); |
| 1288 | } |
| 1289 | |
Dianne Hackborn | 7ff3011 | 2012-11-08 11:12:09 -0800 | [diff] [blame] | 1290 | if (D) Log.d(TAG, "request " + Integer.toHexString(System.identityHashCode(receiver)) |
| 1291 | + " " + name + " " + request + " from " + packageName + "(" + uid + ")"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1292 | |
| 1293 | UpdateRecord record = new UpdateRecord(name, request, receiver); |
| 1294 | UpdateRecord oldRecord = receiver.mUpdateRecords.put(name, record); |
| 1295 | if (oldRecord != null) { |
| 1296 | oldRecord.disposeLocked(false); |
| 1297 | } |
| 1298 | |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1299 | boolean isProviderEnabled = isAllowedByUserSettingsLocked(name, uid); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1300 | if (isProviderEnabled) { |
| 1301 | applyRequirementsLocked(name); |
| 1302 | } else { |
| 1303 | // Notify the listener that updates are currently disabled |
| 1304 | receiver.callProviderEnabledLocked(name, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | } |
| 1306 | } |
| 1307 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1308 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1309 | public void removeUpdates(ILocationListener listener, PendingIntent intent, |
| 1310 | String packageName) { |
| 1311 | checkPackageName(packageName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1312 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1313 | final int pid = Binder.getCallingPid(); |
| 1314 | final int uid = Binder.getCallingUid(); |
| 1315 | Receiver receiver = checkListenerOrIntent(listener, intent, pid, uid, packageName); |
| 1316 | |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1317 | // providers may use public location API's, need to clear identity |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1318 | long identity = Binder.clearCallingIdentity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | try { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1320 | synchronized (mLock) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1321 | removeUpdatesLocked(receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1323 | } finally { |
| 1324 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | private void removeUpdatesLocked(Receiver receiver) { |
Dianne Hackborn | 7ff3011 | 2012-11-08 11:12:09 -0800 | [diff] [blame] | 1329 | if (D) Log.i(TAG, "remove " + Integer.toHexString(System.identityHashCode(receiver))); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1330 | |
| 1331 | if (mReceivers.remove(receiver.mKey) != null && receiver.isListener()) { |
| 1332 | receiver.getListener().asBinder().unlinkToDeath(receiver, 0); |
| 1333 | synchronized (receiver) { |
| 1334 | if (receiver.mPendingBroadcasts > 0) { |
| 1335 | decrementPendingBroadcasts(); |
| 1336 | receiver.mPendingBroadcasts = 0; |
| 1337 | } |
| 1338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1341 | // Record which providers were associated with this listener |
| 1342 | HashSet<String> providers = new HashSet<String>(); |
| 1343 | HashMap<String, UpdateRecord> oldRecords = receiver.mUpdateRecords; |
| 1344 | if (oldRecords != null) { |
| 1345 | // Call dispose() on the obsolete update records. |
| 1346 | for (UpdateRecord record : oldRecords.values()) { |
| 1347 | record.disposeLocked(false); |
| 1348 | } |
| 1349 | // Accumulate providers |
| 1350 | providers.addAll(oldRecords.keySet()); |
| 1351 | } |
| 1352 | |
| 1353 | // update provider |
| 1354 | for (String provider : providers) { |
| 1355 | // If provider is already disabled, don't need to do anything |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1356 | if (!isAllowedByCurrentUserSettingsLocked(provider)) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1357 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1360 | applyRequirementsLocked(provider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1364 | private void applyAllProviderRequirementsLocked() { |
| 1365 | for (LocationProviderInterface p : mProviders) { |
| 1366 | // If provider is already disabled, don't need to do anything |
Dianne Hackborn | 64d41d7 | 2013-02-07 00:33:31 -0800 | [diff] [blame] | 1367 | if (!isAllowedByCurrentUserSettingsLocked(p.getName())) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1368 | continue; |
| 1369 | } |
| 1370 | |
| 1371 | applyRequirementsLocked(p.getName()); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1375 | @Override |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 1376 | public Location getLastLocation(LocationRequest request, String packageName) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1377 | if (D) Log.d(TAG, "getLastLocation: " + request); |
| 1378 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1379 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 1380 | checkPackageName(packageName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1381 | checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, |
| 1382 | request.getProvider()); |
| 1383 | // 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] | 1384 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1385 | final int uid = Binder.getCallingUid(); |
| 1386 | final long identity = Binder.clearCallingIdentity(); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1387 | try { |
| 1388 | if (mBlacklist.isBlacklisted(packageName)) { |
| 1389 | if (D) Log.d(TAG, "not returning last loc for blacklisted app: " + |
| 1390 | packageName); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1391 | return null; |
| 1392 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1393 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1394 | if (!reportLocationAccessNoThrow(uid, packageName, allowedResolutionLevel)) { |
| 1395 | if (D) Log.d(TAG, "not returning last loc for no op app: " + |
| 1396 | packageName); |
| 1397 | return null; |
| 1398 | } |
| 1399 | |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1400 | synchronized (mLock) { |
| 1401 | // Figure out the provider. Either its explicitly request (deprecated API's), |
| 1402 | // or use the fused provider |
| 1403 | String name = request.getProvider(); |
| 1404 | if (name == null) name = LocationManager.FUSED_PROVIDER; |
| 1405 | LocationProviderInterface provider = mProvidersByName.get(name); |
| 1406 | if (provider == null) return null; |
| 1407 | |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1408 | if (!isAllowedByUserSettingsLocked(name, uid)) return null; |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1409 | |
| 1410 | Location location = mLastLocation.get(name); |
| 1411 | if (location == null) { |
| 1412 | return null; |
| 1413 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1414 | if (allowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1415 | Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 1416 | if (noGPSLocation != null) { |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 1417 | return new Location(mLocationFudger.getOrCreate(noGPSLocation)); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1418 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1419 | } else { |
Dianne Hackborn | 6c5406a | 2012-11-29 16:18:01 -0800 | [diff] [blame] | 1420 | return new Location(location); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1421 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1422 | } |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1423 | return null; |
| 1424 | } finally { |
| 1425 | Binder.restoreCallingIdentity(identity); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | @Override |
| 1430 | public void requestGeofence(LocationRequest request, Geofence geofence, PendingIntent intent, |
| 1431 | String packageName) { |
| 1432 | if (request == null) request = DEFAULT_LOCATION_REQUEST; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1433 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 1434 | checkResolutionLevelIsSufficientForGeofenceUse(allowedResolutionLevel); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1435 | checkPendingIntent(intent); |
| 1436 | checkPackageName(packageName); |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1437 | checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, |
| 1438 | request.getProvider()); |
| 1439 | LocationRequest sanitizedRequest = createSanitizedRequest(request, allowedResolutionLevel); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1440 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1441 | if (D) Log.d(TAG, "requestGeofence: " + sanitizedRequest + " " + geofence + " " + intent); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1442 | |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1443 | // geo-fence manager uses the public location API, need to clear identity |
| 1444 | int uid = Binder.getCallingUid(); |
Victoria Lease | 56e675b | 2012-11-05 19:25:06 -0800 | [diff] [blame] | 1445 | if (UserHandle.getUserId(uid) != UserHandle.USER_OWNER) { |
| 1446 | // temporary measure until geofences work for secondary users |
| 1447 | Log.w(TAG, "proximity alerts are currently available only to the primary user"); |
| 1448 | return; |
| 1449 | } |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1450 | long identity = Binder.clearCallingIdentity(); |
| 1451 | try { |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1452 | mGeofenceManager.addFence(sanitizedRequest, geofence, intent, allowedResolutionLevel, |
| 1453 | uid, packageName); |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1454 | } finally { |
| 1455 | Binder.restoreCallingIdentity(identity); |
| 1456 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | @Override |
| 1460 | public void removeGeofence(Geofence geofence, PendingIntent intent, String packageName) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1461 | checkResolutionLevelIsSufficientForGeofenceUse(getCallerAllowedResolutionLevel()); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1462 | checkPendingIntent(intent); |
| 1463 | checkPackageName(packageName); |
| 1464 | |
| 1465 | if (D) Log.d(TAG, "removeGeofence: " + geofence + " " + intent); |
| 1466 | |
Nick Pelly | 2b7a0d0 | 2012-08-17 15:09:44 -0700 | [diff] [blame] | 1467 | // geo-fence manager uses the public location API, need to clear identity |
| 1468 | long identity = Binder.clearCallingIdentity(); |
| 1469 | try { |
| 1470 | mGeofenceManager.removeFence(geofence, intent); |
| 1471 | } finally { |
| 1472 | Binder.restoreCallingIdentity(identity); |
| 1473 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | @Override |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1478 | public boolean addGpsStatusListener(IGpsStatusListener listener, String packageName) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1479 | if (mGpsStatusProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | return false; |
| 1481 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1482 | int allowedResolutionLevel = getCallerAllowedResolutionLevel(); |
| 1483 | checkResolutionLevelIsSufficientForProviderUse(allowedResolutionLevel, |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1484 | LocationManager.GPS_PROVIDER); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1486 | final int uid = Binder.getCallingUid(); |
| 1487 | final long ident = Binder.clearCallingIdentity(); |
| 1488 | try { |
Victoria Lease | 3d5173d | 2013-02-05 16:07:32 -0800 | [diff] [blame] | 1489 | if (!checkLocationAccess(uid, packageName, allowedResolutionLevel)) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1490 | return false; |
| 1491 | } |
| 1492 | } finally { |
| 1493 | Binder.restoreCallingIdentity(ident); |
| 1494 | } |
| 1495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | try { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1497 | mGpsStatusProvider.addGpsStatusListener(listener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1499 | Slog.e(TAG, "mGpsStatusProvider.addGpsStatusListener failed", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | return false; |
| 1501 | } |
| 1502 | return true; |
| 1503 | } |
| 1504 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1505 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | public void removeGpsStatusListener(IGpsStatusListener listener) { |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1507 | synchronized (mLock) { |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1508 | try { |
| 1509 | mGpsStatusProvider.removeGpsStatusListener(listener); |
| 1510 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1511 | Slog.e(TAG, "mGpsStatusProvider.removeGpsStatusListener failed", e); |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 1512 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1516 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | public boolean sendExtraCommand(String provider, String command, Bundle extras) { |
Mike Lockwood | c6cc836 | 2009-08-17 13:16:08 -0400 | [diff] [blame] | 1518 | if (provider == null) { |
| 1519 | // throw NullPointerException to remain compatible with previous implementation |
| 1520 | throw new NullPointerException(); |
| 1521 | } |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1522 | checkResolutionLevelIsSufficientForProviderUse(getCallerAllowedResolutionLevel(), |
| 1523 | provider); |
Mike Lockwood | c6cc836 | 2009-08-17 13:16:08 -0400 | [diff] [blame] | 1524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | // and check for ACCESS_LOCATION_EXTRA_COMMANDS |
Mike Lockwood | b7e9922 | 2009-07-07 13:18:21 -0400 | [diff] [blame] | 1526 | if ((mContext.checkCallingOrSelfPermission(ACCESS_LOCATION_EXTRA_COMMANDS) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | != PackageManager.PERMISSION_GRANTED)) { |
| 1528 | throw new SecurityException("Requires ACCESS_LOCATION_EXTRA_COMMANDS permission"); |
| 1529 | } |
| 1530 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1531 | synchronized (mLock) { |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1532 | LocationProviderInterface p = mProvidersByName.get(provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1533 | if (p == null) return false; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1534 | |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1535 | return p.sendExtraCommand(command, extras); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1539 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1540 | public boolean sendNiResponse(int notifId, int userResponse) { |
Mike Lockwood | 18ad9f6 | 2009-08-27 14:01:23 -0700 | [diff] [blame] | 1541 | if (Binder.getCallingUid() != Process.myUid()) { |
| 1542 | throw new SecurityException( |
| 1543 | "calling sendNiResponse from outside of the system is not allowed"); |
| 1544 | } |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1545 | try { |
| 1546 | return mNetInitiatedListener.sendNiResponse(notifId, userResponse); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1547 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1548 | Slog.e(TAG, "RemoteException in LocationManagerService.sendNiResponse"); |
Danke Xie | 22d1f9f | 2009-08-18 18:28:45 -0400 | [diff] [blame] | 1549 | return false; |
| 1550 | } |
| 1551 | } |
| 1552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | /** |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 1554 | * @return null if the provider does not exist |
Alexey Tarasov | f2db9fb | 2009-09-01 02:37:07 +1100 | [diff] [blame] | 1555 | * @throws SecurityException if the provider is not allowed to be |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | * accessed by the caller |
| 1557 | */ |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1558 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1559 | public ProviderProperties getProviderProperties(String provider) { |
Laurent Tu | b7f9d25 | 2012-10-16 14:25:00 -0700 | [diff] [blame] | 1560 | if (mProvidersByName.get(provider) == null) { |
| 1561 | return null; |
| 1562 | } |
| 1563 | |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1564 | checkResolutionLevelIsSufficientForProviderUse(getCallerAllowedResolutionLevel(), |
| 1565 | provider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1567 | LocationProviderInterface p; |
| 1568 | synchronized (mLock) { |
| 1569 | p = mProvidersByName.get(provider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | } |
| 1571 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1572 | if (p == null) return null; |
| 1573 | return p.getProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1576 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1577 | public boolean isProviderEnabled(String provider) { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1578 | checkResolutionLevelIsSufficientForProviderUse(getCallerAllowedResolutionLevel(), |
| 1579 | provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1580 | if (LocationManager.FUSED_PROVIDER.equals(provider)) return false; |
| 1581 | |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1582 | int uid = Binder.getCallingUid(); |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1583 | long identity = Binder.clearCallingIdentity(); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1584 | try { |
| 1585 | synchronized (mLock) { |
| 1586 | LocationProviderInterface p = mProvidersByName.get(provider); |
| 1587 | if (p == null) return false; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1588 | |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1589 | return isAllowedByUserSettingsLocked(provider, uid); |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1590 | } |
| 1591 | } finally { |
| 1592 | Binder.restoreCallingIdentity(identity); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 1596 | /** |
| 1597 | * Returns "true" if the UID belongs to a bound location provider. |
| 1598 | * |
| 1599 | * @param uid the uid |
| 1600 | * @return true if uid belongs to a bound location provider |
| 1601 | */ |
| 1602 | private boolean isUidALocationProvider(int uid) { |
| 1603 | if (uid == Process.SYSTEM_UID) { |
| 1604 | return true; |
| 1605 | } |
| 1606 | if (mGeocodeProvider != null) { |
| 1607 | if (doesPackageHaveUid(uid, mGeocodeProvider.getConnectedPackageName())) return true; |
| 1608 | } |
| 1609 | for (LocationProviderProxy proxy : mProxyProviders) { |
| 1610 | if (doesPackageHaveUid(uid, proxy.getConnectedPackageName())) return true; |
| 1611 | } |
| 1612 | return false; |
| 1613 | } |
| 1614 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1615 | private void checkCallerIsProvider() { |
| 1616 | if (mContext.checkCallingOrSelfPermission(INSTALL_LOCATION_PROVIDER) |
| 1617 | == PackageManager.PERMISSION_GRANTED) { |
| 1618 | return; |
| 1619 | } |
| 1620 | |
| 1621 | // Previously we only used the INSTALL_LOCATION_PROVIDER |
| 1622 | // check. But that is system or signature |
| 1623 | // protection level which is not flexible enough for |
| 1624 | // providers installed oustide the system image. So |
| 1625 | // also allow providers with a UID matching the |
| 1626 | // currently bound package name |
| 1627 | |
Victoria Lease | 03cdd3d | 2013-02-01 15:15:54 -0800 | [diff] [blame] | 1628 | if (isUidALocationProvider(Binder.getCallingUid())) { |
| 1629 | return; |
| 1630 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1631 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1632 | throw new SecurityException("need INSTALL_LOCATION_PROVIDER permission, " + |
| 1633 | "or UID of a currently bound location provider"); |
| 1634 | } |
| 1635 | |
| 1636 | private boolean doesPackageHaveUid(int uid, String packageName) { |
| 1637 | if (packageName == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | return false; |
| 1639 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1640 | try { |
| 1641 | ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName, 0); |
| 1642 | if (appInfo.uid != uid) { |
| 1643 | return false; |
| 1644 | } |
| 1645 | } catch (NameNotFoundException e) { |
| 1646 | return false; |
| 1647 | } |
| 1648 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | } |
| 1650 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1651 | @Override |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 1652 | public void reportLocation(Location location, boolean passive) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1653 | checkCallerIsProvider(); |
Mike Lockwood | 275555c | 2009-05-01 11:30:34 -0400 | [diff] [blame] | 1654 | |
Nick Pelly | 2eeeec2 | 2012-07-18 13:13:37 -0700 | [diff] [blame] | 1655 | if (!location.isComplete()) { |
| 1656 | Log.w(TAG, "Dropping incomplete location: " + location); |
| 1657 | return; |
| 1658 | } |
| 1659 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1660 | mLocationHandler.removeMessages(MSG_LOCATION_CHANGED, location); |
| 1661 | Message m = Message.obtain(mLocationHandler, MSG_LOCATION_CHANGED, location); |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 1662 | m.arg1 = (passive ? 1 : 0); |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 1663 | mLocationHandler.sendMessageAtFrontOfQueue(m); |
| 1664 | } |
| 1665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1666 | |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 1667 | private static boolean shouldBroadcastSafe( |
| 1668 | Location loc, Location lastLoc, UpdateRecord record, long now) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | // Always broadcast the first update |
| 1670 | if (lastLoc == null) { |
| 1671 | return true; |
| 1672 | } |
| 1673 | |
Nick Pelly | f1be686 | 2012-05-15 10:53:42 -0700 | [diff] [blame] | 1674 | // Check whether sufficient time has passed |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1675 | long minTime = record.mRequest.getFastestInterval(); |
Philip Milne | 4118012 | 2012-09-26 11:29:25 -0700 | [diff] [blame] | 1676 | long delta = (loc.getElapsedRealtimeNanos() - lastLoc.getElapsedRealtimeNanos()) / 1000000L; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1677 | if (delta < minTime - MAX_PROVIDER_SCHEDULING_JITTER_MS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1678 | return false; |
| 1679 | } |
| 1680 | |
| 1681 | // Check whether sufficient distance has been traveled |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1682 | double minDistance = record.mRequest.getSmallestDisplacement(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | if (minDistance > 0.0) { |
| 1684 | if (loc.distanceTo(lastLoc) <= minDistance) { |
| 1685 | return false; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 1689 | // Check whether sufficient number of udpates is left |
| 1690 | if (record.mRequest.getNumUpdates() <= 0) { |
| 1691 | return false; |
| 1692 | } |
| 1693 | |
| 1694 | // Check whether the expiry date has passed |
| 1695 | if (record.mRequest.getExpireAt() < now) { |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | return true; |
| 1700 | } |
| 1701 | |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 1702 | private void handleLocationChangedLocked(Location location, boolean passive) { |
Nick Pelly | 4e31c4f | 2012-08-13 19:35:39 -0700 | [diff] [blame] | 1703 | if (D) Log.d(TAG, "incoming location: " + location); |
| 1704 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1705 | long now = SystemClock.elapsedRealtime(); |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 1706 | String provider = (passive ? LocationManager.PASSIVE_PROVIDER : location.getProvider()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | |
Laurent Tu | 60ec50a | 2012-10-04 17:00:10 -0700 | [diff] [blame] | 1708 | // Skip if the provider is unknown. |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 1709 | LocationProviderInterface p = mProvidersByName.get(provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1710 | if (p == null) return; |
| 1711 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1712 | // Update last known locations |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1713 | Location noGPSLocation = location.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 1714 | Location lastNoGPSLocation = null; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1715 | Location lastLocation = mLastLocation.get(provider); |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 1716 | if (lastLocation == null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1717 | lastLocation = new Location(provider); |
| 1718 | mLastLocation.put(provider, lastLocation); |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1719 | } else { |
| 1720 | lastNoGPSLocation = lastLocation.getExtraLocation(Location.EXTRA_NO_GPS_LOCATION); |
| 1721 | if (noGPSLocation == null && lastNoGPSLocation != null) { |
| 1722 | // New location has no no-GPS location: adopt last no-GPS location. This is set |
| 1723 | // directly into location because we do not want to notify COARSE clients. |
| 1724 | location.setExtraLocation(Location.EXTRA_NO_GPS_LOCATION, lastNoGPSLocation); |
| 1725 | } |
Mike Lockwood | 4e50b78 | 2009-04-03 08:24:43 -0700 | [diff] [blame] | 1726 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1727 | lastLocation.set(location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1728 | |
Laurent Tu | 60ec50a | 2012-10-04 17:00:10 -0700 | [diff] [blame] | 1729 | // Skip if there are no UpdateRecords for this provider. |
| 1730 | ArrayList<UpdateRecord> records = mRecordsByProvider.get(provider); |
| 1731 | if (records == null || records.size() == 0) return; |
| 1732 | |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1733 | // Fetch coarse location |
| 1734 | Location coarseLocation = null; |
| 1735 | if (noGPSLocation != null && !noGPSLocation.equals(lastNoGPSLocation)) { |
| 1736 | coarseLocation = mLocationFudger.getOrCreate(noGPSLocation); |
| 1737 | } |
| 1738 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | // Fetch latest status update time |
| 1740 | long newStatusUpdateTime = p.getStatusUpdateTime(); |
| 1741 | |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 1742 | // Get latest status |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | Bundle extras = new Bundle(); |
| 1744 | int status = p.getStatus(extras); |
| 1745 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | ArrayList<Receiver> deadReceivers = null; |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1747 | ArrayList<UpdateRecord> deadUpdateRecords = null; |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | // Broadcast location or status to all listeners |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1750 | for (UpdateRecord r : records) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | Receiver receiver = r.mReceiver; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1752 | boolean receiverDead = false; |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 1753 | |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1754 | int receiverUserId = UserHandle.getUserId(receiver.mUid); |
| 1755 | if (receiverUserId != mCurrentUserId) { |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1756 | if (D) { |
Victoria Lease | 269518e | 2012-10-29 08:25:39 -0700 | [diff] [blame] | 1757 | Log.d(TAG, "skipping loc update for background user " + receiverUserId + |
Victoria Lease | b711d57 | 2012-10-02 13:14:11 -0700 | [diff] [blame] | 1758 | " (current user: " + mCurrentUserId + ", app: " + |
| 1759 | receiver.mPackageName + ")"); |
| 1760 | } |
| 1761 | continue; |
| 1762 | } |
| 1763 | |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 1764 | if (mBlacklist.isBlacklisted(receiver.mPackageName)) { |
| 1765 | if (D) Log.d(TAG, "skipping loc update for blacklisted app: " + |
| 1766 | receiver.mPackageName); |
| 1767 | continue; |
| 1768 | } |
| 1769 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1770 | if (!reportLocationAccessNoThrow(receiver.mUid, receiver.mPackageName, |
| 1771 | receiver.mAllowedResolutionLevel)) { |
| 1772 | if (D) Log.d(TAG, "skipping loc update for no op app: " + |
| 1773 | receiver.mPackageName); |
| 1774 | continue; |
| 1775 | } |
| 1776 | |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1777 | Location notifyLocation = null; |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1778 | if (receiver.mAllowedResolutionLevel < RESOLUTION_LEVEL_FINE) { |
| 1779 | notifyLocation = coarseLocation; // use coarse location |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1780 | } else { |
Victoria Lease | 37425c3 | 2012-10-16 16:08:48 -0700 | [diff] [blame] | 1781 | notifyLocation = lastLocation; // use fine location |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1782 | } |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1783 | if (notifyLocation != null) { |
| 1784 | Location lastLoc = r.mLastFixBroadcast; |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 1785 | if ((lastLoc == null) || shouldBroadcastSafe(notifyLocation, lastLoc, r, now)) { |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1786 | if (lastLoc == null) { |
| 1787 | lastLoc = new Location(notifyLocation); |
| 1788 | r.mLastFixBroadcast = lastLoc; |
| 1789 | } else { |
| 1790 | lastLoc.set(notifyLocation); |
| 1791 | } |
| 1792 | if (!receiver.callLocationChangedLocked(notifyLocation)) { |
| 1793 | Slog.w(TAG, "RemoteException calling onLocationChanged on " + receiver); |
| 1794 | receiverDead = true; |
| 1795 | } |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 1796 | r.mRequest.decrementNumUpdates(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1800 | long prevStatusUpdateTime = r.mLastStatusBroadcast; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1801 | if ((newStatusUpdateTime > prevStatusUpdateTime) && |
Victoria Lease | 09016ab | 2012-09-16 12:33:15 -0700 | [diff] [blame] | 1802 | (prevStatusUpdateTime != 0 || status != LocationProvider.AVAILABLE)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1803 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 1804 | r.mLastStatusBroadcast = newStatusUpdateTime; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | if (!receiver.callStatusChangedLocked(provider, status, extras)) { |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1806 | receiverDead = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1807 | Slog.w(TAG, "RemoteException calling onStatusChanged on " + receiver); |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1808 | } |
| 1809 | } |
| 1810 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1811 | // track expired records |
Laurent Tu | 75defb6 | 2012-11-01 16:21:52 -0700 | [diff] [blame] | 1812 | if (r.mRequest.getNumUpdates() <= 0 || r.mRequest.getExpireAt() < now) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1813 | if (deadUpdateRecords == null) { |
| 1814 | deadUpdateRecords = new ArrayList<UpdateRecord>(); |
| 1815 | } |
| 1816 | deadUpdateRecords.add(r); |
| 1817 | } |
| 1818 | // track dead receivers |
| 1819 | if (receiverDead) { |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 1820 | if (deadReceivers == null) { |
| 1821 | deadReceivers = new ArrayList<Receiver>(); |
| 1822 | } |
| 1823 | if (!deadReceivers.contains(receiver)) { |
| 1824 | deadReceivers.add(receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1825 | } |
| 1826 | } |
| 1827 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1828 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1829 | // remove dead records and receivers outside the loop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | if (deadReceivers != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1831 | for (Receiver receiver : deadReceivers) { |
| 1832 | removeUpdatesLocked(receiver); |
| 1833 | } |
| 1834 | } |
| 1835 | if (deadUpdateRecords != null) { |
| 1836 | for (UpdateRecord r : deadUpdateRecords) { |
| 1837 | r.disposeLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | } |
Victoria Lease | 8b38b29 | 2012-12-04 15:04:43 -0800 | [diff] [blame] | 1839 | applyRequirementsLocked(provider); |
| 1840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | private class LocationWorkerHandler extends Handler { |
Victoria Lease | 5cd731a | 2012-12-19 15:04:21 -0800 | [diff] [blame] | 1844 | public LocationWorkerHandler(Looper looper) { |
| 1845 | super(looper, null, true); |
| 1846 | } |
| 1847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1848 | @Override |
| 1849 | public void handleMessage(Message msg) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1850 | switch (msg.what) { |
| 1851 | case MSG_LOCATION_CHANGED: |
| 1852 | handleLocationChanged((Location) msg.obj, msg.arg1 == 1); |
| 1853 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | } |
| 1855 | } |
| 1856 | } |
| 1857 | |
Victoria Lease | 54ca7ae | 2013-01-08 09:39:50 -0800 | [diff] [blame] | 1858 | private boolean isMockProvider(String provider) { |
| 1859 | synchronized (mLock) { |
| 1860 | return mMockProviders.containsKey(provider); |
| 1861 | } |
| 1862 | } |
| 1863 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1864 | private void handleLocationChanged(Location location, boolean passive) { |
Victoria Lease | 54ca7ae | 2013-01-08 09:39:50 -0800 | [diff] [blame] | 1865 | // create a working copy of the incoming Location so that the service can modify it without |
| 1866 | // disturbing the caller's copy |
| 1867 | Location myLocation = new Location(location); |
| 1868 | String provider = myLocation.getProvider(); |
| 1869 | |
| 1870 | // set "isFromMockProvider" bit if location came from a mock provider. we do not clear this |
| 1871 | // bit if location did not come from a mock provider because passive/fused providers can |
| 1872 | // forward locations from mock providers, and should not grant them legitimacy in doing so. |
| 1873 | if (!myLocation.isFromMockProvider() && isMockProvider(provider)) { |
| 1874 | myLocation.setIsFromMockProvider(true); |
| 1875 | } |
Jeff Sharkey | 5e61331 | 2012-01-30 11:16:20 -0800 | [diff] [blame] | 1876 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1877 | synchronized (mLock) { |
Victoria Lease | 09eeaec | 2013-02-05 11:34:13 -0800 | [diff] [blame] | 1878 | if (isAllowedByCurrentUserSettingsLocked(provider)) { |
| 1879 | if (!passive) { |
| 1880 | // notify passive provider of the new location |
| 1881 | mPassiveProvider.updateLocation(myLocation); |
| 1882 | } |
Victoria Lease | 54ca7ae | 2013-01-08 09:39:50 -0800 | [diff] [blame] | 1883 | handleLocationChangedLocked(myLocation, passive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1886 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | |
Mike Lockwood | e97ae40 | 2010-09-29 15:23:46 -0400 | [diff] [blame] | 1888 | private final PackageMonitor mPackageMonitor = new PackageMonitor() { |
| 1889 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1890 | public void onPackageDisappeared(String packageName, int reason) { |
| 1891 | // remove all receivers associated with this package name |
| 1892 | synchronized (mLock) { |
| 1893 | ArrayList<Receiver> deadReceivers = null; |
| 1894 | |
| 1895 | for (Receiver receiver : mReceivers.values()) { |
| 1896 | if (receiver.mPackageName.equals(packageName)) { |
| 1897 | if (deadReceivers == null) { |
| 1898 | deadReceivers = new ArrayList<Receiver>(); |
| 1899 | } |
| 1900 | deadReceivers.add(receiver); |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | // perform removal outside of mReceivers loop |
| 1905 | if (deadReceivers != null) { |
| 1906 | for (Receiver receiver : deadReceivers) { |
| 1907 | removeUpdatesLocked(receiver); |
| 1908 | } |
| 1909 | } |
| 1910 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1911 | } |
Mike Lockwood | e97ae40 | 2010-09-29 15:23:46 -0400 | [diff] [blame] | 1912 | }; |
| 1913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | // Wake locks |
| 1915 | |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1916 | private void incrementPendingBroadcasts() { |
| 1917 | synchronized (mWakeLock) { |
| 1918 | if (mPendingBroadcasts++ == 0) { |
| 1919 | try { |
| 1920 | mWakeLock.acquire(); |
| 1921 | log("Acquired wakelock"); |
| 1922 | } catch (Exception e) { |
| 1923 | // This is to catch a runtime exception thrown when we try to release an |
| 1924 | // already released lock. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1925 | Slog.e(TAG, "exception in acquireWakeLock()", e); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1926 | } |
| 1927 | } |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | private void decrementPendingBroadcasts() { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1932 | synchronized (mWakeLock) { |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1933 | if (--mPendingBroadcasts == 0) { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1934 | try { |
| 1935 | // Release wake lock |
| 1936 | if (mWakeLock.isHeld()) { |
| 1937 | mWakeLock.release(); |
| 1938 | log("Released wakelock"); |
| 1939 | } else { |
| 1940 | log("Can't release wakelock again!"); |
| 1941 | } |
| 1942 | } catch (Exception e) { |
| 1943 | // This is to catch a runtime exception thrown when we try to release an |
| 1944 | // already released lock. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1945 | Slog.e(TAG, "exception in releaseWakeLock()", e); |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 1946 | } |
Mike Lockwood | 48f1751 | 2009-04-23 09:12:08 -0700 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | } |
| 1950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | // Geocoder |
| 1952 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1953 | @Override |
Mike Lockwood | e15735a | 2010-09-20 17:48:47 -0400 | [diff] [blame] | 1954 | public boolean geocoderIsPresent() { |
Mark Vandevoorde | 01ac80b | 2010-05-21 15:43:26 -0700 | [diff] [blame] | 1955 | return mGeocodeProvider != null; |
| 1956 | } |
| 1957 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1958 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | public String getFromLocation(double latitude, double longitude, int maxResults, |
Mike Lockwood | 3490140 | 2010-01-04 12:14:21 -0500 | [diff] [blame] | 1960 | GeocoderParams params, List<Address> addrs) { |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1961 | if (mGeocodeProvider != null) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 1962 | return mGeocodeProvider.getFromLocation(latitude, longitude, maxResults, |
| 1963 | params, addrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | } |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1965 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1968 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1969 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | public String getFromLocationName(String locationName, |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1971 | double lowerLeftLatitude, double lowerLeftLongitude, |
| 1972 | double upperRightLatitude, double upperRightLongitude, int maxResults, |
Mike Lockwood | 3490140 | 2010-01-04 12:14:21 -0500 | [diff] [blame] | 1973 | GeocoderParams params, List<Address> addrs) { |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1974 | |
| 1975 | if (mGeocodeProvider != null) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 1976 | return mGeocodeProvider.getFromLocationName(locationName, lowerLeftLatitude, |
| 1977 | lowerLeftLongitude, upperRightLatitude, upperRightLongitude, |
| 1978 | maxResults, params, addrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | } |
Mike Lockwood | a55c321 | 2009-04-15 11:10:11 -0400 | [diff] [blame] | 1980 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | // Mock Providers |
| 1984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1985 | private void checkMockPermissionsSafe() { |
| 1986 | boolean allowMocks = Settings.Secure.getInt(mContext.getContentResolver(), |
| 1987 | Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 1; |
| 1988 | if (!allowMocks) { |
| 1989 | throw new SecurityException("Requires ACCESS_MOCK_LOCATION secure setting"); |
| 1990 | } |
| 1991 | |
| 1992 | if (mContext.checkCallingPermission(ACCESS_MOCK_LOCATION) != |
| 1993 | PackageManager.PERMISSION_GRANTED) { |
| 1994 | throw new SecurityException("Requires ACCESS_MOCK_LOCATION permission"); |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1995 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | } |
| 1997 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 1998 | @Override |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 1999 | public void addTestProvider(String name, ProviderProperties properties) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2000 | checkMockPermissionsSafe(); |
| 2001 | |
Mike Lockwood | a4903f2 | 2010-02-17 06:42:23 -0500 | [diff] [blame] | 2002 | if (LocationManager.PASSIVE_PROVIDER.equals(name)) { |
| 2003 | throw new IllegalArgumentException("Cannot mock the passive location provider"); |
| 2004 | } |
| 2005 | |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2006 | long identity = Binder.clearCallingIdentity(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2007 | synchronized (mLock) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2008 | MockProvider provider = new MockProvider(name, this, properties); |
Mike Lockwood | 7566c1d | 2009-08-25 10:05:18 -0700 | [diff] [blame] | 2009 | // remove the real provider if we are replacing GPS or network provider |
| 2010 | if (LocationManager.GPS_PROVIDER.equals(name) |
Nick Pelly | 1332b53 | 2012-08-21 16:25:47 -0700 | [diff] [blame] | 2011 | || LocationManager.NETWORK_PROVIDER.equals(name) |
| 2012 | || LocationManager.FUSED_PROVIDER.equals(name)) { |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 2013 | LocationProviderInterface p = mProvidersByName.get(name); |
| 2014 | if (p != null) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2015 | removeProviderLocked(p); |
Mike Lockwood | 7566c1d | 2009-08-25 10:05:18 -0700 | [diff] [blame] | 2016 | } |
| 2017 | } |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 2018 | if (mProvidersByName.get(name) != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | throw new IllegalArgumentException("Provider \"" + name + "\" already exists"); |
| 2020 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2021 | addProviderLocked(provider); |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2022 | mMockProviders.put(name, provider); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2023 | mLastLocation.put(name, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | updateProvidersLocked(); |
| 2025 | } |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2026 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2029 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | public void removeTestProvider(String provider) { |
| 2031 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2032 | synchronized (mLock) { |
You Kim | a6d0b6f | 2012-10-28 03:58:44 +0900 | [diff] [blame] | 2033 | MockProvider mockProvider = mMockProviders.remove(provider); |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2034 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2035 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2036 | } |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2037 | long identity = Binder.clearCallingIdentity(); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2038 | removeProviderLocked(mProvidersByName.get(provider)); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2039 | |
| 2040 | // reinstate real provider if available |
| 2041 | LocationProviderInterface realProvider = mRealProviders.get(provider); |
| 2042 | if (realProvider != null) { |
| 2043 | addProviderLocked(realProvider); |
Mike Lockwood | 7566c1d | 2009-08-25 10:05:18 -0700 | [diff] [blame] | 2044 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2045 | mLastLocation.put(provider, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | updateProvidersLocked(); |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2047 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2051 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | public void setTestProviderLocation(String provider, Location loc) { |
| 2053 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2054 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2055 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2056 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2058 | } |
Mike Lockwood | 95427cd | 2009-05-07 13:27:54 -0400 | [diff] [blame] | 2059 | // clear calling identity so INSTALL_LOCATION_PROVIDER permission is not required |
| 2060 | long identity = Binder.clearCallingIdentity(); |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2061 | mockProvider.setLocation(loc); |
Mike Lockwood | 95427cd | 2009-05-07 13:27:54 -0400 | [diff] [blame] | 2062 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2066 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | public void clearTestProviderLocation(String provider) { |
| 2068 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2069 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2070 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2071 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2073 | } |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2074 | mockProvider.clearLocation(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | } |
| 2076 | } |
| 2077 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2078 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | public void setTestProviderEnabled(String provider, boolean enabled) { |
| 2080 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2081 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2082 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2083 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2085 | } |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2086 | long identity = Binder.clearCallingIdentity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | if (enabled) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2088 | mockProvider.enable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | mEnabledProviders.add(provider); |
| 2090 | mDisabledProviders.remove(provider); |
| 2091 | } else { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2092 | mockProvider.disable(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | mEnabledProviders.remove(provider); |
| 2094 | mDisabledProviders.add(provider); |
| 2095 | } |
| 2096 | updateProvidersLocked(); |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2097 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2101 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | public void clearTestProviderEnabled(String provider) { |
| 2103 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2104 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2105 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2106 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2108 | } |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2109 | long identity = Binder.clearCallingIdentity(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | mEnabledProviders.remove(provider); |
| 2111 | mDisabledProviders.remove(provider); |
| 2112 | updateProvidersLocked(); |
Mike Lockwood | 86328a9 | 2009-10-23 08:38:25 -0400 | [diff] [blame] | 2113 | Binder.restoreCallingIdentity(identity); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2117 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | public void setTestProviderStatus(String provider, int status, Bundle extras, long updateTime) { |
| 2119 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2120 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2121 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2122 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2123 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2124 | } |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2125 | mockProvider.setStatus(status, extras, updateTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } |
| 2127 | } |
| 2128 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2129 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2130 | public void clearTestProviderStatus(String provider) { |
| 2131 | checkMockPermissionsSafe(); |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2132 | synchronized (mLock) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2133 | MockProvider mockProvider = mMockProviders.get(provider); |
| 2134 | if (mockProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | throw new IllegalArgumentException("Provider \"" + provider + "\" unknown"); |
| 2136 | } |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2137 | mockProvider.clearStatus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | private void log(String log) { |
| 2142 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2143 | Slog.d(TAG, log); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } |
| 2145 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2146 | |
| 2147 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2149 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2150 | != PackageManager.PERMISSION_GRANTED) { |
Mike Lockwood | 0528b9b | 2009-05-07 10:12:54 -0400 | [diff] [blame] | 2151 | pw.println("Permission Denial: can't dump LocationManagerService from from pid=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | + Binder.getCallingPid() |
| 2153 | + ", uid=" + Binder.getCallingUid()); |
| 2154 | return; |
| 2155 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2156 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 2157 | synchronized (mLock) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | pw.println("Current Location Manager state:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | pw.println(" Location Listeners:"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2160 | for (Receiver receiver : mReceivers.values()) { |
| 2161 | pw.println(" " + receiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | pw.println(" Records by Provider:"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2164 | for (Map.Entry<String, ArrayList<UpdateRecord>> entry : mRecordsByProvider.entrySet()) { |
| 2165 | pw.println(" " + entry.getKey() + ":"); |
| 2166 | for (UpdateRecord record : entry.getValue()) { |
| 2167 | pw.println(" " + record); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2168 | } |
| 2169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | pw.println(" Last Known Locations:"); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2171 | for (Map.Entry<String, Location> entry : mLastLocation.entrySet()) { |
| 2172 | String provider = entry.getKey(); |
| 2173 | Location location = entry.getValue(); |
| 2174 | pw.println(" " + provider + ": " + location); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2176 | |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2177 | mGeofenceManager.dump(pw); |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2179 | if (mEnabledProviders.size() > 0) { |
| 2180 | pw.println(" Enabled Providers:"); |
| 2181 | for (String i : mEnabledProviders) { |
| 2182 | pw.println(" " + i); |
| 2183 | } |
Nick Pelly | e0fd693 | 2012-07-11 10:26:13 -0700 | [diff] [blame] | 2184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | } |
| 2186 | if (mDisabledProviders.size() > 0) { |
| 2187 | pw.println(" Disabled Providers:"); |
| 2188 | for (String i : mDisabledProviders) { |
| 2189 | pw.println(" " + i); |
| 2190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | } |
Nick Pelly | 4035f5a | 2012-08-17 14:43:49 -0700 | [diff] [blame] | 2192 | pw.append(" "); |
| 2193 | mBlacklist.dump(pw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | if (mMockProviders.size() > 0) { |
| 2195 | pw.println(" Mock Providers:"); |
| 2196 | for (Map.Entry<String, MockProvider> i : mMockProviders.entrySet()) { |
Mike Lockwood | 7ec434e | 2009-03-27 07:46:48 -0700 | [diff] [blame] | 2197 | i.getValue().dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | } |
| 2199 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2200 | |
Nick Pelly | 74fa7ea | 2012-08-13 19:36:38 -0700 | [diff] [blame] | 2201 | pw.append(" fudger: "); |
| 2202 | mLocationFudger.dump(fd, pw, args); |
| 2203 | |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2204 | if (args.length > 0 && "short".equals(args[0])) { |
| 2205 | return; |
| 2206 | } |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2207 | for (LocationProviderInterface provider: mProviders) { |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2208 | pw.print(provider.getName() + " Internal State"); |
| 2209 | if (provider instanceof LocationProviderProxy) { |
| 2210 | LocationProviderProxy proxy = (LocationProviderProxy) provider; |
| 2211 | pw.print(" (" + proxy.getConnectedPackageName() + ")"); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2212 | } |
Nick Pelly | 6fa9ad4 | 2012-07-16 12:18:23 -0700 | [diff] [blame] | 2213 | pw.println(":"); |
| 2214 | provider.dump(fd, pw, args); |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 2215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | } |
| 2217 | } |
| 2218 | } |