Merge "Enabling USB Debugging Connected notification on Android TV"
This commit is contained in:
committed by
Android (Google) Code Review
commit
45c87d943d
@ -3064,6 +3064,7 @@
|
||||
<string name="adb_active_notification_title">USB debugging connected</string>
|
||||
<!-- Message of notification shown when ADB is actively connected to the phone. -->
|
||||
<string name="adb_active_notification_message">Tap to disable USB debugging.</string>
|
||||
<string name="adb_active_notification_message" product="tv">Select to disable USB debugging.</string>
|
||||
|
||||
<!-- Title of notification shown to indicate that bug report is being collected. -->
|
||||
<string name="taking_remote_bugreport_notification_title">Taking bug report\u2026</string>
|
||||
@ -4468,4 +4469,6 @@
|
||||
|
||||
<!-- Channel name for DeviceStorageMonitor notifications -->
|
||||
<string name="device_storage_monitor_notification_channel">Device storage</string>
|
||||
<!-- Channel name for UsbDeviceManager adb debugging notifications -->
|
||||
<string name="adb_debugging_notification_channel_tv">USB debugging</string>
|
||||
</resources>
|
||||
|
@ -1914,6 +1914,7 @@
|
||||
<java-symbol type="string" name="smv_process" />
|
||||
<java-symbol type="string" name="tethered_notification_message" />
|
||||
<java-symbol type="string" name="tethered_notification_title" />
|
||||
<java-symbol type="string" name="adb_debugging_notification_channel_tv" />
|
||||
<java-symbol type="string" name="usb_accessory_notification_title" />
|
||||
<java-symbol type="string" name="usb_mtp_notification_title" />
|
||||
<java-symbol type="string" name="usb_charging_notification_title" />
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.android.server.usb;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -134,6 +135,8 @@ public class UsbDeviceManager {
|
||||
|
||||
private static final String BOOT_MODE_PROPERTY = "ro.bootmode";
|
||||
|
||||
private static final String ADB_NOTIFICATION_CHANNEL_ID_TV = "usbdevicemanager.adb.tv";
|
||||
|
||||
private UsbHandler mHandler;
|
||||
private boolean mBootCompleted;
|
||||
|
||||
@ -239,6 +242,16 @@ public class UsbDeviceManager {
|
||||
mNotificationManager = (NotificationManager)
|
||||
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
// Ensure that the notification channels are set up
|
||||
if (isTv()) {
|
||||
// TV-specific notification channel
|
||||
mNotificationManager.createNotificationChannel(
|
||||
new NotificationChannel(ADB_NOTIFICATION_CHANNEL_ID_TV,
|
||||
mContext.getString(
|
||||
com.android.internal.R.string.adb_debugging_notification_channel_tv),
|
||||
NotificationManager.IMPORTANCE_HIGH));
|
||||
}
|
||||
|
||||
// We do not show the USB notification if the primary volume supports mass storage.
|
||||
// The legacy mass storage UI will be used instead.
|
||||
boolean massStorageSupported = false;
|
||||
@ -325,6 +338,10 @@ public class UsbDeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTv() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
||||
}
|
||||
|
||||
private final class UsbHandler extends Handler {
|
||||
|
||||
// current USB state
|
||||
@ -928,9 +945,9 @@ public class UsbDeviceManager {
|
||||
CharSequence message = r.getText(
|
||||
com.android.internal.R.string.adb_active_notification_message);
|
||||
|
||||
Intent intent = Intent.makeRestartActivityTask(
|
||||
new ComponentName("com.android.settings",
|
||||
"com.android.settings.DevelopmentSettings"));
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
|
||||
intent, 0, null, UserHandle.CURRENT);
|
||||
|
||||
@ -947,6 +964,8 @@ public class UsbDeviceManager {
|
||||
.setContentText(message)
|
||||
.setContentIntent(pi)
|
||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||
.extend(new Notification.TvExtender()
|
||||
.setChannel(ADB_NOTIFICATION_CHANNEL_ID_TV))
|
||||
.build();
|
||||
mAdbNotificationShown = true;
|
||||
mNotificationManager.notifyAsUser(null, id, notification,
|
||||
|
Reference in New Issue
Block a user