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

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

Merge "Keep program info consistent with broadcast name if null." into main

parents bfa8c2ef 5b962be3
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);