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

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

HapClient: stop calling NativeInterface in test

Bug: 295237486
Test: atest HapClientTest
Change-Id: Id139b96ddcf16ccc2abb2770b6a087f12ce16d0a
parent aa1ee888
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -33,17 +33,24 @@ import java.util.Arrays;
 * Hearing Access Profile Client Native Interface to/from JNI.
 */
public class HapClientNativeInterface {
    private static final String TAG = "HapClientNativeInterface";
    private static final boolean DBG = true;
    private static final String TAG =
            HapClientNativeInterface.class.getSimpleName().substring(0, 23);
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);

    private final BluetoothAdapter mAdapter;

    @GuardedBy("INSTANCE_LOCK")
    private static HapClientNativeInterface 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();
        }
    }

    private HapClientNativeInterface() {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -64,6 +71,14 @@ public class HapClientNativeInterface {
        }
    }

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

    /**
     * Initiates HapClientService connection to a remote device.
     *
@@ -346,7 +361,7 @@ public class HapClientNativeInterface {
        event.valueList = new ArrayList<>(Arrays.asList(presets));

        if (DBG) {
            Log.d(TAG, "onPresetInfo: " + event);
            Log.d(TAG, "onGroupPresetInfo: " + event);
        }
        sendMessageToService(event);
    }
@@ -360,7 +375,7 @@ public class HapClientNativeInterface {
        event.valueInt2 = presetIndex;

        if (DBG) {
            Log.d(TAG, "OnPresetNameSetError: " + event);
            Log.d(TAG, "onPresetNameSetError: " + event);
        }
        sendMessageToService(event);
    }
@@ -374,7 +389,7 @@ public class HapClientNativeInterface {
        event.valueInt3 = groupId;

        if (DBG) {
            Log.d(TAG, "OnPresetNameSetError: " + event);
            Log.d(TAG, "onGroupPresetNameSetError: " + event);
        }
        sendMessageToService(event);
    }
@@ -402,7 +417,7 @@ public class HapClientNativeInterface {
        event.valueInt3 = groupId;

        if (DBG) {
            Log.d(TAG, "onPresetInfoError: " + event);
            Log.d(TAG, "onGroupPresetInfoError: " + event);
        }
        sendMessageToService(event);
    }
+2 −1
Original line number Diff line number Diff line
@@ -129,8 +129,8 @@ public class HapClientTest {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mAttributionSource = mAdapter.getAttributionSource();

        HapClientNativeInterface.setInstance(mNativeInterface);
        startService();
        mService.mHapClientNativeInterface = mNativeInterface;
        mService.mFactory = mServiceFactory;
        doReturn(mCsipService).when(mServiceFactory).getCsipSetCoordinatorService();
        mServiceBinder = (HapClientService.BluetoothHapClientBinder) mService.initBinder();
@@ -217,6 +217,7 @@ public class HapClientTest {
        mService.mCallbacks.unregister(mCallback);

        stopService();
        HapClientNativeInterface.setInstance(null);

        if (mHasIntentReceiver != null) {
            mTargetContext.unregisterReceiver(mHasIntentReceiver);