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

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

Migrate HFP AG/server enable/disable to sysprops

Tag: #refactor
Bug: 217448211
Test: atest BluetoothInstrumentationTests
Merged-In: I497a1dff4f52e7c220d96c509cbab38d536af7b4
Change-Id: I497a1dff4f52e7c220d96c509cbab38d536af7b4
parent 1b3e4c86
Loading
Loading
Loading
Loading
+22 −20
Original line number Diff line number Diff line
@@ -231,6 +231,28 @@
            </intent-filter>
        </service>

        <!--  Hands-Free Profile (HFP) AG/server Profile Service and owned Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hfp.HeadsetService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHeadset"/>
            </intent-filter>
        </service>
        <service
            android:name="com.android.bluetooth.telephony.BluetoothInCallService"
            android:permission="android.permission.BIND_INCALL_SERVICE"
            android:process="@string/process"
            android:enabled="false"
            android:exported="true">
            <meta-data android:name="android.telecom.INCLUDE_SELF_MANAGED_CALLS"
                       android:value="true" />
            <intent-filter>
              <action android:name="android.telecom.InCallService"/>
            </intent-filter>
         </service>

        <!--  Hands-Free HF/Client Profile Service and owned Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hfpclient.HeadsetClientService"
@@ -531,25 +553,5 @@
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <service android:process="@string/process"
             android:name=".hfp.HeadsetService"
             android:enabled="@bool/profile_supported_hs_hfp"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHeadset"/>
            </intent-filter>
        </service>
        <service
            android:name=".telephony.BluetoothInCallService"
            android:permission="android.permission.BIND_INCALL_SERVICE"
            android:process="@string/process"
            android:enabled="@bool/profile_supported_hfp_incallservice"
            android:exported="true">
            <meta-data android:name="android.telecom.INCLUDE_SELF_MANAGED_CALLS"
                       android:value="true" />
            <intent-filter>
              <action android:name="android.telecom.InCallService"/>
            </intent-filter>
         </service>
    </application>
</manifest>
+0 −2
Original line number Diff line number Diff line
@@ -13,8 +13,6 @@
   limitations under the License.
-->
<resources>
    <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="pbap_include_photos_in_vcard">true</bool>
    <bool name="pbap_use_profile_for_owner_vcard">true</bool>
+6 −14
Original line number Diff line number Diff line
@@ -877,20 +877,6 @@ public class AdapterService extends Service {
        mA2dpService.switchCodecByBufferSize(activeDevices.get(0), isLowLatencyBufferSize);
    }

    /**
     * Enable/disable BluetoothInCallService
     *
     * @param enable to enable/disable BluetoothInCallService.
     */
    public void enableBluetoothInCallService(boolean enable) {
        debugLog("enableBluetoothInCallService() - Enable = " + enable);
        getPackageManager().setComponentEnabledSetting(
                BLUETOOTH_INCALLSERVICE_COMPONENT,
                enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                        : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

    void cleanup() {
        debugLog("cleanup()");
        if (mCleaningUp) {
@@ -4936,6 +4922,12 @@ public class AdapterService extends Service {
        writer.println("mDefaultSnoopLogSettingAtEnable = " + mDefaultSnoopLogSettingAtEnable);

        writer.println();
        writer.println("Enabled Profile Services:");
        for (Class profile : Config.getSupportedProfiles()) {
            writer.println("  " + profile.getSimpleName());
        }
        writer.println();

        mAdapterStateMachine.dump(fd, writer, args);

        StringBuilder sb = new StringBuilder();
+0 −17
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.os.Message;
import android.os.SystemProperties;
import android.util.Log;

import com.android.bluetooth.telephony.BluetoothInCallService;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

@@ -229,21 +228,6 @@ final class AdapterState extends StateMachine {
            return BluetoothAdapter.STATE_ON;
        }

        @Override
        public void enter() {
            super.enter();
            mAdapterService.enableBluetoothInCallService(true);
        }

        @Override
        public void exit() {
            BluetoothInCallService bluetoothInCallService = BluetoothInCallService.getInstance();
            if (bluetoothInCallService == null) {
                mAdapterService.enableBluetoothInCallService(false);
            }
            super.exit();
        }

        @Override
        public boolean processMessage(Message msg) {
            switch (msg.what) {
@@ -392,7 +376,6 @@ final class AdapterState extends StateMachine {
        @Override
        public void enter() {
            super.enter();
            mAdapterService.enableBluetoothInCallService(false);
            final int timeoutDelay = SystemProperties.getInt(
                    BLE_STOP_TIMEOUT_DELAY_PROPERTY, BLE_STOP_TIMEOUT_DELAY);
            Log.d(TAG, "Stop Timeout Delay: " + timeoutDelay);
+18 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetoothHeadset;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -43,6 +44,7 @@ import android.os.Looper;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.sysprop.BluetoothProperties;
import android.telecom.PhoneAccount;
import android.util.Log;

@@ -53,6 +55,7 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.telephony.BluetoothInCallService;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.utils.SynchronousResultReceiver;

@@ -93,6 +96,13 @@ import java.util.Objects;
public class HeadsetService extends ProfileService {
    private static final String TAG = "HeadsetService";
    private static final boolean DBG = false;

    /**
     * HFP AG owned/managed components
     */
    private static final String HFP_AG_IN_CALL_SERVICE =
            BluetoothInCallService.class.getCanonicalName();

    private static final String DISABLE_INBAND_RINGING_PROPERTY =
            "persist.bluetooth.disableinbandringing";
    private static final ParcelUuid[] HEADSET_UUIDS = {BluetoothUuid.HSP, BluetoothUuid.HFP};
@@ -131,6 +141,10 @@ public class HeadsetService extends ProfileService {
    private boolean mCreated;
    private static HeadsetService sHeadsetService;

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

    @Override
    public IProfileServiceBinder initBinder() {
        return new BluetoothHeadsetBinder(this);
@@ -151,6 +165,9 @@ public class HeadsetService extends ProfileService {
        if (mStarted) {
            throw new IllegalStateException("start() called twice");
        }

        setComponentAvailable(HFP_AG_IN_CALL_SERVICE, true);

        // Step 1: Get AdapterService and DatabaseManager, should never be null
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when HeadsetService starts");
@@ -255,6 +272,7 @@ public class HeadsetService extends ProfileService {
        synchronized (mStateMachines) {
            mAdapterService = null;
        }
        setComponentAvailable(HFP_AG_IN_CALL_SERVICE, false);
        return true;
    }

Loading