summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-06-22 20:00:17 -0700
committerDianne Hackborn <hackbod@google.com>2009-06-23 12:51:06 -0700
commit2e418428987132ea66533cbc05f9c526eb59519a (patch)
treeb8ea1812f8e1514f960cb88fc496e25c718707e4
parent61ab270c17094ef1373f54d8fb9ade6d287c3a60 (diff)
downloadframeworks_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.
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java74
-rwxr-xr-xlocation/java/com/android/internal/location/GpsLocationProvider.java79
2 files changed, 64 insertions, 89 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 16a3bad..58a3a83 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -984,11 +984,11 @@ public final class BatteryStatsImpl extends BatteryStats {
}
public void noteStartGps(int uid) {
- mUidStats.get(uid).noteStartGps();
+ getUidStatsLocked(uid).noteStartGps();
}
public void noteStopGps(int uid) {
- mUidStats.get(uid).noteStopGps();
+ getUidStatsLocked(uid).noteStopGps();
}
public void noteScreenOnLocked() {
@@ -1032,10 +1032,7 @@ public final class BatteryStatsImpl extends BatteryStats {
}
public void noteUserActivityLocked(int uid, int event) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteUserActivityLocked(event);
- }
+ getUidStatsLocked(uid).noteUserActivityLocked(event);
}
public void notePhoneOnLocked() {
@@ -1115,16 +1112,10 @@ public final class BatteryStatsImpl extends BatteryStats {
}
if (mWifiOnUid != uid) {
if (mWifiOnUid >= 0) {
- Uid u = mUidStats.get(mWifiOnUid);
- if (u != null) {
- u.noteWifiTurnedOffLocked();
- }
+ getUidStatsLocked(mWifiOnUid).noteWifiTurnedOffLocked();
}
mWifiOnUid = uid;
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteWifiTurnedOnLocked();
- }
+ getUidStatsLocked(uid).noteWifiTurnedOnLocked();
}
}
@@ -1134,10 +1125,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mWifiOnTimer.stopRunningLocked(this);
}
if (mWifiOnUid >= 0) {
- Uid u = mUidStats.get(mWifiOnUid);
- if (u != null) {
- u.noteWifiTurnedOffLocked();
- }
+ getUidStatsLocked(mWifiOnUid).noteWifiTurnedOffLocked();
mWifiOnUid = -1;
}
}
@@ -1147,10 +1135,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mAudioOn = true;
mAudioOnTimer.startRunningLocked(this);
}
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteAudioTurnedOnLocked();
- }
+ getUidStatsLocked(uid).noteAudioTurnedOnLocked();
}
public void noteAudioOffLocked(int uid) {
@@ -1158,10 +1143,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mAudioOn = false;
mAudioOnTimer.stopRunningLocked(this);
}
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteAudioTurnedOffLocked();
- }
+ getUidStatsLocked(uid).noteAudioTurnedOffLocked();
}
public void noteVideoOnLocked(int uid) {
@@ -1169,10 +1151,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mVideoOn = true;
mVideoOnTimer.startRunningLocked(this);
}
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteVideoTurnedOnLocked();
- }
+ getUidStatsLocked(uid).noteVideoTurnedOnLocked();
}
public void noteVideoOffLocked(int uid) {
@@ -1180,10 +1159,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mVideoOn = false;
mVideoOnTimer.stopRunningLocked(this);
}
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteVideoTurnedOffLocked();
- }
+ getUidStatsLocked(uid).noteVideoTurnedOffLocked();
}
public void noteWifiRunningLocked() {
@@ -1215,45 +1191,27 @@ public final class BatteryStatsImpl extends BatteryStats {
}
public void noteFullWifiLockAcquiredLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteFullWifiLockAcquiredLocked();
- }
+ getUidStatsLocked(uid).noteFullWifiLockAcquiredLocked();
}
public void noteFullWifiLockReleasedLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteFullWifiLockReleasedLocked();
- }
+ getUidStatsLocked(uid).noteFullWifiLockReleasedLocked();
}
public void noteScanWifiLockAcquiredLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteScanWifiLockAcquiredLocked();
- }
+ getUidStatsLocked(uid).noteScanWifiLockAcquiredLocked();
}
public void noteScanWifiLockReleasedLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteScanWifiLockReleasedLocked();
- }
+ getUidStatsLocked(uid).noteScanWifiLockReleasedLocked();
}
public void noteWifiMulticastEnabledLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteWifiMulticastEnabledLocked();
- }
+ getUidStatsLocked(uid).noteWifiMulticastEnabledLocked();
}
public void noteWifiMulticastDisabledLocked(int uid) {
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.noteWifiMulticastDisabledLocked();
- }
+ getUidStatsLocked(uid).noteWifiMulticastDisabledLocked();
}
@Override public long getScreenOnTime(long batteryRealtime, int which) {
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--;
}
}