Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 17 | package com.android.server.location; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 18 | |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 19 | import android.content.ComponentName; |
| 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
| 22 | import android.content.ServiceConnection; |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 23 | import android.location.Criteria; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 24 | import android.location.ILocationProvider; |
| 25 | import android.location.Location; |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 26 | import android.net.NetworkInfo; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 27 | import android.os.Bundle; |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 28 | import android.os.Handler; |
Mike Lockwood | 3681f26 | 2009-05-12 10:52:03 -0400 | [diff] [blame] | 29 | import android.os.IBinder; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 30 | import android.os.RemoteException; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 31 | import android.os.WorkSource; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 32 | import android.util.Log; |
| 33 | |
Mike Lockwood | 00b7427 | 2010-03-26 10:41:48 -0400 | [diff] [blame] | 34 | import com.android.internal.location.DummyLocationProvider; |
| 35 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 36 | /** |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 37 | * A class for proxying location providers implemented as services. |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 38 | * |
| 39 | * {@hide} |
| 40 | */ |
Mike Lockwood | d03ff94 | 2010-02-09 08:46:14 -0500 | [diff] [blame] | 41 | public class LocationProviderProxy implements LocationProviderInterface { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 42 | |
| 43 | private static final String TAG = "LocationProviderProxy"; |
| 44 | |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 45 | public static final String SERVICE_ACTION = |
| 46 | "com.android.location.service.NetworkLocationProvider"; |
| 47 | |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 48 | private final Context mContext; |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 49 | private final String mName; |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 50 | private final Intent mIntent; |
| 51 | private final Handler mHandler; |
| 52 | private final Object mMutex = new Object(); // synchronizes access to non-final members |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 53 | private Connection mServiceConnection; // never null after ctor |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 54 | |
| 55 | // cached values set by the location manager |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 56 | private boolean mLocationTracking = false; |
Mike Lockwood | 2cd543a | 2010-02-01 12:16:35 -0500 | [diff] [blame] | 57 | private boolean mEnabled = false; |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 58 | private long mMinTime = -1; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 59 | private WorkSource mMinTimeSource = new WorkSource(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 60 | private int mNetworkState; |
| 61 | private NetworkInfo mNetworkInfo; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 62 | |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 63 | // constructor for proxying location providers implemented in a separate service |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 64 | public LocationProviderProxy(Context context, String name, String packageName, |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 65 | Handler handler) { |
| 66 | mContext = context; |
| 67 | mName = name; |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 68 | mIntent = new Intent(SERVICE_ACTION); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 69 | mHandler = handler; |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 70 | reconnect(packageName); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 71 | } |
| 72 | |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 73 | /** Bind to service. Will reconnect if already connected */ |
| 74 | public void reconnect(String packageName) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 75 | synchronized (mMutex) { |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 76 | if (mServiceConnection != null) { |
| 77 | mContext.unbindService(mServiceConnection); |
| 78 | } |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 79 | mServiceConnection = new Connection(); |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 80 | mIntent.setPackage(packageName); |
Dianne Hackborn | 130b0d2 | 2011-07-26 22:07:48 -0700 | [diff] [blame] | 81 | mContext.bindService(mIntent, mServiceConnection, |
Nick Pelly | 00355d5 | 2012-05-27 16:12:45 -0700 | [diff] [blame^] | 82 | Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | |
| 83 | Context.BIND_ALLOW_OOM_MANAGEMENT); |
Mike Lockwood | e97ae40 | 2010-09-29 15:23:46 -0400 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 87 | private class Connection implements ServiceConnection, Runnable { |
| 88 | |
| 89 | private ILocationProvider mProvider; |
| 90 | |
| 91 | // for caching requiresNetwork, requiresSatellite, etc. |
| 92 | private DummyLocationProvider mCachedAttributes; // synchronized by mMutex |
| 93 | |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 94 | public void onServiceConnected(ComponentName className, IBinder service) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 95 | synchronized (this) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 96 | mProvider = ILocationProvider.Stub.asInterface(service); |
| 97 | if (mProvider != null) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 98 | mHandler.post(this); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | public void onServiceDisconnected(ComponentName className) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 104 | synchronized (this) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 105 | mProvider = null; |
| 106 | } |
Mike Lockwood | 3681f26 | 2009-05-12 10:52:03 -0400 | [diff] [blame] | 107 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 108 | |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 109 | public synchronized ILocationProvider getProvider() { |
| 110 | return mProvider; |
| 111 | } |
| 112 | |
| 113 | public synchronized DummyLocationProvider getCachedAttributes() { |
| 114 | return mCachedAttributes; |
| 115 | } |
| 116 | |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 117 | public void run() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 118 | synchronized (mMutex) { |
| 119 | if (mServiceConnection != this) { |
| 120 | // This ServiceConnection no longer the one we want to bind to. |
| 121 | return; |
| 122 | } |
| 123 | ILocationProvider provider = getProvider(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 124 | if (provider == null) { |
| 125 | return; |
| 126 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 127 | |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 128 | // resend previous values from the location manager if the service has restarted |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 129 | try { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 130 | if (mEnabled) { |
| 131 | provider.enable(); |
| 132 | } |
| 133 | if (mLocationTracking) { |
| 134 | provider.enableLocationTracking(true); |
| 135 | } |
| 136 | if (mMinTime >= 0) { |
| 137 | provider.setMinTime(mMinTime, mMinTimeSource); |
| 138 | } |
| 139 | if (mNetworkInfo != null) { |
| 140 | provider.updateNetworkState(mNetworkState, mNetworkInfo); |
| 141 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 142 | } catch (RemoteException e) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 143 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 144 | |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 145 | // init cache of parameters |
| 146 | if (mCachedAttributes == null) { |
| 147 | try { |
| 148 | mCachedAttributes = new DummyLocationProvider(mName, null); |
| 149 | mCachedAttributes.setRequiresNetwork(provider.requiresNetwork()); |
| 150 | mCachedAttributes.setRequiresSatellite(provider.requiresSatellite()); |
| 151 | mCachedAttributes.setRequiresCell(provider.requiresCell()); |
| 152 | mCachedAttributes.setHasMonetaryCost(provider.hasMonetaryCost()); |
| 153 | mCachedAttributes.setSupportsAltitude(provider.supportsAltitude()); |
| 154 | mCachedAttributes.setSupportsSpeed(provider.supportsSpeed()); |
| 155 | mCachedAttributes.setSupportsBearing(provider.supportsBearing()); |
| 156 | mCachedAttributes.setPowerRequirement(provider.getPowerRequirement()); |
| 157 | mCachedAttributes.setAccuracy(provider.getAccuracy()); |
| 158 | } catch (RemoteException e) { |
| 159 | mCachedAttributes = null; |
| 160 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 161 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 162 | } |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 163 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 164 | }; |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 165 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 166 | public String getName() { |
| 167 | return mName; |
| 168 | } |
| 169 | |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 170 | private DummyLocationProvider getCachedAttributes() { |
| 171 | synchronized (mMutex) { |
| 172 | return mServiceConnection.getCachedAttributes(); |
| 173 | } |
| 174 | } |
| 175 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 176 | public boolean requiresNetwork() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 177 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 178 | if (cachedAttributes != null) { |
| 179 | return cachedAttributes.requiresNetwork(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 180 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 181 | return false; |
| 182 | } |
| 183 | } |
| 184 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 185 | public boolean requiresSatellite() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 186 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 187 | if (cachedAttributes != null) { |
| 188 | return cachedAttributes.requiresSatellite(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 189 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | } |
| 193 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 194 | public boolean requiresCell() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 195 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 196 | if (cachedAttributes != null) { |
| 197 | return cachedAttributes.requiresCell(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 198 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 199 | return false; |
| 200 | } |
| 201 | } |
| 202 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 203 | public boolean hasMonetaryCost() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 204 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 205 | if (cachedAttributes != null) { |
| 206 | return cachedAttributes.hasMonetaryCost(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 207 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | } |
| 211 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 212 | public boolean supportsAltitude() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 213 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 214 | if (cachedAttributes != null) { |
| 215 | return cachedAttributes.supportsAltitude(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 216 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 217 | return false; |
| 218 | } |
| 219 | } |
| 220 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 221 | public boolean supportsSpeed() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 222 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 223 | if (cachedAttributes != null) { |
| 224 | return cachedAttributes.supportsSpeed(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 225 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 226 | return false; |
| 227 | } |
| 228 | } |
| 229 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 230 | public boolean supportsBearing() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 231 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 232 | if (cachedAttributes != null) { |
| 233 | return cachedAttributes.supportsBearing(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 234 | } else { |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 235 | return false; |
| 236 | } |
| 237 | } |
| 238 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 239 | public int getPowerRequirement() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 240 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 241 | if (cachedAttributes != null) { |
| 242 | return cachedAttributes.getPowerRequirement(); |
| 243 | } else { |
| 244 | return -1; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | public int getAccuracy() { |
| 249 | DummyLocationProvider cachedAttributes = getCachedAttributes(); |
| 250 | if (cachedAttributes != null) { |
| 251 | return cachedAttributes.getAccuracy(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 252 | } else { |
| 253 | return -1; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 257 | public boolean meetsCriteria(Criteria criteria) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 258 | synchronized (mMutex) { |
| 259 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 260 | if (provider != null) { |
| 261 | try { |
| 262 | return provider.meetsCriteria(criteria); |
| 263 | } catch (RemoteException e) { |
| 264 | } |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | // default implementation if we lost connection to the provider |
| 268 | if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) && |
| 269 | (criteria.getAccuracy() < getAccuracy())) { |
| 270 | return false; |
| 271 | } |
| 272 | int criteriaPower = criteria.getPowerRequirement(); |
| 273 | if ((criteriaPower != Criteria.NO_REQUIREMENT) && |
| 274 | (criteriaPower < getPowerRequirement())) { |
| 275 | return false; |
| 276 | } |
| 277 | if (criteria.isAltitudeRequired() && !supportsAltitude()) { |
| 278 | return false; |
| 279 | } |
| 280 | if (criteria.isSpeedRequired() && !supportsSpeed()) { |
| 281 | return false; |
| 282 | } |
| 283 | if (criteria.isBearingRequired() && !supportsBearing()) { |
| 284 | return false; |
| 285 | } |
| 286 | return true; |
| 287 | } |
| 288 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 289 | public void enable() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 290 | synchronized (mMutex) { |
| 291 | mEnabled = true; |
| 292 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 293 | if (provider != null) { |
| 294 | try { |
| 295 | provider.enable(); |
| 296 | } catch (RemoteException e) { |
| 297 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 298 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 302 | public void disable() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 303 | synchronized (mMutex) { |
| 304 | mEnabled = false; |
| 305 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 306 | if (provider != null) { |
| 307 | try { |
| 308 | provider.disable(); |
| 309 | } catch (RemoteException e) { |
| 310 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 311 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 315 | public boolean isEnabled() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 316 | synchronized (mMutex) { |
| 317 | return mEnabled; |
| 318 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 321 | public int getStatus(Bundle extras) { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 322 | ILocationProvider provider; |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 323 | synchronized (mMutex) { |
| 324 | provider = mServiceConnection.getProvider(); |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 325 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 326 | if (provider != null) { |
| 327 | try { |
| 328 | return provider.getStatus(extras); |
| 329 | } catch (RemoteException e) { |
| 330 | } |
| 331 | } |
| 332 | return 0; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 335 | public long getStatusUpdateTime() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 336 | ILocationProvider provider; |
| 337 | synchronized (mMutex) { |
| 338 | provider = mServiceConnection.getProvider(); |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 339 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 340 | if (provider != null) { |
| 341 | try { |
| 342 | return provider.getStatusUpdateTime(); |
| 343 | } catch (RemoteException e) { |
| 344 | } |
| 345 | } |
| 346 | return 0; |
| 347 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 348 | |
Fred Fettinger | 3c8fbdf | 2010-01-04 15:38:13 -0600 | [diff] [blame] | 349 | public String getInternalState() { |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 350 | ILocationProvider provider; |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 351 | synchronized (mMutex) { |
| 352 | provider = mServiceConnection.getProvider(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 353 | } |
| 354 | if (provider != null) { |
| 355 | try { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 356 | return provider.getInternalState(); |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 357 | } catch (RemoteException e) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 358 | Log.e(TAG, "getInternalState failed", e); |
| 359 | } |
| 360 | } |
| 361 | return null; |
| 362 | } |
| 363 | |
| 364 | public boolean isLocationTracking() { |
| 365 | synchronized (mMutex) { |
| 366 | return mLocationTracking; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | public void enableLocationTracking(boolean enable) { |
| 371 | synchronized (mMutex) { |
| 372 | mLocationTracking = enable; |
| 373 | if (!enable) { |
| 374 | mMinTime = -1; |
| 375 | mMinTimeSource.clear(); |
| 376 | } |
| 377 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 378 | if (provider != null) { |
| 379 | try { |
| 380 | provider.enableLocationTracking(enable); |
| 381 | } catch (RemoteException e) { |
| 382 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 383 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Mike Lockwood | 03ca216 | 2010-04-01 08:10:09 -0700 | [diff] [blame] | 387 | public boolean requestSingleShotFix() { |
| 388 | return false; |
| 389 | } |
| 390 | |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 391 | public long getMinTime() { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 392 | synchronized (mMutex) { |
| 393 | return mMinTime; |
| 394 | } |
Mike Lockwood | 15e3d0f | 2009-05-01 07:53:28 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 397 | public void setMinTime(long minTime, WorkSource ws) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 398 | synchronized (mMutex) { |
| 399 | mMinTime = minTime; |
| 400 | mMinTimeSource.set(ws); |
| 401 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 402 | if (provider != null) { |
| 403 | try { |
| 404 | provider.setMinTime(minTime, ws); |
| 405 | } catch (RemoteException e) { |
| 406 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 407 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Mike Lockwood | 03d2467 | 2009-10-08 15:45:03 -0400 | [diff] [blame] | 411 | public void updateNetworkState(int state, NetworkInfo info) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 412 | synchronized (mMutex) { |
| 413 | mNetworkState = state; |
| 414 | mNetworkInfo = info; |
| 415 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 416 | if (provider != null) { |
| 417 | try { |
| 418 | provider.updateNetworkState(state, info); |
| 419 | } catch (RemoteException e) { |
| 420 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 421 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 425 | public void updateLocation(Location location) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 426 | synchronized (mMutex) { |
| 427 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 428 | if (provider != null) { |
| 429 | try { |
| 430 | provider.updateLocation(location); |
| 431 | } catch (RemoteException e) { |
| 432 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 433 | } |
Mike Lockwood | fd6e5f0 | 2009-05-21 11:28:20 -0400 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 437 | public boolean sendExtraCommand(String command, Bundle extras) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 438 | synchronized (mMutex) { |
| 439 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 440 | if (provider != null) { |
| 441 | try { |
| 442 | return provider.sendExtraCommand(command, extras); |
| 443 | } catch (RemoteException e) { |
| 444 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | return false; |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 450 | public void addListener(int uid) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 451 | synchronized (mMutex) { |
| 452 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 453 | if (provider != null) { |
| 454 | try { |
| 455 | provider.addListener(uid); |
| 456 | } catch (RemoteException e) { |
| 457 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 458 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Mike Lockwood | 2f82c4e | 2009-04-17 08:24:10 -0400 | [diff] [blame] | 462 | public void removeListener(int uid) { |
Mark Vandevoorde | 8863c43 | 2010-10-04 14:23:24 -0700 | [diff] [blame] | 463 | synchronized (mMutex) { |
| 464 | ILocationProvider provider = mServiceConnection.getProvider(); |
| 465 | if (provider != null) { |
| 466 | try { |
| 467 | provider.removeListener(uid); |
| 468 | } catch (RemoteException e) { |
| 469 | } |
Mike Lockwood | 628fd6d | 2010-01-25 22:46:13 -0500 | [diff] [blame] | 470 | } |
| 471 | } |
Mike Lockwood | 3681f26 | 2009-05-12 10:52:03 -0400 | [diff] [blame] | 472 | } |
Mike Lockwood | e932f7f | 2009-04-06 10:51:26 -0700 | [diff] [blame] | 473 | } |