Merge "Post instant app notifications to an instant apps channel" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-05-13 22:17:46 +00:00
committed by Android (Google) Code Review
4 changed files with 37 additions and 12 deletions

View File

@@ -1909,8 +1909,10 @@
<string name="notification_channel_battery">Battery</string> <string name="notification_channel_battery">Battery</string>
<!-- Title for the notification channel dedicated to screenshot progress. [CHAR LIMIT=NONE] --> <!-- Title for the notification channel dedicated to screenshot progress. [CHAR LIMIT=NONE] -->
<string name="notification_channel_screenshot">Screenshots</string> <string name="notification_channel_screenshot">Screenshots</string>
<!-- Title for the notification channel for miscellaneous notices. [CHAR LIMIT=NONE] --> <!-- Title for the notification channel for instant app notices. [CHAR LIMIT=NONE] -->
<string name="notification_channel_general">General Messages</string> <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] --> <!-- Title for the notification channel for problems with storage (i.e. low disk). [CHAR LIMIT=NONE] -->
<string name="notification_channel_storage">Storage</string> <string name="notification_channel_storage">Storage</string>
<!-- Title for the notification channel for hints and suggestions. [CHAR LIMIT=NONE] --> <!-- Title for the notification channel for hints and suggestions. [CHAR LIMIT=NONE] -->

View File

@@ -260,7 +260,7 @@ public class InstantAppNotifier extends CoreStartable
Intent browserIntent = getTaskIntent(taskId, userId); Intent browserIntent = getTaskIntent(taskId, userId);
Notification.Builder builder = Notification.Builder builder =
new Notification.Builder(mContext, NotificationChannels.GENERAL); new Notification.Builder(mContext, NotificationChannels.INSTANT);
if (browserIntent != null && browserIntent.isWebIntent()) { if (browserIntent != null && browserIntent.isWebIntent()) {
// Make sure that this doesn't resolve back to an instant app // Make sure that this doesn't resolve back to an instant app
browserIntent browserIntent

View File

@@ -35,11 +35,15 @@ import javax.inject.Inject;
public class NotificationChannels extends CoreStartable { public class NotificationChannels extends CoreStartable {
public static String ALERTS = "ALR"; public static String ALERTS = "ALR";
public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; 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 STORAGE = "DSK";
public static String BATTERY = "BAT"; public static String BATTERY = "BAT";
public static String TVPIP = TvPipNotificationController.NOTIFICATION_CHANNEL; // "TVPIP" public static String TVPIP = TvPipNotificationController.NOTIFICATION_CHANNEL; // "TVPIP"
public static String HINTS = "HNT"; public static String HINTS = "HNT";
public static String INSTANT = "INS";
public static String SETUP = "STP";
@Inject @Inject
public NotificationChannels(Context context) { public NotificationChannels(Context context) {
@@ -64,11 +68,17 @@ public class NotificationChannels extends CoreStartable {
context.getString(R.string.notification_channel_alerts), context.getString(R.string.notification_channel_alerts),
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
final NotificationChannel general = new NotificationChannel( final NotificationChannel instant = new NotificationChannel(
GENERAL, INSTANT,
context.getString(R.string.notification_channel_general), context.getString(R.string.notification_channel_instant),
NotificationManager.IMPORTANCE_MIN); 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( final NotificationChannel storage = new NotificationChannel(
STORAGE, STORAGE,
context.getString(R.string.notification_channel_storage), context.getString(R.string.notification_channel_storage),
@@ -84,7 +94,8 @@ public class NotificationChannels extends CoreStartable {
nm.createNotificationChannels(Arrays.asList( nm.createNotificationChannels(Arrays.asList(
alerts, alerts,
general, instant,
setup,
storage, storage,
createScreenshotChannel( createScreenshotChannel(
context.getString(R.string.notification_channel_screenshot)), context.getString(R.string.notification_channel_screenshot)),
@@ -123,6 +134,11 @@ public class NotificationChannels extends CoreStartable {
@Override @Override
public void start() { public void start() {
createAll(mContext); createAll(mContext);
cleanUp();
}
private void cleanUp() {
mContext.getSystemService(NotificationManager.class).deleteNotificationChannel(GENERAL);
} }
private static boolean isTv(Context context) { private static boolean isTv(Context context) {

View File

@@ -28,7 +28,6 @@ import android.util.ArraySet;
import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.util.NotificationChannels;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -41,7 +40,7 @@ import java.util.Set;
@SmallTest @SmallTest
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ChannelsTest extends SysuiTestCase { public class NotificationChannelsTest extends SysuiTestCase {
private final NotificationManager mMockNotificationManager = mock(NotificationManager.class); private final NotificationManager mMockNotificationManager = mock(NotificationManager.class);
@Before @Before
@@ -55,9 +54,10 @@ public class ChannelsTest extends SysuiTestCase {
NotificationChannels.ALERTS, NotificationChannels.ALERTS,
NotificationChannels.SCREENSHOTS_HEADSUP, NotificationChannels.SCREENSHOTS_HEADSUP,
NotificationChannels.STORAGE, NotificationChannels.STORAGE,
NotificationChannels.GENERAL, NotificationChannels.INSTANT,
NotificationChannels.BATTERY, NotificationChannels.BATTERY,
NotificationChannels.HINTS NotificationChannels.HINTS,
NotificationChannels.SETUP
)); ));
NotificationChannels.createAll(mContext); NotificationChannels.createAll(mContext);
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); 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()))); 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());
}
} }