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

Commit d07589fc authored by Chaohui Wang's avatar Chaohui Wang Committed by Automerger Merge Worker
Browse files

Merge "[LE Audio] New logic to generate the QR code" into udc-dev am: 042b2105 am: 566bce01

parents 29799c88 566bce01
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
      "name": "SettingsLibUnitTests"
    },
    {
      "name": "SpaPrivilegedLibTests"
    },
    {
      "name": "SettingsSpaUnitTests"
    }
  ]
}
+1 −35
Original line number Diff line number Diff line
@@ -43,39 +43,5 @@ public final class BluetoothBroadcastUtils {
    /**
     * Bluetooth scheme.
     */
    public static final String SCHEME_BT_BROADCAST_METADATA = "BT:";

    // BluetoothLeBroadcastMetadata
    static final String PREFIX_BT_ADDRESS_TYPE = "T:";
    static final String PREFIX_BT_DEVICE = "D:";
    static final String PREFIX_BT_ADVERTISING_SID = "AS:";
    static final String PREFIX_BT_BROADCAST_ID = "B:";
    static final String PREFIX_BT_SYNC_INTERVAL = "SI:";
    static final String PREFIX_BT_IS_ENCRYPTED = "E:";
    static final String PREFIX_BT_BROADCAST_CODE = "C:";
    static final String PREFIX_BT_PRESENTATION_DELAY = "PD:";
    static final String PREFIX_BT_SUBGROUPS = "SG:";
    static final String PREFIX_BT_ANDROID_VERSION = "V:";

    // BluetoothLeBroadcastSubgroup
    static final String PREFIX_BTSG_CODEC_ID = "CID:";
    static final String PREFIX_BTSG_CODEC_CONFIG = "CC:";
    static final String PREFIX_BTSG_AUDIO_CONTENT = "AC:";
    static final String PREFIX_BTSG_CHANNEL_PREF = "CP:";
    static final String PREFIX_BTSG_BROADCAST_CHANNEL = "BC:";

    // BluetoothLeAudioCodecConfigMetadata
    static final String PREFIX_BTCC_AUDIO_LOCATION = "AL:";
    static final String PREFIX_BTCC_RAW_METADATA = "CCRM:";

    // BluetoothLeAudioContentMetadata
    static final String PREFIX_BTAC_PROGRAM_INFO = "PI:";
    static final String PREFIX_BTAC_LANGUAGE = "L:";
    static final String PREFIX_BTAC_RAW_METADATA = "ACRM:";

    // BluetoothLeBroadcastChannel
    static final String PREFIX_BTBC_CHANNEL_INDEX = "CI:";
    static final String PREFIX_BTBC_CODEC_CONFIG = "BCCM:";

    static final String DELIMITER_QR_CODE = ";";
    public static final String SCHEME_BT_BROADCAST_METADATA = "BT:BluetoothLeBroadcastMetadata:";
}
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settingslib.bluetooth

import android.bluetooth.BluetoothLeBroadcastMetadata
import android.os.Parcel
import android.os.Parcelable
import android.util.Base64
import android.util.Log
import com.android.settingslib.bluetooth.BluetoothBroadcastUtils.SCHEME_BT_BROADCAST_METADATA

object BluetoothLeBroadcastMetadataExt {
    private const val TAG = "BluetoothLeBroadcastMetadataExt"

    /**
     * Converts [BluetoothLeBroadcastMetadata] to QR code string.
     *
     * QR code string will prefix with "BT:BluetoothLeBroadcastMetadata:".
     */
    fun BluetoothLeBroadcastMetadata.toQrCodeString(): String =
        SCHEME_BT_BROADCAST_METADATA + Base64.encodeToString(toBytes(this), Base64.NO_WRAP)

    /**
     * Converts QR code string to [BluetoothLeBroadcastMetadata].
     *
     * QR code string should prefix with "BT:BluetoothLeBroadcastMetadata:".
     */
    fun convertToBroadcastMetadata(qrCodeString: String): BluetoothLeBroadcastMetadata? {
        if (!qrCodeString.startsWith(SCHEME_BT_BROADCAST_METADATA)) return null
        return try {
            val encodedString = qrCodeString.removePrefix(SCHEME_BT_BROADCAST_METADATA)
            val bytes = Base64.decode(encodedString, Base64.NO_WRAP)
            createFromBytes(BluetoothLeBroadcastMetadata.CREATOR, bytes)
        } catch (e: Exception) {
            Log.w(TAG, "Cannot convert QR code string to BluetoothLeBroadcastMetadata", e)
            null
        }
    }

    private fun toBytes(parcelable: Parcelable): ByteArray =
        Parcel.obtain().run {
            parcelable.writeToParcel(this, 0)
            setDataPosition(0)
            val bytes = marshall()
            recycle()
            bytes
        }

    private fun <T> createFromBytes(creator: Parcelable.Creator<T>, bytes: ByteArray): T =
        Parcel.obtain().run {
            unmarshall(bytes, 0, bytes.size)
            setDataPosition(0)
            val created = creator.createFromParcel(this)
            recycle()
            created
        }
}
 No newline at end of file
+0 −454

File deleted.

Preview size limit exceeded, changes collapsed.

+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settingslib.bluetooth

import android.bluetooth.BluetoothLeBroadcastMetadata
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt.toQrCodeString

@Deprecated("Replace with BluetoothLeBroadcastMetadataExt")
class LocalBluetoothLeBroadcastMetadata(private val metadata: BluetoothLeBroadcastMetadata?) {

    constructor() : this(null)

    fun convertToQrCodeString(): String = metadata?.toQrCodeString() ?: ""

    fun convertToBroadcastMetadata(qrCodeString: String) =
        BluetoothLeBroadcastMetadataExt.convertToBroadcastMetadata(qrCodeString)
}
 No newline at end of file
Loading