Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7ee7d4b authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Enabling USB Debugging Connected notification on Android TV

Bug: 34859109
Test: verified that the notification showed up in LeanbackLauncher
Change-Id: I2d5798e994df74b7d3211ccf7f22a6aff44bd681
parent d6bd6b9f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3058,6 +3058,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>
@@ -4462,4 +4463,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>
+1 −0
Original line number Diff line number Diff line
@@ -1913,6 +1913,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" />
+22 −3
Original line number Diff line number Diff line
@@ -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;

@@ -238,6 +241,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;
@@ -324,6 +337,10 @@ public class UsbDeviceManager {
        }
    }

    private boolean isTv() {
        return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
    }

    private final class UsbHandler extends Handler {

        // current USB state
@@ -918,9 +935,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);

@@ -937,6 +954,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,