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

Commit 0580d199 authored by Will Brockman's avatar Will Brockman
Browse files

Mock TelephonyManager in NotificationManagerService tests.

This prevents NMSTest failure due to too many TelephonyService
listeners. (Because NMS never shuts down in normal use, it doesn't
unregister its listeners.)

Bug: 152241061
Test: atest NotificationManagerServiceTest RoleObserverTest BuzzBeepBlinkTest

Change-Id: Ia5988a194aff2e5a83cf15fcd422c063a3ca14f1
parent 7e4732a2
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -1868,7 +1868,8 @@ public class NotificationManagerService extends SystemService {
            ActivityTaskManagerInternal atm, UsageStatsManagerInternal appUsageStats,
            DevicePolicyManagerInternal dpm, IUriGrantsManager ugm,
            UriGrantsManagerInternal ugmInternal, AppOpsManager appOps, UserManager userManager,
            NotificationHistoryManager historyManager, StatsManager statsManager) {
            NotificationHistoryManager historyManager, StatsManager statsManager,
            TelephonyManager telephonyManager) {
        mHandler = handler;
        Resources resources = getContext().getResources();
        mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
@@ -2011,7 +2012,15 @@ public class NotificationManagerService extends SystemService {
        mInterruptionFilter = mZenModeHelper.getZenModeListenerInterruptionFilter();

        mUserProfiles.updateCache(getContext());
        listenForCallState();

        telephonyManager.listen(new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (mCallState == state) return;
                if (DBG) Slog.d(TAG, "Call state changed: " + callStateToString(state));
                mCallState = state;
            }
        }, PhoneStateListener.LISTEN_CALL_STATE);

        mSettingsObserver = new SettingsObserver(mHandler);

@@ -2081,7 +2090,8 @@ public class NotificationManagerService extends SystemService {
                getContext().getSystemService(UserManager.class),
                new NotificationHistoryManager(getContext(), handler),
                mStatsManager = (StatsManager) getContext().getSystemService(
                        Context.STATS_MANAGER));
                        Context.STATS_MANAGER),
                getContext().getSystemService(TelephonyManager.class));

        // register for various Intents
        IntentFilter filter = new IntentFilter();
@@ -8353,17 +8363,6 @@ public class NotificationManagerService extends SystemService {
        }
    }

    private void listenForCallState() {
        getContext().getSystemService(TelephonyManager.class).listen(new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                if (mCallState == state) return;
                if (DBG) Slog.d(TAG, "Call state changed: " + callStateToString(state));
                mCallState = state;
            }
        }, PhoneStateListener.LISTEN_CALL_STATE);
    }

    /**
     * Generates a NotificationRankingUpdate from 'sbns', considering only
     * notifications visible to the given listener.
+3 −1
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;
import android.service.notification.StatusBarNotification;
import android.service.notification.ZenPolicy;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableContext;
@@ -457,7 +458,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager,
                mGroupHelper, mAm, mAtm, mAppUsageStats,
                mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
                mAppOpsManager, mUm, mHistoryManager, mStatsManager);
                mAppOpsManager, mUm, mHistoryManager, mStatsManager,
                mock(TelephonyManager.class));
        mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);

        mService.setAudioManager(mAudioManager);
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.content.pm.UserInfo;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableContext;
@@ -153,7 +154,7 @@ public class RoleObserverTest extends UiServiceTestCase {
                    mock(DevicePolicyManagerInternal.class), mock(IUriGrantsManager.class),
                    mock(UriGrantsManagerInternal.class),
                    mock(AppOpsManager.class), mUm, mock(NotificationHistoryManager.class),
                    mock(StatsManager.class));
                    mock(StatsManager.class), mock(TelephonyManager.class));
        } catch (SecurityException e) {
            if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) {
                throw e;