Post instant app notifications to an instant apps channel
'General' was too undescriptive. Since the channel's importance is fixed, and these notifications already break through DND, I don't think it's worth migrating user settings from the old channel to the new channel. Test: NotificationChannelsTest Test: run an instant app, verify channel Fixes: 225171990 Change-Id: I79b8fe015db1bd177b998752ddee8c037dbf3e1b
This commit is contained in:
@@ -1901,8 +1901,10 @@
|
||||
<string name="notification_channel_battery">Battery</string>
|
||||
<!-- Title for the notification channel dedicated to screenshot progress. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_channel_screenshot">Screenshots</string>
|
||||
<!-- Title for the notification channel for miscellaneous notices. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_channel_general">General Messages</string>
|
||||
<!-- Title for the notification channel for instant app notices. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_channel_instant">Instant Apps</string>
|
||||
<!-- Title for the notification channel for setup notices. [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_channel_setup">Setup</string>
|
||||
<!-- Title for the notification channel for problems with storage (i.e. low disk). [CHAR LIMIT=NONE] -->
|
||||
<string name="notification_channel_storage">Storage</string>
|
||||
<!-- Title for the notification channel for hints and suggestions. [CHAR LIMIT=NONE] -->
|
||||
|
||||
@@ -260,7 +260,7 @@ public class InstantAppNotifier extends CoreStartable
|
||||
|
||||
Intent browserIntent = getTaskIntent(taskId, userId);
|
||||
Notification.Builder builder =
|
||||
new Notification.Builder(mContext, NotificationChannels.GENERAL);
|
||||
new Notification.Builder(mContext, NotificationChannels.INSTANT);
|
||||
if (browserIntent != null && browserIntent.isWebIntent()) {
|
||||
// Make sure that this doesn't resolve back to an instant app
|
||||
browserIntent
|
||||
|
||||
@@ -35,11 +35,15 @@ import javax.inject.Inject;
|
||||
public class NotificationChannels extends CoreStartable {
|
||||
public static String ALERTS = "ALR";
|
||||
public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP";
|
||||
public static String GENERAL = "GEN";
|
||||
// Deprecated. Please use or create a more specific channel that users will better understand
|
||||
@Deprecated
|
||||
static String GENERAL = "GEN";
|
||||
public static String STORAGE = "DSK";
|
||||
public static String BATTERY = "BAT";
|
||||
public static String TVPIP = TvPipNotificationController.NOTIFICATION_CHANNEL; // "TVPIP"
|
||||
public static String HINTS = "HNT";
|
||||
public static String INSTANT = "INS";
|
||||
public static String SETUP = "STP";
|
||||
|
||||
@Inject
|
||||
public NotificationChannels(Context context) {
|
||||
@@ -64,11 +68,17 @@ public class NotificationChannels extends CoreStartable {
|
||||
context.getString(R.string.notification_channel_alerts),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
|
||||
final NotificationChannel general = new NotificationChannel(
|
||||
GENERAL,
|
||||
context.getString(R.string.notification_channel_general),
|
||||
final NotificationChannel instant = new NotificationChannel(
|
||||
INSTANT,
|
||||
context.getString(R.string.notification_channel_instant),
|
||||
NotificationManager.IMPORTANCE_MIN);
|
||||
|
||||
final NotificationChannel setup = new NotificationChannel(
|
||||
SETUP,
|
||||
context.getString(R.string.notification_channel_setup),
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
setup.setSound(null, null);
|
||||
|
||||
final NotificationChannel storage = new NotificationChannel(
|
||||
STORAGE,
|
||||
context.getString(R.string.notification_channel_storage),
|
||||
@@ -84,7 +94,8 @@ public class NotificationChannels extends CoreStartable {
|
||||
|
||||
nm.createNotificationChannels(Arrays.asList(
|
||||
alerts,
|
||||
general,
|
||||
instant,
|
||||
setup,
|
||||
storage,
|
||||
createScreenshotChannel(
|
||||
context.getString(R.string.notification_channel_screenshot)),
|
||||
@@ -123,6 +134,11 @@ public class NotificationChannels extends CoreStartable {
|
||||
@Override
|
||||
public void start() {
|
||||
createAll(mContext);
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
private void cleanUp() {
|
||||
mContext.getSystemService(NotificationManager.class).deleteNotificationChannel(GENERAL);
|
||||
}
|
||||
|
||||
private static boolean isTv(Context context) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.util.ArraySet;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.util.NotificationChannels;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -41,7 +40,7 @@ import java.util.Set;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ChannelsTest extends SysuiTestCase {
|
||||
public class NotificationChannelsTest extends SysuiTestCase {
|
||||
private final NotificationManager mMockNotificationManager = mock(NotificationManager.class);
|
||||
|
||||
@Before
|
||||
@@ -55,9 +54,10 @@ public class ChannelsTest extends SysuiTestCase {
|
||||
NotificationChannels.ALERTS,
|
||||
NotificationChannels.SCREENSHOTS_HEADSUP,
|
||||
NotificationChannels.STORAGE,
|
||||
NotificationChannels.GENERAL,
|
||||
NotificationChannels.INSTANT,
|
||||
NotificationChannels.BATTERY,
|
||||
NotificationChannels.HINTS
|
||||
NotificationChannels.HINTS,
|
||||
NotificationChannels.SETUP
|
||||
));
|
||||
NotificationChannels.createAll(mContext);
|
||||
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
|
||||
@@ -67,4 +67,11 @@ public class ChannelsTest extends SysuiTestCase {
|
||||
list.forEach((chan) -> assertTrue(ALL_CHANNELS.contains(chan.getId())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelCleanup() {
|
||||
new NotificationChannels(mContext).start();
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mMockNotificationManager).deleteNotificationChannel(captor.capture());
|
||||
assertEquals(NotificationChannels.GENERAL, captor.getValue());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user