From ce42134828da4794042112204e854d3a61c78672 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Mon, 13 Mar 2017 15:44:41 -0700 Subject: [PATCH] Enabling bugreport notifications on TV Bug: 36175844 Test: by generating a bugreport (long-press DPAD_CENTER + BACK) Test: verified that BugreportProgressServiceTest still passes Change-Id: If5bf53512c60a359838aa76dc61b90d4e67a45df --- .../res/drawable/ic_bug_report_black_24dp.xml | 9 ++++++++ packages/Shell/res/values/strings.xml | 7 ++++-- .../shell/BugreportProgressService.java | 23 ++++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 packages/Shell/res/drawable/ic_bug_report_black_24dp.xml diff --git a/packages/Shell/res/drawable/ic_bug_report_black_24dp.xml b/packages/Shell/res/drawable/ic_bug_report_black_24dp.xml new file mode 100644 index 0000000000000..a102ceef3e307 --- /dev/null +++ b/packages/Shell/res/drawable/ic_bug_report_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/packages/Shell/res/values/strings.xml b/packages/Shell/res/values/strings.xml index 2a5703a37d9e8..1c49a55d4f3bc 100644 --- a/packages/Shell/res/values/strings.xml +++ b/packages/Shell/res/values/strings.xml @@ -4,9 +4,9 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,6 +16,9 @@ Shell + + Bug reports + Bug report #%d is being generated diff --git a/packages/Shell/src/com/android/shell/BugreportProgressService.java b/packages/Shell/src/com/android/shell/BugreportProgressService.java index 1df626ff9a2f4..bf5e6f8590cc6 100644 --- a/packages/Shell/src/com/android/shell/BugreportProgressService.java +++ b/packages/Shell/src/com/android/shell/BugreportProgressService.java @@ -57,6 +57,7 @@ import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Notification; import android.app.Notification.Action; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -64,6 +65,7 @@ import android.content.ClipData; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Bitmap; import android.net.Uri; @@ -196,6 +198,8 @@ public class BugreportProgressService extends Service { */ private static final String SCREENSHOT_DIR = "bugreports"; + private static final String NOTIFICATION_CHANNEL_ID = "bugreports"; + /** Managed dumpstate processes (keyed by id) */ private final SparseArray mProcesses = new SparseArray<>(); @@ -240,6 +244,12 @@ public class BugreportProgressService extends Service { final Configuration conf = mContext.getResources().getConfiguration(); mIsWatch = (conf.uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH; + NotificationManager nm = NotificationManager.from(mContext); + nm.createNotificationChannel( + new NotificationChannel(NOTIFICATION_CHANNEL_ID, + mContext.getString(R.string.bugreport_notification_channel), + isTv(this) ? NotificationManager.IMPORTANCE_DEFAULT + : NotificationManager.IMPORTANCE_LOW)); } @Override @@ -1008,13 +1018,16 @@ public class BugreportProgressService extends Service { sNotificationBundle.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, context.getString(com.android.internal.R.string.android_system_label)); } - return new Notification.Builder(context) + return new Notification.Builder(context, NOTIFICATION_CHANNEL_ID) .addExtras(sNotificationBundle) .setCategory(Notification.CATEGORY_SYSTEM) - .setSmallIcon(com.android.internal.R.drawable.stat_sys_adb) + .setSmallIcon( + isTv(context) ? R.drawable.ic_bug_report_black_24dp + : com.android.internal.R.drawable.stat_sys_adb) .setLocalOnly(true) .setColor(context.getColor( - com.android.internal.R.color.system_notification_accent_color)); + com.android.internal.R.color.system_notification_accent_color)) + .extend(new Notification.TvExtender()); } /** @@ -1333,6 +1346,10 @@ public class BugreportProgressService extends Service { return false; } + private static boolean isTv(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); + } + /** * Checks whether a character is valid on bugreport names. */