summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chelsea Hao <chelseahao@google.com> 2024-05-23 08:07:51 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-05-23 08:07:51 +0000
commit0d58e64f831623cbb340fcaae5616d3576b8271c (patch)
tree9c98cf0b2ef58965f3e6436165ae467ab856d3c4
parent31c17e402c84b24a5c138dc69f02f64dfb6f9054 (diff)
parentb0ffb8003313595f3de48303742264beed1ee8ee (diff)
Merge changes from topic "bn" into main
* changes: [Audiosharing] Support update broadcastName. [Audiosharing] Save broadcast name in SettingsProvider.
-rw-r--r--core/java/android/provider/Settings.java6
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java76
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java1
-rw-r--r--packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java1
4 files changed, 81 insertions, 3 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 3738c266641b..a409537a57d5 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -7440,6 +7440,12 @@ public final class Settings {
"bluetooth_le_broadcast_program_info";
/**
+ * This is used by LocalBluetoothLeBroadcast to store the broadcast name.
+ * @hide
+ */
+ public static final String BLUETOOTH_LE_BROADCAST_NAME = "bluetooth_le_broadcast_name";
+
+ /**
* This is used by LocalBluetoothLeBroadcast to store the broadcast code.
* @hide
*/
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
index a6b1dd3ae578..27fcdbe0334f 100644
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java
@@ -103,6 +103,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
private static final int UNKNOWN_VALUE_PLACEHOLDER = -1;
private static final Uri[] SETTINGS_URIS =
new Uri[] {
+ Settings.Secure.getUriFor(Settings.Secure.BLUETOOTH_LE_BROADCAST_NAME),
Settings.Secure.getUriFor(Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO),
Settings.Secure.getUriFor(Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE),
Settings.Secure.getUriFor(Settings.Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME),
@@ -123,6 +124,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
private boolean mIsBroadcastAssistantProfileReady = false;
private boolean mImproveCompatibility = false;
private String mProgramInfo;
+ private String mBroadcastName;
private byte[] mBroadcastCode;
private Executor mExecutor;
private ContentResolver mContentResolver;
@@ -456,6 +458,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
Log.d(TAG, "Skip starting the broadcast due to number limit.");
return;
}
+ String broadcastName = getBroadcastName();
String programInfo = getProgramInfo();
boolean improveCompatibility = getImproveCompatibility();
if (DEBUG) {
@@ -463,6 +466,8 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
TAG,
"startBroadcast: language = null , programInfo = "
+ programInfo
+ + ", broadcastName = "
+ + broadcastName
+ ", improveCompatibility = "
+ improveCompatibility);
}
@@ -473,7 +478,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
BluetoothLeBroadcastSettings settings =
buildBroadcastSettings(
true, // TODO: set to false after framework fix
- TextUtils.isEmpty(programInfo) ? null : programInfo,
+ TextUtils.isEmpty(broadcastName) ? null : broadcastName,
(mBroadcastCode != null && mBroadcastCode.length > 0)
? mBroadcastCode
: null,
@@ -556,6 +561,36 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
}
}
+ public String getBroadcastName() {
+ return mBroadcastName;
+ }
+
+ /** Set broadcast name. */
+ public void setBroadcastName(String broadcastName) {
+ setBroadcastName(broadcastName, /* updateContentResolver= */ true);
+ }
+
+ private void setBroadcastName(String broadcastName, boolean updateContentResolver) {
+ if (TextUtils.isEmpty(broadcastName)) {
+ Log.d(TAG, "setBroadcastName: broadcastName is null or empty");
+ return;
+ }
+ if (mBroadcastName != null && TextUtils.equals(mBroadcastName, broadcastName)) {
+ Log.d(TAG, "setBroadcastName: broadcastName is not changed");
+ return;
+ }
+ Log.d(TAG, "setBroadcastName: " + broadcastName);
+ mBroadcastName = broadcastName;
+ if (updateContentResolver) {
+ if (mContentResolver == null) {
+ Log.d(TAG, "mContentResolver is null");
+ return;
+ }
+ Settings.Secure.putString(
+ mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_NAME, broadcastName);
+ }
+ }
+
public byte[] getBroadcastCode() {
return mBroadcastCode;
}
@@ -690,6 +725,14 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
}
setProgramInfo(programInfo, /* updateContentResolver= */ false);
+ String broadcastName =
+ Settings.Secure.getString(
+ mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_NAME);
+ if (broadcastName == null) {
+ broadcastName = getDefaultValueOfBroadcastName();
+ }
+ setBroadcastName(broadcastName, /* updateContentResolver= */ false);
+
String prefBroadcastCode =
Settings.Secure.getString(
mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE);
@@ -719,6 +762,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
Log.d(TAG, "The bluetoothLeBroadcastMetadata is null");
return;
}
+ setBroadcastName(bluetoothLeBroadcastMetadata.getBroadcastName());
setBroadcastCode(bluetoothLeBroadcastMetadata.getBroadcastCode());
setLatestBroadcastId(bluetoothLeBroadcastMetadata.getBroadcastId());
@@ -777,7 +821,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
/**
* Update the LE Broadcast by calling {@link BluetoothLeBroadcast#updateBroadcast(int,
- * BluetoothLeAudioContentMetadata)}, currently only updates programInfo.
+ * BluetoothLeBroadcastSettings)}, currently only updates broadcast name and program info.
*/
public void updateBroadcast() {
if (mServiceBroadcast == null) {
@@ -785,8 +829,28 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
return;
}
String programInfo = getProgramInfo();
+ String broadcastName = getBroadcastName();
mBluetoothLeAudioContentMetadata = mBuilder.setProgramInfo(programInfo).build();
- mServiceBroadcast.updateBroadcast(mBroadcastId, mBluetoothLeAudioContentMetadata);
+ // LeAudioService#updateBroadcast doesn't update broadcastCode, isPublicBroadcast and
+ // preferredQuality, so we leave them unset here.
+ // TODO: maybe setPublicBroadcastMetadata
+ BluetoothLeBroadcastSettings settings =
+ new BluetoothLeBroadcastSettings.Builder()
+ .setBroadcastName(broadcastName)
+ .addSubgroupSettings(
+ new BluetoothLeBroadcastSubgroupSettings.Builder()
+ .setContentMetadata(mBluetoothLeAudioContentMetadata)
+ .build())
+ .build();
+ if (DEBUG) {
+ Log.d(
+ TAG,
+ "updateBroadcast: broadcastName = "
+ + broadcastName
+ + " programInfo = "
+ + programInfo);
+ }
+ mServiceBroadcast.updateBroadcast(mBroadcastId, settings);
}
/**
@@ -985,6 +1049,12 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
}
}
+ private String getDefaultValueOfBroadcastName() {
+ // set the default value;
+ int postfix = ThreadLocalRandom.current().nextInt(DEFAULT_CODE_MIN, DEFAULT_CODE_MAX);
+ return BluetoothAdapter.getDefaultAdapter().getName() + UNDERLINE + postfix;
+ }
+
private String getDefaultValueOfProgramInfo() {
// set the default value;
int postfix = ThreadLocalRandom.current().nextInt(DEFAULT_CODE_MIN, DEFAULT_CODE_MAX);
diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
index 888e39593a2e..9f2ab69acd31 100644
--- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
+++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java
@@ -243,6 +243,7 @@ public class SecureSettings {
Settings.Secure.ASSIST_TOUCH_GESTURE_ENABLED,
Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED,
Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO,
+ Settings.Secure.BLUETOOTH_LE_BROADCAST_NAME,
Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE,
Settings.Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME,
Settings.Secure.BLUETOOTH_LE_BROADCAST_IMPROVE_COMPATIBILITY,
diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
index b992ddc8a397..cb7ac457d991 100644
--- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
+++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java
@@ -393,6 +393,7 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.WEAR_TALKBACK_ENABLED, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.HBM_SETTING_KEY, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO, ANY_STRING_VALIDATOR);
+ VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_NAME, ANY_STRING_VALIDATOR);
VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_CODE, ANY_STRING_VALIDATOR);
VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME, ANY_STRING_VALIDATOR);
VALIDATORS.put(