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

Commit 50777273 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5470312 from 9bc4eea9 to qt-release

Change-Id: I234c9fe8a5ae1a62bb863ccc10dd22575bba37a2
parents 37c3fec8 9bc4eea9
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -110,6 +112,24 @@ public final class Utils {
        return sb.toString();
    }

    /**
     * A parser to transfer a byte array to a UTF8 string
     *
     * @param valueBuf the byte array to transfer
     * @return the transferred UTF8 string
     */
    public static String byteArrayToUtf8String(byte[] valueBuf) {
        CharsetDecoder decoder = Charset.forName("UTF8").newDecoder();
        ByteBuffer byteBuffer = ByteBuffer.wrap(valueBuf);
        String valueStr = "";
        try {
            valueStr = decoder.decode(byteBuffer).toString();
        } catch (Exception ex) {
            Log.e(TAG, "Error when parsing byte array to UTF8 String. " + ex);
        }
        return valueStr;
    }

    public static byte[] intToByteArray(int value) {
        ByteBuffer converter = ByteBuffer.allocate(4);
        converter.order(ByteOrder.nativeOrder());
+7 −7
Original line number Diff line number Diff line
@@ -1694,7 +1694,7 @@ public class AdapterService extends Service {
        }

        @Override
        public boolean setMetadata(BluetoothDevice device, int key, String value) {
        public boolean setMetadata(BluetoothDevice device, int key, byte[] value) {
            AdapterService service = getService();
            if (service == null) {
                return false;
@@ -1703,7 +1703,7 @@ public class AdapterService extends Service {
        }

        @Override
        public String getMetadata(BluetoothDevice device, int key) {
        public byte[] getMetadata(BluetoothDevice device, int key) {
            AdapterService service = getService();
            if (service == null) {
                return null;
@@ -2718,15 +2718,15 @@ public class AdapterService extends Service {
        return true;
    }

    boolean setMetadata(BluetoothDevice device, int key, String value) {
        if (value.length() > BluetoothDevice.METADATA_MAX_LENGTH) {
            Log.e(TAG, "setMetadata: value length too long " + value.length());
    boolean setMetadata(BluetoothDevice device, int key, byte[] value) {
        if (value.length > BluetoothDevice.METADATA_MAX_LENGTH) {
            Log.e(TAG, "setMetadata: value length too long " + value.length);
            return false;
        }
        return mDatabaseManager.setCustomMeta(device, key, value);
    }

    String getMetadata(BluetoothDevice device, int key) {
    byte[] getMetadata(BluetoothDevice device, int key) {
        return mDatabaseManager.getCustomMeta(device, key);
    }

@@ -2734,7 +2734,7 @@ public class AdapterService extends Service {
     * Update metadata change to registered listeners
     */
    @VisibleForTesting
    public void metadataChanged(String address, int key, String value) {
    public void metadataChanged(String address, int key, byte[] value) {
        BluetoothDevice device = mRemoteDevices.getDevice(Utils.getBytesFromAddress(address));
        if (mMetadataListeners.containsKey(device)) {
            ArrayList<IBluetoothMetadataListener> list = mMetadataListeners.get(device);
+2 −2
Original line number Diff line number Diff line
@@ -395,9 +395,9 @@ final class BondStateMachine extends StateMachine {
                mAdapterService.obfuscateAddress(device), classOfDevice);
        mAdapterProperties.onBondStateChanged(device, newState);

        if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC
        if (devProp != null && ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC
                || devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_DUAL)
                && newState == BluetoothDevice.BOND_BONDED && devProp.getUuids() == null) {
                && newState == BluetoothDevice.BOND_BONDED && devProp.getUuids() == null)) {
            infoLog(device + " is bonded, wait for SDP complete to broadcast bonded intent");
            if (!mPendingBondedDevices.contains(device)) {
                mPendingBondedDevices.add(device);
+17 −17
Original line number Diff line number Diff line
@@ -20,21 +20,21 @@ import androidx.room.Entity;

@Entity
class CustomizedMetadataEntity {
    public String manufacturer_name;
    public String model_name;
    public String software_version;
    public String hardware_version;
    public String companion_app;
    public String main_icon;
    public String is_unthethered_headset;
    public String unthethered_left_icon;
    public String unthethered_right_icon;
    public String unthethered_case_icon;
    public String unthethered_left_battery;
    public String unthethered_right_battery;
    public String unthethered_case_battery;
    public String unthethered_left_charging;
    public String unthethered_right_charging;
    public String unthethered_case_charging;
    public String enhanced_settings_ui_uri;
    public byte[] manufacturer_name;
    public byte[] model_name;
    public byte[] software_version;
    public byte[] hardware_version;
    public byte[] companion_app;
    public byte[] main_icon;
    public byte[] is_untethered_headset;
    public byte[] untethered_left_icon;
    public byte[] untethered_right_icon;
    public byte[] untethered_case_icon;
    public byte[] untethered_left_battery;
    public byte[] untethered_right_battery;
    public byte[] untethered_case_battery;
    public byte[] untethered_left_charging;
    public byte[] untethered_right_charging;
    public byte[] untethered_case_charging;
    public byte[] enhanced_settings_ui_uri;
}
+18 −17
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.provider.Settings;
import android.util.Log;
import android.util.StatsLog;

import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.VisibleForTesting;

@@ -184,16 +185,16 @@ public class DatabaseManager {
            case BluetoothDevice.METADATA_HARDWARE_VERSION:
            case BluetoothDevice.METADATA_COMPANION_APP:
            case BluetoothDevice.METADATA_MAIN_ICON:
            case BluetoothDevice.METADATA_IS_UNTHETHERED_HEADSET:
            case BluetoothDevice.METADATA_UNTHETHERED_LEFT_ICON:
            case BluetoothDevice.METADATA_UNTHETHERED_RIGHT_ICON:
            case BluetoothDevice.METADATA_UNTHETHERED_CASE_ICON:
            case BluetoothDevice.METADATA_UNTHETHERED_LEFT_BATTERY:
            case BluetoothDevice.METADATA_UNTHETHERED_RIGHT_BATTERY:
            case BluetoothDevice.METADATA_UNTHETHERED_CASE_BATTERY:
            case BluetoothDevice.METADATA_UNTHETHERED_LEFT_CHARGING:
            case BluetoothDevice.METADATA_UNTHETHERED_RIGHT_CHARGING:
            case BluetoothDevice.METADATA_UNTHETHERED_CASE_CHARGING:
            case BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET:
            case BluetoothDevice.METADATA_UNTETHERED_LEFT_ICON:
            case BluetoothDevice.METADATA_UNTETHERED_RIGHT_ICON:
            case BluetoothDevice.METADATA_UNTETHERED_CASE_ICON:
            case BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY:
            case BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY:
            case BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY:
            case BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING:
            case BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING:
            case BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING:
            case BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI:
                return true;
        }
@@ -205,7 +206,7 @@ public class DatabaseManager {
     * Set customized metadata to database with requested key
     */
    @VisibleForTesting
    public boolean setCustomMeta(BluetoothDevice device, int key, String newValue) {
    public boolean setCustomMeta(BluetoothDevice device, int key, byte[] newValue) {
        synchronized (mMetadataCache) {
            if (device == null) {
                Log.e(TAG, "setCustomMeta: device is null");
@@ -224,8 +225,8 @@ public class DatabaseManager {
                createMetadata(address);
            }
            Metadata data = mMetadataCache.get(address);
            String oldValue = data.getCustomizedMeta(key);
            if (oldValue != null && oldValue.equals(newValue)) {
            byte[] oldValue = data.getCustomizedMeta(key);
            if (oldValue != null && Arrays.equals(oldValue, newValue)) {
                if (VERBOSE) {
                    Log.d(TAG, "setCustomMeta: metadata not changed.");
                }
@@ -244,7 +245,7 @@ public class DatabaseManager {
     * Get customized metadata from database with requested key
     */
    @VisibleForTesting
    public String getCustomMeta(BluetoothDevice device, int key) {
    public byte[] getCustomMeta(BluetoothDevice device, int key) {
        synchronized (mMetadataCache) {
            if (device == null) {
                Log.e(TAG, "getCustomMeta: device is null");
@@ -263,8 +264,7 @@ public class DatabaseManager {
            }

            Metadata data = mMetadataCache.get(address);
            String value = data.getCustomizedMeta(key);
            return value;
            return data.getCustomizedMeta(key);
        }
    }

@@ -763,13 +763,14 @@ public class DatabaseManager {
        mHandler.sendMessage(message);
    }

    private void logManufacturerInfo(BluetoothDevice device, int key, String value) {
    private void logManufacturerInfo(BluetoothDevice device, int key, byte[] bytesValue) {
        String callingApp = mAdapterService.getPackageManager().getNameForUid(
                Binder.getCallingUid());
        String manufacturerName = "";
        String modelName = "";
        String hardwareVersion = "";
        String softwareVersion = "";
        String value = Utils.byteArrayToUtf8String(bytesValue);
        switch (key) {
            case BluetoothDevice.METADATA_MANUFACTURER_NAME:
                manufacturerName = value;
Loading