Merge "As airplane mode turn on, keep BT on if LE audio profile connected" am: f393f17f55 am: 2b008972b8
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1899075 Change-Id: I1b0c3439f17b7d02438bc5074cebde857aa3bda9
This commit is contained in:
@@ -35,6 +35,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
* when Bluetooth is on and Bluetooth is in one of the following situations:
|
* when Bluetooth is on and Bluetooth is in one of the following situations:
|
||||||
* 1. Bluetooth A2DP is connected.
|
* 1. Bluetooth A2DP is connected.
|
||||||
* 2. Bluetooth Hearing Aid profile is connected.
|
* 2. Bluetooth Hearing Aid profile is connected.
|
||||||
|
* 3. Bluetooth LE Audio is connected
|
||||||
*/
|
*/
|
||||||
class BluetoothAirplaneModeListener {
|
class BluetoothAirplaneModeListener {
|
||||||
private static final String TAG = "BluetoothAirplaneModeListener";
|
private static final String TAG = "BluetoothAirplaneModeListener";
|
||||||
@@ -132,7 +133,7 @@ class BluetoothAirplaneModeListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!mAirplaneHelper.isBluetoothOn() || !mAirplaneHelper.isAirplaneModeOn()
|
if (!mAirplaneHelper.isBluetoothOn() || !mAirplaneHelper.isAirplaneModeOn()
|
||||||
|| !mAirplaneHelper.isA2dpOrHearingAidConnected()) {
|
|| !mAirplaneHelper.isMediaProfileConnected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import android.app.BroadcastOptions;
|
|||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothHearingAid;
|
import android.bluetooth.BluetoothHearingAid;
|
||||||
|
import android.bluetooth.BluetoothLeAudio;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothProtoEnums;
|
import android.bluetooth.BluetoothProtoEnums;
|
||||||
import android.bluetooth.IBluetooth;
|
import android.bluetooth.IBluetooth;
|
||||||
@@ -456,12 +457,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equals(action)
|
} 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,
|
final int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
|
||||||
BluetoothProfile.STATE_CONNECTED);
|
BluetoothProfile.STATE_CONNECTED);
|
||||||
if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
|
if (mHandler.hasMessages(MESSAGE_INIT_FLAGS_CHANGED)
|
||||||
&& state == BluetoothProfile.STATE_DISCONNECTED
|
&& state == BluetoothProfile.STATE_DISCONNECTED
|
||||||
&& !mBluetoothModeChangeHelper.isA2dpOrHearingAidConnected()) {
|
&& !mBluetoothModeChangeHelper.isMediaProfileConnected()) {
|
||||||
Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
|
Slog.i(TAG, "Device disconnected, reactivating pending flag changes");
|
||||||
onInitFlagsChanged();
|
onInitFlagsChanged();
|
||||||
}
|
}
|
||||||
@@ -2291,7 +2293,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
Slog.d(TAG, "MESSAGE_INIT_FLAGS_CHANGED");
|
Slog.d(TAG, "MESSAGE_INIT_FLAGS_CHANGED");
|
||||||
}
|
}
|
||||||
mHandler.removeMessages(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 "
|
Slog.i(TAG, "Delaying MESSAGE_INIT_FLAGS_CHANGED by "
|
||||||
+ DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS
|
+ DELAY_FOR_RETRY_INIT_FLAG_CHECK_MS
|
||||||
+ " ms due to existing connections");
|
+ " ms due to existing connections");
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import android.annotation.RequiresPermission;
|
|||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothHearingAid;
|
import android.bluetooth.BluetoothHearingAid;
|
||||||
|
import android.bluetooth.BluetoothLeAudio;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.bluetooth.BluetoothProfile.ServiceListener;
|
import android.bluetooth.BluetoothProfile.ServiceListener;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -37,6 +38,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
|||||||
public class BluetoothModeChangeHelper {
|
public class BluetoothModeChangeHelper {
|
||||||
private volatile BluetoothA2dp mA2dp;
|
private volatile BluetoothA2dp mA2dp;
|
||||||
private volatile BluetoothHearingAid mHearingAid;
|
private volatile BluetoothHearingAid mHearingAid;
|
||||||
|
private volatile BluetoothLeAudio mLeAudio;
|
||||||
private final BluetoothAdapter mAdapter;
|
private final BluetoothAdapter mAdapter;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
@@ -47,6 +49,7 @@ public class BluetoothModeChangeHelper {
|
|||||||
mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.A2DP);
|
mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.A2DP);
|
||||||
mAdapter.getProfileProxy(mContext, mProfileServiceListener,
|
mAdapter.getProfileProxy(mContext, mProfileServiceListener,
|
||||||
BluetoothProfile.HEARING_AID);
|
BluetoothProfile.HEARING_AID);
|
||||||
|
mAdapter.getProfileProxy(mContext, mProfileServiceListener, BluetoothProfile.LE_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ServiceListener mProfileServiceListener = new ServiceListener() {
|
private final ServiceListener mProfileServiceListener = new ServiceListener() {
|
||||||
@@ -60,6 +63,9 @@ public class BluetoothModeChangeHelper {
|
|||||||
case BluetoothProfile.HEARING_AID:
|
case BluetoothProfile.HEARING_AID:
|
||||||
mHearingAid = (BluetoothHearingAid) proxy;
|
mHearingAid = (BluetoothHearingAid) proxy;
|
||||||
break;
|
break;
|
||||||
|
case BluetoothProfile.LE_AUDIO:
|
||||||
|
mLeAudio = (BluetoothLeAudio) proxy;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -75,6 +81,9 @@ public class BluetoothModeChangeHelper {
|
|||||||
case BluetoothProfile.HEARING_AID:
|
case BluetoothProfile.HEARING_AID:
|
||||||
mHearingAid = null;
|
mHearingAid = null;
|
||||||
break;
|
break;
|
||||||
|
case BluetoothProfile.LE_AUDIO:
|
||||||
|
mLeAudio = null;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -82,8 +91,8 @@ public class BluetoothModeChangeHelper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public boolean isA2dpOrHearingAidConnected() {
|
public boolean isMediaProfileConnected() {
|
||||||
return isA2dpConnected() || isHearingAidConnected();
|
return isA2dpConnected() || isHearingAidConnected() || isLeAudioConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -142,4 +151,12 @@ public class BluetoothModeChangeHelper {
|
|||||||
}
|
}
|
||||||
return hearingAid.getConnectedDevices().size() > 0;
|
return hearingAid.getConnectedDevices().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isLeAudioConnected() {
|
||||||
|
final BluetoothLeAudio leAudio = mLeAudio;
|
||||||
|
if (leAudio == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return leAudio.getConnectedDevices().size() > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class BluetoothAirplaneModeListenerTest {
|
|||||||
when(mHelper.isBluetoothOn()).thenReturn(true);
|
when(mHelper.isBluetoothOn()).thenReturn(true);
|
||||||
Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());
|
Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());
|
||||||
|
|
||||||
when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
|
when(mHelper.isMediaProfileConnected()).thenReturn(true);
|
||||||
Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());
|
Assert.assertFalse(mBluetoothAirplaneModeListener.shouldSkipAirplaneModeChange());
|
||||||
|
|
||||||
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
||||||
@@ -83,7 +83,7 @@ public class BluetoothAirplaneModeListenerTest {
|
|||||||
public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_NotPopToast() {
|
public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_NotPopToast() {
|
||||||
mBluetoothAirplaneModeListener.mToastCount = BluetoothAirplaneModeListener.MAX_TOAST_COUNT;
|
mBluetoothAirplaneModeListener.mToastCount = BluetoothAirplaneModeListener.MAX_TOAST_COUNT;
|
||||||
when(mHelper.isBluetoothOn()).thenReturn(true);
|
when(mHelper.isBluetoothOn()).thenReturn(true);
|
||||||
when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
|
when(mHelper.isMediaProfileConnected()).thenReturn(true);
|
||||||
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
||||||
mBluetoothAirplaneModeListener.handleAirplaneModeChange();
|
mBluetoothAirplaneModeListener.handleAirplaneModeChange();
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class BluetoothAirplaneModeListenerTest {
|
|||||||
public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_PopToast() {
|
public void testHandleAirplaneModeChange_NotInvokeAirplaneModeChanged_PopToast() {
|
||||||
mBluetoothAirplaneModeListener.mToastCount = 0;
|
mBluetoothAirplaneModeListener.mToastCount = 0;
|
||||||
when(mHelper.isBluetoothOn()).thenReturn(true);
|
when(mHelper.isBluetoothOn()).thenReturn(true);
|
||||||
when(mHelper.isA2dpOrHearingAidConnected()).thenReturn(true);
|
when(mHelper.isMediaProfileConnected()).thenReturn(true);
|
||||||
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
when(mHelper.isAirplaneModeOn()).thenReturn(true);
|
||||||
mBluetoothAirplaneModeListener.handleAirplaneModeChange();
|
mBluetoothAirplaneModeListener.handleAirplaneModeChange();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user