Merge "Record whether apps have sent msg notifications" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
37e724b15d
@@ -58,6 +58,7 @@ interface INotificationManager
|
||||
|
||||
void setShowBadge(String pkg, int uid, boolean showBadge);
|
||||
boolean canShowBadge(String pkg, int uid);
|
||||
boolean hasSentMessage(String pkg, int uid);
|
||||
void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled);
|
||||
/**
|
||||
* Updates the notification's enabled state. Additionally locks importance for all of the
|
||||
|
||||
@@ -2718,6 +2718,16 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
return text == null ? null : String.valueOf(text);
|
||||
}
|
||||
|
||||
protected void maybeRegisterMessageSent(NotificationRecord r) {
|
||||
Context appContext = r.getSbn().getPackageContext(getContext());
|
||||
Notification.Builder nb =
|
||||
Notification.Builder.recoverBuilder(appContext, r.getNotification());
|
||||
if (nb.getStyle() instanceof Notification.MessagingStyle) {
|
||||
mPreferencesHelper.setMessageSent(r.getSbn().getPackageName(), r.getUid());
|
||||
handleSavePolicyFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report to usage stats that the user interacted with the notification.
|
||||
@@ -3145,6 +3155,12 @@ public class NotificationManagerService extends SystemService {
|
||||
handleSavePolicyFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSentMessage(String pkg, int uid) {
|
||||
checkCallerIsSystem();
|
||||
return mPreferencesHelper.hasSentMessage(pkg, uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotificationDelegate(String callingPkg, String delegate) {
|
||||
checkCallerIsSameApp(callingPkg);
|
||||
@@ -6459,6 +6475,7 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
|
||||
maybeRecordInterruptionLocked(r);
|
||||
maybeRegisterMessageSent(r);
|
||||
|
||||
// Log event to statsd
|
||||
mNotificationRecordLogger.maybeLogNotificationPosted(r, old, position,
|
||||
|
||||
@@ -116,6 +116,7 @@ public class PreferencesHelper implements RankingConfig {
|
||||
private static final String ATT_ENABLED = "enabled";
|
||||
private static final String ATT_USER_ALLOWED = "allowed";
|
||||
private static final String ATT_HIDE_SILENT = "hide_gentle";
|
||||
private static final String ATT_SENT_MESSAGE = "sent_msg";
|
||||
|
||||
private static final int DEFAULT_PRIORITY = Notification.PRIORITY_DEFAULT;
|
||||
private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE;
|
||||
@@ -269,6 +270,8 @@ public class PreferencesHelper implements RankingConfig {
|
||||
parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE);
|
||||
r.lockedAppFields = XmlUtils.readIntAttribute(parser,
|
||||
ATT_APP_USER_LOCKED_FIELDS, DEFAULT_LOCKED_APP_FIELDS);
|
||||
r.hasSentMessage = XmlUtils.readBooleanAttribute(
|
||||
parser, ATT_SENT_MESSAGE, false);
|
||||
|
||||
final int innerDepth = parser.getDepth();
|
||||
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
|
||||
@@ -510,7 +513,8 @@ public class PreferencesHelper implements RankingConfig {
|
||||
|| r.channels.size() > 0
|
||||
|| r.groups.size() > 0
|
||||
|| r.delegate != null
|
||||
|| r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE;
|
||||
|| r.bubblePreference != DEFAULT_BUBBLE_PREFERENCE
|
||||
|| r.hasSentMessage;
|
||||
if (hasNonDefaultSettings) {
|
||||
out.startTag(null, TAG_PACKAGE);
|
||||
out.attribute(null, ATT_NAME, r.pkg);
|
||||
@@ -529,6 +533,7 @@ public class PreferencesHelper implements RankingConfig {
|
||||
out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge));
|
||||
out.attribute(null, ATT_APP_USER_LOCKED_FIELDS,
|
||||
Integer.toString(r.lockedAppFields));
|
||||
out.attribute(null, ATT_SENT_MESSAGE, Boolean.toString(r.hasSentMessage));
|
||||
|
||||
if (!forBackup) {
|
||||
out.attribute(null, ATT_UID, Integer.toString(r.uid));
|
||||
@@ -647,6 +652,18 @@ public class PreferencesHelper implements RankingConfig {
|
||||
updateConfig();
|
||||
}
|
||||
|
||||
public boolean hasSentMessage(String packageName, int uid) {
|
||||
synchronized (mPackagePreferences) {
|
||||
return getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageSent(String packageName, int uid) {
|
||||
synchronized (mPackagePreferences) {
|
||||
getOrCreatePackagePreferencesLocked(packageName, uid).hasSentMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGroupBlocked(String packageName, int uid, String groupId) {
|
||||
if (groupId == null) {
|
||||
@@ -2271,6 +2288,7 @@ public class PreferencesHelper implements RankingConfig {
|
||||
boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
|
||||
List<String> oemLockedChannels = new ArrayList<>();
|
||||
boolean defaultAppLockedImportance = DEFAULT_APP_LOCKED_IMPORTANCE;
|
||||
boolean hasSentMessage = false;
|
||||
|
||||
Delegate delegate = null;
|
||||
ArrayMap<String, NotificationChannel> channels = new ArrayMap<>();
|
||||
|
||||
@@ -6573,4 +6573,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordMessages() throws RemoteException {
|
||||
NotificationRecord nr =
|
||||
generateMessageBubbleNotifRecord(mTestNotificationChannel,
|
||||
"testRecordMessages");
|
||||
mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(),
|
||||
nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId());
|
||||
waitForIdle();
|
||||
|
||||
assertTrue(mBinderService.hasSentMessage(PKG, mUid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,6 +454,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
||||
mHelper.createNotificationChannel(PKG_O, UID_O, getChannel(), true, false);
|
||||
|
||||
mHelper.setShowBadge(PKG_N_MR1, UID_N_MR1, true);
|
||||
mHelper.setMessageSent(PKG_P, UID_P);
|
||||
|
||||
mHelper.setImportance(PKG_O, UID_O, IMPORTANCE_NONE);
|
||||
|
||||
@@ -469,6 +470,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
||||
|
||||
assertEquals(IMPORTANCE_NONE, mHelper.getImportance(PKG_O, UID_O));
|
||||
assertTrue(mHelper.canShowBadge(PKG_N_MR1, UID_N_MR1));
|
||||
assertTrue(mHelper.hasSentMessage(PKG_P, UID_P));
|
||||
assertFalse(mHelper.hasSentMessage(PKG_N_MR1, UID_N_MR1));
|
||||
assertEquals(channel1,
|
||||
mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, channel1.getId(), false));
|
||||
compareChannels(channel2,
|
||||
@@ -3390,4 +3393,17 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
||||
.NOTIFICATION_CHANNEL_CONVERSATION_DELETED,
|
||||
mLogger.get(6).event); // Delete Channel channel2 - Conversation A person calls
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageSent() {
|
||||
// create package preferences
|
||||
mHelper.canShowBadge(PKG_P, UID_P);
|
||||
|
||||
// check default value
|
||||
assertFalse(mHelper.hasSentMessage(PKG_P, UID_P));
|
||||
|
||||
// change it
|
||||
mHelper.setMessageSent(PKG_P, UID_P);
|
||||
assertTrue(mHelper.hasSentMessage(PKG_P, UID_P));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user