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

Commit 5e4d1446 authored by Bill Rassieur's avatar Bill Rassieur
Browse files

Merge master@5406228 into git_qt-dev-plus-aosp.

Change-Id: I1d85bdd66c2fa1a495a4e09f6d6ddd00d15da0a5
BUG: 129345239
parents ac72fb09 c9240e92
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@
    <string name="bt_share_picker_label" msgid="6268100924487046932">"Bluetooth"</string>
    <string name="unknown_device" msgid="9221903979877041009">"Անհայտ սարք"</string>
    <string name="unknownNumber" msgid="4994750948072751566">"Անհայտ"</string>
    <string name="airplane_error_title" msgid="2683839635115739939">"Ինքնաթիռի ռեժիմ"</string>
    <string name="airplane_error_msg" msgid="8698965595254137230">"Դուք չեք կարող օգտվել Bluetooth-ից Ինքնաթիռի ռեժիմում:"</string>
    <string name="airplane_error_title" msgid="2683839635115739939">"Ավիառեժիմ"</string>
    <string name="airplane_error_msg" msgid="8698965595254137230">"Դուք չեք կարող օգտվել Bluetooth-ից Ավիառեժիմում:"</string>
    <string name="bt_enable_title" msgid="8657832550503456572"></string>
    <string name="bt_enable_line1" msgid="7203551583048149">"Bluetooth ծառայություններից օգտվելու համար նախ պետք է միացնեք Bluetooth-ը:"</string>
    <string name="bt_enable_line2" msgid="4341936569415937994">"Միացնե՞լ Bluetooth-ը հիմա:"</string>
+25 −23
Original line number Diff line number Diff line
@@ -34,10 +34,10 @@ import android.util.StatsLog;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
import com.android.bluetooth.avrcp.AvrcpTargetService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

@@ -62,6 +62,8 @@ public class A2dpService extends ProfileService {

    @VisibleForTesting
    A2dpNativeInterface mA2dpNativeInterface;
    @VisibleForTesting
    ServiceFactory mFactory = new ServiceFactory();
    private AudioManager mAudioManager;
    private A2dpCodecConfig mA2dpCodecConfig;

@@ -156,11 +158,6 @@ public class A2dpService extends ProfileService {
            return true;
        }

        // Step 10: Store volume if there is an active device
        if (mActiveDevice != null && AvrcpTargetService.get() != null) {
            AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice);
        }

        // Step 9: Clear active device and stop playing audio
        removeActiveDevice(true);

