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.
This commit is contained in:
@ -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) {
|
||||
|
@ -621,6 +621,12 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
|
||||
public void addListener(int uid) {
|
||||
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 {
|
||||
@ -630,8 +636,15 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener(int uid) {
|
||||
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 {
|
||||
@ -641,6 +654,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendExtraCommand(String command, Bundle extras) {
|
||||
|
||||
@ -836,15 +850,19 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
private void reportStatus(int status) {
|
||||
if (VERBOSE) Log.v(TAG, "reportStatus status: " + status);
|
||||
|
||||
synchronized(mListeners) {
|
||||
boolean wasNavigating = mNavigating;
|
||||
mNavigating = (status == GPS_STATUS_SESSION_BEGIN);
|
||||
|
||||
if (wasNavigating != mNavigating) {
|
||||
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);
|
||||
@ -861,7 +879,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// update battery stats
|
||||
|
Reference in New Issue
Block a user