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

Commit 70097548 authored by Hemant Gupta's avatar Hemant Gupta Committed by Linux Build Service Account
Browse files

HID: Add support for sending priority to btif layer

This patch adds support for sending remote device priority to HID btif
layer. Now with every change in remote input device priority btif layer
would be informed.

Change-Id: I08935a9d733ccab29173ba41ddab795eccad3f7f
CRs-Fixed: 532234
parent 4f62c657
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -566,6 +566,29 @@ static jboolean setIdleTimeNative(JNIEnv *env, jobject object, jbyteArray addres
    return ret;
}

static jboolean setPriorityNative(JNIEnv *env, jobject object, jbyteArray address, jint priority) {
    bt_status_t status;
    jbyte *addr;
    jboolean ret = JNI_TRUE;
    if (!sBluetoothHidInterface) return JNI_FALSE;

    addr = env->GetByteArrayElements(address, NULL);
    if (!addr) {
        ALOGE("Bluetooth device address null");
        return JNI_FALSE;
    }

    if ( (status = sBluetoothHidInterface->set_priority((bt_bdaddr_t *) addr, priority)) !=
         BT_STATUS_SUCCESS) {
        ALOGE("Failed set priority, status: %d", status);
        ret = JNI_FALSE;
    }
    env->ReleaseByteArrayElements(address, addr, 0);

    return ret;
}


static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void *) classInitNative},
    {"initializeNative", "()V", (void *) initializeNative},
@@ -580,6 +603,7 @@ static JNINativeMethod sMethods[] = {
    {"sendDataNative", "([BLjava/lang/String;)Z", (void *) sendDataNative},
    {"getIdleTimeNative", "([B)Z", (void *) getIdleTimeNative},
    {"setIdleTimeNative", "([BB)Z", (void *) setIdleTimeNative},
    {"setPriorityNative", "([BI)Z", (void *) setPriorityNative},
};

int register_com_android_bluetooth_hid(JNIEnv* env)
+15 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public class HidService extends ProfileService {
    private static final int MESSAGE_GET_IDLE_TIME = 14;
    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_PRIORITY = 17;

    static {
        classInitNative();
@@ -313,6 +314,15 @@ public class HidService extends ProfileService {
                    }
                }
                break;
                case MESSAGE_SET_PRIORITY:
                {
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    int priority = msg.arg1;
                    if (!setPriorityNative(Utils.getByteAddress(device), priority)) {
                        Log.e(TAG, "Error: set priority native returns false");
                    }
                }
                break;
            }
        }
    };
@@ -488,6 +498,10 @@ public class HidService extends ProfileService {
            Settings.Global.getBluetoothInputDevicePriorityKey(device.getAddress()),
            priority);
        if (DBG) Log.d(TAG,"Saved priority " + device + " = " + priority);
        Message msg = mHandler.obtainMessage(MESSAGE_SET_PRIORITY,device);
        msg.obj = device;
        msg.arg1 = priority;
        mHandler.sendMessage(msg);
        return true;
    }

@@ -784,4 +798,5 @@ public class HidService extends ProfileService {
    private native boolean sendDataNative(byte[] btAddress, String report);
    private native boolean setIdleTimeNative(byte[] btAddress, byte idleTime);
    private native boolean getIdleTimeNative(byte[] btAddress);
    private native boolean setPriorityNative(byte[] btAddress, int priority);
}