summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hall Liu <hallliu@google.com> 2020-03-28 06:48:56 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-03-28 06:48:56 +0000
commit99f278fc653ea1537ab7f5e34d49c353a5d8f741 (patch)
treef22951144e1f08a0ef498544015a96b46c0e2b56
parent952697b886f1634ae81433897dd9f155bfcabc3f (diff)
parentaf25fbdb75bdfddfad7fa8b906736bc2d28cb6c0 (diff)
Merge "Mock TelephonyManager in NotificationManagerService tests." into rvc-dev
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java27
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java4
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java3
3 files changed, 18 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index ebc1bc4938d6..4aeddc89f6ed 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1870,7 +1870,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(),
@@ -2013,7 +2014,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);
@@ -2083,7 +2092,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();
@@ -8358,17 +8368,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.
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 702642045eeb..f083f0e707bd 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -132,6 +132,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;
@@ -467,7 +468,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);
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java
index 19ff683a46a1..3281c3f4cfb9 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java
@@ -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;