diff options
author | 2024-11-18 17:16:01 +0000 | |
---|---|---|
committer | 2024-11-20 09:40:23 +0000 | |
commit | 57dd116629a04e490f1906c1728ee3473586f724 (patch) | |
tree | 81326c6a5297f548e796fa93c7024da277347692 /packages/PrintSpooler/src | |
parent | c889e1b1d159cae265de654475a6ef7ba5c9f980 (diff) |
Migrate PrintActivity to enableOnBackInvokedCallback=true
Bug: 379263789
Bug: 376407910
Test: CtsPrintTestCases
Test: Manual, i.e. verified that PrintActivity has same back navigation behaviour with and without this CL applied. (tested within Files app after `m PrintSpooler; adevice update`)
Flag: EXEMPT bugfix
Change-Id: I53a34b448b520da7193eadadef09fc2cd99debbd
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index bd2b5ec8436e..4a3a6d248254 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -84,6 +84,7 @@ import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import android.window.OnBackInvokedDispatcher; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; @@ -323,6 +324,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat }); getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this); + getWindow().getOnBackInvokedDispatcher().registerOnBackInvokedCallback( + OnBackInvokedDispatcher.PRIORITY_DEFAULT, this::onBackInvoked); } private void onConnectedToPrintSpooler(final IBinder documentAdapter) { @@ -481,17 +484,21 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE) && event.isTracking() && !event.isCanceled()) { - if (mPrintPreviewController != null && mPrintPreviewController.isOptionsOpened() - && !hasErrors()) { - mPrintPreviewController.closeOptions(); - } else { - cancelPrint(); - } + onBackInvoked(); return true; } return super.onKeyUp(keyCode, event); } + private void onBackInvoked() { + if (mPrintPreviewController != null && mPrintPreviewController.isOptionsOpened() + && !hasErrors()) { + mPrintPreviewController.closeOptions(); + } else { + cancelPrint(); + } + } + @Override public void onRequestContentUpdate() { if (canUpdateDocument()) { |