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

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

Merge changes Iee66ef18,Id5dc18d7,I78ddb76d,I94b1681c,Id979702c, ... into main

* changes:
  Bluetooth: Do not load jni in instrumented test
  AdapterServiceTest: Ignore native test
  AdapterService: Split native interface for test
  ActivityAttribution: Do not call native in test
  Keystore: Remove native call from test
  Bqr: Remove native call from test
  VolumeControl: stop calling NativeInterface in test
  HidDevice: stop calling NativeInterface in test
  AvrcpTarget: Extract NativeInterface
  PeriodicScan: Extract NativeInterface
  SdpManager: Extract NativeInterface
  LeAudio: Make sure test does not call native
  HeadsetClient: Properly mock native
  AtPhonebookTest: Properly mock native
  GattService: Do not call native in test
  ScanManagerTest: only call tested class
  DistanceMeasurement: stop calling NativeInterface in test
  ContextMapTest: only call tested class
  AppScanStatsTest: only call tested class
  HapClient: stop calling NativeInterface in test
  HidHost: stop calling NativeInterface in test
  HeadsetService: stop calling NativeInterface in test
  HearingAidService: stop calling NativeInterface in test
  CsipSetCoordinator: stop calling NativeInterface in test
  KeystoreService: stop calling NativeInterface in test
  AvrcpController: Move some method to static
  AvrcpController: Delete unused code
  A2dpSinkStream: stop calling NativeInterface in test
  AvrcpController: Split NativeInterface for test
  A2dpSinkService: stop calling NativeInterface in test
  A2dpService: stop calling NativeInterface in test
  Test health: Allow test to call doStart and doStop
  Pan: Explicitly require address not to be null
  Pan: Prevent native call from within the test
parents 459f8c84 4484a68a
Loading
Loading
Loading
Loading
+16 −98
Original line number Diff line number Diff line
@@ -24,10 +24,7 @@
#include <shared_mutex>

namespace android {
static jmethodID method_handlePassthroughRsp;
static jmethodID method_onConnectionStateChanged;
static jmethodID method_getRcFeatures;
static jmethodID method_setplayerappsettingrsp;
static jmethodID method_handleplayerappsetting;
static jmethodID method_handleplayerappsettingchanged;
static jmethodID method_handleSetAbsVolume;
@@ -37,7 +34,6 @@ static jmethodID method_handleplaypositionchanged;
static jmethodID method_handleplaystatuschanged;
static jmethodID method_handleGetFolderItemsRsp;
static jmethodID method_handleGetPlayerItemsRsp;
static jmethodID method_handleGroupNavigationRsp;
static jmethodID method_createFromNativeMediaItem;
static jmethodID method_createFromNativeFolderItem;
static jmethodID method_createFromNativePlayerItem;
@@ -58,40 +54,11 @@ static std::shared_timed_mutex sCallbacks_mutex;

static void btavrcp_passthrough_response_callback(const RawAddress& bd_addr,
                                                  int id, int pressed) {
  ALOGI("%s: id: %d, pressed: %d", __func__, id, pressed);
  std::shared_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbacksObj) {
    ALOGE("%s: sCallbacksObj is null", __func__);
    return;
  }

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("%s: Failed to allocate a new byte array", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (jbyte*)&bd_addr.address);
  sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handlePassthroughRsp,
                               (jint)id, (jint)pressed, addr.get());
  ALOGV("%s: id: %d, pressed: %d --- Not implemented", __func__, id, pressed);
}

static void btavrcp_groupnavigation_response_callback(int id, int pressed) {
  ALOGV("%s", __func__);
  std::shared_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbacksObj) {
    ALOGE("%s: sCallbacksObj is null", __func__);
    return;
  }

  sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGroupNavigationRsp,
                               (jint)id, (jint)pressed);
  ALOGV("%s: id: %d, pressed: %d --- Not implemented", __func__, id, pressed);
}

static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect,
@@ -121,50 +88,11 @@ static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect,

