Add keyboard support to bluetooth settings.
Change-Id: I8fe41056acd074374cd249bfd0be6034f2614d37
This commit is contained in:
@@ -754,6 +754,8 @@
|
|||||||
<string name="bluetooth_profile_headset">Phone</string>
|
<string name="bluetooth_profile_headset">Phone</string>
|
||||||
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the OPP profile. -->
|
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the OPP profile. -->
|
||||||
<string name="bluetooth_profile_opp">Transfer</string>
|
<string name="bluetooth_profile_opp">Transfer</string>
|
||||||
|
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the HID profile. -->
|
||||||
|
<string name="bluetooth_profile_hid">Input Device</string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP profile. -->
|
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP profile. -->
|
||||||
<string name="bluetooth_summary_connected_to_a2dp">Connected to media audio</string>
|
<string name="bluetooth_summary_connected_to_a2dp">Connected to media audio</string>
|
||||||
@@ -761,6 +763,8 @@
|
|||||||
<string name="bluetooth_summary_connected_to_headset">Connected to phone audio</string>
|
<string name="bluetooth_summary_connected_to_headset">Connected to phone audio</string>
|
||||||
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP and headset profiles. -->
|
<!-- Bluetooth settings. The summary string when a device is connected to the A2DP and headset profiles. -->
|
||||||
<string name="bluetooth_summary_connected_to_a2dp_headset">Connected to phone and media audio</string>
|
<string name="bluetooth_summary_connected_to_a2dp_headset">Connected to phone and media audio</string>
|
||||||
|
<!-- Bluetooth settings. The summary string when a device is connected to the HID profile. -->
|
||||||
|
<string name="bluetooth_summary_connected_to_hid">Connected to input device</string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. Connection options screen. The title of the screen. -->
|
<!-- Bluetooth settings. Connection options screen. The title of the screen. -->
|
||||||
<string name="bluetooth_device_advanced_title"><xliff:g id="device_name">%1$s</xliff:g> options</string>
|
<string name="bluetooth_device_advanced_title"><xliff:g id="device_name">%1$s</xliff:g> options</string>
|
||||||
@@ -778,6 +782,8 @@
|
|||||||
<string name="bluetooth_opp_profile_summary_connected">Connected to file transfer server</string>
|
<string name="bluetooth_opp_profile_summary_connected">Connected to file transfer server</string>
|
||||||
<!-- Bluetooth settings. Connection options screen. The summary for the OPP checkbox preference when OPP is not connected. -->
|
<!-- Bluetooth settings. Connection options screen. The summary for the OPP checkbox preference when OPP is not connected. -->
|
||||||
<string name="bluetooth_opp_profile_summary_not_connected">Not connected to file transfer server</string>
|
<string name="bluetooth_opp_profile_summary_not_connected">Not connected to file transfer server</string>
|
||||||
|
<!-- Bluetooth settings. Connection options screen. The summary for the HID checkbox preference when HID is connected. -->
|
||||||
|
<string name="bluetooth_hid_profile_summary_connected">Connected to input device</string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. Connection options screen. The summary for the A2DP checkbox preference that describes how checking it will set the A2DP profile as preferred. -->
|
<!-- Bluetooth settings. Connection options screen. The summary for the A2DP checkbox preference that describes how checking it will set the A2DP profile as preferred. -->
|
||||||
<string name="bluetooth_a2dp_profile_summary_use_for">Use for media audio</string>
|
<string name="bluetooth_a2dp_profile_summary_use_for">Use for media audio</string>
|
||||||
@@ -785,6 +791,10 @@
|
|||||||
<string name="bluetooth_headset_profile_summary_use_for">Use for phone audio</string>
|
<string name="bluetooth_headset_profile_summary_use_for">Use for phone audio</string>
|
||||||
<!-- Bluetooth settings. Connection options screen. The summary for the OPP checkbox preference that describes how checking it will set the OPP profile as preferred. -->
|
<!-- Bluetooth settings. Connection options screen. The summary for the OPP checkbox preference that describes how checking it will set the OPP profile as preferred. -->
|
||||||
<string name="bluetooth_opp_profile_summary_use_for">Use for file transfer</string>
|
<string name="bluetooth_opp_profile_summary_use_for">Use for file transfer</string>
|
||||||
|
<!-- Bluetooth settings. Connection options screen. The summary
|
||||||
|
for the HID checkbox preference that describes how checking it
|
||||||
|
will set the HID profile as preferred. -->
|
||||||
|
<string name="bluetooth_hid_profile_summary_use_for">Use for input</string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. Dock Setting Title -->
|
<!-- Bluetooth settings. Dock Setting Title -->
|
||||||
<string name="bluetooth_dock_settings">Dock Settings</string>
|
<string name="bluetooth_dock_settings">Dock Settings</string>
|
||||||
|
@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothHeadset;
|
import android.bluetooth.BluetoothHeadset;
|
||||||
|
import android.bluetooth.BluetoothInputDevice;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -119,6 +120,19 @@ public class BluetoothEventRedirector {
|
|||||||
mManager.getCachedDeviceManager().onProfileStateChanged(device,
|
mManager.getCachedDeviceManager().onProfileStateChanged(device,
|
||||||
Profile.A2DP, newState);
|
Profile.A2DP, newState);
|
||||||
|
|
||||||
|
} else if (action.equals(BluetoothInputDevice.ACTION_INPUT_DEVICE_STATE_CHANGED)) {
|
||||||
|
final int newState = intent.getIntExtra(
|
||||||
|
BluetoothInputDevice.EXTRA_INPUT_DEVICE_STATE, 0);
|
||||||
|
final int oldState = intent.getIntExtra(
|
||||||
|
BluetoothInputDevice.EXTRA_PREVIOUS_INPUT_DEVICE_STATE, 0);
|
||||||
|
if (newState == BluetoothInputDevice.STATE_DISCONNECTED &&
|
||||||
|
oldState == BluetoothInputDevice.STATE_CONNECTING) {
|
||||||
|
Log.i(TAG, "Failed to connect BT HID");
|
||||||
|
}
|
||||||
|
|
||||||
|
mManager.getCachedDeviceManager().onProfileStateChanged(device,
|
||||||
|
Profile.HID, newState);
|
||||||
|
|
||||||
} else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) {
|
} else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) {
|
||||||
mManager.getCachedDeviceManager().onBtClassChanged(device);
|
mManager.getCachedDeviceManager().onBtClassChanged(device);
|
||||||
|
|
||||||
|
@@ -540,6 +540,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
Log.v(TAG, "opp classbits != uuid");
|
Log.v(TAG, "opp classbits != uuid");
|
||||||
printUuids = true;
|
printUuids = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HID) !=
|
||||||
|
mProfiles.contains(Profile.HID)) {
|
||||||
|
Log.v(TAG, "hid classbits != uuid");
|
||||||
|
printUuids = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printUuids) {
|
if (printUuids) {
|
||||||
@@ -629,7 +635,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
* @return A one-off summary that is applicable for the current state, or 0.
|
* @return A one-off summary that is applicable for the current state, or 0.
|
||||||
*/
|
*/
|
||||||
private int getOneOffSummary() {
|
private int getOneOffSummary() {
|
||||||
boolean isA2dpConnected = false, isHeadsetConnected = false, isConnecting = false;
|
boolean isA2dpConnected = false;
|
||||||
|
boolean isHeadsetConnected = false;
|
||||||
|
boolean isHidConnected = false;
|
||||||
|
boolean isConnecting = false;
|
||||||
|
|
||||||
if (mProfiles.contains(Profile.A2DP)) {
|
if (mProfiles.contains(Profile.A2DP)) {
|
||||||
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
||||||
@@ -647,6 +656,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
isHeadsetConnected = profileManager.isConnected(mDevice);
|
isHeadsetConnected = profileManager.isConnected(mDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mProfiles.contains(Profile.HID)) {
|
||||||
|
LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
|
||||||
|
.getProfileManager(mLocalManager, Profile.HID);
|
||||||
|
isConnecting |= profileManager.getConnectionStatus(mDevice) ==
|
||||||
|
SettingsBtStatus.CONNECTION_STATUS_CONNECTING;
|
||||||
|
isHidConnected = profileManager.isConnected(mDevice);
|
||||||
|
}
|
||||||
|
|
||||||
if (isConnecting) {
|
if (isConnecting) {
|
||||||
// If any of these important profiles is connecting, prefer that
|
// If any of these important profiles is connecting, prefer that
|
||||||
return SettingsBtStatus.getConnectionStatusSummary(
|
return SettingsBtStatus.getConnectionStatusSummary(
|
||||||
@@ -657,6 +674,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
return R.string.bluetooth_summary_connected_to_a2dp;
|
return R.string.bluetooth_summary_connected_to_a2dp;
|
||||||
} else if (isHeadsetConnected) {
|
} else if (isHeadsetConnected) {
|
||||||
return R.string.bluetooth_summary_connected_to_headset;
|
return R.string.bluetooth_summary_connected_to_headset;
|
||||||
|
} else if (isHidConnected) {
|
||||||
|
return R.string.bluetooth_summary_connected_to_hid;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -673,7 +692,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConnectableProfile(Profile profile) {
|
private boolean isConnectableProfile(Profile profile) {
|
||||||
return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP);
|
return profile.equals(Profile.HEADSET) || profile.equals(Profile.A2DP) ||
|
||||||
|
profile.equals(Profile.HID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreateContextMenu(ContextMenu menu) {
|
public void onCreateContextMenu(ContextMenu menu) {
|
||||||
|
@@ -299,6 +299,8 @@ public class ConnectSpecificProfilesActivity extends PreferenceActivity
|
|||||||
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
return R.string.bluetooth_a2dp_profile_summary_use_for;
|
||||||
case HEADSET:
|
case HEADSET:
|
||||||
return R.string.bluetooth_headset_profile_summary_use_for;
|
return R.string.bluetooth_headset_profile_summary_use_for;
|
||||||
|
case HID:
|
||||||
|
return R.string.bluetooth_hid_profile_summary_use_for;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import com.android.settings.R;
|
|||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothHeadset;
|
import android.bluetooth.BluetoothHeadset;
|
||||||
|
import android.bluetooth.BluetoothInputDevice;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.ParcelUuid;
|
import android.os.ParcelUuid;
|
||||||
@@ -55,6 +56,10 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
BluetoothUuid.ObexObjectPush
|
BluetoothUuid.ObexObjectPush
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* package */ static final ParcelUuid[] HID_PROFILE_UUIDS = new ParcelUuid[] {
|
||||||
|
BluetoothUuid.Hid
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for notifying BluetoothHeadset IPC clients when they have
|
* An interface for notifying BluetoothHeadset IPC clients when they have
|
||||||
* been connected to the BluetoothHeadset service.
|
* been connected to the BluetoothHeadset service.
|
||||||
@@ -97,6 +102,9 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
|
|
||||||
profileManager = new OppProfileManager(localManager);
|
profileManager = new OppProfileManager(localManager);
|
||||||
sProfileMap.put(Profile.OPP, profileManager);
|
sProfileMap.put(Profile.OPP, profileManager);
|
||||||
|
|
||||||
|
profileManager = new HidProfileManager(localManager);
|
||||||
|
sProfileMap.put(Profile.HID, profileManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,6 +169,10 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) {
|
if (BluetoothUuid.containsAnyUuid(uuids, OPP_PROFILE_UUIDS)) {
|
||||||
profiles.add(Profile.OPP);
|
profiles.add(Profile.OPP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BluetoothUuid.containsAnyUuid(uuids, HID_PROFILE_UUIDS)) {
|
||||||
|
profiles.add(Profile.HID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LocalBluetoothProfileManager(LocalBluetoothManager localManager) {
|
protected LocalBluetoothProfileManager(LocalBluetoothManager localManager) {
|
||||||
@@ -195,7 +207,8 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
public enum Profile {
|
public enum Profile {
|
||||||
HEADSET(R.string.bluetooth_profile_headset),
|
HEADSET(R.string.bluetooth_profile_headset),
|
||||||
A2DP(R.string.bluetooth_profile_a2dp),
|
A2DP(R.string.bluetooth_profile_a2dp),
|
||||||
OPP(R.string.bluetooth_profile_opp);
|
OPP(R.string.bluetooth_profile_opp),
|
||||||
|
HID(R.string.bluetooth_profile_hid);
|
||||||
|
|
||||||
public final int localizedString;
|
public final int localizedString;
|
||||||
|
|
||||||
@@ -518,4 +531,86 @@ public abstract class LocalBluetoothProfileManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class HidProfileManager extends LocalBluetoothProfileManager {
|
||||||
|
private BluetoothInputDevice mService;
|
||||||
|
|
||||||
|
public HidProfileManager(LocalBluetoothManager localManager) {
|
||||||
|
super(localManager);
|
||||||
|
mService = new BluetoothInputDevice(localManager.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean connect(BluetoothDevice device) {
|
||||||
|
return mService.connectInputDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int convertState(int hidState) {
|
||||||
|
switch (hidState) {
|
||||||
|
case BluetoothInputDevice.STATE_CONNECTED:
|
||||||
|
return SettingsBtStatus.CONNECTION_STATUS_CONNECTED;
|
||||||
|
case BluetoothInputDevice.STATE_CONNECTING:
|
||||||
|
return SettingsBtStatus.CONNECTION_STATUS_CONNECTING;
|
||||||
|
case BluetoothInputDevice.STATE_DISCONNECTED:
|
||||||
|
return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTED;
|
||||||
|
case BluetoothInputDevice.STATE_DISCONNECTING:
|
||||||
|
return SettingsBtStatus.CONNECTION_STATUS_DISCONNECTING;
|
||||||
|
default:
|
||||||
|
return SettingsBtStatus.CONNECTION_STATUS_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disconnect(BluetoothDevice device) {
|
||||||
|
return mService.disconnectInputDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BluetoothDevice> getConnectedDevices() {
|
||||||
|
return mService.getConnectedInputDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getConnectionStatus(BluetoothDevice device) {
|
||||||
|
return convertState(mService.getInputDeviceState(device));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPreferred(BluetoothDevice device) {
|
||||||
|
return mService.getInputDevicePriority(device);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSummary(BluetoothDevice device) {
|
||||||
|
final int connectionStatus = getConnectionStatus(device);
|
||||||
|
|
||||||
|
if (SettingsBtStatus.isConnectionStatusConnected(connectionStatus)) {
|
||||||
|
return R.string.bluetooth_hid_profile_summary_connected;
|
||||||
|
} else {
|
||||||
|
return SettingsBtStatus.getConnectionStatusSummary(connectionStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPreferred(BluetoothDevice device) {
|
||||||
|
return mService.getInputDevicePriority(device) > BluetoothInputDevice.PRIORITY_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isProfileReady() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPreferred(BluetoothDevice device, boolean preferred) {
|
||||||
|
if (preferred) {
|
||||||
|
if (mService.getInputDevicePriority(device) < BluetoothInputDevice.PRIORITY_ON) {
|
||||||
|
mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_ON);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mService.setInputDevicePriority(device, BluetoothInputDevice.PRIORITY_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user