DO NOT MERGE Network notifications: revamp keying scheme

This patch changes the (tag: String, id: Int) keying scheme for network
notifications so that TRON notification counters can count network
related notifications unambiguously.

TRON instruments all notifications shown for package "android" as well
as user interactions with these Notifications. These counters are
grouped by id. However the network notifications ("no internet" dialog,
"captive portal sign in" dialog, ...) use a static tag and a dynamic id
for keying notifications, preventing the counters to correctly
aggregate. In addition there is also the risk of collision with other
SystemUi notification ids not managed by NetworkNotificationManager.

In order to make the TRON counters useful for network notifications,
the id is now encoding the network notification type in a stable way
while the tag is used to uniquely identify network notifications.

Test: change covered by previously added new unit tests.
Bug: 32198726
Bug: 33030620

(cherry picked from commit fb2609d3eee1c7a4dda889c000f32183a044978a)

Change-Id: Iadf7f15da38de28587090ed0395f15c24d4ad442
This commit is contained in:
Hugo Benichi
2016-12-08 09:36:52 +09:00
parent 3ca8a0d539
commit e9c9d4bf0c
2 changed files with 70 additions and 25 deletions

View File

@@ -48,8 +48,6 @@ import static org.mockito.Mockito.when;
public class NetworkNotificationManagerTest extends TestCase {
static final String NOTIFICATION_ID = NetworkNotificationManager.NOTIFICATION_ID;
static final NetworkCapabilities CELL_CAPABILITIES = new NetworkCapabilities();
static final NetworkCapabilities WIFI_CAPABILITIES = new NetworkCapabilities();
static {
@@ -108,11 +106,11 @@ public class NetworkNotificationManagerTest extends TestCase {
}
for (int i = 0; i < ids.size(); i++) {
final int expectedId = NETWORK_ID_BASE + i;
verify(mNotificationManager, times(1))
.notifyAsUser(eq(NOTIFICATION_ID), eq(expectedId), any(), any());
verify(mNotificationManager, times(1))
.cancelAsUser(eq(NOTIFICATION_ID), eq(expectedId), any());
final int id = ids.get(i);
final int eventId = types.get(i).eventId;
final String tag = NetworkNotificationManager.tagFor(id);
verify(mNotificationManager, times(1)).notifyAsUser(eq(tag), eq(eventId), any(), any());
verify(mNotificationManager, times(1)).cancelAsUser(eq(tag), eq(eventId), any());
}
}
@@ -125,8 +123,9 @@ public class NetworkNotificationManagerTest extends TestCase {
mManager.showNotification(102, NO_INTERNET, mWifiNai, mCellNai, null, false);
verify(mNotificationManager, times(1))
.notifyAsUser(eq(NOTIFICATION_ID), eq(102), any(), any());
final int eventId = NO_INTERNET.eventId;
final String tag = NetworkNotificationManager.tagFor(102);
verify(mNotificationManager, times(1)).notifyAsUser(eq(tag), eq(eventId), any(), any());
}
@SmallTest