diff options
| author | Dianne Hackborn <hackbod@google.com> | 2009-06-23 13:08:40 -0700 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-06-23 13:08:40 -0700 |
| commit | 3618160a1a10ab7574f14e0e5a45fe79ec660a64 (patch) | |
| tree | 1ee8d98eeee9c33fce3e8638d7f1e0b1baab700c /location/java | |
| parent | 03e53b4a6601823622dc9316f4c57899269b2349 (diff) | |
| parent | 2e418428987132ea66533cbc05f9c526eb59519a (diff) | |
| download | frameworks_base-3618160a1a10ab7574f14e0e5a45fe79ec660a64.zip frameworks_base-3618160a1a10ab7574f14e0e5a45fe79ec660a64.tar.gz frameworks_base-3618160a1a10ab7574f14e0e5a45fe79ec660a64.tar.bz2 | |
am 2e418428: Possibly fix an issue where we thought an app was always using GPS.
Merge commit '2e418428987132ea66533cbc05f9c526eb59519a'
* commit '2e418428987132ea66533cbc05f9c526eb59519a':
Possibly fix an issue where we thought an app was always using GPS.
Diffstat (limited to 'location/java')
| -rwxr-xr-x | location/java/com/android/internal/location/GpsLocationProvider.java | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index 5c8fcf2..edd1ea0 100755 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -621,23 +621,37 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } public void addListener(int uid) { - mClientUids.put(uid, 0); - if (mNavigating) { - try { - mBatteryStats.noteStartGps(uid); - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in addListener"); + synchronized(mListeners) { + if (mClientUids.indexOfKey(uid) >= 0) { + // Shouldn't be here -- already have this uid. + Log.w(TAG, "Duplicate add listener for uid " + uid); + return; + } + mClientUids.put(uid, 0); + if (mNavigating) { + try { + mBatteryStats.noteStartGps(uid); + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in addListener"); + } } } } public void removeListener(int uid) { - mClientUids.delete(uid); - if (mNavigating) { - try { - mBatteryStats.noteStopGps(uid); - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in removeListener"); + synchronized(mListeners) { + if (mClientUids.indexOfKey(uid) < 0) { + // Shouldn't be here -- don't have this uid. + Log.w(TAG, "Unneeded remove listener for uid " + uid); + return; + } + mClientUids.delete(uid); + if (mNavigating) { + try { + mBatteryStats.noteStopGps(uid); + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in removeListener"); + } } } } @@ -836,30 +850,33 @@ public class GpsLocationProvider extends ILocationProvider.Stub { private void reportStatus(int status) { if (VERBOSE) Log.v(TAG, "reportStatus status: " + status); - boolean wasNavigating = mNavigating; - mNavigating = (status == GPS_STATUS_SESSION_BEGIN); - - if (wasNavigating != mNavigating) { + synchronized(mListeners) { + boolean wasNavigating = mNavigating; + mNavigating = (status == GPS_STATUS_SESSION_BEGIN); + + if (wasNavigating == mNavigating) { + return; + } + if (mNavigating) { if (DEBUG) Log.d(TAG, "Acquiring wakelock"); mWakeLock.acquire(); } - synchronized(mListeners) { - 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--; + + 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--; } } |
