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

Commit 0d58e64f authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge changes from topic "bn" into main

* changes:
  [Audiosharing] Support update broadcastName.
  [Audiosharing] Save broadcast name in SettingsProvider.
parents 31c17e40 b0ffb800
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7439,6 +7439,12 @@ public final class Settings {
        public static final String BLUETOOTH_LE_BROADCAST_PROGRAM_INFO =
                "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
+73 −3
Original line number Diff line number Diff line
@@ -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);
+1 −0
Original line number Diff line number Diff line
@@ -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,
+1 −0
Original line number Diff line number Diff line
@@ -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(