Skip to content

Commit 2f3a615

Browse files
committed
GpsLocationProvider: Do not release wakelock until the GPS engine is fully off
Change-Id: I705b1d33af2d70aa1084cca8f6280fade9461d2c Signed-off-by: Mike Lockwood <lockwood@android.com>
1 parent 19563cc commit 2f3a615

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

location/java/com/android/internal/location/GpsLocationProvider.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -875,53 +875,51 @@ private void reportStatus(int status) {
875875
synchronized(mListeners) {
876876
boolean wasNavigating = mNavigating;
877877
mNavigating = (status == GPS_STATUS_SESSION_BEGIN);
878-
879-
if (wasNavigating == mNavigating) {
880-
return;
881-
}
882-
883-
if (mNavigating) {
878+
879+
if (mNavigating && !mWakeLock.isHeld()) {
884880
if (DEBUG) Log.d(TAG, "Acquiring wakelock");
885881
mWakeLock.acquire();
886882
}
887-
888-
int size = mListeners.size();
889-
for (int i = 0; i < size; i++) {
890-
Listener listener = mListeners.get(i);
883+
884+
if (wasNavigating != mNavigating) {
885+
int size = mListeners.size();
886+
for (int i = 0; i < size; i++) {
887+
Listener listener = mListeners.get(i);
888+
try {
889+
if (mNavigating) {
890+
listener.mListener.onGpsStarted();
891+
} else {
892+
listener.mListener.onGpsStopped();
893+
}
894+
} catch (RemoteException e) {
895+
Log.w(TAG, "RemoteException in reportStatus");
896+
mListeners.remove(listener);
897+
// adjust for size of list changing
898+
size--;
899+
}
900+
}
901+
891902
try {
892-
if (mNavigating) {
893-
listener.mListener.onGpsStarted();
894-
} else {
895-
listener.mListener.onGpsStopped();
903+
// update battery stats
904+
for (int i=mClientUids.size() - 1; i >= 0; i--) {
905+
int uid = mClientUids.keyAt(i);
906+
if (mNavigating) {
907+
mBatteryStats.noteStartGps(uid);
908+
} else {
909+
mBatteryStats.noteStopGps(uid);
910+
}
896911
}
897912
} catch (RemoteException e) {
898913
Log.w(TAG, "RemoteException in reportStatus");
899-
mListeners.remove(listener);
900-
// adjust for size of list changing
901-
size--;
902914
}
903-
}
904915

905-
try {
906-
// update battery stats
907-
for (int i=mClientUids.size() - 1; i >= 0; i--) {
908-
int uid = mClientUids.keyAt(i);
909-
if (mNavigating) {
910-
mBatteryStats.noteStartGps(uid);
911-
} else {
912-
mBatteryStats.noteStopGps(uid);
913-
}
914-
}
915-
} catch (RemoteException e) {
916-
Log.w(TAG, "RemoteException in reportStatus");
916+
// send an intent to notify that the GPS has been enabled or disabled.
917+
Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION);
918+
intent.putExtra(EXTRA_ENABLED, mNavigating);
919+
mContext.sendBroadcast(intent);
917920
}
918921

919-
// send an intent to notify that the GPS has been enabled or disabled.
920-
Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION);
921-
intent.putExtra(EXTRA_ENABLED, mNavigating);
922-
mContext.sendBroadcast(intent);
923-
924-
if (!mNavigating) {
922+
if (status == GPS_STATUS_ENGINE_OFF && mWakeLock.isHeld()) {
925923
if (DEBUG) Log.d(TAG, "Releasing wakelock");
926924
mWakeLock.release();
927925
}

0 commit comments

Comments
 (0)