static void btavrcp_get_rcfeatures_callback(const RawAddress& bd_addr,
                                            int features) {
  ALOGV("%s", __func__);
  std::shared_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbacksObj) {
    ALOGE("%s: sCallbacksObj is null", __func__);
    return;
  ALOGV("%s --- Not implemented", __func__);
}

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("%s: Failed to allocate a new byte array", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (jbyte*)&bd_addr.address);
  sCallbackEnv->CallVoidMethod(sCallbacksObj, method_getRcFeatures, addr.get(),
                               (jint)features);
}

static void btavrcp_setplayerapplicationsetting_rsp_callback(
    const RawAddress& bd_addr, uint8_t accepted) {
  ALOGV("%s", __func__);
  std::shared_lock<std::shared_timed_mutex> lock(sCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbacksObj) {
    ALOGE("%s: sCallbacksObj is null", __func__);
    return;
  }

  ScopedLocalRef<jbyteArray> addr(
      sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
  if (!addr.get()) {
    ALOGE("%s: Failed to allocate a new byte array", __func__);
    return;
  }

  sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
                                   (jbyte*)&bd_addr.address);
  sCallbackEnv->CallVoidMethod(sCallbacksObj, method_setplayerappsettingrsp,
                               addr.get(), (jint)accepted);
  ALOGV("%s --- Not implemented", __func__);
}

