diff options
author | Mike Lockwood <lockwood@android.com> | 2009-12-07 18:43:36 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-02-02 13:21:21 -0500 |
commit | 2f3a615feaa1286612576bc15f6bd8cae011301f (patch) | |
tree | 19500de36cbdbd547198df0f4ec4335293e0c8ee /location/java | |
parent | 19563cc278446c2df7a2df6d5f7c89f43228c437 (diff) | |
download | frameworks_base-2f3a615feaa1286612576bc15f6bd8cae011301f.zip frameworks_base-2f3a615feaa1286612576bc15f6bd8cae011301f.tar.gz frameworks_base-2f3a615feaa1286612576bc15f6bd8cae011301f.tar.bz2 |
GpsLocationProvider: Do not release wakelock until the GPS engine is fully off
Change-Id: I705b1d33af2d70aa1084cca8f6280fade9461d2c
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'location/java')
-rwxr-xr-x | location/java/com/android/internal/location/GpsLocationProvider.java | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index cd62ed1..7763549 100755 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -875,53 +875,51 @@ public class GpsLocationProvider extends ILocationProvider.Stub { synchronized(mListeners) { boolean wasNavigating = mNavigating; mNavigating = (status == GPS_STATUS_SESSION_BEGIN); - - if (wasNavigating == mNavigating) { - return; - } - - if (mNavigating) { + + if (mNavigating && !mWakeLock.isHeld()) { if (DEBUG) Log.d(TAG, "Acquiring wakelock"); mWakeLock.acquire(); } - - int size = mListeners.size(); - for (int i = 0; i < size; i++) { - Listener listener = mListeners.get(i); + + if (wasNavigating != mNavigating) { + int size = mListeners.size(); + for (int i = 0; i < size; i++) { + Listener listener = mListeners.get(i); + try { + if (mNavigating) { + listener.mListener.onGpsStarted(); + } else { + listener.mListener.onGpsStopped(); + } + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in reportStatus"); + mListeners.remove(listener); + // adjust for size of list changing + size--; + } + } + try { - if (mNavigating) { - listener.mListener.onGpsStarted(); - } else { - listener.mListener.onGpsStopped(); + // update battery stats + for (int i=mClientUids.size() - 1; i >= 0; i--) { + int uid = mClientUids.keyAt(i); + if (mNavigating) { + mBatteryStats.noteStartGps(uid); + } else { + mBatteryStats.noteStopGps(uid); + } } } catch (RemoteException e) { Log.w(TAG, "RemoteException in reportStatus"); - mListeners.remove(listener); - // adjust for size of list changing - size--; } - } - try { - // update battery stats - for (int i=mClientUids.size() - 1; i >= 0; i--) { - int uid = mClientUids.keyAt(i); - if (mNavigating) { - mBatteryStats.noteStartGps(uid); - } else { - mBatteryStats.noteStopGps(uid); - } - } - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in reportStatus"); + // send an intent to notify that the GPS has been enabled or disabled. + Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION); + intent.putExtra(EXTRA_ENABLED, mNavigating); + mContext.sendBroadcast(intent); } - // send an intent to notify that the GPS has been enabled or disabled. - Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION); - intent.putExtra(EXTRA_ENABLED, mNavigating); - mContext.sendBroadcast(intent); - - if (!mNavigating) { + if (status == GPS_STATUS_ENGINE_OFF && mWakeLock.isHeld()) { if (DEBUG) Log.d(TAG, "Releasing wakelock"); mWakeLock.release(); } |