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

Commit f41c726a authored by Alice Kuo's avatar Alice Kuo Committed by Automerger Merge Worker
Browse files

Merge "As airplane mode turn on, keep BT on if LE audio profile connected" am:...

Merge "As airplane mode turn on, keep BT on if LE audio profile connected" am: f393f17f am: 2b008972 am: ba0641a7 am: 12dd515b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1899075

Change-Id: Iee7c0b5e6c8b2b234bac8e7341381b43c05789d4
parents 19c31b9a 12dd515b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.internal.annotations.VisibleForTesting;
 * when Bluetooth is on and Bluetooth is in one of the following situations:
 *   1. Bluetooth A2DP is connected.
 *   2. Bluetooth Hearing Aid profile is connected.
 *   3. Bluetooth LE Audio is connected
 */
class BluetoothAirplaneModeListener {
    private static final String TAG = "BluetoothAirplaneModeListener";
@@ -132,7 +133,7 @@ class BluetoothAirplaneModeListener {
            return false;
        }
        if (!mAirplaneHelper.isBluetoothOn() || !mAirplaneHelper.isAirplaneModeOn()
                || !mAirplaneHelper.isA2dpOrHearingAidConnected()) {
                || !mAirplaneHelper.isMediaProfileConnected()) {
            return false;
        }
        return true;
+5 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.BroadcastOptions;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.IBluetooth;
@@ -456,12 +457,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    }
                }
            } else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(action)
                    || BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
                    || BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED.equals(action)
                    || BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED.equals(action)) {
                final int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
                        BluetoothProfile.STATE_CONNECTED);
                if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
                        && state == BluetoothProfile.STATE_DISCONNECTED
                        && !mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
                        && !mBluetoothModeChangeHelper.isMediaProfileConnected()) {
                    Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
                    onInitFlagsChanged();
                }
@@ -2291,7 +2293,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        Slog.d(TAG, "MESSAGE_INIT_FLAGS_CHANGED");
                    }
                    mHandler.removeMessages(MESSAGE_INIT_FLAGS_CHANGED);
                    if (mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
                    if (mBluetoothModeChangeHelper.isMediaProfileConnected()) {
                        Slog.i(TAG, "Delaying MESSAGE_INIT_FLAGS_CHANGED by "
                                + DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS
                                + " ms due to existing connections");
+19 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.RequiresPermission;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile.ServiceListener;
import android.content.Context;
@@ -37,6 +38,7 @@ import com.android.internal.annotations.VisibleForTesting;
public class BluetoothModeChangeHelper {
    private volatile BluetoothA2dp mA2dp;
    private volatile BluetoothHearingAid mHearingAid;
    private volatile BluetoothLeAudio mLeAudio;
    private final BluetoothAdapter mAdapter;
    private final Context mContext;

@@ -47,6 +49,7 @@ public class BluetoothModeChangeHelper {
        mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.A2DP);
        mAdapter.getProfileProxy(mContext, mProfileServiceListener,
                BluetoothProfile.HEARING_AID);
        mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.LE_AUDIO);
    }

    private final ServiceListener mProfileServiceListener = new ServiceListener() {
@@ -60,6 +63,9 @@ public class BluetoothModeChangeHelper {
                case BluetoothProfile.HEARING_AID:
                    mHearingAid = (BluetoothHearingAid) proxy;
                    break;
                case BluetoothProfile.LE_AUDIO:
                    mLeAudio = (BluetoothLeAudio) proxy;
                    break;
                default:
                    break;
            }
@@ -75,6 +81,9 @@ public class BluetoothModeChangeHelper {
                case BluetoothProfile.HEARING_AID:
                    mHearingAid = null;
                    break;
                case BluetoothProfile.LE_AUDIO:
                    mLeAudio = null;
                    break;
                default:
                    break;
            }
@@ -82,8 +91,8 @@ public class BluetoothModeChangeHelper {
    };

    @VisibleForTesting
    public boolean isA2dpOrHearingAidConnected() {
        return isA2dpConnected() || isHearingAidConnected();
    public boolean isMediaProfileConnected() {
        return isA2dpConnected() || isHearingAidConnected() || isLeAudioConnected();
    }

    @VisibleForTesting
@@ -142,4 +151,12 @@ public class BluetoothModeChangeHelper {
        }
        return hearingAid.getConnectedDevices().size() > 0;
    }

    private boolean isLeAudioConnected() {
        final BluetoothLeAudio leAudio = mLeAudio;
        if (leAudio == null) {
            return false;
        }
        return leAudio.getConnectedDevices().size() > 0;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class BluetoothAirplaneModeListenerTest {
        when(mHelper.isBluetoothOn()).thenReturn(true);
        Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());

        when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
        when(mHelper.isMediaProfileConnected()).thenReturn(true);
        Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());

        when(mHelper.isAirplaneModeOn()).thenReturn(true);
@@ -83,7 +83,7 @@ public class BluetoothAirplaneModeListenerTest {
    public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_NotPopToast() {
        mBluetoothAirplaneModeListener.mToastCount = BluetoothAirplaneModeListener.MAX_TOAST_COUNT;
        when(mHelper.isBluetoothOn()).thenReturn(true);
        when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
        when(mHelper.isMediaProfileConnected()).thenReturn(true);
        when(mHelper.isAirplaneModeOn()).thenReturn(true);
        mBluetoothAirplaneModeListener.handleAirplaneModeChange();

@@ -97,7 +97,7 @@ public class BluetoothAirplaneModeListenerTest {
    public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_PopToast() {
        mBluetoothAirplaneModeListener.mToastCount = 0;
        when(mHelper.isBluetoothOn()).thenReturn(true);
        when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
        when(mHelper.isMediaProfileConnected()).thenReturn(true);
        when(mHelper.isAirplaneModeOn()).thenReturn(true);
        mBluetoothAirplaneModeListener.handleAirplaneModeChange();