Dismiss dialog with Escape key if closeable

At the moment the Escape key will dismiss a dialog if it's not
cancelable; however, this may not match the developer's intent,
as it is not defined in the documentation that the system may
opt to just dismiss it.

At the moment, this can still happen if the developer called
`setCanceledWhenTouchOutside(true)`, and `setCancelable(false)`
afterwards.

Escape should behave like "touching outside when possible, so
this CL implements that behavior.

Bug: 333416590
Test: Flashed on device, confirmed dialogs can still be closed
with the Escape key.
Flag: EXCEMPT bugfix

Change-Id: I7a6823744b239809024af0152eb2b77f802d851e
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index 0e20138..cd7f1e4 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -679,11 +679,13 @@
         if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
             if (mCancelable) {
                 cancel();
-            } else {
+                event.startTracking();
+                return true;
+            } else if (mWindow.shouldCloseOnTouchOutside()) {
                 dismiss();
+                event.startTracking();
+                return true;
             }
-            event.startTracking();
-            return true;
         }
 
         return false;