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

Commit 86ddcab0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "HFP: Add isInbandRingingEnabled() API (2/4)"

parents 24739545 87e1283a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -401,7 +401,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
}

static void initializeNative(JNIEnv* env, jobject object, jint max_hf_clients,
                             jboolean inband_ringing_support) {
                             jboolean inband_ringing_enabled) {
  std::unique_lock<std::shared_timed_mutex> interface_lock(interface_mutex);
  std::unique_lock<std::shared_timed_mutex> callbacks_lock(callbacks_mutex);

@@ -433,7 +433,7 @@ static void initializeNative(JNIEnv* env, jobject object, jint max_hf_clients,

  bt_status_t status =
      sBluetoothHfpInterface->Init(JniHeadsetCallbacks::GetInstance(),
                                   max_hf_clients, inband_ringing_support);
                                   max_hf_clients, inband_ringing_enabled);
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed to initialize Bluetooth HFP, status: %d", status);
    sBluetoothHfpInterface = nullptr;
+4 −4
Original line number Diff line number Diff line
@@ -203,11 +203,11 @@ public class HeadsetNativeInterface {
     * Initialize native stack
     *
     * @param maxHfClients maximum number of headset clients that can be connected simultaneously
     * @param inbandRingingSupported whether in-band ringing is supported on this AG
     * @param inbandRingingEnabled whether in-band ringing is enabled on this AG
     */
    @VisibleForTesting
    public void init(int maxHfClients, boolean inbandRingingSupported) {
        initializeNative(maxHfClients, inbandRingingSupported);
    public void init(int maxHfClients, boolean inbandRingingEnabled) {
        initializeNative(maxHfClients, inbandRingingEnabled);
    }

    /**
@@ -450,7 +450,7 @@ public class HeadsetNativeInterface {

    private native boolean atResponseStringNative(String responseString, byte[] address);

    private native void initializeNative(int maxHfClients, boolean inbandRingEnable);
    private native void initializeNative(int maxHfClients, boolean inbandRingingEnabled);

    private native void cleanupNative();

+19 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.BatteryManager;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
@@ -47,6 +48,8 @@ public class HeadsetService extends ProfileService {
    private static final boolean DBG = false;
    private static final String MODIFY_PHONE_STATE = android.Manifest.permission.MODIFY_PHONE_STATE;
    private static final int MAX_HEADSET_CONNECTIONS = 1;
    private static final String DISABLE_INBAND_RINGING_PROPERTY =
            "persist.bluetooth.disableinbandringing";

    private BluetoothDevice mActiveDevice;
    private HandlerThread mStateMachinesThread;
@@ -83,8 +86,7 @@ public class HeadsetService extends ProfileService {
        mSystemInterface.init();
        // Step 3: Initialize native interface
        mNativeInterface = HeadsetNativeInterface.getInstance();
        mNativeInterface.init(MAX_HEADSET_CONNECTIONS,
                BluetoothHeadset.isInbandRingingSupported(this));
        mNativeInterface.init(MAX_HEADSET_CONNECTIONS, isInbandRingingEnabled());
        // Step 4: Initialize state machine
        mStateMachine =
                HeadsetStateMachine.make(mStateMachinesThread.getLooper(), this, mNativeInterface,
@@ -463,6 +465,15 @@ public class HeadsetService extends ProfileService {
            }
            return service.getActiveDevice();
        }

        @Override
        public boolean isInbandRingingEnabled() {
            HeadsetService service = getService();
            if (service == null) {
                return false;
            }
            return service.isInbandRingingEnabled();
        }
    }

    // API methods
@@ -727,6 +738,12 @@ public class HeadsetService extends ProfileService {
        return true;
    }

    boolean isInbandRingingEnabled() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return BluetoothHeadset.isInbandRingingSupported(this)
                && !SystemProperties.getBoolean(DISABLE_INBAND_RINGING_PROPERTY, false);
    }

    void connectionStateChanged(BluetoothDevice device, int fromState, int toState) {
        if (fromState != BluetoothProfile.STATE_CONNECTED
                && toState == BluetoothProfile.STATE_CONNECTED) {
+1 −1
Original line number Diff line number Diff line
@@ -2450,7 +2450,7 @@ final class HeadsetStateMachine extends StateMachine {
        if (isInCall() || mVoiceRecognitionStarted) {
            return true;
        }
        if (isRinging() && BluetoothHeadset.isInbandRingingSupported(mService)) {
        if (isRinging() && mService.isInbandRingingEnabled()) {
            return true;
        }
        return false;