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

Commit 86fca420 authored by Martin Brabham's avatar Martin Brabham
Browse files

Clean up JNI

The callbacks for HeadsetClientConnectionService's NativeInterface was
failing when a non static function, declared in C++, had a matching
method in the corresponding Java file that was declared as static. This
caused a signature mismatch due to the class being a different InstanceOf.

Bug: 34334230
Change-Id: Ib3d18d1615190d5835f72e00bc4d28adfa86a48e
parent d30c9b03
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -64,10 +64,6 @@ public class HeadsetClientService extends ProfileService {

    public static final String HFP_CLIENT_STOP_TAG = "hfp_client_stop_tag";

    static {
        NativeInterface.classInitNative();
    }

    @Override
    public IProfileServiceBinder initBinder() {
        return new BluetoothHeadsetClientBinder(this);
@@ -78,8 +74,15 @@ public class HeadsetClientService extends ProfileService {
        if (DBG) {
            Log.d(TAG, "start()");
        }
        if (sHeadsetClientService != null) {
            Log.w(TAG, "start(): start called without stop");
            return false;
        }

        // Setup the JNI service
        NativeInterface.initializeNative();
        mNativeInterface = new NativeInterface();
        mNativeInterface.initializeNative();

        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

        mSmFactory = new HeadsetClientStateMachineFactory();
@@ -88,8 +91,6 @@ public class HeadsetClientService extends ProfileService {
        IntentFilter filter = new IntentFilter(AudioManager.VOLUME_CHANGED_ACTION);
        registerReceiver(mBroadcastReceiver, filter);

        mNativeInterface = new NativeInterface();

        // Start the HfpClientConnectionService to create connection with telecom when HFP
        // connection is available.
        Intent startIntent = new Intent(this, HfpClientConnectionService.class);
@@ -125,13 +126,13 @@ public class HeadsetClientService extends ProfileService {
        Intent stopIntent = new Intent(this, HfpClientConnectionService.class);
        stopIntent.putExtra(HFP_CLIENT_STOP_TAG, true);
        startService(stopIntent);
        mNativeInterface = null;

        // Stop the handler thread
        mSmThread.quit();
        mSmThread = null;

        NativeInterface.cleanupNative();
        mNativeInterface.cleanupNative();
        mNativeInterface = null;

        return true;
    }
+6 −2
Original line number Diff line number Diff line
@@ -28,14 +28,18 @@ class NativeInterface {
    private static final String TAG = "NativeInterface";
    private static final boolean DBG = false;

    static {
        classInitNative();
    }

    NativeInterface() {}

    // Native methods that call into the JNI interface
    static native void classInitNative();

    static native void initializeNative();
    native void initializeNative();

    static native void cleanupNative();
    native void cleanupNative();

    static native boolean connectNative(byte[] address);