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

Commit 7f1e7803 authored by Sal Savage's avatar Sal Savage
Browse files

Safely clean up the cover art manager

This patch changes 3 things:
(1) Cover art is assumed false until read true
(2) We no longer clean up the CA manager if the feature isn't
enabled. This will keep us from having NPEs since an enabled feature on
start always translates to an object. Plus, since its defaulted to off,
this makes calling stop() before start() safe for cover art.
(3) The stop and start functions are now synchronized so there are no
race conditions inviting rare errors.

Bug: b/154132155
Test: Build, flash, interop test with AVRCP target device
Change-Id: I5a3733160424bd71a40ceb85d685e2e5e8414f99
parent d4220355
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class AvrcpControllerService extends ProfileService {
    protected Map<BluetoothDevice, AvrcpControllerStateMachine> mDeviceStateMap =
            new ConcurrentHashMap<>(1);

    private boolean mCoverArtEnabled;
    private boolean mCoverArtEnabled = false;
    protected AvrcpCoverArtManager mCoverArtManager;

    private class ImageDownloadCallback implements AvrcpCoverArtManager.Callback {
@@ -127,7 +127,7 @@ public class AvrcpControllerService extends ProfileService {
    }

    @Override
    protected boolean start() {
    protected synchronized boolean start() {
        initNative();
        mCoverArtEnabled = getResources().getBoolean(R.bool.avrcp_controller_enable_cover_art);
        if (mCoverArtEnabled) {
@@ -143,7 +143,7 @@ public class AvrcpControllerService extends ProfileService {
    }

    @Override
    protected boolean stop() {
    protected synchronized boolean stop() {
        Intent stopIntent = new Intent(this, BluetoothMediaBrowserService.class);
        stopService(stopIntent);
        for (AvrcpControllerStateMachine stateMachine : mDeviceStateMap.values()) {
@@ -152,8 +152,10 @@ public class AvrcpControllerService extends ProfileService {

        sService = null;
        sBrowseTree = null;
        if (mCoverArtManager != null) {
            mCoverArtManager.cleanup();
            mCoverArtManager = null;
        }
        return true;
    }