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

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

Migrate PBAP client enable/disable to sysprops

Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: Id9f4e897d2b4cef63000096c7ef556ef22e3bd9d
Change-Id: Id9f4e897d2b4cef63000096c7ef556ef22e3bd9d
parent 21f021a8
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -343,6 +343,26 @@
             android:enabled="false">
        </activity>

        <!--  Phonebook Access Profile (PBAP) client Profile Service and owned Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.PbapClientService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbapClient"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name="com.android.bluetooth.pbapclient.AuthenticationService"
             android:enabled="false"
             android:exported="true">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"/>
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator"
                 android:resource="@xml/authenticator"/>
        </service>

        <!--  Telephony Bearer Service (TBS) server Profile Service  -->
        <service
            android:process="@string/process"
@@ -517,25 +537,6 @@
                <action android:name="android.bluetooth.IBluetoothHeadset"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name=".pbapclient.PbapClientService"
             android:enabled="@bool/profile_supported_pbapclient"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbapClient"/>
            </intent-filter>
        </service>
        <!-- Authenticator for PBAP account. -->
        <service android:process="@string/process"
             android:name=".pbapclient.AuthenticationService"
             android:exported="true"
             android:enabled="@bool/profile_supported_pbapclient">
            <intent-filter>
                <action android:name="android.accounts.AccountAuthenticator"/>
            </intent-filter>
            <meta-data android:name="android.accounts.AccountAuthenticator"
                 android:resource="@xml/authenticator"/>
        </service>
        <service
            android:name=".telephony.BluetoothInCallService"
            android:permission="android.permission.BIND_INCALL_SERVICE"
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
    <bool name="pbap_include_photos_in_vcard">true</bool>
    <bool name="pbap_use_profile_for_owner_vcard">true</bool>
    <bool name="profile_supported_sap">false</bool>
    <bool name="profile_supported_pbapclient">false</bool>

    <!-- If true, we will require location to be enabled on the device to
         fire Bluetooth LE scan result callbacks in addition to having one
+15 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.CallLog;
import android.sysprop.BluetoothProperties;
import android.util.Log;

import com.android.bluetooth.R;
@@ -58,6 +59,13 @@ public class PbapClientService extends ProfileService {

    private static final String TAG = "PbapClientService";
    private static final String SERVICE_NAME = "Phonebook Access PCE";

    /**
     * The component names for the owned authenticator service
     */
    private static final String AUTHENTICATOR_SERVICE =
            AuthenticationService.class.getCanonicalName();

    // MAXIMUM_DEVICES set to 10 to prevent an excessive number of simultaneous devices.
    private static final int MAXIMUM_DEVICES = 10;
    private Map<BluetoothDevice, PbapClientStateMachine> mPbapClientStateMachineMap =
@@ -68,6 +76,10 @@ public class PbapClientService extends ProfileService {

    private DatabaseManager mDatabaseManager;

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

    @Override
    public IProfileServiceBinder initBinder() {
        return new BluetoothPbapClientBinder(this);
@@ -82,6 +94,8 @@ public class PbapClientService extends ProfileService {
        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
                "DatabaseManager cannot be null when PbapClientService starts");

        setComponentAvailable(AUTHENTICATOR_SERVICE, true);

        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        // delay initial download until after the user is unlocked to add an account.
@@ -114,6 +128,7 @@ public class PbapClientService extends ProfileService {
            pbapClientStateMachine.doQuit();
        }
        removeUncleanAccounts();
        setComponentAvailable(AUTHENTICATOR_SERVICE, false);
        return true;
    }

+2 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class PbapClientServiceTest {
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when PbapClientService is not enabled",
                mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbapclient));
                PbapClientService.isEnabled());
        MockitoAnnotations.initMocks(this);
        TestUtils.setAdapterService(mAdapterService);
        doReturn(mDatabaseManager).when(mAdapterService).getDatabase();
@@ -73,7 +73,7 @@ public class PbapClientServiceTest {

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbapclient)) {
        if (!PbapClientService.isEnabled()) {
            return;
        }
        TestUtils.stopService(mServiceRule, PbapClientService.class);
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class PbapParserTest {
    public void setUp() {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when PbapClientService is not enabled",
                mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbapclient));
                PbapClientService.isEnabled());
        mAccount = new Account(TEST_ACCOUNT_NAME,
                mTargetContext.getString(com.android.bluetooth.R.string.pbap_account_type));
        try {