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

Commit fb00fe60 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "register JNI callback during JNI_Onload" into main

parents c5beb877 6fd21eda
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -168,6 +168,23 @@ int register_com_android_bluetooth_csip_set_coordinator(JNIEnv* env);

int register_com_android_bluetooth_btservice_BluetoothQualityReport(
    JNIEnv* env);

struct JNIJavaMethod {
    const char* name;
    const char* signature;
    jmethodID* id;
    bool is_static{false};
};

void jniGetMethodsOrDie(JNIEnv* env, const char* className,
                        const JNIJavaMethod* methods, int nMethods);

#define REGISTER_NATIVE_METHODS(env, classname, methodsArray) \
    jniRegisterNativeMethods(env, classname, methodsArray, NELEM(methodsArray))

#define GET_JAVA_METHODS(env, classname, methodsArray) \
    jniGetMethodsOrDie(env, classname, methodsArray, NELEM(methodsArray))

}  // namespace android

#endif /* COM_ANDROID_BLUETOOTH_H */
+21 −16
Original line number Diff line number Diff line
@@ -82,12 +82,6 @@ class BluetoothQualityReportCallbacksImpl

static BluetoothQualityReportCallbacksImpl sBluetoothQualityReportCallbacks;

static void classInitNative(JNIEnv* env, jclass clazz) {
  method_bqrDeliver = env->GetMethodID(clazz, "bqrDeliver", "([BIII[B)V");

  LOG(INFO) << __func__ << ": succeeds";
}

static void initNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> interface_lock(interface_mutex);
  std::unique_lock<std::shared_timed_mutex> callbacks_lock(callbacks_mutex);
@@ -151,17 +145,28 @@ static void cleanupNative(JNIEnv* env, jobject object) {
  }
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
int register_com_android_bluetooth_btservice_BluetoothQualityReport(
    JNIEnv* env) {
  const JNINativeMethod methods[] = {
      {"initNative", "()V", (void*)initNative},
      {"cleanupNative", "()V", (void*)cleanupNative},
  };
  const int result = REGISTER_NATIVE_METHODS(
      env,
      "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
      methods);
  if (result != 0) {
    return result;
  }

int register_com_android_bluetooth_btservice_BluetoothQualityReport(
    JNIEnv* env) {
  return jniRegisterNativeMethods(env,
                                  "com/android/bluetooth/btservice/"
                                  "BluetoothQualityReportNativeInterface",
                                  sMethods, NELEM(sMethods));
  const JNIJavaMethod javaMethods[] = {
      {"bqrDeliver", "([BIII[B)V", &method_bqrDeliver},
  };
  GET_JAVA_METHODS(
      env,
      "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
      javaMethods);

  return 0;
}
}  // namespace android
+59 −60
Original line number Diff line number Diff line
@@ -191,48 +191,6 @@ static btav_source_callbacks_t sBluetoothA2dpCallbacks = {
    bta2dp_mandatory_codec_preferred_callback,
};

static void classInitNative(JNIEnv* env, jclass clazz) {
  jclass jniBluetoothCodecConfigClass =
      env->FindClass("android/bluetooth/BluetoothCodecConfig");
  android_bluetooth_BluetoothCodecConfig.constructor =
      env->GetMethodID(jniBluetoothCodecConfigClass, "<init>", "(IIIIIJJJJ)V");
  android_bluetooth_BluetoothCodecConfig.getCodecType =
      env->GetMethodID(jniBluetoothCodecConfigClass, "getCodecType", "()I");
  android_bluetooth_BluetoothCodecConfig.getCodecPriority =
      env->GetMethodID(jniBluetoothCodecConfigClass, "getCodecPriority", "()I");
  android_bluetooth_BluetoothCodecConfig.getSampleRate =
      env->GetMethodID(jniBluetoothCodecConfigClass, "getSampleRate", "()I");
  android_bluetooth_BluetoothCodecConfig.getBitsPerSample =
      env->GetMethodID(jniBluetoothCodecConfigClass, "getBitsPerSample", "()I");
  android_bluetooth_BluetoothCodecConfig.getChannelMode =
      env->GetMethodID(jniBluetoothCodecConfigClass, "getChannelMode", "()I");
  android_bluetooth_BluetoothCodecConfig.getCodecSpecific1 = env->GetMethodID(
      jniBluetoothCodecConfigClass, "getCodecSpecific1", "()J");
  android_bluetooth_BluetoothCodecConfig.getCodecSpecific2 = env->GetMethodID(
      jniBluetoothCodecConfigClass, "getCodecSpecific2", "()J");
  android_bluetooth_BluetoothCodecConfig.getCodecSpecific3 = env->GetMethodID(
      jniBluetoothCodecConfigClass, "getCodecSpecific3", "()J");
  android_bluetooth_BluetoothCodecConfig.getCodecSpecific4 = env->GetMethodID(
      jniBluetoothCodecConfigClass, "getCodecSpecific4", "()J");

  method_onConnectionStateChanged =
      env->GetMethodID(clazz, "onConnectionStateChanged", "([BI)V");

  method_onAudioStateChanged =
      env->GetMethodID(clazz, "onAudioStateChanged", "([BI)V");

  method_onCodecConfigChanged =
      env->GetMethodID(clazz, "onCodecConfigChanged",
                       "([BLandroid/bluetooth/BluetoothCodecConfig;"
                       "[Landroid/bluetooth/BluetoothCodecConfig;"
                       "[Landroid/bluetooth/BluetoothCodecConfig;)V");

  method_isMandatoryCodecPreferred =
      env->GetMethodID(clazz, "isMandatoryCodecPreferred", "([B)Z");

  ALOGI("%s: succeeds", __func__);
}

