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

Commit 35487662 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Automerger Merge Worker
Browse files

Merge "HidHost: Use handler thread to send data" into main am: 7f1703a4

parents 3f002755 7f1703a4
Loading
Loading
Loading
Loading
+33 −2
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public class HidHostService extends ProfileService {
    private static final int MESSAGE_ON_GET_IDLE_TIME = 15;
    private static final int MESSAGE_SET_IDLE_TIME = 16;
    private static final int MESSAGE_SET_PREFERRED_TRANSPORT = 17;
    private static final int MESSAGE_SEND_DATA = 18;

    public static final int STATE_DISCONNECTED = BluetoothProfile.STATE_DISCONNECTED;
    public static final int STATE_CONNECTING = BluetoothProfile.STATE_CONNECTING;
@@ -433,10 +434,28 @@ public class HidHostService extends ProfileService {
                        case MESSAGE_SET_PREFERRED_TRANSPORT:
                            handleMessageSetPreferredTransport(msg);
                            break;
                        case MESSAGE_SEND_DATA:
                            handleMessageSendData(msg);
                            break;
                    }
                }
            };

    private void handleMessageSendData(Message msg) {
        if (!Flags.allowSwitchingHidAndHogp()) {
            return;
        }
        BluetoothDevice device = mAdapterService.getDeviceFromByte((byte[]) msg.obj);

        Bundle data = msg.getData();
        String report = data.getString(BluetoothHidHost.EXTRA_REPORT);

        if (!mNativeInterface.sendData(
                getByteAddress(device), getAddressType(device), getTransport(device), report)) {
            Log.e(TAG, "handleMessageSendData: Failed to send data");
        }
    }

    private void handleMessageSetPreferredTransport(Message msg) {
        BluetoothDevice device = (BluetoothDevice) msg.obj;
        int transport = msg.arg1;
@@ -1323,8 +1342,20 @@ public class HidHostService extends ProfileService {
            return false;
        }

        if (!Flags.allowSwitchingHidAndHogp()) {
            return mNativeInterface.sendData(
                getByteAddress(device), getAddressType(device), getTransport(device), report);
                    getByteAddress(device),
                    getAddressType(device),
                    getTransport(device),
                    report);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_SEND_DATA, device);
        Bundle data = new Bundle();
        data.putString(BluetoothHidHost.EXTRA_REPORT, report);
        msg.setData(data);
        mHandler.sendMessage(msg);
        return true;
    }

    boolean getIdleTime(BluetoothDevice device) {