Fetch the Bluetooth name and address without enabling the whole stack
After factory reset and first bootup, fetching the Bluetooth device
name and address is now done without explicitly enabling/disabling
the whole Bluetooth stack.
Apparently, enabling/disabling the whole stack during th first bootup
was somehow holding the kernel wakelock without releasing it.
Also, disable debug log messages for class BluetoothManagerService.
Bug: 21949364
Change-Id: Iffc14f7969d05c1456159d1f4246c53fb5df0f7a
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index f9f6714..b33b10b 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -61,7 +61,7 @@
import java.util.Map;
class BluetoothManagerService extends IBluetoothManager.Stub {
private static final String TAG = "BluetoothManagerService";
- private static final boolean DBG = true;
+ private static final boolean DBG = false;
private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
@@ -227,21 +227,23 @@
}
}
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
+ if (DBG) Log.d(TAG, "Bluetooth user switched");
mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_USER_SWITCHED,
intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0), 0));
} else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
+ if (DBG) Log.d(TAG, "Bluetooth boot completed");
synchronized(mReceiver) {
if (mEnableExternal && isBluetoothPersistedStateOnBluetooth()) {
//Enable
if (DBG) Log.d(TAG, "Auto-enabling Bluetooth.");
sendEnableMsg(mQuietEnableExternal);
}
- }
-
- if (!isNameAndAddressSet()) {
- // Sync the Bluetooth name and address from the Bluetooth Adapter
- if (DBG) Log.d(TAG,"Retrieving Bluetooth Adapter name and address...");
- getNameAndAddress();
+ if (!isNameAndAddressSet()) {
+ // Sync the Bluetooth name and address from the
+ // Bluetooth Adapter
+ if (DBG) Log.d(TAG, "Retrieving Bluetooth Adapter name and address...");
+ getNameAndAddress();
+ }
}
}
}
@@ -1099,7 +1101,7 @@
boolean unbind = false;
if (DBG) Log.d(TAG,"MESSAGE_SAVE_NAME_AND_ADDRESS");
synchronized(mConnection) {
- if (!mEnable && mBluetooth != null) {
+ if (!mEnable && mBluetooth != null && !mConnection.isGetNameAddressOnly()) {
try {
mBluetooth.enable();
} catch (RemoteException e) {
@@ -1107,7 +1109,7 @@
}
}
}
- if (mBluetooth != null) waitForOnOff(true, false);
+ if (mBluetooth != null && !mConnection.isGetNameAddressOnly()) waitForOnOff(true, false);
synchronized(mConnection) {
if (mBluetooth != null) {
String name = null;
@@ -1137,7 +1139,7 @@
}
}
}
- if (!mEnable) {
+ if (!mEnable && !mConnection.isGetNameAddressOnly()) {
try {
mBluetooth.disable();
} catch (RemoteException e) {
@@ -1152,7 +1154,9 @@
mHandler.sendMessage(getMsg);
}
}
- if (!mEnable && mBluetooth != null) waitForOnOff(false, true);
+ if (!mEnable && mBluetooth != null && !mConnection.isGetNameAddressOnly()) {
+ waitForOnOff(false, true);
+ }
if (unbind) {
unbindAndFinish();
}