BtProfileConnectionInfo update api review

BtProfileConnectionInfo: rename class to BluetoothProfileConnectionInfo
<>.hearingAidInfo: rename to createHearingAidInfo
<>.leAudio: rename to createLeAudio
<>.getIsLeOutput: rename to isLeOutput
<>.getSuppressNoisyIntent: rename to isSuppressNoisyIntent

Did a bit more to keep consistency with a2dp & a2dpSink

Test: build
Test: atest frameworks/base/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/BluetoothProfileConnectionInfoTest.java
Fix: 216294722
Tag: #refactor
Change-Id: I2c4cf8d93b1a8840da1bf92c26d4e76140d0d8da
This commit is contained in:
William Escande 2022-01-25 18:01:15 +01:00
parent 853b6f6ede
commit ac11d77264
10 changed files with 76 additions and 70 deletions

View File

@ -140,7 +140,7 @@ package android.media {
method public void adjustSuggestedStreamVolumeForUid(int, int, int, @NonNull String, int, int, int);
method @NonNull public java.util.List<android.bluetooth.BluetoothCodecConfig> getHwOffloadFormatsSupportedForA2dp();
method @NonNull public java.util.List<android.bluetooth.BluetoothLeAudioCodecConfig> getHwOffloadFormatsSupportedForLeAudio();
method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void handleBluetoothActiveDeviceChanged(@Nullable android.bluetooth.BluetoothDevice, @Nullable android.bluetooth.BluetoothDevice, @NonNull android.media.BtProfileConnectionInfo);
method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void handleBluetoothActiveDeviceChanged(@Nullable android.bluetooth.BluetoothDevice, @Nullable android.bluetooth.BluetoothDevice, @NonNull android.media.BluetoothProfileConnectionInfo);
method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void setA2dpSuspended(boolean);
method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void setBluetoothHeadsetProperties(@NonNull String, boolean, boolean);
method @RequiresPermission("android.permission.BLUETOOTH_STACK") public void setHfpEnabled(boolean);
@ -150,18 +150,18 @@ package android.media {
field public static final int FLAG_FROM_KEY = 4096; // 0x1000
}
public final class BtProfileConnectionInfo implements android.os.Parcelable {
method @NonNull public static android.media.BtProfileConnectionInfo a2dpInfo(boolean, int);
method @NonNull public static android.media.BtProfileConnectionInfo a2dpSinkInfo(int);
public final class BluetoothProfileConnectionInfo implements android.os.Parcelable {
method @NonNull public static android.media.BluetoothProfileConnectionInfo createA2dpInfo(boolean, int);
method @NonNull public static android.media.BluetoothProfileConnectionInfo createA2dpSinkInfo(int);
method @NonNull public static android.media.BluetoothProfileConnectionInfo createHearingAidInfo(boolean);
method @NonNull public static android.media.BluetoothProfileConnectionInfo createLeAudioInfo(boolean, boolean);
method public int describeContents();
method public boolean getIsLeOutput();
method public int getProfile();
method public boolean getSuppressNoisyIntent();
method public int getVolume();
method @NonNull public static android.media.BtProfileConnectionInfo hearingAidInfo(boolean);
method @NonNull public static android.media.BtProfileConnectionInfo leAudio(boolean, boolean);
method public boolean isLeOutput();
method public boolean isSuppressNoisyIntent();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.media.BtProfileConnectionInfo> CREATOR;
field @NonNull public static final android.os.Parcelable.Creator<android.media.BluetoothProfileConnectionInfo> CREATOR;
}
public class MediaMetadataRetriever implements java.lang.AutoCloseable {

View File

@ -5806,13 +5806,14 @@ public class AudioManager {
* @param newDevice Bluetooth device connected or null if there is no new devices
* @param previousDevice Bluetooth device disconnected or null if there is no disconnected
* devices
* @param info contain all info related to the device. {@link BtProfileConnectionInfo}
* @param info contain all info related to the device. {@link BluetoothProfileConnectionInfo}
* {@hide}
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
@RequiresPermission(android.Manifest.permission.BLUETOOTH_STACK)
public void handleBluetoothActiveDeviceChanged(@Nullable BluetoothDevice newDevice,
@Nullable BluetoothDevice previousDevice, @NonNull BtProfileConnectionInfo info) {
@Nullable BluetoothDevice previousDevice,
@NonNull BluetoothProfileConnectionInfo info) {
final IAudioService service = getService();
try {
service.handleBluetoothActiveDeviceChanged(newDevice, previousDevice, info);

View File

@ -16,5 +16,5 @@
package android.media;
parcelable BtProfileConnectionInfo;
parcelable BluetoothProfileConnectionInfo;

View File

@ -26,15 +26,14 @@ import android.os.Parcelable;
* {@hide}
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public final class BtProfileConnectionInfo implements Parcelable {
public final class BluetoothProfileConnectionInfo implements Parcelable {
private final int mProfile;
private final boolean mSupprNoisy;
private final int mVolume;
private final boolean mIsLeOutput;
private BtProfileConnectionInfo(int profile, boolean suppressNoisyIntent, int volume,
boolean isLeOutput) {
private BluetoothProfileConnectionInfo(int profile, boolean suppressNoisyIntent,
int volume, boolean isLeOutput) {
mProfile = profile;
mSupprNoisy = suppressNoisyIntent;
mVolume = volume;
@ -45,21 +44,21 @@ public final class BtProfileConnectionInfo implements Parcelable {
* Constructor used by BtHelper when a profile is connected
* {@hide}
*/
public BtProfileConnectionInfo(int profile) {
public BluetoothProfileConnectionInfo(int profile) {
this(profile, false, -1, false);
}
public static final @NonNull Parcelable.Creator<BtProfileConnectionInfo> CREATOR =
new Parcelable.Creator<BtProfileConnectionInfo>() {
public static final @NonNull Parcelable.Creator<BluetoothProfileConnectionInfo> CREATOR =
new Parcelable.Creator<BluetoothProfileConnectionInfo>() {
@Override
public BtProfileConnectionInfo createFromParcel(Parcel source) {
return new BtProfileConnectionInfo(source.readInt(), source.readBoolean(),
source.readInt(), source.readBoolean());
public BluetoothProfileConnectionInfo createFromParcel(Parcel source) {
return new BluetoothProfileConnectionInfo(source.readInt(),
source.readBoolean(), source.readInt(), source.readBoolean());
}
@Override
public BtProfileConnectionInfo[] newArray(int size) {
return new BtProfileConnectionInfo[size];
public BluetoothProfileConnectionInfo[] newArray(int size) {
return new BluetoothProfileConnectionInfo[size];
}
};
@ -84,10 +83,10 @@ public final class BtProfileConnectionInfo implements Parcelable {
*
* @param volume of device -1 to ignore value
*/
public static @NonNull BtProfileConnectionInfo a2dpInfo(boolean suppressNoisyIntent,
int volume) {
return new BtProfileConnectionInfo(BluetoothProfile.A2DP, suppressNoisyIntent, volume,
false);
public static @NonNull BluetoothProfileConnectionInfo createA2dpInfo(
boolean suppressNoisyIntent, int volume) {
return new BluetoothProfileConnectionInfo(BluetoothProfile.A2DP, suppressNoisyIntent,
volume, false);
}
/**
@ -96,8 +95,8 @@ public final class BtProfileConnectionInfo implements Parcelable {
*
* @param volume of device -1 to ignore value
*/
public static @NonNull BtProfileConnectionInfo a2dpSinkInfo(int volume) {
return new BtProfileConnectionInfo(BluetoothProfile.A2DP_SINK, true, volume, false);
public static @NonNull BluetoothProfileConnectionInfo createA2dpSinkInfo(int volume) {
return new BluetoothProfileConnectionInfo(BluetoothProfile.A2DP_SINK, true, volume, false);
}
/**
@ -106,9 +105,10 @@ public final class BtProfileConnectionInfo implements Parcelable {
* @param suppressNoisyIntent if true the {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY}
* intent will not be sent.
*/
public static @NonNull BtProfileConnectionInfo hearingAidInfo(boolean suppressNoisyIntent) {
return new BtProfileConnectionInfo(BluetoothProfile.HEARING_AID, suppressNoisyIntent, -1,
false);
public static @NonNull BluetoothProfileConnectionInfo createHearingAidInfo(
boolean suppressNoisyIntent) {
return new BluetoothProfileConnectionInfo(BluetoothProfile.HEARING_AID, suppressNoisyIntent,
-1, false);
}
/**
@ -119,10 +119,10 @@ public final class BtProfileConnectionInfo implements Parcelable {
*
* @param isLeOutput if true mean the device is an output device, if false it's an input device
*/
public static @NonNull BtProfileConnectionInfo leAudio(boolean suppressNoisyIntent,
boolean isLeOutput) {
return new BtProfileConnectionInfo(BluetoothProfile.LE_AUDIO, suppressNoisyIntent, -1,
isLeOutput);
public static @NonNull BluetoothProfileConnectionInfo createLeAudioInfo(
boolean suppressNoisyIntent, boolean isLeOutput) {
return new BluetoothProfileConnectionInfo(BluetoothProfile.LE_AUDIO, suppressNoisyIntent,
-1, isLeOutput);
}
/**
@ -136,7 +136,7 @@ public final class BtProfileConnectionInfo implements Parcelable {
* @return {@code true} if {@link AudioManager.ACTION_AUDIO_BECOMING_NOISY} intent will not be
* sent
*/
public boolean getSuppressNoisyIntent() {
public boolean isSuppressNoisyIntent() {
return mSupprNoisy;
}
@ -153,7 +153,7 @@ public final class BtProfileConnectionInfo implements Parcelable {
* @return {@code true} is the LE device is an output device, {@code false} if it's an input
* device
*/
public boolean getIsLeOutput() {
public boolean isLeOutput() {
return mIsLeOutput;
}
}

View File

@ -24,7 +24,7 @@ import android.media.AudioFocusInfo;
import android.media.AudioPlaybackConfiguration;
import android.media.AudioRecordingConfiguration;
import android.media.AudioRoutesInfo;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import android.media.IAudioFocusDispatcher;
import android.media.IAudioModeDispatcher;
import android.media.IAudioRoutesObserver;
@ -268,7 +268,7 @@ interface IAudioService {
oneway void playerHasOpPlayAudio(in int piid, in boolean hasOpPlayAudio);
void handleBluetoothActiveDeviceChanged(in BluetoothDevice newDevice,
in BluetoothDevice previousDevice, in BtProfileConnectionInfo info);
in BluetoothDevice previousDevice, in BluetoothProfileConnectionInfo info);
oneway void setFocusRequestResultFromExtPolicy(in AudioFocusInfo afi, int requestResult,
in IAudioPolicyCallback pcb);

View File

@ -19,7 +19,7 @@ package com.android.mediaframeworktest.unit;
import static org.junit.Assert.assertEquals;
import android.bluetooth.BluetoothProfile;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import androidx.test.runner.AndroidJUnit4;
@ -27,22 +27,24 @@ import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class BtProfileConnectionInfoTest {
public class BluetoothProfileConnectionInfoTest {
@Test
public void testCoverageA2dp() {
final boolean supprNoisy = false;
final int volume = 42;
final BtProfileConnectionInfo info = BtProfileConnectionInfo.a2dpInfo(supprNoisy, volume);
final BluetoothProfileConnectionInfo info = BluetoothProfileConnectionInfo
.createA2dpInfo(supprNoisy, volume);
assertEquals(info.getProfile(), BluetoothProfile.A2DP);
assertEquals(info.getSuppressNoisyIntent(), supprNoisy);
assertEquals(info.isSuppressNoisyIntent(), supprNoisy);
assertEquals(info.getVolume(), volume);
}
@Test
public void testCoverageA2dpSink() {
final int volume = 42;
final BtProfileConnectionInfo info = BtProfileConnectionInfo.a2dpSinkInfo(volume);
final BluetoothProfileConnectionInfo info = BluetoothProfileConnectionInfo
.createA2dpSinkInfo(volume);
assertEquals(info.getProfile(), BluetoothProfile.A2DP_SINK);
assertEquals(info.getVolume(), volume);
}
@ -50,20 +52,21 @@ public class BtProfileConnectionInfoTest {
@Test
public void testCoveragehearingAid() {
final boolean supprNoisy = true;
final BtProfileConnectionInfo info = BtProfileConnectionInfo.hearingAidInfo(supprNoisy);
final BluetoothProfileConnectionInfo info = BluetoothProfileConnectionInfo
.createHearingAidInfo(supprNoisy);
assertEquals(info.getProfile(), BluetoothProfile.HEARING_AID);
assertEquals(info.getSuppressNoisyIntent(), supprNoisy);
assertEquals(info.isSuppressNoisyIntent(), supprNoisy);
}
@Test
public void testCoverageLeAudio() {
final boolean supprNoisy = false;
final boolean isLeOutput = true;
final BtProfileConnectionInfo info = BtProfileConnectionInfo.leAudio(supprNoisy,
isLeOutput);
final BluetoothProfileConnectionInfo info = BluetoothProfileConnectionInfo
.createLeAudioInfo(supprNoisy, isLeOutput);
assertEquals(info.getProfile(), BluetoothProfile.LE_AUDIO);
assertEquals(info.getSuppressNoisyIntent(), supprNoisy);
assertEquals(info.getIsLeOutput(), isLeOutput);
assertEquals(info.isSuppressNoisyIntent(), supprNoisy);
assertEquals(info.isLeOutput(), isLeOutput);
}
}

View File

@ -29,7 +29,7 @@ import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.AudioRoutesInfo;
import android.media.AudioSystem;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import android.media.IAudioRoutesObserver;
import android.media.ICapturePresetDevicesRoleDispatcher;
import android.media.ICommunicationDeviceDispatcher;
@ -517,12 +517,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
/*package*/ static final class BtDeviceChangedData {
final @Nullable BluetoothDevice mNewDevice;
final @Nullable BluetoothDevice mPreviousDevice;
final @NonNull BtProfileConnectionInfo mInfo;
final @NonNull BluetoothProfileConnectionInfo mInfo;
final @NonNull String mEventSource;
BtDeviceChangedData(@Nullable BluetoothDevice newDevice,
@Nullable BluetoothDevice previousDevice,
@NonNull BtProfileConnectionInfo info, @NonNull String eventSource) {
@NonNull BluetoothProfileConnectionInfo info, @NonNull String eventSource) {
mNewDevice = newDevice;
mPreviousDevice = previousDevice;
mInfo = info;
@ -554,9 +554,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
mDevice = device;
mState = state;
mProfile = d.mInfo.getProfile();
mSupprNoisy = d.mInfo.getSuppressNoisyIntent();
mSupprNoisy = d.mInfo.isSuppressNoisyIntent();
mVolume = d.mInfo.getVolume();
mIsLeOutput = d.mInfo.getIsLeOutput();
mIsLeOutput = d.mInfo.isLeOutput();
mEventSource = d.mEventSource;
mAudioSystemDevice = audioDevice;
mMusicDevice = AudioSystem.DEVICE_NONE;
@ -627,7 +627,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
audioDevice = AudioSystem.DEVICE_OUT_HEARING_AID;
break;
case BluetoothProfile.LE_AUDIO:
if (d.mInfo.getIsLeOutput()) {
if (d.mInfo.isLeOutput()) {
audioDevice = AudioSystem.DEVICE_OUT_BLE_HEADSET;
} else {
audioDevice = AudioSystem.DEVICE_IN_BLE_HEADSET;

View File

@ -83,7 +83,7 @@ import android.media.AudioPlaybackConfiguration;
import android.media.AudioRecordingConfiguration;
import android.media.AudioRoutesInfo;
import android.media.AudioSystem;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import android.media.IAudioFocusDispatcher;
import android.media.IAudioModeDispatcher;
import android.media.IAudioRoutesObserver;
@ -6301,14 +6301,14 @@ public class AudioService extends IAudioService.Stub
* See AudioManager.handleBluetoothActiveDeviceChanged(...)
*/
public void handleBluetoothActiveDeviceChanged(BluetoothDevice newDevice,
BluetoothDevice previousDevice, @NonNull BtProfileConnectionInfo info) {
BluetoothDevice previousDevice, @NonNull BluetoothProfileConnectionInfo info) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.BLUETOOTH_STACK)
!= PackageManager.PERMISSION_GRANTED) {
throw new SecurityException("Bluetooth is the only caller allowed");
}
if (info == null) {
throw new IllegalArgumentException("Illegal null BtProfileConnectionInfo for device "
+ previousDevice + " -> " + newDevice);
throw new IllegalArgumentException("Illegal null BluetoothProfileConnectionInfo for"
+ " device " + previousDevice + " -> " + newDevice);
}
final int profile = info.getProfile();
if (profile != BluetoothProfile.A2DP && profile != BluetoothProfile.A2DP_SINK

View File

@ -31,7 +31,7 @@ import android.content.Intent;
import android.media.AudioDeviceAttributes;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import android.os.Binder;
import android.os.UserHandle;
import android.provider.Settings;
@ -495,11 +495,13 @@ public class BtHelper {
if (state == BluetoothProfile.STATE_CONNECTED) {
mDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(btDevice, null,
new BtProfileConnectionInfo(profile), "mBluetoothProfileServiceListener"));
new BluetoothProfileConnectionInfo(profile),
"mBluetoothProfileServiceListener"));
} else {
mDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(null, btDevice,
new BtProfileConnectionInfo(profile), "mBluetoothProfileServiceListener"));
new BluetoothProfileConnectionInfo(profile),
"mBluetoothProfileServiceListener"));
}
}

View File

@ -30,7 +30,7 @@ import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.BtProfileConnectionInfo;
import android.media.BluetoothProfileConnectionInfo;
import android.util.Log;
import androidx.test.InstrumentationRegistry;
@ -100,7 +100,7 @@ public class AudioDeviceBrokerTest {
mAudioDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(mFakeBtDevice, null,
BtProfileConnectionInfo.a2dpInfo(true, 1), "testSource"));
BluetoothProfileConnectionInfo.createA2dpInfo(true, 1), "testSource"));
Thread.sleep(2 * MAX_MESSAGE_HANDLING_DELAY_MS);
verify(mSpyDevInventory, times(1)).setBluetoothActiveDevice(
any(AudioDeviceBroker.BtDeviceInfo.class)
@ -208,13 +208,13 @@ public class AudioDeviceBrokerTest {
// first connection: ensure the device is connected as a starting condition for the test
mAudioDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(mFakeBtDevice, null,
BtProfileConnectionInfo.a2dpInfo(true, 1), "testSource"));
BluetoothProfileConnectionInfo.createA2dpInfo(true, 1), "testSource"));
Thread.sleep(MAX_MESSAGE_HANDLING_DELAY_MS);
// disconnection
mAudioDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(null, mFakeBtDevice,
BtProfileConnectionInfo.a2dpInfo(false, -1), "testSource"));
BluetoothProfileConnectionInfo.createA2dpInfo(false, -1), "testSource"));
if (delayAfterDisconnection > 0) {
Thread.sleep(delayAfterDisconnection);
}
@ -222,7 +222,7 @@ public class AudioDeviceBrokerTest {
// reconnection
mAudioDeviceBroker.queueOnBluetoothActiveDeviceChanged(
new AudioDeviceBroker.BtDeviceChangedData(mFakeBtDevice, null,
BtProfileConnectionInfo.a2dpInfo(true, 2), "testSource"));
BluetoothProfileConnectionInfo.createA2dpInfo(true, 2), "testSource"));
Thread.sleep(AudioService.BECOMING_NOISY_DELAY_MS + MAX_MESSAGE_HANDLING_DELAY_MS);
// Verify disconnection has been cancelled and we're seeing two connections attempts,