static std::vector<btav_a2dp_codec_config_t> prepareCodecPreferences(
    JNIEnv* env, jobject object, jobjectArray codecConfigArray) {
  std::vector<btav_a2dp_codec_config_t> codec_preferences;
@@ -501,10 +459,11 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
int register_com_android_bluetooth_a2dp(JNIEnv* env) {
  const JNINativeMethod methods[] = {
      {"initNative",
     "(I[Landroid/bluetooth/BluetoothCodecConfig;[Landroid/bluetooth/BluetoothCodecConfig;)V",
       "(I[Landroid/bluetooth/BluetoothCodecConfig;"
       "[Landroid/bluetooth/BluetoothCodecConfig;)V",
       (void*)initNative},
      {"cleanupNative", "()V", (void*)cleanupNative},
      {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
@@ -515,10 +474,50 @@ static JNINativeMethod sMethods[] = {
       "([B[Landroid/bluetooth/BluetoothCodecConfig;)Z",
       (void*)setCodecConfigPreferenceNative},
  };
  const int result = REGISTER_NATIVE_METHODS(
      env, "com/android/bluetooth/a2dp/A2dpNativeInterface", methods);
  if (result != 0) {
    return result;
  }

int register_com_android_bluetooth_a2dp(JNIEnv* env) {
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/a2dp/A2dpNativeInterface", sMethods,
      NELEM(sMethods));
  const JNIJavaMethod javaMethods[] = {
      {"onConnectionStateChanged", "([BI)V", &method_onConnectionStateChanged},
      {"onAudioStateChanged", "([BI)V", &method_onAudioStateChanged},
      {"onCodecConfigChanged",
       "([BLandroid/bluetooth/BluetoothCodecConfig;"
       "[Landroid/bluetooth/BluetoothCodecConfig;"
       "[Landroid/bluetooth/BluetoothCodecConfig;)V",
       &method_onCodecConfigChanged},
      {"isMandatoryCodecPreferred", "([B)Z", &method_isMandatoryCodecPreferred},
  };
  GET_JAVA_METHODS(env, "com/android/bluetooth/a2dp/A2dpNativeInterface",
                   javaMethods);

  const JNIJavaMethod codecConfigCallbacksMethods[] = {
      {"<init>", "(IIIIIJJJJ)V",
       &android_bluetooth_BluetoothCodecConfig.constructor},
      {"getCodecType", "()I",
       &android_bluetooth_BluetoothCodecConfig.getCodecType},
      {"getCodecPriority", "()I",
       &android_bluetooth_BluetoothCodecConfig.getCodecPriority},
      {"getSampleRate", "()I",
       &android_bluetooth_BluetoothCodecConfig.getSampleRate},
      {"getBitsPerSample", "()I",
       &android_bluetooth_BluetoothCodecConfig.getBitsPerSample},
      {"getChannelMode", "()I",
       &android_bluetooth_BluetoothCodecConfig.getChannelMode},
      {"getCodecSpecific1", "()J",
       &android_bluetooth_BluetoothCodecConfig.getCodecSpecific1},
      {"getCodecSpecific2", "()J",
       &android_bluetooth_BluetoothCodecConfig.getCodecSpecific2},
      {"getCodecSpecific3", "()J",
       &android_bluetooth_BluetoothCodecConfig.getCodecSpecific3},
      {"getCodecSpecific4", "()J",
       &android_bluetooth_BluetoothCodecConfig.getCodecSpecific4},
  };
  GET_JAVA_METHODS(env, "android/bluetooth/BluetoothCodecConfig",
                   codecConfigCallbacksMethods);

  return 0;
}
}
+26 −27
Original line number Diff line number Diff line
@@ -110,19 +110,6 @@ static btav_sink_callbacks_t sBluetoothA2dpCallbacks = {
    a2dp_sink_audio_config_callback,
};

static void classInitNative(JNIEnv* env, jclass clazz) {
  method_onConnectionStateChanged =
      env->GetMethodID(clazz, "onConnectionStateChanged", "([BI)V");

  method_onAudioStateChanged =
      env->GetMethodID(clazz, "onAudioStateChanged", "([BI)V");

  method_onAudioConfigChanged =
      env->GetMethodID(clazz, "onAudioConfigChanged", "([BII)V");

  ALOGI("%s: succeeds", __func__);
}

static void initNative(JNIEnv* env, jobject object,
                       jint maxConnectedAudioDevices) {
  std::unique_lock<std::shared_timed_mutex> lock(callbacks_mutex);
@@ -260,20 +247,32 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
  return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
  const JNINativeMethod methods[] = {
      {"initNative", "(I)V", (void*)initNative},
      {"cleanupNative", "()V", (void*)cleanupNative},
      {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
      {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
    {"informAudioFocusStateNative", "(I)V", (void*)informAudioFocusStateNative},
      {"informAudioFocusStateNative", "(I)V",
       (void*)informAudioFocusStateNative},
      {"informAudioTrackGainNative", "(F)V", (void*)informAudioTrackGainNative},
      {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
  };
  const int result = REGISTER_NATIVE_METHODS(
      env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", methods);
  if (result != 0) {
    return result;
  }

int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", sMethods,
      NELEM(sMethods));
  const JNIJavaMethod javaMethods[] = {
      {"onConnectionStateChanged", "([BI)V", &method_onConnectionStateChanged},
      {"onAudioStateChanged", "([BI)V", &method_onAudioStateChanged},
      {"onAudioConfigChanged", "([BII)V", &method_onAudioConfigChanged},
  };
  GET_JAVA_METHODS(env,
                   "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface",
                   javaMethods);

  return 0;
}
}
+78 −90
Original line number Diff line number Diff line
@@ -716,70 +716,8 @@ static btrc_ctrl_callbacks_t sBluetoothAvrcpCallbacks = {
    btavrcp_addressed_player_changed_callback,
    btavrcp_now_playing_content_changed_callback,
    btavrcp_available_player_changed_callback,
    btavrcp_get_rcpsm_callback};

static void classInitNative(JNIEnv* env, jclass clazz) {
  method_onConnectionStateChanged =
      env->GetMethodID(clazz, "onConnectionStateChanged", "(ZZ[B)V");

  method_getRcPsm = env->GetMethodID(clazz, "getRcPsm", "([BI)V");

  method_handleplayerappsetting =
      env->GetMethodID(clazz, "handlePlayerAppSetting", "([B[BI)V");

  method_handleplayerappsettingchanged =
      env->GetMethodID(clazz, "onPlayerAppSettingChanged", "([B[BI)V");

  method_handleSetAbsVolume =
      env->GetMethodID(clazz, "handleSetAbsVolume", "([BBB)V");

  method_handleRegisterNotificationAbsVol =
      env->GetMethodID(clazz, "handleRegisterNotificationAbsVol", "([BB)V");

  method_handletrackchanged =
      env->GetMethodID(clazz, "onTrackChanged", "([BB[I[Ljava/lang/String;)V");

  method_handleplaypositionchanged =
      env->GetMethodID(clazz, "onPlayPositionChanged", "([BII)V");

  method_handleplaystatuschanged =
      env->GetMethodID(clazz, "onPlayStatusChanged", "([BB)V");

  method_handleGetFolderItemsRsp =
      env->GetMethodID(clazz, "handleGetFolderItemsRsp",
                       "([BI[Lcom/android/bluetooth/avrcpcontroller/"
                       "AvrcpItem;)V");
  method_handleGetPlayerItemsRsp = env->GetMethodID(
      clazz, "handleGetPlayerItemsRsp",
      "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");

  method_createFromNativeMediaItem = env->GetStaticMethodID(
      clazz, "createFromNativeMediaItem",
      "([BJILjava/lang/String;[I[Ljava/lang/String;)Lcom/"
      "android/bluetooth/avrcpcontroller/AvrcpItem;");
  method_createFromNativeFolderItem = env->GetStaticMethodID(
      clazz, "createFromNativeFolderItem",
      "([BJILjava/lang/String;I)Lcom/android/bluetooth/avrcpcontroller/"
      "AvrcpItem;");
  method_createFromNativePlayerItem = env->GetStaticMethodID(
      clazz, "createFromNativePlayerItem",
      "([BILjava/lang/String;[BII)Lcom/android/bluetooth/"
      "avrcpcontroller/AvrcpPlayer;");
  method_handleChangeFolderRsp =
      env->GetMethodID(clazz, "handleChangeFolderRsp", "([BI)V");
  method_handleSetBrowsedPlayerRsp =
      env->GetMethodID(clazz, "handleSetBrowsedPlayerRsp", "([BII)V");
  method_handleSetAddressedPlayerRsp =
      env->GetMethodID(clazz, "handleSetAddressedPlayerRsp", "([BI)V");
  method_handleAddressedPlayerChanged =
      env->GetMethodID(clazz, "handleAddressedPlayerChanged", "([BI)V");
  method_handleNowPlayingContentChanged =
      env->GetMethodID(clazz, "handleNowPlayingContentChanged", "([B)V");
  method_onAvailablePlayerChanged =
      env->GetMethodID(clazz, "onAvailablePlayerChanged", "([B)V");

  ALOGI("%s: succeeds", __func__);
}
    btavrcp_get_rcpsm_callback,
};

static void initNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);
@@ -1199,8 +1137,8 @@ static void playItemNative(JNIEnv* env, jobject object, jbyteArray address,
  env->ReleaseByteArrayElements(address, addr, 0);
}

static JNINativeMethod sMethods[] = {
    {"classInitNative", "()V", (void*)classInitNative},
int register_com_android_bluetooth_avrcp_controller(JNIEnv* env) {
  const JNINativeMethod methods[] = {
      {"initNative", "()V", (void*)initNative},
      {"cleanupNative", "()V", (void*)cleanupNative},
      {"sendPassThroughCommandNative", "([BII)Z",
@@ -1222,11 +1160,61 @@ static JNINativeMethod sMethods[] = {
      {"setBrowsedPlayerNative", "([BI)V", (void*)setBrowsedPlayerNative},
      {"setAddressedPlayerNative", "([BI)V", (void*)setAddressedPlayerNative},
  };

int register_com_android_bluetooth_avrcp_controller(JNIEnv* env) {
  return jniRegisterNativeMethods(
  const int result = REGISTER_NATIVE_METHODS(
      env,
      "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface",
      methods);
  if (result != 0) {
    return result;
  }

  const JNIJavaMethod javaMethods[] = {
      {"onConnectionStateChanged", "(ZZ[B)V", &method_onConnectionStateChanged},
      {"getRcPsm", "([BI)V", &method_getRcPsm},
      {"handlePlayerAppSetting", "([B[BI)V", &method_handleplayerappsetting},
      {"onPlayerAppSettingChanged", "([B[BI)V",
       &method_handleplayerappsettingchanged},
      {"handleSetAbsVolume", "([BBB)V", &method_handleSetAbsVolume},
      {"handleRegisterNotificationAbsVol", "([BB)V",
       &method_handleRegisterNotificationAbsVol},
      {"onTrackChanged", "([BB[I[Ljava/lang/String;)V",
       &method_handletrackchanged},
      {"onPlayPositionChanged", "([BII)V", &method_handleplaypositionchanged},
      {"onPlayStatusChanged", "([BB)V", &method_handleplaystatuschanged},
      {"handleGetFolderItemsRsp",
       "([BI[Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;)V",
       &method_handleGetFolderItemsRsp},
      {"handleGetPlayerItemsRsp",
       "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V",
       &method_handleGetPlayerItemsRsp},
      {"handleChangeFolderRsp", "([BI)V", &method_handleChangeFolderRsp},
      {"handleSetBrowsedPlayerRsp", "([BII)V",
       &method_handleSetBrowsedPlayerRsp},
      {"handleSetAddressedPlayerRsp", "([BI)V",
       &method_handleSetAddressedPlayerRsp},
      {"handleAddressedPlayerChanged", "([BI)V",
       &method_handleAddressedPlayerChanged},
      {"handleNowPlayingContentChanged", "([B)V",
       &method_handleNowPlayingContentChanged},
      {"onAvailablePlayerChanged", "([B)V", &method_onAvailablePlayerChanged},
      // Fetch static method
      {"createFromNativeMediaItem",
       "([BJILjava/lang/String;[I[Ljava/lang/String;)"
       "Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;",
       &method_createFromNativeMediaItem, true},
      {"createFromNativeFolderItem",
       "([BJILjava/lang/String;I)"
       "Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;",
       &method_createFromNativeFolderItem, true},
      {"createFromNativePlayerItem",
       "([BILjava/lang/String;[BII)"
       "Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;",
       &method_createFromNativePlayerItem, true},
  };
  GET_JAVA_METHODS(
      env,
      "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface",
      sMethods, NELEM(sMethods));
      javaMethods);
  return 0;
}
}  // namespace android
Loading