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

Commit b6c83748 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Clean up mockito references

Mockito has a leak that will OOM our tests otherwise.

Also mock out handler that was running on a background thread
because once the mock clean up code exists no mocks can
be used after the completion of the test.

Also in order to debug that I started making notification tags
more clear and I've left that debugging in for the future

Test: atest
Fixes: 138642368
Change-Id: Ib63d2035bd2476e3b57963b1aefb640a70d106cc
parent 3c8783a3
Loading
Loading
Loading
Loading
+11 −14
Original line number Diff line number Diff line
@@ -457,7 +457,7 @@ public class NotificationManagerService extends SystemService {
    private static final int MY_UID = Process.myUid();
    private static final int MY_PID = Process.myPid();
    private static final IBinder WHITELIST_TOKEN = new Binder();
    private RankingHandler mRankingHandler;
    protected RankingHandler mRankingHandler;
    private long mLastOverRateLogTime;
    private float mMaxPackageEnqueueRate = DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE;

@@ -1550,11 +1550,13 @@ public class NotificationManagerService extends SystemService {

    @VisibleForTesting
    void clearNotifications() {
        synchronized (mNotificationList) {
            mEnqueuedNotifications.clear();
            mNotificationList.clear();
            mNotificationsByKey.clear();
            mSummaryByGroupKey.clear();
        }
    }

    @VisibleForTesting
    void addNotification(NotificationRecord r) {
@@ -1604,11 +1606,6 @@ public class NotificationManagerService extends SystemService {
    @VisibleForTesting
    void setPreferencesHelper(PreferencesHelper prefHelper) { mPreferencesHelper = prefHelper; }

    @VisibleForTesting
    void setRankingHandler(RankingHandler rankingHandler) {
        mRankingHandler = rankingHandler;
    }

    @VisibleForTesting
    void setZenHelper(ZenModeHelper zenHelper) {
        mZenModeHelper = zenHelper;
@@ -1641,7 +1638,7 @@ public class NotificationManagerService extends SystemService {

    // TODO: All tests should use this init instead of the one-off setters above.
    @VisibleForTesting
    void init(Looper looper, IPackageManager packageManager,
    void init(Looper looper, RankingHandler rankingHandler, IPackageManager packageManager,
            PackageManager packageManagerClient,
            LightsManager lightsManager, NotificationListeners notificationListeners,
            NotificationAssistants notificationAssistants, ConditionProviders conditionProviders,
@@ -1675,7 +1672,6 @@ public class NotificationManagerService extends SystemService {
        mUm = userManager;

        mHandler = new WorkerHandler(looper);
        mRankingThread.start();
        String[] extractorNames;
        try {
            extractorNames = resources.getStringArray(R.array.config_notificationSignalExtractors);
@@ -1684,7 +1680,7 @@ public class NotificationManagerService extends SystemService {
        }
        mUsageStats = usageStats;
        mMetricsLogger = new MetricsLogger();
        mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
        mRankingHandler = rankingHandler;
        mConditionProviders = conditionProviders;
        mZenModeHelper = new ZenModeHelper(getContext(), mHandler.getLooper(), mConditionProviders);
        mZenModeHelper.addCallback(new ZenModeHelper.Callback() {
@@ -1829,8 +1825,9 @@ public class NotificationManagerService extends SystemService {
        }, mUserProfiles);

        final File systemDir = new File(Environment.getDataDirectory(), "system");
        mRankingThread.start();

        init(Looper.myLooper(),
        init(Looper.myLooper(), new RankingHandlerWorker(mRankingThread.getLooper()),
                AppGlobals.getPackageManager(), getContext().getPackageManager(),
                getLocalService(LightsManager.class),
                new NotificationListeners(AppGlobals.getPackageManager()),
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.OBSERVE_ROLE_HOLDERS" />
    <uses-permission android:name="android.permission.GET_INTENT_SENDER_INTENT"/>
    <uses-permission android:name="android.permission.WRITE_DEVICE_CONFIG" />

    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
+7 −0
Original line number Diff line number Diff line
@@ -27,9 +27,11 @@ import androidx.test.InstrumentationRegistry;

import com.android.server.uri.UriGrantsManagerInternal;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

public class UiServiceTestCase {
@@ -77,4 +79,9 @@ public class UiServiceTestCase {
        when(mUgmInternal.checkGrantUriPermission(
                anyInt(), anyString(), any(Uri.class), anyInt(), anyInt())).thenReturn(-1);
    }

    @After
    public final void cleanUpMockito() {
        Mockito.framework().clearInlineMocks();
    }
}
+169 −123

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class RoleObserverTest extends UiServiceTestCase {
        mRoleObserver = mService.new RoleObserver(mRoleManager, mPm, mExecutor);

        try {
            mService.init(mock(Looper.class),
            mService.init(mock(Looper.class), mock(RankingHandler.class),
                    mock(IPackageManager.class), mock(PackageManager.class),
                    mock(LightsManager.class),
                    mock(NotificationListeners.class), mock(NotificationAssistants.class),