diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2d96ff6bd1c..27bcf19d70e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -837,6 +837,17 @@
Tethered
+
+ %1$s will be disconnected from media audio.
+
+ %1$s will be disconnected from tablet audio.
+
+ %1$s will be disconnected from phone audio.
+
+ %1$s will be disconnected from input device.
+
+ %1$s will be disconnected from tethering.
+
%1$s options
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
index 42118149cbf..890da3dff34 100644
--- a/src/com/android/settings/SettingsPreferenceFragment.java
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -155,7 +155,6 @@ public class SettingsPreferenceFragment extends PreferenceFragment
mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId));
}
- @Override
public Dialog onCreateDialog(int dialogId) {
return null;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
index acbb99c8a4c..4b7a0e071ce 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java
@@ -46,8 +46,8 @@ public class BluetoothPairingDialog extends AlertActivity implements DialogInter
TextWatcher {
private static final String TAG = "BluetoothPairingDialog";
- private final int BLUETOOTH_PIN_MAX_LENGTH = 16;
- private final int BLUETOOTH_PASSKEY_MAX_LENGTH = 6;
+ private static final int BLUETOOTH_PIN_MAX_LENGTH = 16;
+ private static final int BLUETOOTH_PASSKEY_MAX_LENGTH = 6;
private LocalBluetoothManager mLocalManager;
private BluetoothDevice mDevice;
private int mType;
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 841c9abc4c9..e206c3dc0bc 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -251,7 +251,6 @@ public class BluetoothSettings extends SettingsPreferenceFragment
}
}
- @Override
public void onUserLeaveHint() {
mLocalManager.stopScanning();
}
diff --git a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
index 22fa0055ede..bfd2e9927c3 100644
--- a/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
+++ b/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
@@ -104,9 +104,9 @@ public class CachedBluetoothDevice implements Comparable
* @param profile Profile to describe
* @return Description of the device and profile
*/
- private String describe(CachedBluetoothDevice cachedDevice, Profile profile) {
+ private String describe(Profile profile) {
StringBuilder sb = new StringBuilder();
- sb.append("Address:").append(cachedDevice.mDevice);
+ sb.append("Address:").append(mDevice);
if (profile != null) {
sb.append(" Profile:").append(profile.name());
}
@@ -114,10 +114,6 @@ public class CachedBluetoothDevice implements Comparable
return sb.toString();
}
- private String describe(Profile profile) {
- return describe(this, profile);
- }
-
public void onProfileStateChanged(Profile profile, int newProfileState) {
if (D) {
Log.d(TAG, "onProfileStateChanged: profile " + profile.toString() +
@@ -166,20 +162,13 @@ public class CachedBluetoothDevice implements Comparable
}
public void disconnect(Profile profile) {
- disconnectInt(this, profile);
- }
-
- private boolean disconnectInt(CachedBluetoothDevice cachedDevice, Profile profile) {
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
- int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
- if (profileManager.disconnect(cachedDevice.mDevice)) {
+ if (profileManager.disconnect(mDevice)) {
if (D) {
Log.d(TAG, "Command sent successfully:DISCONNECT " + describe(profile));
}
- return true;
}
- return false;
}
public void askDisconnect() {
@@ -204,6 +193,57 @@ public class CachedBluetoothDevice implements Comparable
}
};
+ showDisconnectDialog(context, disconnectListener, message);
+ }
+
+ public void askDisconnect(final Profile profile) {
+ Context context = mLocalManager.getForegroundActivity();
+ if (context == null) {
+ // Cannot ask, since we need an activity context
+ disconnect(profile);
+ return;
+ }
+
+ Resources res = context.getResources();
+
+ String name = getName();
+ if (TextUtils.isEmpty(name)) {
+ name = res.getString(R.string.bluetooth_device);
+ }
+ int disconnectMessage;
+ switch (profile) {
+ case A2DP:
+ disconnectMessage = R.string.bluetooth_disconnect_a2dp_profile;
+ break;
+ case HEADSET:
+ disconnectMessage = R.string.bluetooth_disconnect_headset_profile;
+ break;
+ case HID:
+ disconnectMessage = R.string.bluetooth_disconnect_hid_profile;
+ break;
+ case PAN:
+ disconnectMessage = R.string.bluetooth_disconnect_pan_profile;
+ break;
+ default:
+ Log.w(TAG, "askDisconnect: unexpected profile " + profile);
+ disconnectMessage = R.string.bluetooth_disconnect_blank;
+ break;
+ }
+ String message = res.getString(disconnectMessage, name);
+
+ DialogInterface.OnClickListener disconnectListener =
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ disconnect(profile);
+ }
+ };
+
+ showDisconnectDialog(context, disconnectListener, message);
+ }
+
+ private void showDisconnectDialog(Context context,
+ DialogInterface.OnClickListener disconnectListener,
+ String message) {
if (mDialog == null) {
mDialog = new AlertDialog.Builder(context)
.setPositiveButton(android.R.string.ok, disconnectListener)
@@ -213,6 +253,10 @@ public class CachedBluetoothDevice implements Comparable
if (mDialog.isShowing()) {
mDialog.dismiss();
}
+ // use disconnectListener for the correct profile(s)
+ CharSequence okText = context.getText(android.R.string.ok);
+ mDialog.setButton(DialogInterface.BUTTON_POSITIVE,
+ okText, disconnectListener);
}
mDialog.setTitle(getName());
mDialog.setMessage(message);
@@ -311,7 +355,7 @@ public class CachedBluetoothDevice implements Comparable
CachedBluetoothDevice cachedDevice = cachedDeviceManager.findDevice(btDevice);
if (cachedDevice != null && !cachedDevice.equals(device)) {
- disconnectInt(cachedDevice, profile);
+ cachedDevice.disconnect(profile);
}
}
}
@@ -321,7 +365,7 @@ public class CachedBluetoothDevice implements Comparable
LocalBluetoothProfileManager profileManager =
LocalBluetoothProfileManager.getProfileManager(mLocalManager, profile);
- int status = profileManager.getConnectionStatus(cachedDevice.mDevice);
+
if (profileManager.connect(cachedDevice.mDevice)) {
if (D) {
Log.d(TAG, "Command sent successfully:CONNECT " + describe(profile));
diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
index f8a66f68063..d6f192a119c 100644
--- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
+++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java
@@ -21,7 +21,6 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.bluetooth.LocalBluetoothProfileManager.Profile;
import android.bluetooth.BluetoothDevice;
-import android.content.Context;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@@ -35,8 +34,8 @@ import android.view.View;
import java.util.HashMap;
/**
- * ConnectSpecificProfilesActivity presents the user with all of the profiles
- * for a particular device, and allows him to choose which should be connected
+ * This preference fragment presents the user with all of the profiles
+ * for a particular device, and allows them to be individually connected
* (or disconnected).
*/
public class DeviceProfilesSettings extends SettingsPreferenceFragment
@@ -155,9 +154,6 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
pref.setOrder(getProfilePreferenceIndex(profile));
pref.setOnExpandClickListener(this);
- LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
- .getProfileManager(mManager, profile);
-
/**
* Gray out profile while connecting and disconnecting
*/
@@ -172,7 +168,7 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
String key = preference.getKey();
if (preference instanceof BluetoothProfilePreference) {
- onProfileClicked(preference, Profile.valueOf(key));
+ onProfileClicked(Profile.valueOf(key));
return true;
} else if (key.equals(KEY_UNPAIR)) {
unpairDevice();
@@ -196,18 +192,24 @@ public class DeviceProfilesSettings extends SettingsPreferenceFragment
return true;
}
- private void onProfileClicked(Preference preference, Profile profile) {
+ private void onProfileClicked(Profile profile) {
+ BluetoothDevice device = mCachedDevice.getDevice();
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
.getProfileManager(mManager, profile);
- // TODO: Get the current state and flip it, updating the summary for the preference
-// profileManager.setPreferred(mCachedDevice.getDevice(), checked);
-//
-// if (checked) {
-// mCachedDevice.connect(profile);
-// } else {
-// mCachedDevice.disconnect(profile);
-// }
+ int status = profileManager.getConnectionStatus(device);
+ boolean isConnected =
+ SettingsBtStatus.isConnectionStatusConnected(status);
+
+ // TODO: only change the preference on disconnect if user confirms
+ // TODO: add method to change priority of individual profiles
+ // profileManager.setPreferred(device, !isConnected);
+
+ if (isConnected) {
+ mCachedDevice.askDisconnect(profile);
+ } else {
+ mCachedDevice.connect(profile);
+ }
}
public void onDeviceAttributesChanged(CachedBluetoothDevice cachedDevice) {
diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java
index e817e787250..0641a034fb3 100644
--- a/src/com/android/settings/bluetooth/DockService.java
+++ b/src/com/android/settings/bluetooth/DockService.java
@@ -496,7 +496,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
private CharSequence[] initBtSettings(DockService service, BluetoothDevice device, int state,
boolean firstTime) {
// TODO Avoid hardcoding dock and profiles. Read from system properties
- int numOfProfiles = 0;
+ int numOfProfiles;
switch (state) {
case Intent.EXTRA_DOCK_STATE_DESK:
numOfProfiles = 1;
@@ -729,7 +729,7 @@ public class DockService extends Service implements AlertDialog.OnMultiChoiceCli
profileManager.setPreferred(device, mCheckedItems[i]);
if (DEBUG) {
if (mCheckedItems[i] != profileManager.isPreferred(device)) {
- Log.e(TAG, "Can't save prefered value");
+ Log.e(TAG, "Can't save preferred value");
}
}
}
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothManager.java b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
index b46cc96d2f1..07d39311e04 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothManager.java
@@ -70,7 +70,7 @@ public class LocalBluetoothManager {
// If a device was picked from the device picker or was in discoverable mode
// in the last 60 seconds, show the pairing dialogs in foreground instead
// of raising notifications
- private static long GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000;
+ private static final int GRACE_PERIOD_TO_SHOW_DIALOGS_IN_FOREGROUND = 60 * 1000;
public static final String SHARED_PREFERENCES_KEY_DISCOVERING_TIMESTAMP =
"last_discovering_time";
diff --git a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
index f7ad3d3c4b5..a01fdecd646 100644
--- a/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
+++ b/src/com/android/settings/bluetooth/LocalBluetoothProfileManager.java
@@ -225,7 +225,7 @@ public abstract class LocalBluetoothProfileManager {
}
// TODO: int instead of enum
- public enum Profile {
+ public static enum Profile {
HEADSET(R.string.bluetooth_profile_headset),
A2DP(R.string.bluetooth_profile_a2dp),
OPP(R.string.bluetooth_profile_opp),
@@ -433,7 +433,7 @@ public abstract class LocalBluetoothProfileManager {
public boolean disconnect(BluetoothDevice device) {
List deviceList = getConnectedDevices();
if (deviceList.size() != 0 && deviceList.get(0).equals(device)) {
- // Downgrade prority as user is disconnecting the headset.
+ // Downgrade priority as user is disconnecting the headset.
if (mService.getPriority(device) > BluetoothProfile.PRIORITY_ON) {
mService.setPriority(device, BluetoothProfile.PRIORITY_ON);
}