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

Commit 4d1f3862 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Inform UsageStatsManager about notification related events.

This change updates NotificationManagerService to inform
UsageStatsManager about notification posted/updated/cancelled
events.

Bug: 206518114
Test: atest services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
Test: atest core/tests/coretests/src/android/service/notification/StatusBarNotificationTest.java
Test: atest services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java
Test: atest cts/tests/app/src/android/app/cts/StatusBarNotificationTest.java
Change-Id: Idde09e4c72eb6a0635e4ee1c2c7e5887be170297
parent 4e508891
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -499,6 +499,7 @@ public class NotificationManagerService extends SystemService {
    private IPlatformCompat mPlatformCompat;
    private ShortcutHelper mShortcutHelper;
    private PermissionHelper mPermissionHelper;
    private UsageStatsManagerInternal mUsageStatsManagerInternal;

    final IBinder mForegroundToken = new Binder();
    private WorkerHandler mHandler;
@@ -2092,7 +2093,8 @@ public class NotificationManagerService extends SystemService {
            UserManager userManager,
            NotificationHistoryManager historyManager, StatsManager statsManager,
            TelephonyManager telephonyManager, ActivityManagerInternal ami,
            MultiRateLimiter toastRateLimiter, PermissionHelper permissionHelper) {
            MultiRateLimiter toastRateLimiter, PermissionHelper permissionHelper,
            UsageStatsManagerInternal usageStatsManagerInternal) {
        mHandler = handler;
        Resources resources = getContext().getResources();
        mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(),
@@ -2110,6 +2112,7 @@ public class NotificationManagerService extends SystemService {
        mPackageManagerClient = packageManagerClient;
        mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
        mPermissionPolicyInternal = LocalServices.getService(PermissionPolicyInternal.class);
        mUsageStatsManagerInternal = usageStatsManagerInternal;
        mAppOps = appOps;
        mAppOpsService = iAppOps;
        try {
@@ -2411,7 +2414,8 @@ public class NotificationManagerService extends SystemService {
                LocalServices.getService(ActivityManagerInternal.class),
                createToastRateLimiter(), new PermissionHelper(LocalServices.getService(
                        PermissionManagerServiceInternal.class), AppGlobals.getPackageManager(),
                        AppGlobals.getPermissionManager(), mEnableAppSettingMigration));
                        AppGlobals.getPermissionManager(), mEnableAppSettingMigration),
                LocalServices.getService(UsageStatsManagerInternal.class));

        publishBinderService(Context.NOTIFICATION_SERVICE, mService, /* allowIsolated= */ false,
                DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_NORMAL);
@@ -7259,6 +7263,8 @@ public class NotificationManagerService extends SystemService {
                    if (index < 0) {
                        mNotificationList.add(r);
                        mUsageStats.registerPostedByApp(r);
                        mUsageStatsManagerInternal.reportNotificationPosted(r.getSbn().getOpPkg(),
                                r.getSbn().getUser(), SystemClock.elapsedRealtime());
                        final boolean isInterruptive = isVisuallyInterruptive(null, r);
                        r.setInterruptive(isInterruptive);
                        r.setTextChanged(isInterruptive);
@@ -7266,6 +7272,8 @@ public class NotificationManagerService extends SystemService {
                        old = mNotificationList.get(index);  // Potentially *changes* old
                        mNotificationList.set(index, r);
                        mUsageStats.registerUpdatedByApp(r, old);
                        mUsageStatsManagerInternal.reportNotificationUpdated(r.getSbn().getOpPkg(),
                                r.getSbn().getUser(), SystemClock.elapsedRealtime());
                        // Make sure we don't lose the foreground service state.
                        notification.flags |=
                                old.getNotification().flags & FLAG_FOREGROUND_SERVICE;
@@ -8748,6 +8756,8 @@ public class NotificationManagerService extends SystemService {
            case REASON_APP_CANCEL:
            case REASON_APP_CANCEL_ALL:
                mUsageStats.registerRemovedByApp(r);
                mUsageStatsManagerInternal.reportNotificationRemoved(r.getSbn().getOpPkg(),
                        r.getUser(), SystemClock.elapsedRealtime());
                break;
        }

+1 −1
Original line number Diff line number Diff line
@@ -483,7 +483,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                mAppUsageStats, mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
                mAppOpsManager, mAppOpsService, mUm, mHistoryManager, mStatsManager,
                mock(TelephonyManager.class),
                mAmi, mToastRateLimiter, mPermissionHelper);
                mAmi, mToastRateLimiter, mPermissionHelper, mock(UsageStatsManagerInternal.class));
        // Return first true for RoleObserver main-thread check
        when(mMainLooper.isCurrentThread()).thenReturn(true).thenReturn(false);
        mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY, mMainLooper);
+2 −1
Original line number Diff line number Diff line
@@ -371,7 +371,8 @@ public class NotificationPermissionMigrationTest extends UiServiceTestCase {
                mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAtm,
                mAppUsageStats, mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal,
                mAppOpsManager, mock(IAppOpsService.class), mUm, mHistoryManager, mStatsManager,
                mock(TelephonyManager.class), mAmi, mToastRateLimiter, mPermissionHelper);
                mock(TelephonyManager.class), mAmi, mToastRateLimiter, mPermissionHelper,
                mock(UsageStatsManagerInternal.class));
        // Return first true for RoleObserver main-thread check
        when(mMainLooper.isCurrentThread()).thenReturn(true).thenReturn(false);
        mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY, mMainLooper);
+2 −1
Original line number Diff line number Diff line
@@ -166,7 +166,8 @@ public class RoleObserverTest extends UiServiceTestCase {
                    mUm, mock(NotificationHistoryManager.class),
                    mock(StatsManager.class), mock(TelephonyManager.class),
                    mock(ActivityManagerInternal.class),
                    mock(MultiRateLimiter.class), mock(PermissionHelper.class));
                    mock(MultiRateLimiter.class), mock(PermissionHelper.class),
                    mock(UsageStatsManagerInternal.class));
        } catch (SecurityException e) {
            if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) {
                throw e;