location: Location Manager wakelock cleanup
Location Providers are now responsible for their own wakelocks and scheduling. Also fixed a deadlock in LocationManagerService in the code for releasing wakelocks after client notifications have been received. The fix is to use the Receiver object and mWakeLock for synchronization instead of the global mLock lock. Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -44,6 +44,4 @@ interface ILocationProvider {
|
||||
boolean sendExtraCommand(String command, inout Bundle extras);
|
||||
void addListener(int uid);
|
||||
void removeListener(int uid);
|
||||
void wakeLockAcquired();
|
||||
void wakeLockReleased();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.SntpClient;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.SystemClock;
|
||||
@@ -207,6 +208,10 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
private int mSuplDataConnectionState;
|
||||
private final ConnectivityManager mConnMgr;
|
||||
|
||||
// Wakelocks
|
||||
private final static String WAKELOCK_KEY = "GpsLocationProvider";
|
||||
private final PowerManager.WakeLock mWakeLock;
|
||||
|
||||
// Alarms
|
||||
private final static String ALARM_WAKEUP = "com.android.internal.location.ALARM_WAKEUP";
|
||||
private final AlarmManager mAlarmManager;
|
||||
@@ -307,6 +312,10 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
mContext = context;
|
||||
mLocationManager = locationManager;
|
||||
|
||||
// Create a wake lock
|
||||
PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY);
|
||||
|
||||
mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
|
||||
mWakeupIntent = PendingIntent.getBroadcast(mContext, 0, new Intent(ALARM_WAKEUP), 0);
|
||||
|
||||
@@ -574,12 +583,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeLockAcquired() {
|
||||
}
|
||||
|
||||
public void wakeLockReleased() {
|
||||
}
|
||||
|
||||
public void addListener(int uid) {
|
||||
mClientUids.put(uid, 0);
|
||||
if (mNavigating) {
|
||||
@@ -767,6 +770,10 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
mNavigating = (status == GPS_STATUS_SESSION_BEGIN);
|
||||
|
||||
if (wasNavigating != mNavigating) {
|
||||
if (mNavigating) {
|
||||
if (DEBUG) Log.d(TAG, "Acquiring wakelock");
|
||||
mWakeLock.acquire();
|
||||
}
|
||||
synchronized(mListeners) {
|
||||
int size = mListeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -804,6 +811,11 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
|
||||
Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION);
|
||||
intent.putExtra(EXTRA_ENABLED, mNavigating);
|
||||
mContext.sendBroadcast(intent);
|
||||
|
||||
if (!mNavigating) {
|
||||
if (DEBUG) Log.d(TAG, "Releasing wakelock");
|
||||
mWakeLock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,20 +231,4 @@ public class LocationProviderProxy {
|
||||
Log.e(TAG, "removeListener failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeLockAcquired() {
|
||||
try {
|
||||
mProvider.wakeLockAcquired();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "wakeLockAcquired failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void wakeLockReleased() {
|
||||
try {
|
||||
mProvider.wakeLockReleased();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "wakeLockReleased failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,12 +182,6 @@ public class MockProvider extends ILocationProvider.Stub {
|
||||
public void removeListener(int uid) {
|
||||
}
|
||||
|
||||
public void wakeLockAcquired() {
|
||||
}
|
||||
|
||||
public void wakeLockReleased() {
|
||||
}
|
||||
|
||||
public void dump(PrintWriter pw, String prefix) {
|
||||
pw.println(prefix + mName);
|
||||
pw.println(prefix + "mHasLocation=" + mHasLocation);
|
||||
|
||||
Reference in New Issue
Block a user