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

Commit df032ead authored by Sanket Agarwal's avatar Sanket Agarwal
Browse files

Init JNI in Bluetooth Service not the Bluetooth State machine

Since we can have multiple state machines the right lifecycle management
should be done in the Bluetooth service with start and stop operations.
Otherwise, there could be JNI crashes, due to JNI callbacks before the
JNI is setup.

Bug: b/34681827
Test: Connect device over HFP and make a call
Change-Id: I3ebe9d035511ca830f131d5b09461ecccfcc4672
parent 2894e3fd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -490,6 +490,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
}

static void initializeNative(JNIEnv* env, jobject object) {
  ALOGD("%s: HfpClient", __func__);
  const bt_interface_t* btInf = getBluetoothInterface();
  if (btInf == NULL) {
    ALOGE("Bluetooth module is not loaded");
+7 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class HeadsetClientService extends ProfileService {
    public static String HFP_CLIENT_STOP_TAG = "hfp_client_stop_tag";

    static {
        NativeInterface.initializeNative();
        NativeInterface.classInitNative();
    }

    @Override
@@ -81,6 +81,12 @@ public class HeadsetClientService extends ProfileService {

    @Override
    protected synchronized boolean start() {
        if (DBG) {
            Log.d(TAG, "start()");
        }
        // Setup the JNI service
        NativeInterface.initializeNative();

        mSmFactory = new HeadsetClientStateMachineFactory();
        mStateMachineMap.clear();

+0 −4
Original line number Diff line number Diff line
@@ -166,10 +166,6 @@ public class HeadsetClientStateMachine extends StateMachine {
        return mDisconnected;
    }

    static {
        NativeInterface.classInitNative();
    }

    public void dump(StringBuilder sb) {
        ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
        ProfileService.println(sb, "mAudioOn: " + mAudioOn);