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

Commit ba4a1c5f authored by Sal Savage's avatar Sal Savage
Browse files

Add BIP Client status setting API to JNI interface

This change allows Java to notify the native stack of any devices with
an active BIP client.

Tag: #feature
Bug: 153076316
Test: atest BluetoothInstrumentationTests
Test: Build, flash, make sure existing UX isn't impacted. Change will be
used in future changes and can be verified by making sure image handle
data is present or missing based on client status.

Change-Id: Ia3238721dac71394e42d8a337bb67e4e76a9c005
parent edbe5b24
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -829,6 +829,25 @@ static void setVolume(int8_t volume) {
  sCallbackEnv->CallVoidMethod(mJavaInterface, method_setVolume, volume);
}

static void setBipClientStatusNative(JNIEnv* env, jobject object,
                                    jstring address, jboolean connected) {
  std::unique_lock<std::shared_timed_mutex> interface_lock(interface_mutex);
  if (mServiceCallbacks == nullptr) {
    ALOGW("%s: Service not loaded.", __func__);
    return;
  }

  const char* tmp_addr = env->GetStringUTFChars(address, 0);
  RawAddress bdaddr;
  bool success = RawAddress::FromString(tmp_addr, bdaddr);
  env->ReleaseStringUTFChars(address, tmp_addr);

  if (!success) return;

  bool status = (connected == JNI_TRUE);
  sServiceInterface->SetBipClientStatus(bdaddr, status);
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
    {"initNative", "()V", (void*)initNative},
@@ -847,6 +866,8 @@ static JNINativeMethod sMethods[] = {
     (void*)disconnectDeviceNative},
    {"sendVolumeChangedNative", "(Ljava/lang/String;I)V",
     (void*)sendVolumeChangedNative},
    {"setBipClientStatusNative", "(Ljava/lang/String;Z)V",
     (void*)setBipClientStatusNative},
};

int register_com_android_bluetooth_avrcp_target(JNIEnv* env) {
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,10 @@ public class AvrcpNativeInterface {
        unregisterBipServerNative();
    }

    void setBipClientStatus(String bdaddr, boolean connected) {
        setBipClientStatusNative(bdaddr, connected);
    }

    Metadata getCurrentSongInfo() {
        d("getCurrentSongInfo");
        if (mAvrcpService == null) {
@@ -263,6 +267,7 @@ public class AvrcpNativeInterface {
    private native boolean connectDeviceNative(String bdaddr);
    private native boolean disconnectDeviceNative(String bdaddr);
    private native void sendVolumeChangedNative(String bdaddr, int volume);
    private native void setBipClientStatusNative(String bdaddr, boolean connected);

    private static void d(String msg) {
        if (DEBUG) {