Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4fc44fb2 authored by Erin Yueh's avatar Erin Yueh Committed by Steve Kondik
Browse files

Add Bluetooth HID (Human Interface Devices) profile. reference from OESF...

Add Bluetooth HID (Human Interface Devices) profile. reference from OESF bluetooth extension. http://github.com/OESF/Embedded-Master-ARM

Change-Id: I85803305f8ced882fef44d5ec31ff60f8fa06394
parent aedcddc9
Loading
Loading
Loading
Loading
+963 B
Loading image diff...
+963 B
Loading image diff...
+9 −1
Original line number Diff line number Diff line
@@ -716,13 +716,16 @@
    <string name="bluetooth_profile_headset">Phone</string>
    <!-- Bluetooth settings.  The user-visible string that is used whenever referring to the OPP profile. -->
    <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">HID</string>
    <!-- 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>
    <!-- Bluetooth settings.  The summary string when a device is connected to the headset profile. -->
    <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. -->
    <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 hid device</string>

    <!-- 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>
@@ -747,6 +750,11 @@
    <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. -->
    <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 when HID device is connected. -->
    <string name="bluetooth_hid_profile_summary_connected">Connected to hid device</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 hid device</string>


    <!-- Bluetooth settings.  Dock Setting Title -->
    <string name="bluetooth_dock_settings">Dock Settings</string>
+12 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHid;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -118,6 +119,16 @@ public class BluetoothEventRedirector {

                mManager.getCachedDeviceManager().onProfileStateChanged(device,
                        Profile.A2DP, newState);
            } else if (action.equals(BluetoothHid.HID_DEVICE_STATE_CHANGED_ACTION)){
                int newState = intent.getIntExtra(BluetoothHid.HID_DEVICE_STATE, 0);
                int oldState = intent.getIntExtra(BluetoothHid.HID_DEVICE_PREVIOUS_STATE, 0);
                if (newState == BluetoothHid.STATE_DISCONNECTED &&
                        oldState == BluetoothHid.STATE_CONNECTING) {
                    Log.i(TAG, "Failed to connect BT HID");
                }
                Log.d(TAG, "HID profile ProfileStateChanged");
                mManager.getCachedDeviceManager().onProfileStateChanged(device,
                        Profile.HID, newState);

            } else if (action.equals(BluetoothDevice.ACTION_CLASS_CHANGED)) {
                mManager.getCachedDeviceManager().onBtClassChanged(device);
@@ -168,6 +179,7 @@ public class BluetoothEventRedirector {
        filter.addAction(BluetoothHeadset.ACTION_STATE_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_CLASS_CHANGED);
        filter.addAction(BluetoothDevice.ACTION_UUID);
        filter.addAction(BluetoothHid.HID_DEVICE_STATE_CHANGED_ACTION);

        // Dock event broadcasts
        filter.addAction(Intent.ACTION_DOCK_EVENT);
+24 −3
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    private static final String TAG = "CachedBluetoothDevice";
    private static final boolean D = LocalBluetoothManager.D;
    private static final boolean V = LocalBluetoothManager.V;
    private static final boolean DEBUG = false;
    private static final boolean DEBUG = true;

    private static final int CONTEXT_ITEM_CONNECT = Menu.FIRST + 1;
    private static final int CONTEXT_ITEM_DISCONNECT = Menu.FIRST + 2;
@@ -651,6 +651,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                return R.drawable.ic_bt_headphones_a2dp;
            } else if (mProfiles.contains(Profile.HEADSET)) {
                return R.drawable.ic_bt_headset_hfp;
            } else if (mProfiles.contains(Profile.HID)) {
                return R.drawable.ic_bt_hidp;
            }
        } else if (mBtClass != null) {
            if (mBtClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
@@ -660,6 +662,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            if (mBtClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
                return R.drawable.ic_bt_headset_hfp;
            }
            if (mBtClass.doesClassMatch(BluetoothClass.PROFILE_HID)) {
                return R.drawable.ic_bt_hidp;
            }

        }
        return 0;
    }
@@ -701,6 +707,11 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
                    Log.v(TAG, "opp classbits != uuid");
                    printUuids = true;
                }
                if (bluetoothClass.doesClassMatch(BluetoothClass.PROFILE_HID) !=
                    mProfiles.contains(Profile.HID)) {
                    Log.v(TAG, "HID classbits != uuid");
                    printUuids = true;
                }
            }

            if (printUuids) {
@@ -815,7 +826,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
     */
    private int getOneOffSummary() {
        boolean isA2dpConnected = false, isHeadsetConnected = false, isConnecting = false;

        boolean isHidConnected = false;
        if (mProfiles.contains(Profile.A2DP)) {
            LocalBluetoothProfileManager profileManager = LocalBluetoothProfileManager
                    .getProfileManager(mLocalManager, Profile.A2DP);
@@ -832,6 +843,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            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 any of these important profiles is connecting, prefer that
            return SettingsBtStatus.getConnectionStatusSummary(
@@ -842,6 +861,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
            return R.string.bluetooth_summary_connected_to_a2dp;
        } else if (isHeadsetConnected) {
            return R.string.bluetooth_summary_connected_to_headset;
        } else if (isHidConnected) {
            return R.string.bluetooth_summary_connected_to_hid;
        } else {
            return 0;
        }
@@ -858,7 +879,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    }

    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) {
Loading