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

Commit 5b962be3 authored by chelseahao's avatar chelseahao
Browse files

Keep program info consistent with broadcast name if null.

Flag: EXEMPT bug fix
Test: atest
Bug: 308368124
Change-Id: Ia4e8098202613bd70cda6fc116e04e12bb71695f
parent c10e66c9
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -806,14 +806,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
            Log.d(TAG, "updateBroadcastInfoFromContentProvider: mContentResolver is null");
            return;
        }
        String programInfo =
                Settings.Secure.getString(
                        mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO);
        if (programInfo == null) {
            programInfo = getDefaultValueOfProgramInfo();
        }
        setProgramInfo(programInfo, /* updateContentResolver= */ false);

        String broadcastName =
                Settings.Secure.getString(
                        mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_NAME);
@@ -822,6 +814,14 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
        }
        setBroadcastName(broadcastName, /* updateContentResolver= */ false);

        String programInfo =
                Settings.Secure.getString(
                        mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO);
        if (programInfo == null) {
            programInfo = broadcastName;
        }
        setProgramInfo(programInfo, /* updateContentResolver= */ false);

        String prefBroadcastCode =
                Settings.Secure.getString(
                        mContentResolver, Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE);
@@ -1143,17 +1143,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile {
                BROADCAST_NAME_PREFIX_MAX_LENGTH)) + UNDERLINE + postfix;
    }

    private String getDefaultValueOfProgramInfo() {
        // set the default value;
        int postfix = ThreadLocalRandom.current().nextInt(DEFAULT_CODE_MIN, DEFAULT_CODE_MAX);
        String name = BluetoothAdapter.getDefaultAdapter().getName();
        if (name == null || name.isEmpty()) {
            name = DEFAULT_BROADCAST_NAME_PREFIX;
        }
        return (name.length() < BROADCAST_NAME_PREFIX_MAX_LENGTH ? name : name.substring(0,
                BROADCAST_NAME_PREFIX_MAX_LENGTH)) + UNDERLINE + postfix;
    }

    private byte[] getDefaultValueOfBroadcastCode() {
        // set the default value;
        return generateRandomPassword().getBytes(StandardCharsets.UTF_8);