Loading cmds/statsd/src/atoms.proto +66 −1 Original line number Diff line number Diff line Loading @@ -396,7 +396,7 @@ message Atom { } // Pulled events will start at field 10000. // Next: 10071 // Next: 10074 oneof pulled { WifiBytesTransfer wifi_bytes_transfer = 10000 [(module) = "framework"]; WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001 [(module) = "framework"]; Loading Loading @@ -471,6 +471,12 @@ message Atom { GraphicsStats graphics_stats = 10068; RuntimeAppOpAccess runtime_app_op_access = 10069 [(module) = "framework"]; IonHeapSize ion_heap_size = 10070 [(module) = "framework"]; PackageNotificationPreferences package_notification_preferences = 10071 [(module) = "framework"]; PackageNotificationChannelPreferences package_notification_channel_preferences = 10072 [(module) = "framework"]; PackageNotificationChannelGroupPreferences package_notification_channel_group_preferences = 10073 [(module) = "framework"]; } // DO NOT USE field numbers above 100,000 in AOSP. Loading Loading @@ -5467,6 +5473,65 @@ message NotificationRemoteViews { optional NotificationRemoteViewsProto notification_remote_views = 1; } /** * Atom that contains a list of a package's preferences, pulled from NotificationManagerService.java */ message PackageNotificationPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Notification importance, which specifies when and how a notification is displayed. // Specified under core/java/android/app/NotificationManager.java. optional int32 importance = 2; // Lockscreen visibility as set by the user. optional int32 visibility = 3; // Bitfield mask indicating what fields were locked by the user (see LockableAppfields in // PreferencesHelper.java) optional int32 user_locked_fields = 4; } /** * Atom that contains a list of a package's channel preferences, pulled from * NotificationManagerService.java. */ message PackageNotificationChannelPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Channel's ID. Should always be available. optional string channel_id = 2; // Channel's name. Should always be available. optional string channel_name = 3; // Channel's description. Optionally set by the channel creator. optional string description = 4; // Notification importance, which specifies when and how a notification is displayed. Specified // under core/java/android/app/NotificationManager.java. optional int32 importance = 5; // Bitmask representing which fields have been set by the user. See field bitmask descriptions // at core/java/android/app/NotificationChannel.java optional int32 user_locked_fields = 6; // Indicates if the channel was deleted by the app. optional bool is_deleted = 7; } /** * Atom that contains a list of a package's channel group preferences, pulled from * NotificationManagerService.java. */ message PackageNotificationChannelGroupPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Channel Group's ID. Should always be available. optional string group_id = 2; // Channel Group's name. Should always be available. optional string group_name = 3; // Channel Group's description. Optionally set by group creator. optional string description = 4; // Indicates if notifications from this channel group are blocked. optional bool is_blocked = 5; // Bitmask representing which fields have been set by the user. See field bitmask descriptions // at core/java/android/app/NotificationChannelGroup.java optional int32 user_locked_fields = 6; } message PowerProfileProto { optional double cpu_suspend = 1; Loading services/core/java/com/android/server/notification/NotificationManagerService.java +65 −2 Original line number Diff line number Diff line Loading @@ -94,6 +94,9 @@ import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static com.android.internal.util.FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING; import static com.android.internal.util.FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES; import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER; Loading Loading @@ -129,6 +132,7 @@ import android.app.NotificationManager.Policy; import android.app.PendingIntent; import android.app.Person; import android.app.RemoteInput; import android.app.StatsManager; import android.app.StatusBarManager; import android.app.UriGrantsManager; import android.app.admin.DeviceAdminInfo; Loading Loading @@ -221,6 +225,7 @@ import android.util.Log; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; import android.util.StatsEvent; import android.util.Xml; import android.util.proto.ProtoOutputStream; import android.view.accessibility.AccessibilityEvent; Loading Loading @@ -474,6 +479,8 @@ public class NotificationManagerService extends SystemService { private AppOpsManager mAppOps; private UsageStatsManagerInternal mAppUsageStats; private DevicePolicyManagerInternal mDpm; private StatsManager mStatsManager; private StatsPullAtomCallbackImpl mPullAtomCallback; private Archive mArchive; Loading Loading @@ -1894,7 +1901,8 @@ public class NotificationManagerService extends SystemService { ActivityManager activityManager, GroupHelper groupHelper, IActivityManager am, UsageStatsManagerInternal appUsageStats, DevicePolicyManagerInternal dpm, IUriGrantsManager ugm, UriGrantsManagerInternal ugmInternal, AppOpsManager appOps, UserManager userManager, NotificationHistoryManager historyManager) { UserManager userManager, NotificationHistoryManager historyManager, StatsManager statsManager) { mHandler = handler; Resources resources = getContext().getResources(); mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(), Loading Loading @@ -2054,6 +2062,7 @@ public class NotificationManagerService extends SystemService { mStripRemoteViewsSizeBytes = getContext().getResources().getInteger( com.android.internal.R.integer.config_notificationStripRemoteViewSizeBytes); mStatsManager = statsManager; } @Override Loading Loading @@ -2097,7 +2106,9 @@ public class NotificationManagerService extends SystemService { LocalServices.getService(UriGrantsManagerInternal.class), (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE), getContext().getSystemService(UserManager.class), new NotificationHistoryManager(getContext(), handler)); new NotificationHistoryManager(getContext(), handler), mStatsManager = (StatsManager) getContext().getSystemService( Context.STATS_MANAGER)); // register for various Intents IntentFilter filter = new IntentFilter(); Loading Loading @@ -2172,6 +2183,57 @@ public class NotificationManagerService extends SystemService { } } private void registerNotificationPreferencesPullers() { mPullAtomCallback = new StatsPullAtomCallbackImpl(); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); } private class StatsPullAtomCallbackImpl implements StatsManager.StatsPullAtomCallback { @Override public int onPullAtom(int atomTag, List<StatsEvent> data) { switch (atomTag) { case PACKAGE_NOTIFICATION_PREFERENCES: case PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES: case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES: return pullNotificationStates(atomTag, data); default: throw new UnsupportedOperationException("Unknown tagId=" + atomTag); } } } private int pullNotificationStates(int atomTag, List<StatsEvent> data) { switch(atomTag) { case PACKAGE_NOTIFICATION_PREFERENCES: mPreferencesHelper.pullPackagePreferencesStats(data); break; case PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES: mPreferencesHelper.pullPackageChannelPreferencesStats(data); break; case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES: mPreferencesHelper.pullPackageChannelGroupPreferencesStats(data); break; } return StatsManager.PULL_SUCCESS; } private GroupHelper getGroupHelper() { mAutoGroupAtCount = getContext().getResources().getInteger(R.integer.config_autoGroupAtCount); Loading Loading @@ -2250,6 +2312,7 @@ public class NotificationManagerService extends SystemService { mRoleObserver.init(); mLauncherAppsService = (LauncherApps) getContext().getSystemService(Context.LAUNCHER_APPS_SERVICE); registerNotificationPreferencesPullers(); } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { // This observer will force an update when observe is called, causing us to // bind to listener services. Loading services/core/java/com/android/server/notification/PreferencesHelper.java +91 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,10 @@ import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading @@ -46,6 +50,7 @@ import android.util.FeatureFlagUtils; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.StatsEvent; import android.util.proto.ProtoOutputStream; import com.android.internal.R; Loading Loading @@ -80,6 +85,10 @@ public class PreferencesHelper implements RankingConfig { @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 5000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; private static final int NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT = 1000; @VisibleForTesting static final String TAG_RANKING = "ranking"; private static final String TAG_PACKAGE = "package"; Loading Loading @@ -1682,6 +1691,88 @@ public class PreferencesHelper implements RankingConfig { } } /** * Fills out {@link PackageNotificationPreferences} proto and wraps it in a {@link StatsEvent}. */ public void pullPackagePreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { for (int i = 0; i < mPackagePreferences.size(); i++) { if (i > NOTIFICATION_PREFERENCES_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_PREFERENCES); final PackagePreferences r = mPackagePreferences.valueAt(i); event.writeInt(r.uid); event.writeInt(r.importance); event.writeInt(r.visibility); event.writeInt(r.lockedAppFields); events.add(event.build()); } } } /** * Fills out {@link PackageNotificationChannelPreferences} proto and wraps it in a * {@link StatsEvent}. */ public void pullPackageChannelPreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { int totalChannelsPulled = 0; for (int i = 0; i < mPackagePreferences.size(); i++) { if (totalChannelsPulled > NOTIFICATION_CHANNEL_PULL_LIMIT) { break; } final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannel channel : r.channels.values()) { if (++totalChannelsPulled > NOTIFICATION_CHANNEL_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES); event.writeInt(r.uid); event.writeString(channel.getId()); event.writeString(channel.getName().toString()); event.writeString(channel.getDescription()); event.writeInt(channel.getImportance()); event.writeInt(channel.getUserLockedFields()); event.writeBoolean(channel.isDeleted()); events.add(event.build()); } } } } /** * Fills out {@link PackageNotificationChannelGroupPreferences} proto and wraps it in a * {@link StatsEvent}. */ public void pullPackageChannelGroupPreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { int totalGroupsPulled = 0; for (int i = 0; i < mPackagePreferences.size(); i++) { if (totalGroupsPulled > NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT) { break; } final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannelGroup groupChannel : r.groups.values()) { if (++totalGroupsPulled > NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES); event.writeInt(r.uid); event.writeString(groupChannel.getId()); event.writeString(groupChannel.getName().toString()); event.writeString(groupChannel.getDescription()); event.writeBoolean(groupChannel.isBlocked()); event.writeInt(groupChannel.getUserLockedFields()); events.add(event.build()); } } } } public JSONObject dumpJson(NotificationManagerService.DumpFilter filter) { JSONObject ranking = new JSONObject(); JSONArray PackagePreferencess = new JSONArray(); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Person; import android.app.RemoteInput; import android.app.StatsManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; Loading Loading @@ -267,6 +268,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { UserManager mUm; @Mock NotificationHistoryManager mHistoryManager; @Mock StatsManager mStatsManager; NotificationRecordLoggerFake mNotificationRecordLogger = new NotificationRecordLoggerFake(); private InstanceIdSequence mNotificationInstanceIdSequence = new InstanceIdSequenceFake( 1 << 30); Loading Loading @@ -440,7 +443,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAppUsageStats, mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal, mAppOpsManager, mUm, mHistoryManager); mAppOpsManager, mUm, mHistoryManager, mStatsManager); mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mService.setAudioManager(mAudioManager); Loading services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.IUriGrantsManager; import android.app.StatsManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.role.RoleManager; import android.app.usage.UsageStatsManagerInternal; Loading Loading @@ -142,7 +143,8 @@ public class RoleObserverTest extends UiServiceTestCase { mock(UsageStatsManagerInternal.class), mock(DevicePolicyManagerInternal.class), mock(IUriGrantsManager.class), mock(UriGrantsManagerInternal.class), mock(AppOpsManager.class), mUm, mock(NotificationHistoryManager.class)); mock(AppOpsManager.class), mUm, mock(NotificationHistoryManager.class), mock(StatsManager.class)); } catch (SecurityException e) { if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) { throw e; Loading Loading
cmds/statsd/src/atoms.proto +66 −1 Original line number Diff line number Diff line Loading @@ -396,7 +396,7 @@ message Atom { } // Pulled events will start at field 10000. // Next: 10071 // Next: 10074 oneof pulled { WifiBytesTransfer wifi_bytes_transfer = 10000 [(module) = "framework"]; WifiBytesTransferByFgBg wifi_bytes_transfer_by_fg_bg = 10001 [(module) = "framework"]; Loading Loading @@ -471,6 +471,12 @@ message Atom { GraphicsStats graphics_stats = 10068; RuntimeAppOpAccess runtime_app_op_access = 10069 [(module) = "framework"]; IonHeapSize ion_heap_size = 10070 [(module) = "framework"]; PackageNotificationPreferences package_notification_preferences = 10071 [(module) = "framework"]; PackageNotificationChannelPreferences package_notification_channel_preferences = 10072 [(module) = "framework"]; PackageNotificationChannelGroupPreferences package_notification_channel_group_preferences = 10073 [(module) = "framework"]; } // DO NOT USE field numbers above 100,000 in AOSP. Loading Loading @@ -5467,6 +5473,65 @@ message NotificationRemoteViews { optional NotificationRemoteViewsProto notification_remote_views = 1; } /** * Atom that contains a list of a package's preferences, pulled from NotificationManagerService.java */ message PackageNotificationPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Notification importance, which specifies when and how a notification is displayed. // Specified under core/java/android/app/NotificationManager.java. optional int32 importance = 2; // Lockscreen visibility as set by the user. optional int32 visibility = 3; // Bitfield mask indicating what fields were locked by the user (see LockableAppfields in // PreferencesHelper.java) optional int32 user_locked_fields = 4; } /** * Atom that contains a list of a package's channel preferences, pulled from * NotificationManagerService.java. */ message PackageNotificationChannelPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Channel's ID. Should always be available. optional string channel_id = 2; // Channel's name. Should always be available. optional string channel_name = 3; // Channel's description. Optionally set by the channel creator. optional string description = 4; // Notification importance, which specifies when and how a notification is displayed. Specified // under core/java/android/app/NotificationManager.java. optional int32 importance = 5; // Bitmask representing which fields have been set by the user. See field bitmask descriptions // at core/java/android/app/NotificationChannel.java optional int32 user_locked_fields = 6; // Indicates if the channel was deleted by the app. optional bool is_deleted = 7; } /** * Atom that contains a list of a package's channel group preferences, pulled from * NotificationManagerService.java. */ message PackageNotificationChannelGroupPreferences { // Uid under which the package is installed. optional int32 uid = 1; // Channel Group's ID. Should always be available. optional string group_id = 2; // Channel Group's name. Should always be available. optional string group_name = 3; // Channel Group's description. Optionally set by group creator. optional string description = 4; // Indicates if notifications from this channel group are blocked. optional bool is_blocked = 5; // Bitmask representing which fields have been set by the user. See field bitmask descriptions // at core/java/android/app/NotificationChannelGroup.java optional int32 user_locked_fields = 6; } message PowerProfileProto { optional double cpu_suspend = 1; Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +65 −2 Original line number Diff line number Diff line Loading @@ -94,6 +94,9 @@ import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static com.android.internal.util.FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING; import static com.android.internal.util.FrameworkStatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES; import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER; import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER; Loading Loading @@ -129,6 +132,7 @@ import android.app.NotificationManager.Policy; import android.app.PendingIntent; import android.app.Person; import android.app.RemoteInput; import android.app.StatsManager; import android.app.StatusBarManager; import android.app.UriGrantsManager; import android.app.admin.DeviceAdminInfo; Loading Loading @@ -221,6 +225,7 @@ import android.util.Log; import android.util.Pair; import android.util.Slog; import android.util.SparseArray; import android.util.StatsEvent; import android.util.Xml; import android.util.proto.ProtoOutputStream; import android.view.accessibility.AccessibilityEvent; Loading Loading @@ -474,6 +479,8 @@ public class NotificationManagerService extends SystemService { private AppOpsManager mAppOps; private UsageStatsManagerInternal mAppUsageStats; private DevicePolicyManagerInternal mDpm; private StatsManager mStatsManager; private StatsPullAtomCallbackImpl mPullAtomCallback; private Archive mArchive; Loading Loading @@ -1894,7 +1901,8 @@ public class NotificationManagerService extends SystemService { ActivityManager activityManager, GroupHelper groupHelper, IActivityManager am, UsageStatsManagerInternal appUsageStats, DevicePolicyManagerInternal dpm, IUriGrantsManager ugm, UriGrantsManagerInternal ugmInternal, AppOpsManager appOps, UserManager userManager, NotificationHistoryManager historyManager) { UserManager userManager, NotificationHistoryManager historyManager, StatsManager statsManager) { mHandler = handler; Resources resources = getContext().getResources(); mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(), Loading Loading @@ -2054,6 +2062,7 @@ public class NotificationManagerService extends SystemService { mStripRemoteViewsSizeBytes = getContext().getResources().getInteger( com.android.internal.R.integer.config_notificationStripRemoteViewSizeBytes); mStatsManager = statsManager; } @Override Loading Loading @@ -2097,7 +2106,9 @@ public class NotificationManagerService extends SystemService { LocalServices.getService(UriGrantsManagerInternal.class), (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE), getContext().getSystemService(UserManager.class), new NotificationHistoryManager(getContext(), handler)); new NotificationHistoryManager(getContext(), handler), mStatsManager = (StatsManager) getContext().getSystemService( Context.STATS_MANAGER)); // register for various Intents IntentFilter filter = new IntentFilter(); Loading Loading @@ -2172,6 +2183,57 @@ public class NotificationManagerService extends SystemService { } } private void registerNotificationPreferencesPullers() { mPullAtomCallback = new StatsPullAtomCallbackImpl(); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); mStatsManager.registerPullAtomCallback( PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES, null, // use default PullAtomMetadata values BackgroundThread.getExecutor(), mPullAtomCallback ); } private class StatsPullAtomCallbackImpl implements StatsManager.StatsPullAtomCallback { @Override public int onPullAtom(int atomTag, List<StatsEvent> data) { switch (atomTag) { case PACKAGE_NOTIFICATION_PREFERENCES: case PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES: case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES: return pullNotificationStates(atomTag, data); default: throw new UnsupportedOperationException("Unknown tagId=" + atomTag); } } } private int pullNotificationStates(int atomTag, List<StatsEvent> data) { switch(atomTag) { case PACKAGE_NOTIFICATION_PREFERENCES: mPreferencesHelper.pullPackagePreferencesStats(data); break; case PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES: mPreferencesHelper.pullPackageChannelPreferencesStats(data); break; case PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES: mPreferencesHelper.pullPackageChannelGroupPreferencesStats(data); break; } return StatsManager.PULL_SUCCESS; } private GroupHelper getGroupHelper() { mAutoGroupAtCount = getContext().getResources().getInteger(R.integer.config_autoGroupAtCount); Loading Loading @@ -2250,6 +2312,7 @@ public class NotificationManagerService extends SystemService { mRoleObserver.init(); mLauncherAppsService = (LauncherApps) getContext().getSystemService(Context.LAUNCHER_APPS_SERVICE); registerNotificationPreferencesPullers(); } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { // This observer will force an update when observe is called, causing us to // bind to listener services. Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +91 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,10 @@ import static android.app.NotificationChannel.PLACEHOLDER_CONVERSATION_ID; import static android.app.NotificationManager.IMPORTANCE_NONE; import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; Loading @@ -46,6 +50,7 @@ import android.util.FeatureFlagUtils; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.StatsEvent; import android.util.proto.ProtoOutputStream; import com.android.internal.R; Loading Loading @@ -80,6 +85,10 @@ public class PreferencesHelper implements RankingConfig { @VisibleForTesting static final int NOTIFICATION_CHANNEL_COUNT_LIMIT = 5000; private static final int NOTIFICATION_PREFERENCES_PULL_LIMIT = 1000; private static final int NOTIFICATION_CHANNEL_PULL_LIMIT = 2000; private static final int NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT = 1000; @VisibleForTesting static final String TAG_RANKING = "ranking"; private static final String TAG_PACKAGE = "package"; Loading Loading @@ -1682,6 +1691,88 @@ public class PreferencesHelper implements RankingConfig { } } /** * Fills out {@link PackageNotificationPreferences} proto and wraps it in a {@link StatsEvent}. */ public void pullPackagePreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { for (int i = 0; i < mPackagePreferences.size(); i++) { if (i > NOTIFICATION_PREFERENCES_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_PREFERENCES); final PackagePreferences r = mPackagePreferences.valueAt(i); event.writeInt(r.uid); event.writeInt(r.importance); event.writeInt(r.visibility); event.writeInt(r.lockedAppFields); events.add(event.build()); } } } /** * Fills out {@link PackageNotificationChannelPreferences} proto and wraps it in a * {@link StatsEvent}. */ public void pullPackageChannelPreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { int totalChannelsPulled = 0; for (int i = 0; i < mPackagePreferences.size(); i++) { if (totalChannelsPulled > NOTIFICATION_CHANNEL_PULL_LIMIT) { break; } final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannel channel : r.channels.values()) { if (++totalChannelsPulled > NOTIFICATION_CHANNEL_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES); event.writeInt(r.uid); event.writeString(channel.getId()); event.writeString(channel.getName().toString()); event.writeString(channel.getDescription()); event.writeInt(channel.getImportance()); event.writeInt(channel.getUserLockedFields()); event.writeBoolean(channel.isDeleted()); events.add(event.build()); } } } } /** * Fills out {@link PackageNotificationChannelGroupPreferences} proto and wraps it in a * {@link StatsEvent}. */ public void pullPackageChannelGroupPreferencesStats(List<StatsEvent> events) { synchronized (mPackagePreferences) { int totalGroupsPulled = 0; for (int i = 0; i < mPackagePreferences.size(); i++) { if (totalGroupsPulled > NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT) { break; } final PackagePreferences r = mPackagePreferences.valueAt(i); for (NotificationChannelGroup groupChannel : r.groups.values()) { if (++totalGroupsPulled > NOTIFICATION_CHANNEL_GROUP_PULL_LIMIT) { break; } StatsEvent.Builder event = StatsEvent.newBuilder() .setAtomId(PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES); event.writeInt(r.uid); event.writeString(groupChannel.getId()); event.writeString(groupChannel.getName().toString()); event.writeString(groupChannel.getDescription()); event.writeBoolean(groupChannel.isBlocked()); event.writeInt(groupChannel.getUserLockedFields()); events.add(event.build()); } } } } public JSONObject dumpJson(NotificationManagerService.DumpFilter filter) { JSONObject ranking = new JSONObject(); JSONArray PackagePreferencess = new JSONArray(); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Person; import android.app.RemoteInput; import android.app.StatsManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; Loading Loading @@ -267,6 +268,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { UserManager mUm; @Mock NotificationHistoryManager mHistoryManager; @Mock StatsManager mStatsManager; NotificationRecordLoggerFake mNotificationRecordLogger = new NotificationRecordLoggerFake(); private InstanceIdSequence mNotificationInstanceIdSequence = new InstanceIdSequenceFake( 1 << 30); Loading Loading @@ -440,7 +443,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mCompanionMgr, mSnoozeHelper, mUsageStats, mPolicyFile, mActivityManager, mGroupHelper, mAm, mAppUsageStats, mock(DevicePolicyManagerInternal.class), mUgm, mUgmInternal, mAppOpsManager, mUm, mHistoryManager); mAppOpsManager, mUm, mHistoryManager, mStatsManager); mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mService.setAudioManager(mAudioManager); Loading
services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.IActivityManager; import android.app.IUriGrantsManager; import android.app.StatsManager; import android.app.admin.DevicePolicyManagerInternal; import android.app.role.RoleManager; import android.app.usage.UsageStatsManagerInternal; Loading Loading @@ -142,7 +143,8 @@ public class RoleObserverTest extends UiServiceTestCase { mock(UsageStatsManagerInternal.class), mock(DevicePolicyManagerInternal.class), mock(IUriGrantsManager.class), mock(UriGrantsManagerInternal.class), mock(AppOpsManager.class), mUm, mock(NotificationHistoryManager.class)); mock(AppOpsManager.class), mUm, mock(NotificationHistoryManager.class), mock(StatsManager.class)); } catch (SecurityException e) { if (!e.getMessage().contains("Permission Denial: not allowed to send broadcast")) { throw e; Loading