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

Commit c80ea58e authored by Sal Savage's avatar Sal Savage
Browse files

Migrate AVRCP Controller enable/disable to sysprops

Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: Id9a6fe1151cdf2a4de6280e41a7a017f6e3c28ec
Change-Id: Id9a6fe1151cdf2a4de6280e41a7a017f6e3c28ec
parent bbcaa919
Loading
Loading
Loading
Loading
+33 −32
Original line number Diff line number Diff line
@@ -123,6 +123,39 @@
            </intent-filter>
        </service>

        <!--  Audio/Video Remote Control Profile (AVRCP) controller Profile Service and owned Services, Providers and Activiies  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.avrcpcontroller.AvrcpControllerService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothAvrcpController"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name="com.android.bluetooth.avrcpcontroller.BluetoothMediaBrowserService"
             android:enabled="true"
             android:exported="true"
             android:label="@string/a2dp_sink_mbs_label">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>
        <provider android:process="@string/process"
             android:name="com.android.bluetooth.avrcpcontroller.AvrcpCoverArtProvider"
             android:authorities="com.android.bluetooth.avrcpcontroller.AvrcpCoverArtProvider"
             android:enabled="false"
             android:grantUriPermissions="true"
             android:exported="true">
        </provider>
        <activity android:name="com.android.bluetooth.BluetoothPrefs"
             android:exported="true"
             android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.APPLICATION_PREFERENCES"/>
            </intent-filter>
        </activity>

        <provider android:name=".opp.BluetoothOppProvider"
             android:authorities="com.android.bluetooth.opp"
             android:exported="true"
@@ -329,38 +362,6 @@
                <action android:name="android.bluetooth.IBluetoothHeadset"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name=".avrcpcontroller.BluetoothMediaBrowserService"
             android:exported="true"
             android:enabled="@bool/profile_supported_a2dp_sink"
             android:label="@string/a2dp_sink_mbs_label">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>

        <activity android:name=".BluetoothPrefs"
             android:exported="@bool/profile_supported_a2dp_sink"
             android:enabled="@bool/profile_supported_a2dp_sink">
            <intent-filter>
                <action android:name="android.intent.action.APPLICATION_PREFERENCES"/>
            </intent-filter>
        </activity>
        <service android:process="@string/process"
             android:name=".avrcpcontroller.AvrcpControllerService"
             android:enabled="@bool/profile_supported_avrcp_controller"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothAvrcpController"/>
            </intent-filter>
        </service>
        <provider android:process="@string/process"
             android:name=".avrcpcontroller.AvrcpCoverArtProvider"
             android:authorities="com.android.bluetooth.avrcpcontroller.AvrcpCoverArtProvider"
             android:enabled="@bool/avrcp_controller_enable_cover_art"
             android:grantUriPermissions="true"
             android:exported="true">
        </provider>
        <service android:process="@string/process"
             android:name=".hid.HidHostService"
             android:enabled="@bool/profile_supported_hid_host"
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
    <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_controller">false</bool>
    <bool name="profile_supported_sap">false</bool>
    <bool name="profile_supported_pbapclient">false</bool>
    <bool name="profile_supported_mapmce">false</bool>
+18 −0
Original line number Diff line number Diff line
@@ -23,11 +23,14 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothAvrcpController;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v4.media.MediaBrowserCompat.MediaItem;
import android.support.v4.media.session.PlaybackStateCompat;
import android.sysprop.BluetoothProperties;
import android.util.Log;

import com.android.bluetooth.BluetoothPrefs;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dpsink.A2dpSinkService;
@@ -51,6 +54,13 @@ public class AvrcpControllerService extends ProfileService {
    static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);

    /**
     * Owned Components
     */
    private static final String ON_ERROR_SETTINGS_ACTIVITY =
            BluetoothPrefs.class.getCanonicalName();
    private static final String COVER_ART_PROVIDER = AvrcpCoverArtProvider.class.getCanonicalName();

    /*
     *  Play State Values from JNI
     */
@@ -132,12 +142,18 @@ public class AvrcpControllerService extends ProfileService {
        classInitNative();
    }

    public static boolean isEnabled() {
        return BluetoothProperties.isProfileAvrcpControllerEnabled().orElse(false);
    }

    @Override
    protected synchronized boolean start() {
        initNative();
        setComponentAvailable(ON_ERROR_SETTINGS_ACTIVITY, true);
        mAdapterService = AdapterService.getAdapterService();
        mCoverArtEnabled = getResources().getBoolean(R.bool.avrcp_controller_enable_cover_art);
        if (mCoverArtEnabled) {
            setComponentAvailable(COVER_ART_PROVIDER, true);
            mCoverArtManager = new AvrcpCoverArtManager(this, new ImageDownloadCallback());
        }
        sBrowseTree = new BrowseTree(null);
@@ -164,7 +180,9 @@ public class AvrcpControllerService extends ProfileService {
        if (mCoverArtManager != null) {
            mCoverArtManager.cleanup();
            mCoverArtManager = null;
            setComponentAvailable(COVER_ART_PROVIDER, false);
        }
        setComponentAvailable(ON_ERROR_SETTINGS_ACTIVITY, false);
        return true;
    }

+2 −3
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ public class AvrcpControllerServiceTest {
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when AvrcpControllerService is not enabled",
                mTargetContext.getResources()
                        .getBoolean(R.bool.profile_supported_avrcp_controller));
                AvrcpControllerService.isEnabled());
        MockitoAnnotations.initMocks(this);
        TestUtils.setAdapterService(mAdapterService);
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());
@@ -70,7 +69,7 @@ public class AvrcpControllerServiceTest {

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_avrcp_controller)) {
        if (!AvrcpControllerService.isEnabled()) {
            return;
        }
        TestUtils.stopService(mServiceRule, AvrcpControllerService.class);
+2 −6
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.SparseArray;

import androidx.test.InstrumentationRegistry;
import androidx.test.filters.FlakyTest;
import androidx.test.filters.MediumTest;
import androidx.test.rule.ServiceTestRule;
@@ -72,7 +71,6 @@ public class AvrcpControllerStateMachineTest {
    private static final int KEY_UP = 1;

    private BluetoothAdapter mAdapter;
    private Context mTargetContext;

    @Rule public final ServiceTestRule mAvrcpServiceRule = new ServiceTestRule();
    @Rule public final ServiceTestRule mA2dpServiceRule = new ServiceTestRule();
@@ -92,10 +90,8 @@ public class AvrcpControllerStateMachineTest {

    @Before
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when AVRCP Controller is not enabled",
                mTargetContext.getResources().getBoolean(
                        R.bool.profile_supported_avrcp_controller));
                AvrcpControllerService.isEnabled());
        if (Looper.myLooper() == null) {
            Looper.prepare();
        }
@@ -145,7 +141,7 @@ public class AvrcpControllerStateMachineTest {

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_avrcp_controller)) {
        if (!AvrcpControllerService.isEnabled()) {
            return;
        }
        destroyStateMachine(mAvrcpStateMachine);