diff options
author | Dianne Hackborn <hackbod@google.com> | 2009-06-22 20:00:17 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2009-06-23 12:51:06 -0700 |
commit | 2e418428987132ea66533cbc05f9c526eb59519a (patch) | |
tree | b8ea1812f8e1514f960cb88fc496e25c718707e4 /location | |
parent | 61ab270c17094ef1373f54d8fb9ade6d287c3a60 (diff) | |
download | frameworks_base-2e418428987132ea66533cbc05f9c526eb59519a.zip frameworks_base-2e418428987132ea66533cbc05f9c526eb59519a.tar.gz frameworks_base-2e418428987132ea66533cbc05f9c526eb59519a.tar.bz2 |
Possibly fix an issue where we thought an app was always using GPS.
There may be some race conditions in the gps provider where it can cause a uid
to be double booked for gps usage and never released. Address this by tweaking
some locking (so mLocation and the uid array are protected by a lock both when
reading and writing). Also add some code to log a warning if someone tries to
note a particular uid multiple times, since the code will break in that case.
Finally, fix a problem in the battery stats where we weren't allowing a new Uid
structure to be created in many cases for calls coming in.
Diffstat (limited to 'location')
-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--; } } |