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

Commit 571b25f8 authored by William Escande's avatar William Escande Committed by David Duarte
Browse files

Construct profiles instead of remotely starting them

Each profile was exposed as a service that was interacted
with in two ways asynchronously:
- startService: by the Bluetooth app, calling into ActivityManager
  to start a service inside the Bluetooth app itself.
- bindService: by the bluetooth_manager to retrieve the binder
  of this service.

Bluetooth was making an asynchronous call to ActivityManager from
the main thread of its process to start a Service on the main
thread of its process.
This forces a lot of things to be passed as a global variable, as
the creation of the service was externaly managed, which comes with
all the issues associated with global variables.

The flow for the framework to retrieve the binder of a service
was 3rd party app -> system_server (bluetooth manager then activity
manager) -> Bluetooth app. This is unnecessarily complex and is
replaced by this CL to just 3rd party app -> Bluetooth app.

Also all is synchronous now, simplifying some tests and making the
lifecycle easier and removing some races like:
- https://r.android.com/1626228
- https://r.android.com/2810743



A lot of things can be simplified as follow-up thanks to this:
- Removing most global variables of the Bluetooth app.
- Easier and static startup of profiles.

Co-authored-by: default avatarDavid Duarte <licorne@google.com>
Bug: 291815510
Bug: 305741984
Test: atest BluetoothInstrumentationTest
Flag: EXEMPT, Manifest flagging is not available and this change
  is unsafe to do if we don't remove the service entries from the
  manifest
Change-Id: I83a38e1d67de95d8717b5f866868b740e364335d
parent fe306f36
Loading
Loading
Loading
Loading
+0 −240
Original line number Diff line number Diff line
@@ -113,55 +113,6 @@
            </intent-filter>
        </service>

        <!--  Advanced Audio Distribution Profile (A2DP) source Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.a2dp.A2dpService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothA2dp"/>
            </intent-filter>
        </service>

        <!--  Advanced Audio Distribution Profile (A2DP) sink Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.a2dpsink.A2dpSinkService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothA2dpSink"/>
            </intent-filter>
        </service>

        <!--  Android Audio Support for Hearing Aids (ASHA) central Profile Service -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hearingaid.HearingAidService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHearingAid"/>
            </intent-filter>
        </service>

        <!--  Audio/Video Remote Control Profile (AVRCP) target Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.avrcp.AvrcpTargetService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothAvrcp"/>
            </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"
@@ -187,69 +138,6 @@
            </intent-filter>
        </activity>

        <!--  Basic Audio Profile (BAP) Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.le_audio.LeAudioService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothLeAudio" />
            </intent-filter>
        </service>

        <!-- Basic Audio Profile (BAP) Broadcast Assistant Profle Service -->
        <service
            android:process="@string/process"
            android:name = "com.android.bluetooth.bass_client.BassClientService"
            android:enabled="true"
            android:exported = "true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothLeBroadcastAssistant" />
            </intent-filter>
        </service>

        <!-- Battery Service (BAS) Client Profle Service -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.bas.BatteryService"
            android:enabled="true"
            android:exported = "true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothBattery" />
            </intent-filter>
        </service>

        <!--  Coordinated Set Identification Profile (CSIP) set coordinator Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.csip.CsipSetCoordinatorService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothCsipSetCoordinator" />
            </intent-filter>
        </service>

        <!--  Hearing Aid Profile (HAP) client Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hap.HapClientService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHapClient"/>
            </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"
@@ -262,16 +150,6 @@
              <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"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHeadsetClient"/>
            </intent-filter>
        </service>
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hfpclient.HfpClientConnectionService"
             android:permission="android.permission.BIND_CONNECTION_SERVICE"
@@ -282,36 +160,6 @@
            </intent-filter>
        </service>

        <!--  Human Interface Device (HID) host Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hid.HidHostService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHidHost"/>
            </intent-filter>
        </service>

        <!--  Human Interface Device (HID) device Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.hid.HidDeviceService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothHidDevice"/>
            </intent-filter>
        </service>

        <!--  Message Access Profile (MAP) server Profile Service and owned Provider and Activiie  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.map.BluetoothMapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothMap"/>
                <action android:name="com.android.bluetooth.map.USER_CONFIRM_TIMEOUT"/>
            </intent-filter>
        </service>
        <activity android:name="com.android.bluetooth.map.BluetoothMapSettings"
              android:process="@string/process"
              android:label="@string/bluetooth_map_settings_title"
