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