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

Commit 21f021a8 authored by Sal Savage's avatar Sal Savage
Browse files

Migrate PBAP server enable/disable to sysprops

Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: I4d4747e67fdb6d459b62ddb8b1782c640463cdbb
Change-Id: I4d4747e67fdb6d459b62ddb8b1782c640463cdbb
parent 21111f72
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -326,6 +326,23 @@
            </intent-filter>
        </service>

        <!--  Phonebook Access Profile (PBAP) server Profile Service and owned Activiie  -->
        <service android:process="@string/process"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED"
             android:name="com.android.bluetooth.pbap.BluetoothPbapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbap"/>
            </intent-filter>
        </service>
        <activity android:name="com.android.bluetooth.pbap.BluetoothPbapActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="false">
        </activity>

        <!--  Telephony Bearer Service (TBS) server Profile Service  -->
        <service
            android:process="@string/process"
@@ -484,21 +501,6 @@
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".pbap.BluetoothPbapActivity"
             android:process="@string/process"
             android:excludeFromRecents="true"
             android:theme="@style/dialog"
             android:enabled="@bool/profile_supported_pbap">
        </activity>
        <service android:process="@string/process"
             android:permission="android.permission.BLUETOOTH_PRIVILEGED"
             android:name=".pbap.BluetoothPbapService"
             android:enabled="@bool/profile_supported_pbap"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPbap"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name=".sap.SapService"
             android:enabled="@bool/profile_supported_sap"
+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
    <bool name="profile_supported_hs_hfp">true</bool>
    <bool name="profile_supported_hfp_incallservice">true</bool>
    <bool name="profile_supported_opp">true</bool>
    <bool name="profile_supported_pbap">true</bool>
    <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>
+15 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.bluetooth.BluetoothSocket;
import android.bluetooth.IBluetoothPbap;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -55,6 +56,7 @@ import android.os.Message;
import android.os.PowerManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.sysprop.BluetoothProperties;
import android.telephony.TelephonyManager;
import android.util.Log;

@@ -88,6 +90,11 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect

    public static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);

    /**
     * The component name of the owned BluetoothPbapActivity
     */
    private static final String PBAP_ACTIVITY = BluetoothPbapActivity.class.getCanonicalName();

    /**
     * Intent indicating incoming obex authentication request which is from
     * PCE(Carkit)
@@ -176,6 +183,10 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect

    private static BluetoothPbapService sBluetoothPbapService;

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

    private class BluetoothPbapContentObserver extends ContentObserver {
        BluetoothPbapContentObserver() {
            super(new Handler());
@@ -562,6 +573,9 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
            "DatabaseManager cannot be null when PbapService starts");

        // Enable owned Activity component
        setComponentAvailable(PBAP_ACTIVITY, true);

        mContext = this;
        mContactsLoaded = false;
        mHandlerThread = new HandlerThread("PbapHandlerThread");
@@ -613,6 +627,7 @@ public class BluetoothPbapService extends ProfileService implements IObexConnect
        unregisterReceiver(mPbapReceiver);
        getContentResolver().unregisterContentObserver(mContactChangeObserver);
        mContactChangeObserver = null;
        setComponentAvailable(PBAP_ACTIVITY, false);
        return true;
    }

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

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbap)) {
        if (!BluetoothPbapService.isEnabled()) {
            return;
        }
        TestUtils.stopService(mServiceRule, BluetoothPbapService.class);
+2 −2
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class PbapStateMachineTest {
    public void setUp() throws Exception {
        mTargetContext = InstrumentationRegistry.getTargetContext();
        Assume.assumeTrue("Ignore test when BluetoothPbapService is not enabled",
                mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbap));
                BluetoothPbapService.isEnabled());
        MockitoAnnotations.initMocks(this);
        TestUtils.setAdapterService(mAdapterService);
        // This line must be called to make sure relevant objects are initialized properly
@@ -84,7 +84,7 @@ public class PbapStateMachineTest {

    @After
    public void tearDown() throws Exception {
        if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_pbap)) {
        if (!BluetoothPbapService.isEnabled()) {
            return;
        }
        mHandlerThread.quitSafely();