@@ -326,32 +174,6 @@
             android:exported="false">
        </provider>

        <!--  Message Access Profile (MAP) client Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.mapclient.MapClientService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothMapClient"/>
            </intent-filter>
        </service>

        <!--  Media Control Profile (MCP) server Profile Service  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.mcp.McpService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothMcpServiceManager" />
            </intent-filter>
        </service>

        <!--  Object Push Profile (OPP) Profile Service and owned Receives, Providers and Activiies  -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.opp.BluetoothOppService"
             android:permission="android.permission.ACCESS_BLUETOOTH_SHARE"
             android:enabled="true"
             android:exported="true"/>
        <provider android:name="com.android.bluetooth.opp.BluetoothOppProvider"
             android:authorities="com.android.bluetooth.opp"
             android:enabled="false"
@@ -474,27 +296,6 @@
            </intent-filter>
        </activity>

        <!--  Personal Area Network (PAN) Profile Service  -->
        <service
             android:process="@string/process"
             android:name="com.android.bluetooth.pan.PanService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothPan"/>
            </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"
@@ -502,15 +303,6 @@
             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"
@@ -521,37 +313,5 @@
            <meta-data android:name="android.accounts.AccountAuthenticator"
                 android:resource="@xml/authenticator"/>
        </service>

        <!--  SIM Access Profile (SAP) server Profile Service -->
        <service android:process="@string/process"
             android:name="com.android.bluetooth.sap.SapService"
             android:enabled="true"
             android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothSap"/>
            </intent-filter>
        </service>

        <!--  Telephony Bearer Service (TBS) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.tbs.TbsService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothLeCallControl" />
            </intent-filter>
        </service>

        <!--  Volume Control Profile (VCP) server Profile Service  -->
        <service
            android:process="@string/process"
            android:name="com.android.bluetooth.vc.VolumeControlService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.bluetooth.IBluetoothVolumeControl" />
            </intent-filter>
        </service>
    </application>
</manifest>
+0 −1
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ filegroup {
        "android/bluetooth/IBluetoothQualityReportReadyCallback.aidl",
        "android/bluetooth/IBluetoothSap.aidl",
        "android/bluetooth/IBluetoothSocketManager.aidl",
        "android/bluetooth/IBluetoothStateChangeCallback.aidl",
        "android/bluetooth/IBluetoothVolumeControl.aidl",
        "android/bluetooth/IBluetoothVolumeControlCallback.aidl",
        "android/bluetooth/IncomingRfcommSocketInfo.aidl",
+3 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.bluetooth.IBluetoothConnectionCallback;
import android.bluetooth.IBluetoothMetadataListener;
import android.bluetooth.IBluetoothOobDataCallback;
import android.bluetooth.IBluetoothSocketManager;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.bluetooth.BluetoothActivityEnergyInfo;
import android.bluetooth.BluetoothSinkAudioPolicy;
import android.bluetooth.BluetoothClass;
@@ -309,4 +308,7 @@ interface IBluetooth

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    oneway void unregAllGattClient(in AttributionSource attributionSource, in SynchronousResultReceiver receiver);

    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    oneway void getProfile(int profile, in SynchronousResultReceiver receiver);
}
+2 −1
Original line number Diff line number Diff line
@@ -127,7 +127,8 @@ public class A2dpService extends ProfileService {
    private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback =
            new AudioManagerAudioDeviceCallback();

    A2dpService() {
    public A2dpService(Context ctx) {
        super(ctx);
        mNativeInterface = requireNonNull(A2dpNativeInterface.getInstance());
        mFeatureFlags = new FeatureFlagsImpl();
    }
+2 −1
Original line number Diff line number Diff line
@@ -74,7 +74,8 @@ public class A2dpSinkService extends ProfileService {
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;

    A2dpSinkService() {
    public A2dpSinkService(Context ctx) {
        super(ctx);
        mNativeInterface = requireNonNull(A2dpSinkNativeInterface.getInstance());
        mLooper = Looper.getMainLooper();
    }
Loading