static void btavrcp_playerapplicationsetting_callback(
@@ -791,22 +719,11 @@ static btrc_ctrl_callbacks_t sBluetoothAvrcpCallbacks = {
    btavrcp_get_rcpsm_callback};

static void classInitNative(JNIEnv* env, jclass clazz) {
  method_handlePassthroughRsp =
      env->GetMethodID(clazz, "handlePassthroughRsp", "(II[B)V");

  method_handleGroupNavigationRsp =
      env->GetMethodID(clazz, "handleGroupNavigationRsp", "(II)V");

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

  method_getRcFeatures = env->GetMethodID(clazz, "getRcFeatures", "([BI)V");

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

  method_setplayerappsettingrsp =
      env->GetMethodID(clazz, "setPlayerAppSettingRsp", "([BB)V");

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

@@ -836,16 +753,16 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      clazz, "handleGetPlayerItemsRsp",
      "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");

  method_createFromNativeMediaItem =
      env->GetMethodID(clazz, "createFromNativeMediaItem",
  method_createFromNativeMediaItem = env->GetStaticMethodID(
      clazz, "createFromNativeMediaItem",
      "([BJILjava/lang/String;[I[Ljava/lang/String;)Lcom/"
      "android/bluetooth/avrcpcontroller/AvrcpItem;");
  method_createFromNativeFolderItem = env->GetMethodID(
  method_createFromNativeFolderItem = env->GetStaticMethodID(
      clazz, "createFromNativeFolderItem",
      "([BJILjava/lang/String;I)Lcom/android/bluetooth/avrcpcontroller/"
      "AvrcpItem;");
  method_createFromNativePlayerItem =
      env->GetMethodID(clazz, "createFromNativePlayerItem",
  method_createFromNativePlayerItem = env->GetStaticMethodID(
      clazz, "createFromNativePlayerItem",
      "([BILjava/lang/String;[BII)Lcom/android/bluetooth/"
      "avrcpcontroller/AvrcpPlayer;");
  method_handleChangeFolderRsp =
@@ -1308,7 +1225,8 @@ static JNINativeMethod sMethods[] = {

int register_com_android_bluetooth_avrcp_controller(JNIEnv* env) {
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/avrcpcontroller/AvrcpControllerService",
      env,
      "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface",
      sMethods, NELEM(sMethods));
}
}
}  // namespace android
+21 −14
Original line number Diff line number Diff line
@@ -817,7 +817,7 @@ static void energy_info_recv_callback(bt_activity_energy_info* p_energy_info,
  }

  sCallbackEnv->CallVoidMethod(
      sJniAdapterServiceObj, method_energyInfo, p_energy_info->status,
      sJniCallbacksObj, method_energyInfo, p_energy_info->status,
      p_energy_info->ctrl_state, p_energy_info->tx_time, p_energy_info->rx_time,
      p_energy_info->idle_time, p_energy_info->energy_used, array.get());
}
@@ -910,7 +910,7 @@ static int acquire_wake_lock_callout(const char* lock_name) {
    ScopedLocalRef<jstring> lock_name_jni(env, env->NewStringUTF(lock_name));
    if (lock_name_jni.get()) {
      bool acquired = env->CallBooleanMethod(
          sJniAdapterServiceObj, method_acquireWakeLock, lock_name_jni.get());
          sJniCallbacksObj, method_acquireWakeLock, lock_name_jni.get());
      if (!acquired) ret = BT_STATUS_WAKELOCK_ERROR;
    } else {
      ALOGE("%s unable to allocate string: %s", __func__, lock_name);
@@ -941,7 +941,7 @@ static int release_wake_lock_callout(const char* lock_name) {
    ScopedLocalRef<jstring> lock_name_jni(env, env->NewStringUTF(lock_name));
    if (lock_name_jni.get()) {
      bool released = env->CallBooleanMethod(
          sJniAdapterServiceObj, method_releaseWakeLock, lock_name_jni.get());
          sJniCallbacksObj, method_releaseWakeLock, lock_name_jni.get());
      if (!released) ret = BT_STATUS_WAKELOCK_ERROR;
    } else {
      ALOGE("%s unable to allocate string: %s", __func__, lock_name);
@@ -1014,15 +1014,19 @@ static void classInitNative(JNIEnv* env, jclass clazz) {

  method_adapterPropertyChangedCallback = env->GetMethodID(
      jniCallbackClass, "adapterPropertyChangedCallback", "([I[[B)V");

  method_discoveryStateChangeCallback = env->GetMethodID(
      jniCallbackClass, "discoveryStateChangeCallback", "(I)V");

  method_devicePropertyChangedCallback = env->GetMethodID(
      jniCallbackClass, "devicePropertyChangedCallback", "([B[I[[B)V");

  method_deviceFoundCallback =
      env->GetMethodID(jniCallbackClass, "deviceFoundCallback", "([B)V");

  method_pinRequestCallback =
      env->GetMethodID(jniCallbackClass, "pinRequestCallback", "([B[BIZ)V");

  method_sspRequestCallback =
      env->GetMethodID(jniCallbackClass, "sspRequestCallback", "([B[BIII)V");

@@ -1047,12 +1051,15 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_switchCodecCallback =
      env->GetMethodID(jniCallbackClass, "switchCodecCallback", "(Z)V");

  method_acquireWakeLock =
      env->GetMethodID(clazz, "acquireWakeLock", "(Ljava/lang/String;)Z");
  method_releaseWakeLock =
      env->GetMethodID(clazz, "releaseWakeLock", "(Ljava/lang/String;)Z");
  method_energyInfo = env->GetMethodID(
      clazz, "energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V");
  method_acquireWakeLock = env->GetMethodID(jniCallbackClass, "acquireWakeLock",
                                            "(Ljava/lang/String;)Z");

  method_releaseWakeLock = env->GetMethodID(jniCallbackClass, "releaseWakeLock",
                                            "(Ljava/lang/String;)Z");

  method_energyInfo =
      env->GetMethodID(jniCallbackClass, "energyInfoCallback",
                       "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V");

  if (env->GetJavaVM(&vm) != JNI_OK) {
    ALOGE("Could not get JavaVM");
@@ -1705,7 +1712,7 @@ static jboolean getRemoteServicesNative(JNIEnv* env, jobject obj,
  return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}

static int readEnergyInfo() {
static int readEnergyInfoNative() {
  ALOGV("%s", __func__);

  if (!sBluetoothInterface) return JNI_FALSE;
@@ -1934,7 +1941,7 @@ static void metadataChangedNative(JNIEnv* env, jobject obj, jbyteArray address,
  return;
}

static jboolean isLogRedactionEnabled(JNIEnv* env, jobject obj) {
static jboolean isLogRedactionEnabledNative(JNIEnv* env, jobject obj) {
  ALOGV("%s", __func__);
  return bluetooth::os::should_log_be_redacted();
}
@@ -2181,7 +2188,7 @@ static JNINativeMethod sMethods[] = {
    {"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative},
    {"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative},
    {"getRemoteServicesNative", "([BI)Z", (void*)getRemoteServicesNative},
    {"readEnergyInfo", "()I", (void*)readEnergyInfo},
    {"readEnergyInfoNative", "()I", (void*)readEnergyInfoNative},
    {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V",
     (void*)dumpNative},
    {"dumpMetricsNative", "()[B", (void*)dumpMetricsNative},
@@ -2197,7 +2204,7 @@ static JNINativeMethod sMethods[] = {
     (void*)requestMaximumTxDataLengthNative},
    {"allowLowLatencyAudioNative", "(Z[B)Z", (void*)allowLowLatencyAudioNative},
    {"metadataChangedNative", "([BI[B)V", (void*)metadataChangedNative},
    {"isLogRedactionEnabled", "()Z", (void*)isLogRedactionEnabled},
    {"isLogRedactionEnabledNative", "()Z", (void*)isLogRedactionEnabledNative},
    {"interopMatchAddrNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
     (void*)interopMatchAddrNative},
    {"interopMatchNameNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
@@ -2218,7 +2225,7 @@ static JNINativeMethod sMethods[] = {

int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/btservice/AdapterService", sMethods,
      env, "com/android/bluetooth/btservice/AdapterNativeInterface", sMethods,
      NELEM(sMethods));
}

+1 −1
Original line number Diff line number Diff line
@@ -2851,7 +2851,7 @@ int register_com_android_bluetooth_gatt(JNIEnv* env) {
      env, "com/android/bluetooth/gatt/AdvertiseManagerNativeInterface",
      sAdvertiseMethods, NELEM(sAdvertiseMethods));
  register_success &= jniRegisterNativeMethods(
      env, "com/android/bluetooth/gatt/PeriodicScanManager",
      env, "com/android/bluetooth/gatt/PeriodicScanNativeInterface",
      sPeriodicScanMethods, NELEM(sPeriodicScanMethods));
  register_success &= jniRegisterNativeMethods(
      env, "com/android/bluetooth/gatt/DistanceMeasurementNativeInterface",
+3 −3
Original line number Diff line number Diff line
@@ -521,8 +521,8 @@ static JNINativeMethod sMethods[] = {
};

int register_com_android_bluetooth_hid_host(JNIEnv* env) {
  return jniRegisterNativeMethods(env,
                                  "com/android/bluetooth/hid/HidHostService",
                                  sMethods, NELEM(sMethods));
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/hid/HidHostNativeInterface", sMethods,
      NELEM(sMethods));
}
}  // namespace android
+7 −5
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
static const bt_interface_t* btIf;

static void initializeNative(JNIEnv* env, jobject object) {
  debug("pan");
  debug("Initialize pan");
  if (btIf) return;

  btIf = getBluetoothInterface();
@@ -153,6 +153,7 @@ static void initializeNative(JNIEnv* env, jobject object) {
}

static void cleanupNative(JNIEnv* env, jobject object) {
  debug("Cleanup pan");
  if (!btIf) return;

  if (sPanIf != NULL) {
@@ -172,7 +173,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
static jboolean connectPanNative(JNIEnv* env, jobject object,
                                 jbyteArray address, jint src_role,
                                 jint dest_role) {
  debug("in");
  debug("Connect pan");
  if (!sPanIf) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -194,6 +195,7 @@ static jboolean connectPanNative(JNIEnv* env, jobject object,

static jboolean disconnectPanNative(JNIEnv* env, jobject object,
                                    jbyteArray address) {
  debug("Disconnects pan");
  if (!sPanIf) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -219,11 +221,11 @@ static JNINativeMethod sMethods[] = {
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"connectPanNative", "([BII)Z", (void*)connectPanNative},
    {"disconnectPanNative", "([B)Z", (void*)disconnectPanNative},
    // TBD cleanup
};

int register_com_android_bluetooth_pan(JNIEnv* env) {
  return jniRegisterNativeMethods(env, "com/android/bluetooth/pan/PanService",
                                  sMethods, NELEM(sMethods));
  return jniRegisterNativeMethods(
      env, "com/android/bluetooth/pan/PanNativeInterface", sMethods,
      NELEM(sMethods));
}
}
Loading