summaryrefslogtreecommitdiff
path: root/com/android/server/notification/NotificationManagerService.java
diff options
context:
space:
mode:
Diffstat (limited to 'com/android/server/notification/NotificationManagerService.java')
-rw-r--r--com/android/server/notification/NotificationManagerService.java84
1 files changed, 71 insertions, 13 deletions
diff --git a/com/android/server/notification/NotificationManagerService.java b/com/android/server/notification/NotificationManagerService.java
index f31ca0a2..d59c9de2 100644
--- a/com/android/server/notification/NotificationManagerService.java
+++ b/com/android/server/notification/NotificationManagerService.java
@@ -114,12 +114,14 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
+import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioManagerInternal;
import android.media.IRingtonePlayer;
+import android.metrics.LogMaker;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -394,6 +396,8 @@ public class NotificationManagerService extends SystemService {
private GroupHelper mGroupHelper;
private boolean mIsTelevision;
+ private MetricsLogger mMetricsLogger;
+
private static class Archive {
final int mBufferSize;
final ArrayDeque<StatusBarNotification> mBuffer;
@@ -492,8 +496,8 @@ public class NotificationManagerService extends SystemService {
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
for (ComponentName cn : approvedAssistants) {
try {
- getBinderService().setNotificationAssistantAccessGrantedForUser(cn,
- userId, true);
+ getBinderService().setNotificationAssistantAccessGrantedForUser(
+ cn, userId, true);
} catch (RemoteException e) {
e.printStackTrace();
}
@@ -535,6 +539,8 @@ public class NotificationManagerService extends SystemService {
mConditionProviders.migrateToXml();
savePolicyFile();
}
+
+ mAssistants.ensureAssistant();
}
private void loadPolicyFile() {
@@ -798,6 +804,18 @@ public class NotificationManagerService extends SystemService {
// Report to usage stats that notification was made visible
if (DBG) Slog.d(TAG, "Marking notification as visible " + nv.key);
reportSeen(r);
+
+ // If the newly visible notification has smart replies
+ // then log that the user has seen them.
+ if (r.getNumSmartRepliesAdded() > 0
+ && !r.hasSeenSmartReplies()) {
+ r.setSeenSmartReplies(true);
+ LogMaker logMaker = r.getLogMaker()
+ .setCategory(MetricsEvent.SMART_REPLY_VISIBLE)
+ .addTaggedData(MetricsEvent.NOTIFICATION_SMART_REPLY_COUNT,
+ r.getNumSmartRepliesAdded());
+ mMetricsLogger.write(logMaker);
+ }
}
r.setVisibility(true, nv.rank);
nv.recycle();
@@ -852,6 +870,31 @@ public class NotificationManagerService extends SystemService {
}
@Override
+ public void onNotificationSmartRepliesAdded(String key, int replyCount) {
+ synchronized (mNotificationLock) {
+ NotificationRecord r = mNotificationsByKey.get(key);
+ if (r != null) {
+ r.setNumSmartRepliesAdded(replyCount);
+ }
+ }
+ }
+
+ @Override
+ public void onNotificationSmartReplySent(String key, int replyIndex) {
+ synchronized (mNotificationLock) {
+ NotificationRecord r = mNotificationsByKey.get(key);
+ if (r != null) {
+ LogMaker logMaker = r.getLogMaker()
+ .setCategory(MetricsEvent.SMART_REPLY_ACTION)
+ .setSubtype(replyIndex);
+ mMetricsLogger.write(logMaker);
+ // Treat clicking on a smart reply as a user interaction.
+ reportUserInteraction(r);
+ }
+ }
+ }
+
+ @Override
public void onNotificationSettingsViewed(String key) {
synchronized (mNotificationLock) {
NotificationRecord r = mNotificationsByKey.get(key);
@@ -1346,6 +1389,7 @@ public class NotificationManagerService extends SystemService {
extractorNames = new String[0];
}
mUsageStats = usageStats;
+ mMetricsLogger = new MetricsLogger();
mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper());
mConditionProviders = conditionProviders;
mZenModeHelper = new ZenModeHelper(getContext(), mHandler.getLooper(), mConditionProviders);
@@ -1828,7 +1872,7 @@ public class NotificationManagerService extends SystemService {
};
int newSuppressedVisualEffects = incomingPolicy.suppressedVisualEffects;
- if (targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+ if (targetSdkVersion < Build.VERSION_CODES.P) {
// unset higher order bits introduced in P, maintain the user's higher order bits
for (int i = 0; i < effectsIntroducedInP.length ; i++) {
newSuppressedVisualEffects &= ~effectsIntroducedInP[i];
@@ -2063,7 +2107,7 @@ public class NotificationManagerService extends SystemService {
@Override
public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
- checkCallerIsSystem();
+ enforceSystemOrSystemUI("setNotificationsEnabledForPackage");
mRankingHelper.setEnabled(pkg, uid, enabled);
// Now, cancel any outstanding notifications that are part of a just-disabled app
@@ -2286,6 +2330,12 @@ public class NotificationManagerService extends SystemService {
}
@Override
+ public int getBlockedChannelCount(String pkg, int uid) {
+ enforceSystemOrSystemUI("getBlockedChannelCount");
+ return mRankingHelper.getBlockedChannelCount(pkg, uid);
+ }
+
+ @Override
public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage(
String pkg, int uid, boolean includeDeleted) {
checkCallerIsSystem();
@@ -3179,7 +3229,7 @@ public class NotificationManagerService extends SystemService {
0, UserHandle.getUserId(MY_UID));
Policy currPolicy = mZenModeHelper.getNotificationPolicy();
- if (applicationInfo.targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+ if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.P) {
int priorityCategories = policy.priorityCategories;
// ignore alarm and media values from new policy
priorityCategories &= ~Policy.PRIORITY_CATEGORY_ALARMS;
@@ -3947,9 +3997,14 @@ public class NotificationManagerService extends SystemService {
+ ", notificationUid=" + notificationUid
+ ", notification=" + notification;
Log.e(TAG, noChannelStr);
- doChannelWarningToast("Developer warning for package \"" + pkg + "\"\n" +
- "Failed to post notification on channel \"" + channelId + "\"\n" +
- "See log for more details");
+ boolean appNotificationsOff = mRankingHelper.getImportance(pkg, notificationUid)
+ == NotificationManager.IMPORTANCE_NONE;
+
+ if (!appNotificationsOff) {
+ doChannelWarningToast("Developer warning for package \"" + pkg + "\"\n" +
+ "Failed to post notification on channel \"" + channelId + "\"\n" +
+ "See log for more details");
+ }
return;
}
@@ -6134,11 +6189,14 @@ public class NotificationManagerService extends SystemService {
return !getServices().isEmpty();
}
- protected void upgradeXml(final int xmlVersion, final int userId) {
- if (xmlVersion == 0) {
- // one time approval of the OOB assistant
- Slog.d(TAG, "Approving default notification assistant for user " + userId);
- readDefaultAssistant(userId);
+ protected void ensureAssistant() {
+ final List<UserInfo> activeUsers = mUm.getUsers(true);
+ for (UserInfo userInfo : activeUsers) {
+ int userId = userInfo.getUserHandle().getIdentifier();
+ if (getAllowedPackages(userId).isEmpty()) {
+ Slog.d(TAG, "Approving default notification assistant for user " + userId);
+ readDefaultAssistant(userId);
+ }
}
}
}