Enable Traceur notifications for AndroidTV
Add tv extender so the notifications will be displayed on AndroidTV.
Bug: 111254803
Test: Manual testing
Change-Id: Icc49c992665a6da970a8d5d6c04c62d318b5296a
diff --git a/src/com/google/android/traceur/AtraceService.java b/src/com/google/android/traceur/AtraceService.java
index 2c0f15f..08fa3ef 100644
--- a/src/com/google/android/traceur/AtraceService.java
+++ b/src/com/google/android/traceur/AtraceService.java
@@ -25,6 +25,7 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import java.io.File;
@@ -85,7 +86,7 @@
String title = context.getString(R.string.trace_is_being_recorded);
String msg = context.getString(R.string.tap_to_stop_tracing);
- Notification notification =
+ Notification.Builder notification =
new Notification.Builder(context, Receiver.NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.stat_sys_adb)
.setContentTitle(title)
@@ -96,10 +97,13 @@
.setOngoing(true)
.setLocalOnly(true)
.setColor(getColor(
- com.android.internal.R.color.system_notification_accent_color))
- .build();
+ com.android.internal.R.color.system_notification_accent_color));
- startForeground(TRACE_NOTIFICATION, notification);
+ if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
+ notification.extend(new Notification.TvExtender());
+ }
+
+ startForeground(TRACE_NOTIFICATION, notification.build());
if (AtraceUtils.atraceStart(tags, bufferSizeKb, appTracing)) {
stopForeground(Service.STOP_FOREGROUND_DETACH);
@@ -116,10 +120,11 @@
}
private void stopTracingInternal(String outputFilename) {
+ Context context = getApplicationContext();
NotificationManager notificationManager =
getSystemService(NotificationManager.class);
- Notification notification =
+ Notification.Builder notification =
new Notification.Builder(this, Receiver.NOTIFICATION_CHANNEL)
.setSmallIcon(R.drawable.stat_sys_adb)
.setContentTitle(getString(R.string.saving_trace))
@@ -127,10 +132,13 @@
.setLocalOnly(true)
.setProgress(1, 0, true)
.setColor(getColor(
- com.android.internal.R.color.system_notification_accent_color))
- .build();
+ com.android.internal.R.color.system_notification_accent_color));
- startForeground(SAVING_TRACE_NOTIFICATION, notification);
+ if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
+ notification.extend(new Notification.TvExtender());
+ }
+
+ startForeground(SAVING_TRACE_NOTIFICATION, notification.build());
notificationManager.cancel(TRACE_NOTIFICATION);
diff --git a/src/com/google/android/traceur/FileSender.java b/src/com/google/android/traceur/FileSender.java
index d38a1be..7f02109 100644
--- a/src/com/google/android/traceur/FileSender.java
+++ b/src/com/google/android/traceur/FileSender.java
@@ -24,6 +24,7 @@
import android.content.Context;
import android.support.v4.content.FileProvider;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.SystemProperties;
import android.util.Patterns;
@@ -59,6 +60,10 @@
.setColor(context.getColor(
com.android.internal.R.color.system_notification_accent_color));
+ if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
+ builder.extend(new Notification.TvExtender());
+ }
+
NotificationManager.from(context).notify(file.getName(), 0, builder.build());
}
diff --git a/src/com/google/android/traceur/Receiver.java b/src/com/google/android/traceur/Receiver.java
index 9eb1d76..e299059 100644
--- a/src/com/google/android/traceur/Receiver.java
+++ b/src/com/google/android/traceur/Receiver.java
@@ -217,6 +217,10 @@
.setColor(context.getColor(
com.android.internal.R.color.system_notification_accent_color));
+ if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
+ builder.extend(new Notification.TvExtender());
+ }
+
context.getSystemService(NotificationManager.class)
.notify(Receiver.class.getName(), 0, builder.build());
}