b/2335780 Fixed race conditions which causes BT to not be in the correct state in respect to the dock state. DO NOT MERGE
Change-Id: I02825cbde24ff0215787bb2d4f78cd6e7e1f4033
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.app.Service;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -35,9 +36,11 @@ public class DockEventReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final int EXTRA_INVALID = -1234;
|
||||
|
||||
static final Object mStartingServiceSync = new Object();
|
||||
private static final Object mStartingServiceSync = new Object();
|
||||
|
||||
static PowerManager.WakeLock mStartingService;
|
||||
private static final long WAKELOCK_TIMEOUT = 5000;
|
||||
|
||||
private static PowerManager.WakeLock mStartingService;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -84,14 +87,12 @@ public class DockEventReceiver extends BroadcastReceiver {
|
||||
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
mStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||
"StartingDockService");
|
||||
mStartingService.setReferenceCounted(false);
|
||||
}
|
||||
|
||||
mStartingService.acquire();
|
||||
mStartingService.acquire(WAKELOCK_TIMEOUT);
|
||||
|
||||
if (context.startService(intent) == null) {
|
||||
Log.e(TAG, "Can't start DockService");
|
||||
mStartingService.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,9 +105,7 @@ public class DockEventReceiver extends BroadcastReceiver {
|
||||
synchronized (mStartingServiceSync) {
|
||||
if (mStartingService != null) {
|
||||
if (DEBUG) Log.d(TAG, "stopSelf id = "+ startId);
|
||||
if (service.stopSelfResult(startId)) {
|
||||
mStartingService.release();
|
||||
}
|
||||
service.stopSelfResult(startId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user