From 2f5e1b400449eee83ae87e0a5a9d9a509196d3d9 Mon Sep 17 00:00:00 2001 From: Heemin Seog Date: Tue, 26 Jan 2021 18:10:56 -0800 Subject: [PATCH] DO NOT MERGE Handle back button for notification panel Bug: 178504029 Test: manual Change-Id: If44048ab1772b85d13aa1f96a23eded896c53883 --- .../NotificationPanelViewController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java index fd804c71c9d0a..b83fcf4bf8b5c 100644 --- a/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java +++ b/packages/CarSystemUI/src/com/android/systemui/car/notification/NotificationPanelViewController.java @@ -28,6 +28,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.view.GestureDetector; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -245,6 +246,17 @@ public class NotificationPanelViewController extends OverlayPanelViewController mNotificationView = (CarNotificationView) LayoutInflater.from(mContext).inflate( R.layout.notification_center_activity, container, /* attachToRoot= */ false); + mNotificationView.setKeyEventHandler( + event -> { + if (event.getKeyCode() != KeyEvent.KEYCODE_BACK) { + return false; + } + + if (event.getAction() == KeyEvent.ACTION_UP && isPanelExpanded()) { + toggle(); + } + return true; + }); container.addView(mNotificationView); onNotificationViewInflated();