Merge "Log usage of addPerson() and setStyle() in notifications." into qt-dev
am: 029190c1bc
Change-Id: If5b6463d6c44df9660088e14b6357321c85c095d
This commit is contained in:
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.UnsupportedAppUsage;
|
import android.annotation.UnsupportedAppUsage;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.app.Person;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -32,6 +33,8 @@ import android.os.UserHandle;
|
|||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class encapsulating a Notification. Sent by the NotificationManagerService to clients including
|
* Class encapsulating a Notification. Sent by the NotificationManagerService to clients including
|
||||||
* the status bar and any {@link android.service.notification.NotificationListenerService}s.
|
* the status bar and any {@link android.service.notification.NotificationListenerService}s.
|
||||||
@@ -166,6 +169,7 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if application asked that this notification be part of a group.
|
* Returns true if application asked that this notification be part of a group.
|
||||||
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean isAppGroup() {
|
public boolean isAppGroup() {
|
||||||
@@ -203,18 +207,16 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final @android.annotation.NonNull Parcelable.Creator<StatusBarNotification> CREATOR
|
public static final @android.annotation.NonNull
|
||||||
= new Parcelable.Creator<StatusBarNotification>()
|
Parcelable.Creator<StatusBarNotification> CREATOR =
|
||||||
{
|
new Parcelable.Creator<StatusBarNotification>() {
|
||||||
public StatusBarNotification createFromParcel(Parcel parcel)
|
public StatusBarNotification createFromParcel(Parcel parcel) {
|
||||||
{
|
return new StatusBarNotification(parcel);
|
||||||
return new StatusBarNotification(parcel);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public StatusBarNotification[] newArray(int size)
|
public StatusBarNotification[] newArray(int size) {
|
||||||
{
|
return new StatusBarNotification[size];
|
||||||
return new StatusBarNotification[size];
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,14 +245,16 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
this.key, this.notification);
|
this.key, this.notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convenience method to check the notification's flags for
|
/**
|
||||||
|
* Convenience method to check the notification's flags for
|
||||||
* {@link Notification#FLAG_ONGOING_EVENT}.
|
* {@link Notification#FLAG_ONGOING_EVENT}.
|
||||||
*/
|
*/
|
||||||
public boolean isOngoing() {
|
public boolean isOngoing() {
|
||||||
return (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0;
|
return (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convenience method to check the notification's flags for
|
/**
|
||||||
|
* Convenience method to check the notification's flags for
|
||||||
* either {@link Notification#FLAG_ONGOING_EVENT} or
|
* either {@link Notification#FLAG_ONGOING_EVENT} or
|
||||||
* {@link Notification#FLAG_NO_CLEAR}.
|
* {@link Notification#FLAG_NO_CLEAR}.
|
||||||
*/
|
*/
|
||||||
@@ -274,13 +278,15 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
return pkg;
|
return pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The id supplied to {@link android.app.NotificationManager#notify(int,Notification)}. */
|
/** The id supplied to {@link android.app.NotificationManager#notify(int, Notification)}. */
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The tag supplied to {@link android.app.NotificationManager#notify(int,Notification)},
|
/**
|
||||||
* or null if no tag was specified. */
|
* The tag supplied to {@link android.app.NotificationManager#notify(int, Notification)},
|
||||||
|
* or null if no tag was specified.
|
||||||
|
*/
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@@ -307,8 +313,10 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
return initialPid;
|
return initialPid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The {@link android.app.Notification} supplied to
|
/**
|
||||||
* {@link android.app.NotificationManager#notify(int,Notification)}. */
|
* The {@link android.app.Notification} supplied to
|
||||||
|
* {@link android.app.NotificationManager#notify(int, Notification)}.
|
||||||
|
*/
|
||||||
public Notification getNotification() {
|
public Notification getNotification() {
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
@@ -320,7 +328,8 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The time (in {@link System#currentTimeMillis} time) the notification was posted,
|
/**
|
||||||
|
* The time (in {@link System#currentTimeMillis} time) the notification was posted,
|
||||||
* which may be different than {@link android.app.Notification#when}.
|
* which may be different than {@link android.app.Notification#when}.
|
||||||
*/
|
*/
|
||||||
public long getPostTime() {
|
public long getPostTime() {
|
||||||
@@ -343,6 +352,7 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID passed to setGroup(), or the override, or null.
|
* The ID passed to setGroup(), or the override, or null.
|
||||||
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
@@ -398,10 +408,11 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a LogMaker that contains all basic information of the notification.
|
* Returns a LogMaker that contains all basic information of the notification.
|
||||||
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public LogMaker getLogMaker() {
|
public LogMaker getLogMaker() {
|
||||||
return new LogMaker(MetricsEvent.VIEW_UNKNOWN).setPackageName(getPackageName())
|
LogMaker logMaker = new LogMaker(MetricsEvent.VIEW_UNKNOWN).setPackageName(getPackageName())
|
||||||
.addTaggedData(MetricsEvent.NOTIFICATION_ID, getId())
|
.addTaggedData(MetricsEvent.NOTIFICATION_ID, getId())
|
||||||
.addTaggedData(MetricsEvent.NOTIFICATION_TAG, getTag())
|
.addTaggedData(MetricsEvent.NOTIFICATION_TAG, getTag())
|
||||||
.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID, getChannelIdLogTag())
|
.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_ID, getChannelIdLogTag())
|
||||||
@@ -410,6 +421,21 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
getNotification().isGroupSummary() ? 1 : 0)
|
getNotification().isGroupSummary() ? 1 : 0)
|
||||||
.addTaggedData(MetricsProto.MetricsEvent.FIELD_NOTIFICATION_CATEGORY,
|
.addTaggedData(MetricsProto.MetricsEvent.FIELD_NOTIFICATION_CATEGORY,
|
||||||
getNotification().category);
|
getNotification().category);
|
||||||
|
if (getNotification().extras != null) {
|
||||||
|
// Log the style used, if present. We only log the hash here, as notification log
|
||||||
|
// events are frequent, while there are few styles (hence low chance of collisions).
|
||||||
|
String template = getNotification().extras.getString(Notification.EXTRA_TEMPLATE);
|
||||||
|
if (template != null && !template.isEmpty()) {
|
||||||
|
logMaker.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_STYLE,
|
||||||
|
template.hashCode());
|
||||||
|
}
|
||||||
|
ArrayList<Person> people = getNotification().extras.getParcelableArrayList(
|
||||||
|
Notification.EXTRA_PEOPLE_LIST);
|
||||||
|
if (people != null && !people.isEmpty()) {
|
||||||
|
logMaker.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_PEOPLE, people.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return logMaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getGroupLogTag() {
|
private String getGroupLogTag() {
|
||||||
@@ -433,6 +459,6 @@ public class StatusBarNotification implements Parcelable {
|
|||||||
}
|
}
|
||||||
String hash = Integer.toHexString(logTag.hashCode());
|
String hash = Integer.toHexString(logTag.hashCode());
|
||||||
return logTag.substring(0, MAX_LOG_TAG_LENGTH - hash.length() - 1) + "-"
|
return logTag.substring(0, MAX_LOG_TAG_LENGTH - hash.length() - 1) + "-"
|
||||||
+ hash;
|
+ hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.Person;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -87,6 +88,9 @@ public class StatusBarNotificationTest {
|
|||||||
assertEquals(0,
|
assertEquals(0,
|
||||||
logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY));
|
logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_SUMMARY));
|
||||||
assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CATEGORY));
|
assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_CATEGORY));
|
||||||
|
assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_STYLE));
|
||||||
|
assertNull(logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_PEOPLE));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Verify that modifying the returned logMaker won't leave stale data behind for
|
/** Verify that modifying the returned logMaker won't leave stale data behind for
|
||||||
@@ -159,6 +163,24 @@ public class StatusBarNotificationTest {
|
|||||||
sbn.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID));
|
sbn.getLogMaker().getTaggedData(MetricsEvent.FIELD_NOTIFICATION_GROUP_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogMakerWithPerson() {
|
||||||
|
Notification.Builder builder = getNotificationBuilder(GROUP_ID_1, CHANNEL_ID)
|
||||||
|
.addPerson(new Person.Builder().build());
|
||||||
|
final LogMaker logMaker = getNotification(PKG, builder).getLogMaker();
|
||||||
|
assertEquals(1,
|
||||||
|
logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_PEOPLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogMakerWithStyle() {
|
||||||
|
Notification.Builder builder = getNotificationBuilder(GROUP_ID_1, CHANNEL_ID)
|
||||||
|
.setStyle(new Notification.MessagingStyle(new Person.Builder().build()));
|
||||||
|
final LogMaker logMaker = getNotification(PKG, builder).getLogMaker();
|
||||||
|
assertEquals("android.app.Notification$MessagingStyle".hashCode(),
|
||||||
|
logMaker.getTaggedData(MetricsEvent.FIELD_NOTIFICATION_STYLE));
|
||||||
|
}
|
||||||
|
|
||||||
private StatusBarNotification getNotification(String pkg, String group, String channelId) {
|
private StatusBarNotification getNotification(String pkg, String group, String channelId) {
|
||||||
return getNotification(pkg, getNotificationBuilder(group, channelId));
|
return getNotification(pkg, getNotificationBuilder(group, channelId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7388,6 +7388,15 @@ message MetricsEvent {
|
|||||||
// CATEGORY: NOTIFICATION
|
// CATEGORY: NOTIFICATION
|
||||||
MEDIA_NOTIFICATION_SEEKBAR = 1743;
|
MEDIA_NOTIFICATION_SEEKBAR = 1743;
|
||||||
|
|
||||||
|
// Custom tag for StatusBarNotification. Length of
|
||||||
|
// Notification.extras[EXTRA_PEOPLE_LIST], set by addPerson().
|
||||||
|
FIELD_NOTIFICATION_PEOPLE = 1744;
|
||||||
|
|
||||||
|
// Custom tag for StatusBarNotification. The Java hashcode of
|
||||||
|
// Notification.extras[EXTRA_TEMPLATE], which is a string like
|
||||||
|
// android.app.Notification$MessagingStyle, set by setStyle().
|
||||||
|
FIELD_NOTIFICATION_STYLE = 1745;
|
||||||
|
|
||||||
// ---- End Q Constants, all Q constants go above this line ----
|
// ---- End Q Constants, all Q constants go above this line ----
|
||||||
// Add new aosp constants above this line.
|
// Add new aosp constants above this line.
|
||||||
// END OF AOSP CONSTANTS
|
// END OF AOSP CONSTANTS
|
||||||
|
|||||||
Reference in New Issue
Block a user