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

Commit acc8f915 authored by Ajay Panicker's avatar Ajay Panicker
Browse files

Init the AVRCP Target Service before user unlock

A2DP was trying to use the AVRCP service before it was initialized since
A2DP is started at boot. Now both profiles will be started at boot.

Bug: 77549528
Test: Add a passcode to phone and then connect to device before
unlocking phone.

Change-Id: Ie661d412a9219d5baa5ba40d01cb1c75afa19954
parent a60c0cdb
Loading
Loading
Loading
Loading
+32 −17
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Looper;
import android.os.SystemProperties;
import android.os.UserManager;
import android.util.Log;

import com.android.bluetooth.Utils;
@@ -110,19 +111,23 @@ public class AvrcpTargetService extends ProfileService {
        Log.i(TAG, "User unlocked, initializing the service");

        if (!SystemProperties.getBoolean(AVRCP_ENABLE_PROPERTY, false)) {
            Log.w(TAG, "Skipping initialization of the new AVRCP Target Service");
            Log.w(TAG, "Skipping initialization of the new AVRCP Target Player List");
            sInstance = null;
            return;
        }

        init();

        // Only allow the service to be used once it is initialized
        sInstance = this;
        if (mMediaPlayerList != null) {
            mMediaPlayerList.init(new ListCallback());
        }
    }

    @Override
    protected boolean start() {
        if (sInstance != null) {
            Log.wtfStack(TAG, "The service has already been initialized");
            return false;
        }

        Log.i(TAG, "Starting the AVRCP Target Service");
        mCurrentData = new MediaData(null, null, null);

@@ -131,6 +136,28 @@ public class AvrcpTargetService extends ProfileService {
        filter.addAction(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        registerReceiver(mReceiver, filter);

        if (!SystemProperties.getBoolean(AVRCP_ENABLE_PROPERTY, false)) {
            Log.w(TAG, "Skipping initialization of the new AVRCP Target Service");
            sInstance = null;
            return true;
        }

        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        sDeviceMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

        mMediaPlayerList = new MediaPlayerList(Looper.myLooper(), this);

        UserManager userManager = UserManager.get(getApplicationContext());
        if (userManager.isUserUnlocked()) {
            mMediaPlayerList.init(new ListCallback());
        }

        mNativeInterface = AvrcpNativeInterface.getInterface();
        mNativeInterface.init(AvrcpTargetService.this);

        // Only allow the service to be used once it is initialized
        sInstance = this;

        return true;
    }

@@ -153,18 +180,6 @@ public class AvrcpTargetService extends ProfileService {
    }

    private void init() {
        if (mMediaPlayerList != null) {
            Log.wtfStack(TAG, "init: The service has already been initialized");
            return;
        }

        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        sDeviceMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

        mMediaPlayerList = new MediaPlayerList();
        mMediaPlayerList.init(Looper.myLooper(), this, new ListCallback());
        mNativeInterface = AvrcpNativeInterface.getInterface();
        mNativeInterface.init(AvrcpTargetService.this);
    }

    void deviceConnected(String bdaddr, boolean absoluteVolume) {
+8 −3
Original line number Diff line number Diff line
@@ -100,11 +100,11 @@ public class MediaPlayerList {
        void run(String parentId, List<ListItem> items);
    }

    void init(Looper looper, Context context, MediaUpdateCallback callback) {
        Log.v(TAG, "Initializing MediaPlayerList");
    MediaPlayerList(Looper looper, Context context) {
        Log.v(TAG, "Creating MediaPlayerList");

        mLooper = looper;
        mContext = context;
        mCallback = callback;

        // Register for intents where available players might have changed
        IntentFilter pkgFilter = new IntentFilter();
@@ -120,6 +120,11 @@ public class MediaPlayerList {
        mMediaSessionManager.addOnActiveSessionsChangedListener(
                mActiveSessionsChangedListener, null, new Handler(looper));
        mMediaSessionManager.setCallback(mButtonDispatchCallback, null);
    }

    void init(MediaUpdateCallback callback) {
        Log.v(TAG, "Initializing MediaPlayerList");
        mCallback = callback;

        // Build the list of browsable players and afterwards, build the list of media players
        Intent intent = new Intent(android.service.media.MediaBrowserService.SERVICE_INTERFACE);