Merge change 750 into donut
* changes: Fixed the Bluetooth On/Off Checkbox in settings so it is enabled/disable properly.
This commit is contained in:
@@ -30,7 +30,6 @@ import android.os.Handler;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
|
* BluetoothDiscoverableEnabler is a helper to manage the "Discoverable"
|
||||||
@@ -39,7 +38,6 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChangeListener {
|
public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChangeListener {
|
||||||
private static final String TAG = "BluetoothDiscoverableEnabler";
|
private static final String TAG = "BluetoothDiscoverableEnabler";
|
||||||
private static final boolean V = LocalBluetoothManager.V;
|
|
||||||
|
|
||||||
private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
|
private static final String SYSTEM_PROPERTY_DISCOVERABLE_TIMEOUT =
|
||||||
"debug.bt.discoverable_time";
|
"debug.bt.discoverable_time";
|
||||||
@@ -109,10 +107,6 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||||
if (V) {
|
|
||||||
Log.v(TAG, "Preference changed to " + value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn on/off BT discoverability
|
// Turn on/off BT discoverability
|
||||||
setEnabled((Boolean) value);
|
setEnabled((Boolean) value);
|
||||||
|
|
||||||
@@ -155,10 +149,6 @@ public class BluetoothDiscoverableEnabler implements Preference.OnPreferenceChan
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleModeChanged(int mode) {
|
private void handleModeChanged(int mode) {
|
||||||
if (V) {
|
|
||||||
Log.v(TAG, "Got mode changed: " + mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
if (mode == BluetoothDevice.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||||
mCheckBoxPreference.setChecked(true);
|
mCheckBoxPreference.setChecked(true);
|
||||||
updateCountdownSummary();
|
updateCountdownSummary();
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothError;
|
||||||
import android.bluetooth.BluetoothIntent;
|
import android.bluetooth.BluetoothIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -48,7 +49,9 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
handleStateChanged(mLocalManager.getBluetoothState());
|
int state = intent.getIntExtra(BluetoothIntent.BLUETOOTH_STATE,
|
||||||
|
BluetoothError.ERROR);
|
||||||
|
handleStateChanged(state);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -47,6 +47,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||||
private static final String TAG = "LocalBluetoothDevice";
|
private static final String TAG = "LocalBluetoothDevice";
|
||||||
|
private static final boolean D = LocalBluetoothManager.D;
|
||||||
|
private static final boolean V = LocalBluetoothManager.V;
|
||||||
|
|
||||||
private static final int CONTEXT_ITEM_CONNECT = Menu.FIRST + 1;
|
private static final int CONTEXT_ITEM_CONNECT = Menu.FIRST + 1;
|
||||||
private static final int CONTEXT_ITEM_DISCONNECT = Menu.FIRST + 2;
|
private static final int CONTEXT_ITEM_DISCONNECT = Menu.FIRST + 2;
|
||||||
@@ -124,18 +126,21 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
private static LinkedList<BluetoothJob> workQueue = new LinkedList<BluetoothJob>();
|
private static LinkedList<BluetoothJob> workQueue = new LinkedList<BluetoothJob>();
|
||||||
|
|
||||||
private void queueCommand(BluetoothJob job) {
|
private void queueCommand(BluetoothJob job) {
|
||||||
Log.d(TAG, workQueue.toString());
|
if (D) {
|
||||||
|
Log.d(TAG, workQueue.toString());
|
||||||
|
}
|
||||||
synchronized (workQueue) {
|
synchronized (workQueue) {
|
||||||
boolean processNow = pruneQueue(job);
|
boolean processNow = pruneQueue(job);
|
||||||
|
|
||||||
// Add job to queue
|
// Add job to queue
|
||||||
Log.d(TAG, "Adding: " + job.toString());
|
if (D) {
|
||||||
|
Log.d(TAG, "Adding: " + job.toString());
|
||||||
|
}
|
||||||
workQueue.add(job);
|
workQueue.add(job);
|
||||||
|
|
||||||
// if there's nothing pending from before, send the command to bt
|
// if there's nothing pending from before, send the command to bt
|
||||||
// framework immediately.
|
// framework immediately.
|
||||||
if (workQueue.size() == 1 || processNow) {
|
if (workQueue.size() == 1 || processNow) {
|
||||||
Log.d(TAG, "workQueue.size() == 1 || TimeOut -> process command now");
|
|
||||||
// If the failed to process, just drop it from the queue.
|
// If the failed to process, just drop it from the queue.
|
||||||
// There will be no callback to remove this from the queue.
|
// There will be no callback to remove this from the queue.
|
||||||
processCommands();
|
processCommands();
|
||||||
@@ -156,7 +161,9 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
&& existingJob.command == BluetoothCommand.CONNECT
|
&& existingJob.command == BluetoothCommand.CONNECT
|
||||||
&& existingJob.device.mAddress.equals(job.device.mAddress)
|
&& existingJob.device.mAddress.equals(job.device.mAddress)
|
||||||
&& existingJob.profile == job.profile) {
|
&& existingJob.profile == job.profile) {
|
||||||
Log.d(TAG, "Removed because of a pending disconnect. " + existingJob);
|
if (D) {
|
||||||
|
Log.d(TAG, "Removed because of a pending disconnect. " + existingJob);
|
||||||
|
}
|
||||||
it.remove();
|
it.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -165,7 +172,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
// Defensive Code: Remove any job that older than a preset time.
|
// Defensive Code: Remove any job that older than a preset time.
|
||||||
// We never got a call back. It is better to have overlapping
|
// We never got a call back. It is better to have overlapping
|
||||||
// calls than to get stuck.
|
// calls than to get stuck.
|
||||||
Log.d(TAG, "Age:" + (now - existingJob.timeSent));
|
|
||||||
if (existingJob.timeSent != 0
|
if (existingJob.timeSent != 0
|
||||||
&& (now - existingJob.timeSent) >= MAX_WAIT_TIME_FOR_FRAMEWORK) {
|
&& (now - existingJob.timeSent) >= MAX_WAIT_TIME_FOR_FRAMEWORK) {
|
||||||
Log.w(TAG, "Timeout. Removing Job:" + existingJob.toString());
|
Log.w(TAG, "Timeout. Removing Job:" + existingJob.toString());
|
||||||
@@ -191,12 +197,13 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (successful) {
|
if (successful) {
|
||||||
Log.d(TAG, "Command sent successfully:" + job.toString());
|
if (D) {
|
||||||
} else {
|
Log.d(TAG, "Command sent successfully:" + job.toString());
|
||||||
Log.d(TAG, "Framework rejected command immediately:" + job.toString());
|
}
|
||||||
|
} else if (V) {
|
||||||
|
Log.v(TAG, "Framework rejected command immediately:" + job.toString());
|
||||||
}
|
}
|
||||||
|
} else if (D) {
|
||||||
} else {
|
|
||||||
Log.d(TAG, "Job already has a sent time. Skip. " + job.toString());
|
Log.d(TAG, "Job already has a sent time. Skip. " + job.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,19 +211,19 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onProfileStateChanged() {
|
public void onProfileStateChanged() {
|
||||||
Log.d(TAG, "onProfileStateChanged:" + workQueue.toString());
|
if (D) {
|
||||||
|
Log.d(TAG, "onProfileStateChanged:" + workQueue.toString());
|
||||||
|
}
|
||||||
BluetoothJob job = workQueue.peek();
|
BluetoothJob job = workQueue.peek();
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
Log.v(TAG, "Yikes, onProfileStateChanged called but job queue is empty. "
|
|
||||||
+ "(Okay for device initiated actions and BluetoothA2dpService initiated "
|
|
||||||
+ "Auto-connections)");
|
|
||||||
return;
|
return;
|
||||||
} else if (job.device.mAddress != mAddress) {
|
} else if (job.device.mAddress != mAddress) {
|
||||||
// This can happen in 2 cases: 1) BT device initiated pairing and
|
// This can happen in 2 cases: 1) BT device initiated pairing and
|
||||||
// 2) disconnects of one headset that's triggered by connects of
|
// 2) disconnects of one headset that's triggered by connects of
|
||||||
// another.
|
// another.
|
||||||
Log.v(TAG, "onProfileStateChanged called. The addresses differ. this.mAddress="
|
if (D) {
|
||||||
+ mAddress + " workQueue.head=" + job.toString());
|
Log.d(TAG, "mAddresses:" + mAddress + " != head:" + job.toString());
|
||||||
|
}
|
||||||
|
|
||||||
// Check to see if we need to remove the stale items from the queue
|
// Check to see if we need to remove the stale items from the queue
|
||||||
if (!pruneQueue(null)) {
|
if (!pruneQueue(null)) {
|
||||||
@@ -225,7 +232,6 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remove the first item and process the next one
|
// Remove the first item and process the next one
|
||||||
Log.d(TAG, "LocalBluetoothDevice.onProfileStateChanged() called. MAC addr matched");
|
|
||||||
workQueue.poll();
|
workQueue.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +246,9 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
|||||||
* notification when it finishes processing a command
|
* notification when it finishes processing a command
|
||||||
*/
|
*/
|
||||||
private void processCommands() {
|
private void processCommands() {
|
||||||
Log.d(TAG, "processCommands:" + workQueue.toString());
|
if (D) {
|
||||||
|
Log.d(TAG, "processCommands:" + workQueue.toString());
|
||||||
|
}
|
||||||
Iterator<BluetoothJob> it = workQueue.iterator();
|
Iterator<BluetoothJob> it = workQueue.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
BluetoothJob job = it.next();
|
BluetoothJob job = it.next();
|
||||||
|
@@ -30,6 +30,7 @@ import android.bluetooth.BluetoothIntent;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.util.Config;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -40,7 +41,8 @@ import android.widget.Toast;
|
|||||||
*/
|
*/
|
||||||
public class LocalBluetoothManager {
|
public class LocalBluetoothManager {
|
||||||
private static final String TAG = "LocalBluetoothManager";
|
private static final String TAG = "LocalBluetoothManager";
|
||||||
static final boolean V = true;
|
static final boolean V = Config.LOGV;
|
||||||
|
static final boolean D = Config.LOGD && false;
|
||||||
|
|
||||||
private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
|
private static final String SHARED_PREFERENCES_NAME = "bluetooth_settings";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user