summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-08 02:08:28 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-03-08 02:08:28 +0000
commit22389fee67a014fed221aadadcfbc1dc9cd7335f (patch)
tree24b5864c0fccfd1ae7549e3616dbc5ee1aa5bafb /framework/java/android/bluetooth
parent4739b8feb4c2a5becbb584b1f62f0e5321079d17 (diff)
parentc4c4f9227fb198e838b5b7de5d1a048f2d3a0c52 (diff)
Snap for 8270536 from c4c4f9227fb198e838b5b7de5d1a048f2d3a0c52 to tm-release
Change-Id: I11136ce6eeaed10d012ef29fb7c081cbc5c1ced2
Diffstat (limited to 'framework/java/android/bluetooth')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java36
-rw-r--r--framework/java/android/bluetooth/BluetoothDevice.java16
-rw-r--r--framework/java/android/bluetooth/BluetoothHeadsetClient.java23
-rw-r--r--framework/java/android/bluetooth/BluetoothLeAudio.java29
-rw-r--r--framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java18
5 files changed, 85 insertions, 37 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 936a08569b..5767abb2b5 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -32,7 +32,6 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.PendingIntent;
-import android.app.PropertyInvalidatedCache;
import android.bluetooth.BluetoothDevice.AddressType;
import android.bluetooth.BluetoothDevice.Transport;
import android.bluetooth.BluetoothProfile.ConnectionPolicy;
@@ -57,6 +56,7 @@ import android.os.Binder;
import android.os.BluetoothServiceManager;
import android.os.Build;
import android.os.IBinder;
+import android.os.IpcDataCache;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.os.ResultReceiver;
@@ -1125,13 +1125,13 @@ public final class BluetoothAdapter {
}
/**
- * There are several instances of PropertyInvalidatedCache used in this class.
+ * There are several instances of IpcDataCache used in this class.
* BluetoothCache wraps up the common code. All caches are created with a maximum of
* eight entries, and the key is in the bluetooth module. The name is set to the api.
*/
- private static class BluetoothCache<Q, R> extends PropertyInvalidatedCache<Q, R> {
- BluetoothCache(String api, PropertyInvalidatedCache.QueryHandler query) {
- super(8, PropertyInvalidatedCache.MODULE_BLUETOOTH, api, api, query);
+ private static class BluetoothCache<Q, R> extends IpcDataCache<Q, R> {
+ BluetoothCache(String api, IpcDataCache.QueryHandler query) {
+ super(8, IpcDataCache.MODULE_BLUETOOTH, api, api, query);
}};
/**
@@ -1139,7 +1139,7 @@ public final class BluetoothAdapter {
* enforces the bluetooth module.
*/
private static void invalidateCache(@NonNull String api) {
- PropertyInvalidatedCache.invalidateCache(PropertyInvalidatedCache.MODULE_BLUETOOTH, api);
+ IpcDataCache.invalidateCache(IpcDataCache.MODULE_BLUETOOTH, api);
}
/**
@@ -1147,8 +1147,8 @@ public final class BluetoothAdapter {
*/
private static final String GET_STATE_API = "getState";
- private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetStateQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
+ private final IpcDataCache.QueryHandler<Void, Integer> mBluetoothGetStateQuery =
+ new IpcDataCache.QueryHandler<>() {
@RequiresLegacyBluetoothPermission
@RequiresNoPermission
@AdapterState
@@ -1174,7 +1174,7 @@ public final class BluetoothAdapter {
return state;
}};
- private final PropertyInvalidatedCache<Void, Integer> mBluetoothGetStateCache =
+ private final IpcDataCache<Void, Integer> mBluetoothGetStateCache =
new BluetoothCache<Void, Integer>(GET_STATE_API, mBluetoothGetStateQuery);
/** @hide */
@@ -2267,8 +2267,8 @@ public final class BluetoothAdapter {
}
}
- private final PropertyInvalidatedCache.QueryHandler<Void, Boolean> mBluetoothFilteringQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
+ private final IpcDataCache.QueryHandler<Void, Boolean> mBluetoothFilteringQuery =
+ new IpcDataCache.QueryHandler<>() {
@RequiresLegacyBluetoothPermission
@RequiresNoPermission
@Override
@@ -2290,7 +2290,7 @@ public final class BluetoothAdapter {
private static final String FILTERING_API = "isOffloadedFilteringSupported";
- private final PropertyInvalidatedCache<Void, Boolean> mBluetoothFilteringCache =
+ private final IpcDataCache<Void, Boolean> mBluetoothFilteringCache =
new BluetoothCache<Void, Boolean>(FILTERING_API, mBluetoothFilteringQuery);
/** @hide */
@@ -2810,8 +2810,8 @@ public final class BluetoothAdapter {
return supportedProfiles;
}
- private final PropertyInvalidatedCache.QueryHandler<Void, Integer> mBluetoothGetAdapterQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
+ private final IpcDataCache.QueryHandler<Void, Integer> mBluetoothGetAdapterQuery =
+ new IpcDataCache.QueryHandler<>() {
@RequiresLegacyBluetoothPermission
@RequiresNoPermission
@Override
@@ -2836,7 +2836,7 @@ public final class BluetoothAdapter {
}};
private static final String GET_CONNECTION_API = "getAdapterConnectionState";
- private final PropertyInvalidatedCache<Void, Integer>
+ private final IpcDataCache<Void, Integer>
mBluetoothGetAdapterConnectionStateCache =
new BluetoothCache<Void, Integer>(GET_CONNECTION_API, mBluetoothGetAdapterQuery);
@@ -2872,8 +2872,8 @@ public final class BluetoothAdapter {
return mBluetoothGetAdapterConnectionStateCache.query(null);
}
- private final PropertyInvalidatedCache.QueryHandler<Integer, Integer> mBluetoothProfileQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
+ private final IpcDataCache.QueryHandler<Integer, Integer> mBluetoothProfileQuery =
+ new IpcDataCache.QueryHandler<>() {
@RequiresNoPermission
@Override
public Integer apply(Integer query) {
@@ -2896,7 +2896,7 @@ public final class BluetoothAdapter {
}};
private static final String PROFILE_API = "getProfileConnectionState";
- private final PropertyInvalidatedCache<Integer, Integer>
+ private final IpcDataCache<Integer, Integer>
mGetProfileConnectionStateCache =
new BluetoothCache<Integer, Integer>(PROFILE_API, mBluetoothProfileQuery);
diff --git a/framework/java/android/bluetooth/BluetoothDevice.java b/framework/java/android/bluetooth/BluetoothDevice.java
index 8c591e897d..71e15f0063 100644
--- a/framework/java/android/bluetooth/BluetoothDevice.java
+++ b/framework/java/android/bluetooth/BluetoothDevice.java
@@ -26,7 +26,6 @@ import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
-import android.app.PropertyInvalidatedCache;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresBluetoothLocationPermission;
import android.bluetooth.annotations.RequiresBluetoothScanPermission;
@@ -38,6 +37,7 @@ import android.content.AttributionSource;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
+import android.os.IpcDataCache;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;
@@ -1823,13 +1823,13 @@ public final class BluetoothDevice implements Parcelable, Attributable {
}
/**
- * There are several instances of PropertyInvalidatedCache used in this class.
+ * There are several instances of IpcDataCache used in this class.
* BluetoothCache wraps up the common code. All caches are created with a maximum of
* eight entries, and the key is in the bluetooth module. The name is set to the api.
*/
- private static class BluetoothCache<Q, R> extends PropertyInvalidatedCache<Q, R> {
- BluetoothCache(String api, PropertyInvalidatedCache.QueryHandler query) {
- super(8, PropertyInvalidatedCache.MODULE_BLUETOOTH, api, api, query);
+ private static class BluetoothCache<Q, R> extends IpcDataCache<Q, R> {
+ BluetoothCache(String api, IpcDataCache.QueryHandler query) {
+ super(8, IpcDataCache.MODULE_BLUETOOTH, api, api, query);
}};
/**
@@ -1837,12 +1837,12 @@ public final class BluetoothDevice implements Parcelable, Attributable {
* enforces the bluetooth module.
*/
private static void invalidateCache(@NonNull String api) {
- PropertyInvalidatedCache.invalidateCache(PropertyInvalidatedCache.MODULE_BLUETOOTH, api);
+ IpcDataCache.invalidateCache(IpcDataCache.MODULE_BLUETOOTH, api);
}
private final
- PropertyInvalidatedCache.QueryHandler<BluetoothDevice, Integer> mBluetoothBondQuery =
- new PropertyInvalidatedCache.QueryHandler<>() {
+ IpcDataCache.QueryHandler<BluetoothDevice, Integer> mBluetoothBondQuery =
+ new IpcDataCache.QueryHandler<>() {
@RequiresLegacyBluetoothPermission
@RequiresBluetoothConnectPermission
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
diff --git a/framework/java/android/bluetooth/BluetoothHeadsetClient.java b/framework/java/android/bluetooth/BluetoothHeadsetClient.java
index 9be1b328f3..6a67923f11 100644
--- a/framework/java/android/bluetooth/BluetoothHeadsetClient.java
+++ b/framework/java/android/bluetooth/BluetoothHeadsetClient.java
@@ -17,6 +17,7 @@ package android.bluetooth;
import static android.bluetooth.BluetoothUtils.getSyncTimeout;
+import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -1742,8 +1743,19 @@ public final class BluetoothHeadsetClient implements BluetoothProfile, AutoClose
private final String mOperatorName;
/**
- * The general signal strength
- * (0 - Unknown, 1 - Poor, 2 - Fair, 3 - Good, 4 - Great, 5 - Excellent)
+ * The general signal strength, from 0 to 5.
+ *
+ * Bluetooth HFP v1.8 specifies that the signal strength of a device can be [0, 5]. It does
+ * place any requirements on how a device derives those values. While they're typically
+ * derived from signal quality/RSSI buckets, there's way to be certain on the exact meaning.
+ *
+ * That said, you can "generally" interpret the values relative to each other as follows:
+ * - Level 0: None/Unknown
+ * - Level 1: Very Poor
+ * - Level 2: Poor
+ * - Level 3: Fair
+ * - Level 4: Good
+ * - Level 5: Great
*/
private final int mSignalStrength;
@@ -1804,20 +1816,19 @@ public final class BluetoothHeadsetClient implements BluetoothProfile, AutoClose
* @hide
*/
@SystemApi
- public @Nullable String getOperatorName() {
+ public @Nullable String getNetworkOperatorName() {
return mOperatorName;
}
/**
* Get the network's general signal strength
*
- * @return The general signal strength (0 - None, 1 - Poor, 2 - Fair, 3 - Good,
- * 4 - Great, 5 - Excellent)
+ * @return The general signal strength, range [0, 5]
*
* @hide
*/
@SystemApi
- public int getSignalStrength() {
+ public @IntRange(from = 0, to = 5) int getSignalStrength() {
return mSignalStrength;
}
diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java
index 2db1d1afe5..23e9a039f4 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudio.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudio.java
@@ -966,9 +966,22 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
Log.d(TAG, "getCodecStatus(" + device + ")");
}
+ final IBluetoothLeAudio service = getService();
final BluetoothLeAudioCodecStatus defaultValue = null;
- // TODO: Add the implementation to get codec status
+ if (service == null) {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) log(Log.getStackTraceString(new Throwable()));
+ } else if (mAdapter.isEnabled() && isValidDevice(device)) {
+ try {
+ final SynchronousResultReceiver<BluetoothLeAudioCodecStatus> recv =
+ new SynchronousResultReceiver();
+ service.getCodecStatus(device, mAttributionSource, recv);
+ return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue);
+ } catch (RemoteException | TimeoutException e) {
+ Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
+ }
+ }
return defaultValue;
}
@@ -994,8 +1007,18 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable {
throw new IllegalArgumentException("codecConfig cannot be null");
}
- // TODO: Add the implementation to set config preference
- return;
+ final IBluetoothLeAudio service = getService();
+
+ if (service == null) {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) log(Log.getStackTraceString(new Throwable()));
+ } else if (mAdapter.isEnabled() && isValidDevice(device)) {
+ try {
+ service.setCodecConfigPreference(device, codecConfig, mAttributionSource);
+ } catch (RemoteException e) {
+ Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
+ }
+ }
}
}
diff --git a/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java b/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
index dea0642041..399ffa743c 100644
--- a/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
+++ b/framework/java/android/bluetooth/BluetoothLeAudioCodecStatus.java
@@ -109,8 +109,15 @@ public final class BluetoothLeAudioCodecStatus implements Parcelable {
* @return {@code true} if the codec config matches, {@code false} otherwise
*/
public boolean isCodecConfigSelectable(@Nullable BluetoothLeAudioCodecConfig codecConfig) {
- // TODO: Add the implementation to check the config is selectable
- return true;
+ if (codecConfig == null) {
+ return false;
+ }
+ for (BluetoothLeAudioCodecConfig selectableConfig : mCodecsSelectableCapabilities) {
+ if (codecConfig.equals(selectableConfig)) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -171,6 +178,8 @@ public final class BluetoothLeAudioCodecStatus implements Parcelable {
/**
* Returns the current codec configuration.
+ *
+ * @return The current codec config.
*/
public @Nullable BluetoothLeAudioCodecConfig getCodecConfig() {
return mCodecConfig;
@@ -178,6 +187,8 @@ public final class BluetoothLeAudioCodecStatus implements Parcelable {
/**
* Returns the codecs local capabilities.
+ *
+ * @return The list of codec config that supported by the local system.
*/
public @NonNull List<BluetoothLeAudioCodecConfig> getCodecLocalCapabilities() {
return (mCodecsLocalCapabilities == null)
@@ -186,6 +197,9 @@ public final class BluetoothLeAudioCodecStatus implements Parcelable {
/**
* Returns the codecs selectable capabilities.
+ *
+ * @return The list of codec config that supported by both of the local system and
+ * remote devices.
*/
public @NonNull List<BluetoothLeAudioCodecConfig> getCodecSelectableCapabilities() {
return (mCodecsSelectableCapabilities == null)