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

Commit bfb0cba9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "SystemServer: use test cache in test" into main

parents e7c723e3 869bf1d2
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ android_test {


    static_libs: [
    static_libs: [
        "androidx.test.rules",
        "androidx.test.rules",
        "flag-junit",
        "frameworks-base-testutils",
        "frameworks-base-testutils",
        "kotlinx_coroutines_test",
        "kotlinx_coroutines_test",
        "libprotobuf-java-nano",
        "libprotobuf-java-nano",
+21 −22
Original line number Original line Diff line number Diff line
@@ -18,8 +18,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.server.bluetooth.test">
    package="com.android.server.bluetooth.test">


    <application android:debuggable="true"
    <application android:debuggable="true" android:largeHeap="true">
         android:largeHeap="true">
        <uses-library android:name="android.test.runner"/>
        <uses-library android:name="android.test.runner"/>
        <activity android:label="BluetoothTestFakeLabel"
        <activity android:label="BluetoothTestFakeLabel"
            android:name="BluetoothTestFakeName"
            android:name="BluetoothTestFakeName"
+25 −0
Original line number Original line Diff line number Diff line
@@ -41,8 +41,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.validateMockitoUsage;
import static org.mockito.Mockito.validateMockitoUsage;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;


import android.app.PropertyInvalidatedCache;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothManager;
import android.bluetooth.IBluetoothManagerCallback;
import android.bluetooth.IBluetoothManagerCallback;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.bluetooth.IBluetoothStateChangeCallback;
import android.content.ComponentName;
import android.content.ComponentName;
@@ -95,6 +97,19 @@ public class BluetoothManagerServiceTest {


    TestLooper mLooper;
    TestLooper mLooper;


    private static class ServerQuery
            extends PropertyInvalidatedCache.QueryHandler<IBluetoothManager, Integer> {
        @Override
        public Integer apply(IBluetoothManager x) {
            return -1;
        }

        @Override
        public boolean shouldBypassCache(IBluetoothManager x) {
            return true;
        }
    }

    static {
    static {
        // Required for reading DeviceConfig.
        // Required for reading DeviceConfig.
        InstrumentationRegistry.getInstrumentation()
        InstrumentationRegistry.getInstrumentation()
@@ -107,6 +122,15 @@ public class BluetoothManagerServiceTest {
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);


        PropertyInvalidatedCache<IBluetoothManager, Integer> testCache =
                new PropertyInvalidatedCache<>(
                        8,
                        IBluetoothManager.IPC_CACHE_MODULE_SYSTEM,
                        IBluetoothManager.GET_SYSTEM_STATE_API,
                        IBluetoothManager.GET_SYSTEM_STATE_API,
                        new ServerQuery());
        PropertyInvalidatedCache.setTestMode(true);
        testCache.testPropertyName();
        // Mock these functions so security errors won't throw
        // Mock these functions so security errors won't throw
        doReturn("name")
        doReturn("name")
                .when(mBluetoothServerProxy)
                .when(mBluetoothServerProxy)
@@ -162,6 +186,7 @@ public class BluetoothManagerServiceTest {


    @After
    @After
    public void tearDown() {
    public void tearDown() {
        PropertyInvalidatedCache.setTestMode(false);
        if (mManagerService != null) {
        if (mManagerService != null) {
            mManagerService.unregisterAdapter(mManagerCallback);
            mManagerService.unregisterAdapter(mManagerCallback);
            mManagerService = null;
            mManagerService = null;
+16 −0
Original line number Original line Diff line number Diff line
@@ -48,11 +48,16 @@ import android.content.ContextWrapper;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Process;
import android.os.Process;
import android.os.UserManager;
import android.os.UserManager;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;


import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;


import com.android.bluetooth.flags.Flags;

import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;


@@ -80,6 +85,8 @@ public class BluetoothServiceBinderTest {


    @Rule public MockitoRule mockito = MockitoJUnit.rule().strictness(STRICT_STUBS);
    @Rule public MockitoRule mockito = MockitoJUnit.rule().strictness(STRICT_STUBS);


    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Rule public TestRule compatChangeRule = new PlatformCompatChangeRule();
    @Rule public TestRule compatChangeRule = new PlatformCompatChangeRule();


    @Mock private BluetoothManagerService mManagerService;
    @Mock private BluetoothManagerService mManagerService;
@@ -217,6 +224,7 @@ public class BluetoothServiceBinderTest {
    }
    }


    @Test
    @Test
    @DisableFlags(Flags.FLAG_GET_STATE_FROM_SYSTEM_SERVER)
    public void getState() {
    public void getState() {
        // TODO(b/280518177): add more test from not System / ...
        // TODO(b/280518177): add more test from not System / ...
        // TODO(b/280518177): add more test when caller is not in foreground
        // TODO(b/280518177): add more test when caller is not in foreground
@@ -227,6 +235,14 @@ public class BluetoothServiceBinderTest {
        verifyMock();
        verifyMock();
    }
    }


    @Test
    @EnableFlags(Flags.FLAG_GET_STATE_FROM_SYSTEM_SERVER)
    public void getStateFromSystemServer() {
        mBinder.getState();
        verify(mManagerService).getState();
        verifyMock();
    }

    @Test
    @Test
    public void getAddress() {
    public void getAddress() {
        assertThrows(NullPointerException.class, () -> mBinder.getAddress(null));
        assertThrows(NullPointerException.class, () -> mBinder.getAddress(null));