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

Commit 223dd636 authored by William Escande's avatar William Escande
Browse files

VolumeControl: stop calling NativeInterface in test

Bug: 295237486
Test: atest VolumeControlServiceTest
Change-Id: I17ec5b8af09f48a8d04689be76a46949d7f9853e
parent f1128998
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -32,11 +32,16 @@ public class VolumeControlNativeInterface {

    @GuardedBy("INSTANCE_LOCK")
    private static VolumeControlNativeInterface 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 VolumeControlNativeInterface() {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -57,6 +62,14 @@ public class VolumeControlNativeInterface {
        }
    }

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

    /**
     * Initializes the native interface.
     *
+0 −1
Original line number Diff line number Diff line
@@ -182,7 +182,6 @@ public class VolumeControlService extends ProfileService {
        }
    }

    @VisibleForTesting
    VolumeControlNativeInterface mVolumeControlNativeInterface;
    @VisibleForTesting
    AudioManager mAudioManager;
+2 −3
Original line number Diff line number Diff line
@@ -44,13 +44,11 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.R;
import com.android.bluetooth.TestUtils;
import com.android.bluetooth.x.com.android.modules.utils.SynchronousResultReceiver;

import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -121,8 +119,8 @@ public class VolumeControlServiceTest {
        doReturn(CALL_MAX_VOL).when(mAudioManager)
                .getStreamMaxVolume(eq(AudioManager.STREAM_VOICE_CALL));

        VolumeControlNativeInterface.setInstance(mNativeInterface);
        startService();
        mService.mVolumeControlNativeInterface = mNativeInterface;
        mService.mAudioManager = mAudioManager;
        mService.mFactory = mServiceFactory;
        mServiceBinder = (VolumeControlService.BluetoothVolumeControlBinder) mService.initBinder();
@@ -160,6 +158,7 @@ public class VolumeControlServiceTest {
        }

        stopService();
        VolumeControlNativeInterface.setInstance(null);
        mTargetContext.unregisterReceiver(mVolumeControlIntentReceiver);
        mDeviceQueueMap.clear();
        TestUtils.clearAdapterService(mAdapterService);