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

Commit 6236a0a6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "HID: Fix the potential NPE in HidHostService jni callback"

parents 50db58cc 774eb159
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
#include "utils/Log.h"

#include <string.h>

#include <shared_mutex>
namespace android {

static jmethodID method_onConnectStateChanged;
@@ -36,6 +36,7 @@ static jmethodID method_onGetIdleTime;

static const bthh_interface_t* sBluetoothHidInterface = NULL;
static jobject mCallbacksObj = NULL;
static std::shared_timed_mutex mCallbacks_mutex;

static jbyteArray marshall_bda(RawAddress* bd_addr) {
  CallbackEnv sCallbackEnv(__func__);
@@ -53,6 +54,7 @@ static jbyteArray marshall_bda(RawAddress* bd_addr) {

static void connection_state_callback(RawAddress* bd_addr,
                                      bthh_connection_state_t state) {
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!mCallbacksObj) {
@@ -72,6 +74,7 @@ static void connection_state_callback(RawAddress* bd_addr,
static void get_protocol_mode_callback(RawAddress* bd_addr,
                                       bthh_status_t hh_status,
                                       bthh_protocol_mode_t mode) {
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!mCallbacksObj) {
@@ -95,6 +98,7 @@ static void get_protocol_mode_callback(RawAddress* bd_addr,

static void get_report_callback(RawAddress* bd_addr, bthh_status_t hh_status,
                                uint8_t* rpt_data, int rpt_size) {
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!mCallbacksObj) {
@@ -126,6 +130,7 @@ static void get_report_callback(RawAddress* bd_addr, bthh_status_t hh_status,
static void virtual_unplug_callback(RawAddress* bd_addr,
                                    bthh_status_t hh_status) {
  ALOGV("call to virtual_unplug_callback");
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!mCallbacksObj) {
@@ -142,6 +147,7 @@ static void virtual_unplug_callback(RawAddress* bd_addr,
}

static void handshake_callback(RawAddress* bd_addr, bthh_status_t hh_status) {
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!mCallbacksObj) {
@@ -160,6 +166,7 @@ static void handshake_callback(RawAddress* bd_addr, bthh_status_t hh_status) {

static void get_idle_time_callback(RawAddress* bd_addr, bthh_status_t hh_status,
                                   int idle_time) {
  std::shared_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;

@@ -198,6 +205,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
}

static void initializeNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == NULL) {
    ALOGE("Bluetooth module is not loaded");
@@ -234,6 +242,7 @@ static void initializeNative(JNIEnv* env, jobject object) {
}

static void cleanupNative(JNIEnv* env, jobject object) {
  std::unique_lock<std::shared_timed_mutex> lock(mCallbacks_mutex);
  const bt_interface_t* btInf = getBluetoothInterface();

  if (btInf == NULL) {