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

Commit 6226c2ff authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Injecting system calls into alarm manager

Injecting and mocking dependencies to make the service unit testable.
Shuffled around initialization to make that possible.

Also added the first batch of unit tests. The idea is to have extensive
coverage of minute pieces of alarm manager logic, which should help us
catch any regressions caused by future changes to the code.

Test: atest com.android.server.AlarmManagerServiceTest
atest CtsAlarmManagerTestCases

Bug: 111454659
Change-Id: Ifa1c09646f688cf5c41abe17d98dbc19978eac70
parent 0d100c0a
Loading
Loading
Loading
Loading
+242 −164

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -878,7 +878,8 @@ public final class SystemServer {
            }

            traceBeginAndSlog("StartAlarmManagerService");
            mSystemServiceManager.startService(AlarmManagerService.class);
            mSystemServiceManager.startService(new AlarmManagerService(context));

            traceEnd();

            traceBeginAndSlog("InitWatchdog");
+6 −7
Original line number Diff line number Diff line
@@ -20,22 +20,21 @@ LOCAL_MODULE_TAGS := tests
LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_STATIC_JAVA_LIBRARIES := \
    services.core \
    services.devicepolicy \
    frameworks-base-testutils \
    services.core \
    androidx-test \
    mockito-target-extended-minus-junit4 \
    platform-test-annotations \
    ShortcutManagerTestUtils \
    compatibility-device-util \
    truth-prebuilt
    truth-prebuilt \

LOCAL_JAVA_LIBRARIES := \
    android.test.mock
LOCAL_JAVA_LIBRARIES := android.test.mock android.test.base android.test.runner

LOCAL_JNI_SHARED_LIBRARIES := \
    libdexmakerjvmtiagent \
    libstaticjvmtiagent
    libstaticjvmtiagent \

LOCAL_CERTIFICATE := platform
LOCAL_PACKAGE_NAME := FrameworksMockingServicesTests
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_COMPATIBILITY_SUITE := device-tests
+4 −1
Original line number Diff line number Diff line
@@ -17,7 +17,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.android.frameworks.mockingservicestests">

    <application android:debuggable="true">
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />

    <application android:testOnly="true"
                 android:debuggable="true">
        <uses-library android:name="android.test.runner" />
    </application>

+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <option name="cleanup-apks" value="true" />
        <option name="install-arg" value="-t" />
        <option name="test-file-name" value="FrameworksMockingServicesTests.apk" />
    </target_preparer>

Loading