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

Commit 8294cfcd authored by Mingguang Xu's avatar Mingguang Xu
Browse files

BTAA: notify the App information when starting and stopping service

Tag: #feature

Bug: 202527952
Bug: 172501038

Test: atest BluetoothInstrumentationTests:com.android.bluetooth.btservice
Change-Id: I7163fe2aec982698a5634a6f1b1674deb9d3e3a0
parent 98f24eb4
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -161,6 +161,11 @@ public class A2dpService extends ProfileService {

        // Step 8: Mark service as started
        setA2dpService(this);
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);

        // Step 9: Clear active device
        setActiveDevice(null);
@@ -180,6 +185,11 @@ public class A2dpService extends ProfileService {
        removeActiveDevice(true);

        // Step 8: Mark service as stopped
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        setA2dpService(null);

        // Step 7: Unregister broadcast receivers
+10 −0
Original line number Diff line number Diff line
@@ -78,11 +78,21 @@ public class A2dpSinkService extends ProfileService {
        }

        setA2dpSinkService(this);
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        return true;
    }

    @Override
    protected boolean stop() {
        BluetoothDevice activeDevice = getActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(), deviceAddress);
        setA2dpSinkService(null);
        mNativeInterface.cleanup();
        for (A2dpSinkStateMachine stateMachine : mDeviceStateMap.values()) {
+13 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.bluetooth.audio_util.MediaPlayerWrapper;
import com.android.bluetooth.audio_util.Metadata;
import com.android.bluetooth.audio_util.PlayStatus;
import com.android.bluetooth.audio_util.PlayerInfo;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
@@ -244,6 +245,12 @@ public class AvrcpTargetService extends ProfileService {

        // Only allow the service to be used once it is initialized
        sInstance = this;
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        AdapterService.getAdapterService().notifyActivityAttributionInfo(
                getAttributionSource(), deviceAddress);

        return true;
    }
@@ -261,6 +268,12 @@ public class AvrcpTargetService extends ProfileService {
            mAvrcpCoverArtService.stop();
        }
        mAvrcpCoverArtService = null;
        BluetoothDevice activeDevice = getA2dpActiveDevice();
        String deviceAddress = activeDevice != null ?
                activeDevice.getAddress() :
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS;
        AdapterService.getAdapterService().notifyActivityAttributionInfo(
                getAttributionSource(), deviceAddress);

        sInstance = null;
        unregisterReceiver(mReceiver);
+3 −0
Original line number Diff line number Diff line
@@ -199,6 +199,9 @@ public class AdapterService extends Service {
            new ComponentName("com.android.bluetooth",
                    BluetoothInCallService.class.getCanonicalName());

    public static final String ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS =
            "no_active_device_address";

    // Report ID definition
    public enum BqrQualityReportId {
        QUALITY_REPORT_ID_MONITOR_MODE(0x01),
+4 −0
Original line number Diff line number Diff line
@@ -140,6 +140,8 @@ public class CsipSetCoordinatorService extends ProfileService {

        // Initialize native interface
        mCsipSetCoordinatorNativeInterface.init();
        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(),
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS);

        return true;
    }
@@ -154,6 +156,8 @@ public class CsipSetCoordinatorService extends ProfileService {
            return true;
        }

        mAdapterService.notifyActivityAttributionInfo(getAttributionSource(),
                AdapterService.ACTIVITY_ATTRIBUTION_NO_ACTIVE_DEVICE_ADDRESS);
        // Cleanup native interface
        mCsipSetCoordinatorNativeInterface.cleanup();
        mCsipSetCoordinatorNativeInterface = null;
Loading