summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dmitri Plotnikov <dplotnikov@google.com> 2017-01-27 16:42:12 -0800
committer Dmitri Plotnikov <dplotnikov@google.com> 2017-01-30 17:11:13 -0800
commitd6bd6b9f649809dfaa2017a4ab54787a584b7748 (patch)
tree7281099a629e83d257fc2b27863808a683d78a3f
parent9e7f883a436b991eaf4eb2f6c25b76f1411b64e7 (diff)
Enabling low storage notification on Android TV
Bug: 34471528 Test: Test apk attached to the bug Change-Id: Idc96b913f1d2b67a4c52a2ecd762ee4056802d56
-rw-r--r--core/res/res/values/strings.xml2
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--services/core/java/com/android/server/storage/DeviceStorageMonitorService.java27
3 files changed, 27 insertions, 3 deletions
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index ac8c89644f95..2ab091444ed8 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -4460,4 +4460,6 @@
<!-- Category title for apps which are primarily productivity apps, such as cloud storage or workplace apps. [CHAR LIMIT=32] -->
<string name="app_category_productivity">Productivity</string>
+ <!-- Channel name for DeviceStorageMonitor notifications -->
+ <string name="device_storage_monitor_notification_channel">Device storage</string>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 25ebb876da53..a755bdb2bafb 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1880,6 +1880,7 @@
<java-symbol type="string" name="data_usage_wifi_limit_snoozed_title" />
<java-symbol type="string" name="data_usage_wifi_limit_title" />
<java-symbol type="string" name="default_wallpaper_component" />
+ <java-symbol type="string" name="device_storage_monitor_notification_channel" />
<java-symbol type="string" name="dlg_ok" />
<java-symbol type="string" name="dump_heap_notification" />
<java-symbol type="string" name="dump_heap_notification_detail" />
diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
index a3837b28b168..afdec9ffddc3 100644
--- a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
+++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
@@ -16,6 +16,7 @@
package com.android.server.storage;
+import android.app.NotificationChannel;
import com.android.server.EventLogTags;
import com.android.server.SystemService;
import com.android.server.pm.InstructionSets;
@@ -140,6 +141,8 @@ public class DeviceStorageMonitorService extends SystemService {
*/
static final String SERVICE = "devicestoragemonitor";
+ private static final String NOTIFICATION_CHANNEL_ID = SERVICE;
+
/**
* Handler that checks the amount of disk space on the device and sends a
* notification if the device runs low on disk space
@@ -365,7 +368,8 @@ public class DeviceStorageMonitorService extends SystemService {
@Override
public void onStart() {
// cache storage thresholds
- final StorageManager sm = StorageManager.from(getContext());
+ Context context = getContext();
+ final StorageManager sm = StorageManager.from(context);
mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
@@ -378,6 +382,21 @@ public class DeviceStorageMonitorService extends SystemService {
mCacheFileDeletedObserver = new CacheFileDeletedObserver();
mCacheFileDeletedObserver.startWatching();
+ // Ensure that the notification channel is set up
+ NotificationManager notificationMgr =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ PackageManager packageManager = context.getPackageManager();
+ boolean isTv = packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);
+
+ int importance = isTv
+ ? NotificationManager.IMPORTANCE_HIGH // Do not change: this is TV-specific
+ : NotificationManager.IMPORTANCE_LOW;
+ notificationMgr.createNotificationChannel(
+ new NotificationChannel(NOTIFICATION_CHANNEL_ID,
+ context.getString(
+ com.android.internal.R.string.device_storage_monitor_notification_channel),
+ importance));
+
publishBinderService(SERVICE, mRemoteService);
publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);
}
@@ -466,7 +485,7 @@ public class DeviceStorageMonitorService extends SystemService {
Intent lowMemIntent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
lowMemIntent.putExtra("memory", mFreeMem);
lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- NotificationManager mNotificationMgr =
+ NotificationManager notificationMgr =
(NotificationManager)context.getSystemService(
Context.NOTIFICATION_SERVICE);
CharSequence title = context.getText(
@@ -488,9 +507,11 @@ public class DeviceStorageMonitorService extends SystemService {
.bigText(details))
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setCategory(Notification.CATEGORY_SYSTEM)
+ .setChannel(NOTIFICATION_CHANNEL_ID)
+ .extend(new Notification.TvExtender())
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
- mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
+ notificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
UserHandle.ALL);
context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}