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

Commit 58f6e944 authored by William Escande's avatar William Escande
Browse files

AvrcpTarget: Extract NativeInterface

Bug: 295237486
Test: atest ProfileServiceTest
Change-Id: I99ab6b81031ecc6ee383222061782ca683a67de2
parent 26b5711c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class AvrcpCoverArtService {

    public AvrcpCoverArtService(Context context) {
        mContext = context;
        mNativeInterface = AvrcpNativeInterface.getInterface();
        mNativeInterface = AvrcpNativeInterface.getInstance();
        mAcceptThread = new SocketAcceptor();
        mStorage = new AvrcpCoverArtStorage(COVER_ART_STORAGE_MAX_ITEMS);
    }
+24 −4
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import com.android.bluetooth.audio_util.PlayStatus;
import com.android.bluetooth.audio_util.PlayerInfo;
import com.android.bluetooth.audio_util.PlayerSettingsManager.PlayerSettingsValues;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

import java.util.List;
import java.util.Objects;
@@ -38,27 +40,45 @@ public class AvrcpNativeInterface {
    private static final String TAG = "AvrcpNativeInterface";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    @GuardedBy("INSTANCE_LOCK")
    private static AvrcpNativeInterface sInstance;

    private static final Object INSTANCE_LOCK = new Object();

    private AvrcpTargetService mAvrcpService;
    private AdapterService mAdapterService;

    static {
        if (Utils.isInstrumentationTestMode()) {
            Log.w(TAG, "App is instrumented. Skip loading the native");
        } else {
            classInitNative();
        }
    }

    private AvrcpNativeInterface() {
        mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(),
                "AdapterService cannot be null when AvrcpNativeInterface init");
    }

    static AvrcpNativeInterface getInterface() {
    static AvrcpNativeInterface getInstance() {
        synchronized (INSTANCE_LOCK) {
            if (sInstance == null) {
                sInstance = new AvrcpNativeInterface();
            }
        }

        return sInstance;
    }

    /** Set singleton instance. */
    @VisibleForTesting
    public static void setInstance(AvrcpNativeInterface instance) {
        synchronized (INSTANCE_LOCK) {
            sInstance = instance;
        }
    }

    void init(AvrcpTargetService service) {
        d("Init AvrcpNativeInterface");
        mAvrcpService = service;
+1 −1
Original line number Diff line number Diff line
@@ -224,7 +224,7 @@ public class AvrcpTargetService extends ProfileService {

        mPlayerSettingsManager = new PlayerSettingsManager(mMediaPlayerList, this);

        mNativeInterface = AvrcpNativeInterface.getInterface();
        mNativeInterface = AvrcpNativeInterface.getInstance();
        mNativeInterface.init(AvrcpTargetService.this);

        mAvrcpVersion = AvrcpVersion.getCurrentSystemPropertiesValue();
+4 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;
import com.android.bluetooth.a2dp.A2dpNativeInterface;
import com.android.bluetooth.avrcp.AvrcpNativeInterface;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.hearingaid.HearingAidNativeInterface;
@@ -88,6 +89,7 @@ public class ProfileServiceTest {
    }

    @Mock private A2dpNativeInterface mA2dpNativeInterface;
    @Mock private AvrcpNativeInterface mAvrcpNativeInterface;
    @Mock private HeadsetNativeInterface mHeadsetNativeInterface;
    @Mock private HearingAidNativeInterface mHearingAidNativeInterface;
    @Mock private HidHostNativeInterface mHidHostNativeInterface;
@@ -172,6 +174,7 @@ public class ProfileServiceTest {
                new String[0], false, "");
        mMockAdapterService.enableNative();
        A2dpNativeInterface.setInstance(mA2dpNativeInterface);
        AvrcpNativeInterface.setInstance(mAvrcpNativeInterface);
        HeadsetNativeInterface.setInstance(mHeadsetNativeInterface);
        HearingAidNativeInterface.setInstance(mHearingAidNativeInterface);
        HidHostNativeInterface.setInstance(mHidHostNativeInterface);
@@ -188,6 +191,7 @@ public class ProfileServiceTest {
        mMockAdapterService = null;
        mProfiles = null;
        A2dpNativeInterface.setInstance(null);
        AvrcpNativeInterface.setInstance(null);
        HeadsetNativeInterface.setInstance(null);
        HearingAidNativeInterface.setInstance(null);
        HidHostNativeInterface.setInstance(null);