Enabling storage notifications on TV
Bug: 35164265 Test: Using the Sabrent 120Gb external drive and manually going through all flows Change-Id: If856cfd3b67bb97b60998d805f9ebb3d459cf28f
This commit is contained in:
@@ -3195,11 +3195,15 @@
|
||||
<string name="ext_media_unmountable_notification_title">Corrupted <xliff:g id="name" example="SD card">%s</xliff:g></string>
|
||||
<!-- Notification body when external media is unmountable (corrupt) [CHAR LIMIT=NONE] -->
|
||||
<string name="ext_media_unmountable_notification_message"><xliff:g id="name" example="SD card">%s</xliff:g> is corrupt. Tap to fix.</string>
|
||||
<!-- TV-specifiv notification body when external media is unmountable (corrupt) [CHAR LIMIT=NONE] -->
|
||||
<string name="ext_media_unmountable_notification_message" product="tv"><xliff:g id="name" example="SD card">%s</xliff:g> is corrupt. Select to fix.</string>
|
||||
|
||||
<!-- Notification title when external media is unsupported [CHAR LIMIT=30] -->
|
||||
<string name="ext_media_unsupported_notification_title">Unsupported <xliff:g id="name" example="SD card">%s</xliff:g></string>
|
||||
<!-- Notification body when external media is unsupported [CHAR LIMIT=NONE] -->
|
||||
<string name="ext_media_unsupported_notification_message">This device doesn\u2019t support this <xliff:g id="name" example="SD card">%s</xliff:g>. Tap to set up in a supported format.</string>
|
||||
<!-- TV-specific notification body when external media is unsupported [CHAR LIMIT=NONE] -->
|
||||
<string name="ext_media_unsupported_notification_message" product="tv">This device doesn\u2019t support this <xliff:g id="name" example="SD card">%s</xliff:g>. Select to set up in a supported format.</string>
|
||||
|
||||
<!-- Notification title when external media is unsafely removed [CHAR LIMIT=30] -->
|
||||
<string name="ext_media_badremoval_notification_title"><xliff:g id="name" example="SD card">%s</xliff:g> unexpectedly removed</string>
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.systemui.usb;
|
||||
import android.annotation.NonNull;
|
||||
import android.app.Notification;
|
||||
import android.app.Notification.Action;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -35,6 +36,7 @@ import android.os.storage.StorageEventListener;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.os.storage.VolumeRecord;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
@@ -181,6 +183,11 @@ public class StorageNotification extends SystemUI {
|
||||
}
|
||||
|
||||
private void updateMissingPrivateVolumes() {
|
||||
if (isTv()) {
|
||||
// On TV, TvSettings displays a modal full-screen activity in this case.
|
||||
return;
|
||||
}
|
||||
|
||||
final List<VolumeRecord> recs = mStorageManager.getVolumeRecords();
|
||||
for (VolumeRecord rec : recs) {
|
||||
if (rec.getType() != VolumeInfo.TYPE_PRIVATE) continue;
|
||||
@@ -210,7 +217,8 @@ public class StorageNotification extends SystemUI {
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.setLocalOnly(true)
|
||||
.setCategory(Notification.CATEGORY_SYSTEM)
|
||||
.setDeleteIntent(buildSnoozeIntent(fsUuid));
|
||||
.setDeleteIntent(buildSnoozeIntent(fsUuid))
|
||||
.extend(new Notification.TvExtender());
|
||||
SystemUI.overrideNotificationAppName(mContext, builder);
|
||||
|
||||
mNotificationManager.notifyAsUser(fsUuid, SystemMessage.NOTE_STORAGE_PRIVATE,
|
||||
@@ -237,7 +245,8 @@ public class StorageNotification extends SystemUI {
|
||||
.setStyle(new Notification.BigTextStyle().bigText(text))
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.setLocalOnly(true)
|
||||
.setCategory(Notification.CATEGORY_ERROR);
|
||||
.setCategory(Notification.CATEGORY_ERROR)
|
||||
.extend(new Notification.TvExtender());
|
||||
SystemUI.overrideNotificationAppName(mContext, builder);
|
||||
|
||||
mNotificationManager.notifyAsUser(disk.getId(), SystemMessage.NOTE_STORAGE_DISK,
|
||||
@@ -378,7 +387,7 @@ public class StorageNotification extends SystemUI {
|
||||
.addAction(new Action(R.drawable.ic_eject_24dp,
|
||||
mContext.getString(R.string.ext_media_unmount_action),
|
||||
buildUnmountPendingIntent(vol)))
|
||||
.setContentIntent(browseIntent)
|
||||
.setContentIntent(buildUnmountPendingIntent(vol))
|
||||
.setCategory(Notification.CATEGORY_SYSTEM);
|
||||
// Non-adoptable disks can't be snoozed.
|
||||
if (disk.isAdoptable()) {
|
||||
@@ -571,15 +580,21 @@ public class StorageNotification extends SystemUI {
|
||||
.setContentText(text)
|
||||
.setStyle(new Notification.BigTextStyle().bigText(text))
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.setLocalOnly(true);
|
||||
.setLocalOnly(true)
|
||||
.extend(new Notification.TvExtender());
|
||||
overrideNotificationAppName(mContext, builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private PendingIntent buildInitPendingIntent(DiskInfo disk) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardInit");
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction("com.android.tv.settings.action.NEW_STORAGE");
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardInit");
|
||||
}
|
||||
intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId());
|
||||
|
||||
final int requestKey = disk.getId().hashCode();
|
||||
@@ -589,8 +604,13 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildInitPendingIntent(VolumeInfo vol) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardInit");
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction("com.android.tv.settings.action.NEW_STORAGE");
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardInit");
|
||||
}
|
||||
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
|
||||
final int requestKey = vol.getId().hashCode();
|
||||
@@ -600,13 +620,23 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildUnmountPendingIntent(VolumeInfo vol) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageUnmountReceiver");
|
||||
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction("com.android.tv.settings.action.UNMOUNT_STORAGE");
|
||||
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
|
||||
final int requestKey = vol.getId().hashCode();
|
||||
return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT);
|
||||
final int requestKey = vol.getId().hashCode();
|
||||
return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageUnmountReceiver");
|
||||
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
|
||||
final int requestKey = vol.getId().hashCode();
|
||||
return PendingIntent.getBroadcastAsUser(mContext, requestKey, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
private PendingIntent buildBrowsePendingIntent(VolumeInfo vol) {
|
||||
@@ -619,17 +649,22 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildVolumeSettingsPendingIntent(VolumeInfo vol) {
|
||||
final Intent intent = new Intent();
|
||||
switch (vol.getType()) {
|
||||
case VolumeInfo.TYPE_PRIVATE:
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.Settings$PrivateVolumeSettingsActivity");
|
||||
break;
|
||||
case VolumeInfo.TYPE_PUBLIC:
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.Settings$PublicVolumeSettingsActivity");
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
|
||||
} else {
|
||||
switch (vol.getType()) {
|
||||
case VolumeInfo.TYPE_PRIVATE:
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.Settings$PrivateVolumeSettingsActivity");
|
||||
break;
|
||||
case VolumeInfo.TYPE_PUBLIC:
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.Settings$PublicVolumeSettingsActivity");
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||
|
||||
@@ -648,6 +683,7 @@ public class StorageNotification extends SystemUI {
|
||||
}
|
||||
|
||||
private PendingIntent buildForgetPendingIntent(VolumeRecord rec) {
|
||||
// Not used on TV
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.Settings$PrivateVolumeForgetActivity");
|
||||
@@ -660,8 +696,13 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildWizardMigratePendingIntent(MoveInfo move) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardMigrateProgress");
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction("com.android.tv.settings.action.MIGRATE_STORAGE");
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardMigrateProgress");
|
||||
}
|
||||
intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId);
|
||||
|
||||
final VolumeInfo vol = mStorageManager.findVolumeByQualifiedUuid(move.volumeUuid);
|
||||
@@ -674,8 +715,13 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildWizardMovePendingIntent(MoveInfo move) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardMoveProgress");
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction("com.android.tv.settings.action.MOVE_APP");
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardMoveProgress");
|
||||
}
|
||||
intent.putExtra(PackageManager.EXTRA_MOVE_ID, move.moveId);
|
||||
|
||||
return PendingIntent.getActivityAsUser(mContext, move.moveId, intent,
|
||||
@@ -684,12 +730,22 @@ public class StorageNotification extends SystemUI {
|
||||
|
||||
private PendingIntent buildWizardReadyPendingIntent(DiskInfo disk) {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardReady");
|
||||
if (isTv()) {
|
||||
intent.setPackage("com.android.tv.settings");
|
||||
intent.setAction(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
|
||||
} else {
|
||||
intent.setClassName("com.android.settings",
|
||||
"com.android.settings.deviceinfo.StorageWizardReady");
|
||||
}
|
||||
intent.putExtra(DiskInfo.EXTRA_DISK_ID, disk.getId());
|
||||
|
||||
final int requestKey = disk.getId().hashCode();
|
||||
return PendingIntent.getActivityAsUser(mContext, requestKey, intent,
|
||||
PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
|
||||
}
|
||||
|
||||
private boolean isTv() {
|
||||
PackageManager packageManager = mContext.getPackageManager();
|
||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SystemUI;
|
||||
@@ -32,6 +33,7 @@ public class NotificationChannels extends SystemUI {
|
||||
|
||||
@VisibleForTesting
|
||||
static void createAll(Context context) {
|
||||
|
||||
final NotificationManager nm = context.getSystemService(NotificationManager.class);
|
||||
nm.createNotificationChannels(Arrays.asList(
|
||||
new NotificationChannel(
|
||||
@@ -49,7 +51,9 @@ public class NotificationChannels extends SystemUI {
|
||||
new NotificationChannel(
|
||||
STORAGE,
|
||||
R.string.notification_channel_storage,
|
||||
NotificationManager.IMPORTANCE_LOW)
|
||||
isTv(context)
|
||||
? NotificationManager.IMPORTANCE_DEFAULT
|
||||
: NotificationManager.IMPORTANCE_LOW)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -57,4 +61,9 @@ public class NotificationChannels extends SystemUI {
|
||||
public void start() {
|
||||
createAll(mContext);
|
||||
}
|
||||
|
||||
private static boolean isTv(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
return packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user