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

Commit f1128998 authored by William Escande's avatar William Escande
Browse files

HidDevice: stop calling NativeInterface in test

Bug: 295237486
Test: atest ProfileServiceTest
Change-Id: I8d81eb35ec49e24dd4d5ec0f152b37895e105b25
parent 58f6e944
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.util.Log;

import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -42,11 +43,16 @@ public class HidDeviceNativeInterface {

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

    private static final Object INSTANCE_LOCK = new Object();

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

    @VisibleForTesting
    private HidDeviceNativeInterface() {
@@ -70,13 +76,12 @@ public class HidDeviceNativeInterface {
        }
    }

    /**
     * Set the singleton instance.
     *
     * @param nativeInterface native interface
     */
    private static void setInstance(HidDeviceNativeInterface nativeInterface) {
        sInstance = nativeInterface;
    /** Set singleton instance. */
    @VisibleForTesting
    public static void setInstance(HidDeviceNativeInterface instance) {
        synchronized (INSTANCE_LOCK) {
            sInstance = instance;
        }
    }

    /**
+5 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.hearingaid.HearingAidNativeInterface;
import com.android.bluetooth.hfp.HeadsetNativeInterface;
import com.android.bluetooth.hid.HidDeviceNativeInterface;
import com.android.bluetooth.hid.HidHostNativeInterface;
import com.android.bluetooth.pan.PanNativeInterface;

@@ -92,6 +93,7 @@ public class ProfileServiceTest {
    @Mock private AvrcpNativeInterface mAvrcpNativeInterface;
    @Mock private HeadsetNativeInterface mHeadsetNativeInterface;
    @Mock private HearingAidNativeInterface mHearingAidNativeInterface;
    @Mock private HidDeviceNativeInterface mHidDeviceNativeInterface;
    @Mock private HidHostNativeInterface mHidHostNativeInterface;
    @Mock private PanNativeInterface mPanNativeInterface;

@@ -177,6 +179,7 @@ public class ProfileServiceTest {
        AvrcpNativeInterface.setInstance(mAvrcpNativeInterface);
        HeadsetNativeInterface.setInstance(mHeadsetNativeInterface);
        HearingAidNativeInterface.setInstance(mHearingAidNativeInterface);
        HidDeviceNativeInterface.setInstance(mHidDeviceNativeInterface);
        HidHostNativeInterface.setInstance(mHidHostNativeInterface);
        PanNativeInterface.setInstance(mPanNativeInterface);
    }
@@ -194,6 +197,7 @@ public class ProfileServiceTest {
        AvrcpNativeInterface.setInstance(null);
        HeadsetNativeInterface.setInstance(null);
        HearingAidNativeInterface.setInstance(null);
        HidDeviceNativeInterface.setInstance(null);
        HidHostNativeInterface.setInstance(null);
        PanNativeInterface.setInstance(null);
    }
@@ -208,8 +212,7 @@ public class ProfileServiceTest {
    }

    /**
     * Test: Start the Bluetooth services that are configured twice.
     * Verify that the services start.
     * Test: Start the Bluetooth services that are configured twice. Verify that the services start.
     */
    @Test
    public void testEnableDisableTwice() throws TimeoutException {