@@ -430,9 +427,19 @@ public class A2dpService extends ProfileService {
        }
    }

    private void storeActiveDeviceVolume() {
        // Make sure volume has been stored before been removed from active.
        if (mFactory.getAvrcpTargetService() != null && mActiveDevice != null) {
            mFactory.getAvrcpTargetService().storeVolumeForDevice(mActiveDevice);
        }
    }

    private void removeActiveDevice(boolean forceStopPlayingAudio) {
        BluetoothDevice previousActiveDevice = mActiveDevice;
        synchronized (mStateMachines) {
            // Make sure volume has been store before device been remove from active.
            storeActiveDeviceVolume();

            // This needs to happen before we inform the audio manager that the device
            // disconnected. Please see comment in updateAndBroadcastActiveDevice() for why.
            updateAndBroadcastActiveDevice(null);
@@ -474,9 +481,6 @@ public class A2dpService extends ProfileService {
            Log.d(TAG, "setSilenceMode(" + device + "): " + silence);
        }
        if (silence && Objects.equals(mActiveDevice, device)) {
            if (mActiveDevice != null && AvrcpTargetService.get() != null) {
                AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice);
            }
            removeActiveDevice(true);
        } else if (!silence && mActiveDevice == null) {
            // Set the device as the active device if currently no active device.
@@ -497,13 +501,11 @@ public class A2dpService extends ProfileService {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");

        synchronized (mStateMachines) {
            if ((mActiveDevice != null) && (AvrcpTargetService.get() != null)) {
            // Switch active device from A2DP to Hearing Aids.
            if (DBG) {
                Log.d(TAG, "earlyNotifyHearingAidActive: Save volume for " + mActiveDevice);
            }
                AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice);
            }
            storeActiveDeviceVolume();
        }
    }

@@ -546,12 +548,12 @@ public class A2dpService extends ProfileService {
            codecStatus = sm.getCodecStatus();

            boolean deviceChanged = !Objects.equals(device, mActiveDevice);
            if ((AvrcpTargetService.get() != null) && (mActiveDevice != null) && deviceChanged) {
            if (deviceChanged) {
                // Switch from one A2DP to another A2DP device
                if (DBG) {
                    Log.d(TAG, "Switch A2DP devices to " + device + " from " + mActiveDevice);
                }
                AvrcpTargetService.get().storeVolumeForDevice(mActiveDevice);
                storeActiveDeviceVolume();
            }

            // This needs to happen before we inform the audio manager that the device
@@ -578,8 +580,8 @@ public class A2dpService extends ProfileService {
                }

                int rememberedVolume = -1;
                if (AvrcpTargetService.get() != null) {
                    rememberedVolume = AvrcpTargetService.get()
                if (mFactory.getAvrcpTargetService() != null) {
                    rememberedVolume = mFactory.getAvrcpTargetService()
                            .getRememberedVolumeForDevice(mActiveDevice);
                }

@@ -643,8 +645,8 @@ public class A2dpService extends ProfileService {
    public void setAvrcpAbsoluteVolume(int volume) {
        // TODO (apanicke): Instead of using A2DP as a middleman for volume changes, add a binder
        // service to the new AVRCP Profile and have the audio manager use that instead.
        if (AvrcpTargetService.get() != null) {
            AvrcpTargetService.get().sendVolumeChanged(volume);
        if (mFactory.getAvrcpTargetService() != null) {
            mFactory.getAvrcpTargetService().sendVolumeChanged(volume);
            return;
        }
    }
@@ -923,8 +925,8 @@ public class A2dpService extends ProfileService {
        }

        synchronized (mStateMachines) {
            if (AvrcpTargetService.get() != null) {
                AvrcpTargetService.get().volumeDeviceSwitched(device);
            if (mFactory.getAvrcpTargetService() != null) {
                mFactory.getAvrcpTargetService().volumeDeviceSwitched(device);
            }

            mActiveDevice = device;
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.bluetooth.btservice;

import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.avrcp.AvrcpTargetService;
import com.android.bluetooth.hearingaid.HearingAidService;
import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.hid.HidDeviceService;
@@ -48,4 +49,8 @@ public class ServiceFactory {
    public HearingAidService getHearingAidService() {
        return HearingAidService.getHearingAidService();
    }

    public AvrcpTargetService getAvrcpTargetService() {
        return AvrcpTargetService.get();
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -89,7 +89,15 @@ public class DatabaseManager {
            switch (msg.what) {
                case MSG_LOAD_DATABASE: {
                    synchronized (mDatabase) {
                        List<Metadata> list = mDatabase.load();
                        List<Metadata> list;
                        try {
                            list = mDatabase.load();
                        } catch (IllegalStateException e) {
                            Log.e(TAG, "Unable to open database: " + e);
                            mDatabase = MetadataDatabase
                                    .createDatabaseWithoutMigration(mAdapterService);
                            list = mDatabase.load();
                        }
                        cacheMetadata(list);
                    }
                    break;
+15 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public abstract class MetadataDatabase extends RoomDatabase {
    protected abstract MetadataDao mMetadataDao();

    /**
     * Create a {@link MetadataDatabase} database
     * Create a {@link MetadataDatabase} database with migrations
     *
     * @param context the Context to create database
     * @return the created {@link MetadataDatabase}
@@ -51,6 +51,20 @@ public abstract class MetadataDatabase extends RoomDatabase {
                .build();
    }

    /**
     * Create a {@link MetadataDatabase} database without migration, database
     * would be reset if any load failure happens
     *
     * @param context the Context to create database
     * @return the created {@link MetadataDatabase}
     */
    public static MetadataDatabase createDatabaseWithoutMigration(Context context) {
        return Room.databaseBuilder(context,
                MetadataDatabase.class, DATABASE_NAME)
                .fallbackToDestructiveMigration()
                .build();
    }

    /**
     * Insert a {@link Metadata} to database
     *
Loading