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

Commit 98d3fcaf authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "JNI: Prevent duplicate construction of Socket Manager" am: bf37af8e

am: f445d199

Change-Id: I815bf8f9cb158a9f5b74e6bdf0a59f547d3498e4
parents 266f3696 f445d199
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@
#include <sys/prctl.h>
#include <sys/stat.h>

#include <mutex>

using base::StringPrintf;
using bluetooth::Uuid;
using android::bluetooth::BluetoothSocketManagerBinderServer;
@@ -75,7 +77,8 @@ static jobject sJniCallbacksObj;
static jfieldID sJniCallbacksField;

namespace {
android::sp<BluetoothSocketManagerBinderServer> socketManager = NULL;
android::sp<BluetoothSocketManagerBinderServer> sSocketManager = NULL;
std::mutex sSocketManagerMutex;
}

const bt_interface_t* getBluetoothInterface() { return sBluetoothInterface; }
@@ -738,8 +741,10 @@ static bool cleanupNative(JNIEnv* env, jobject obj) {
    env->DeleteGlobalRef(android_bluetooth_UidTraffic.clazz);
    android_bluetooth_UidTraffic.clazz = NULL;
  }

  socketManager = nullptr;
  {
    std::lock_guard<std::mutex> lock(sSocketManagerMutex);
    sSocketManager = nullptr;
  }
  return JNI_TRUE;
}

@@ -1114,11 +1119,12 @@ static jboolean getRemoteServicesNative(JNIEnv* env, jobject obj,
}

static jobject getSocketManagerNative(JNIEnv* env) {
  if (!socketManager.get())
    socketManager =
  std::lock_guard<std::mutex> lock(sSocketManagerMutex);
  if (!sSocketManager.get()) {
    sSocketManager =
        new BluetoothSocketManagerBinderServer(sBluetoothSocketInterface);

  return javaObjectForIBinder(env, IInterface::asBinder(socketManager));
  }
  return javaObjectForIBinder(env, IInterface::asBinder(sSocketManager));
}

static void setSystemUiUidNative(JNIEnv* env, jobject obj, jint uid) {