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

Commit 2bae10e8 authored by William Escande's avatar William Escande
Browse files

Metadata: Add builder

Test: Build test only as this is no - op change. Same test are passing
Test: m Bluetooth
Bug: 290553699
Change-Id: Ia8efdcb0bd34bcdc1aa9b23050be52ee5af6f7ed
parent 40bf9f85
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -723,7 +723,6 @@ public class DatabaseManager {
                    mostRecentLastActiveTime = metadata.last_active_time;
                    mostRecentDevice = device;
                }

            }
        }
        return mostRecentDevice;
@@ -776,20 +775,20 @@ public class DatabaseManager {
    }

    /**
     * Sets the preferred profile for the supplied audio modes. See
     * {@link BluetoothAdapter#setPreferredAudioProfiles(BluetoothDevice, Bundle)} for more details.
     * Sets the preferred profile for the supplied audio modes. See {@link
     * BluetoothAdapter#setPreferredAudioProfiles(BluetoothDevice, Bundle)} for more details.
     *
     * If a device in the group has been designated to store the preference for the group, this will
     * update its database preferences. If there is not one designated, the first device from the
     * group list will be chosen for this purpose. From then on, any preferred audio profile changes
     * for this group will be stored on that device.
     * <p>If a device in the group has been designated to store the preference for the group, this
     * will update its database preferences. If there is not one designated, the first device from
     * the group list will be chosen for this purpose. From then on, any preferred audio profile
     * changes for this group will be stored on that device.
     *
     * @param groupDevices is the CSIP group for which we are setting the preferred audio profiles
     * @param modeToProfileBundle contains the preferred profile
     * @return whether the new preferences were saved in the database
     */
    public int setPreferredAudioProfiles(List<BluetoothDevice> groupDevices,
            Bundle modeToProfileBundle) {
    public int setPreferredAudioProfiles(
            List<BluetoothDevice> groupDevices, Bundle modeToProfileBundle) {
        Objects.requireNonNull(groupDevices, "groupDevices must not be null");
        Objects.requireNonNull(modeToProfileBundle, "modeToProfileBundle must not be null");
        if (groupDevices.isEmpty()) {
@@ -894,8 +893,8 @@ public class DatabaseManager {

            Bundle modeToProfileBundle = new Bundle();
            if (outputOnlyProfile != 0) {
                modeToProfileBundle.putInt(BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY,
                        outputOnlyProfile);
                modeToProfileBundle.putInt(
                        BluetoothAdapter.AUDIO_MODE_OUTPUT_ONLY, outputOnlyProfile);
            }
            if (duplexProfile != 0) {
                modeToProfileBundle.putInt(BluetoothAdapter.AUDIO_MODE_DUPLEX, duplexProfile);
@@ -982,8 +981,13 @@ public class DatabaseManager {
    }

    void createMetadata(String address, boolean isActiveA2dpDevice) {
        Metadata data = new Metadata(address);
        data.is_active_a2dp_device = isActiveA2dpDevice;
        Metadata.Builder dataBuilder = new Metadata.Builder(address);

        if (isActiveA2dpDevice) {
            dataBuilder.setActiveA2dp();
        }

        Metadata data = dataBuilder.build();
        mMetadataCache.put(address, data);
        updateDatabase(data);
        logMetadataChange(data, "Metadata created");
+23 −1
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ public class Metadata {
    public int preferred_duplex_profile;

    Metadata(String address) {
        this(address, false);
    }

    private Metadata(String address, boolean isActiveA2dp) {
        this.address = address;
        migrated = false;
        profileConnectionPolicies = new ProfilePrioritiesEntity();
@@ -85,12 +89,30 @@ public class Metadata {
        a2dpSupportsOptionalCodecs = BluetoothA2dp.OPTIONAL_CODECS_SUPPORT_UNKNOWN;
        a2dpOptionalCodecsEnabled = BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN;
        last_active_time = MetadataDatabase.sCurrentConnectionNumber++;
        is_active_a2dp_device = true;
        is_active_a2dp_device = isActiveA2dp;
        audioPolicyMetadata = new AudioPolicyEntity();
        preferred_output_only_profile = 0;
        preferred_duplex_profile = 0;
    }

    static final class Builder {
        final String mAddress;
        boolean mIsActiveA2dpDevice = false;

        Builder(String address) {
            mAddress = address;
        }

        Builder setActiveA2dp() {
            mIsActiveA2dpDevice = true;
            return this;
        }

        Metadata build() {
            return new Metadata(mAddress, mIsActiveA2dpDevice);
        }
    }

    /**
     * @hide
     */