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

Commit 4d92790d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add a property to enable the New AVRCP Profile (2/2)"

parents d4e5c9f2 030bab94
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
    <bool name="pbap_include_photos_in_vcard">true</bool>
    <bool name="pbap_use_profile_for_owner_vcard">true</bool>
    <bool name="profile_supported_map">true</bool>
    <bool name="profile_supported_avrcp_target">false</bool>
    <bool name="profile_supported_avrcp_target">true</bool>
    <bool name="profile_supported_avrcp_controller">false</bool>
    <bool name="profile_supported_sap">false</bool>
    <bool name="profile_supported_pbapclient">false</bool>
+8 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.Log;

import com.android.bluetooth.Utils;
import com.android.bluetooth.avrcp.Avrcp;
import com.android.bluetooth.avrcp.AvrcpTargetService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;

@@ -531,6 +532,13 @@ 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);
            return;
        }

        mAvrcp.setAbsoluteVolume(volume);
    }

+47 −4
Original line number Diff line number Diff line
@@ -19,14 +19,17 @@ package com.android.bluetooth.avrcp;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.IBluetoothAvrcpTarget;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Looper;
import android.os.SystemProperties;
import android.util.Log;

import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.btservice.ProfileService;

@@ -40,6 +43,7 @@ import java.util.Objects;
public class AvrcpTargetService extends ProfileService {
    private static final String TAG = "NewAvrcpTargetService";
    private static final boolean DEBUG = true;
    private static final String AVRCP_ENABLE_PROPERTY = "persist.bluetooth.enablenewavrcp";

    private static final int AVRCP_MAX_VOL = 127;
    private static int sDeviceMaxVolume = 0;
@@ -76,6 +80,8 @@ public class AvrcpTargetService extends ProfileService {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
                if (mNativeInterface == null) return;

                // Update all the playback status info for each connected device
                mNativeInterface.sendMediaUpdate(false, true, false);
            }
@@ -83,7 +89,7 @@ public class AvrcpTargetService extends ProfileService {
    }

    /**
     * Get the AvrcpTargetService instance. Returns null if the service hasn't been started yet.
     * Get the AvrcpTargetService instance. Returns null if the service hasn't been initialized.
     */
    public static AvrcpTargetService get() {
        return sInstance;
@@ -96,21 +102,29 @@ public class AvrcpTargetService extends ProfileService {

    @Override
    protected IProfileServiceBinder initBinder() {
        return null;
        return new AvrcpTargetBinder(this);
    }

    @Override
    protected void setUserUnlocked(int userId) {
        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");
            sInstance = null;
            return;
        }

        init();

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

    @Override
    protected boolean start() {
        Log.i(TAG, "Starting the AVRCP Target Service");
        sInstance = this;
        mCurrentData = new MediaData(null, null, null);
        mNativeInterface = AvrcpNativeInterface.getInterface();

        mReceiver = new AvrcpBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
@@ -149,6 +163,7 @@ public class AvrcpTargetService extends ProfileService {

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

@@ -260,4 +275,32 @@ public class AvrcpTargetService extends ProfileService {
    public void dump(StringBuilder sb) {
        mMediaPlayerList.dump(sb);
    }

    private static class AvrcpTargetBinder extends IBluetoothAvrcpTarget.Stub
            implements IProfileServiceBinder {
        private AvrcpTargetService mService;

        AvrcpTargetBinder(AvrcpTargetService service) {
            mService = service;
        }

        @Override
        public void cleanup() {
            mService = null;
        }

        @Override
        public void sendVolumeChanged(int volume) {
            if (!Utils.checkCaller()) {
                Log.w(TAG, "sendVolumeChanged not allowed for non-active user");
                return;
            }

            if (mService == null) {
                return;
            }

            mService.sendVolumeChanged(volume);
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -132,6 +132,11 @@ public class MediaPlayerList {
                (List<BrowsedPlayerWrapper> players) -> {
                Log.i(TAG, "init: Browsable Player list size is " + players.size());

                // Check to see if the list has been cleaned up before this completed
                if (mMediaSessionManager == null) {
                    return;
                }

                for (BrowsedPlayerWrapper wrapper : players) {
                    // Generate new id and add the browsable player
                    if (!mMediaPlayerIds.containsKey(wrapper.getPackageName())) {