From 78c1b935b9844461e9b2a566994721e9ebb588f2 Mon Sep 17 00:00:00 2001 From: Tarcio Saraiva Date: Sun, 7 Jan 2018 04:18:33 +1100 Subject: [PATCH] refactor support for application overlay in api v >= 26 (#364) --- .../pwdstore/autofill/AutofillService.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java index 0a60201a..dcc74840 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java @@ -424,12 +424,7 @@ public class AutofillService extends AccessibilityService { builder.setMessage(getString(R.string.autofill_paste_username, password.getUsername())); dialog = builder.create(); - //noinspection ConstantConditions - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - } else { - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); - } + this.setDialogType(dialog); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); dialog.show(); @@ -494,8 +489,7 @@ public class AutofillService extends AccessibilityService { }); dialog = builder.create(); - //noinspection ConstantConditions - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + this.setDialogType(dialog); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); // arbitrary non-annoying size @@ -508,6 +502,15 @@ public class AutofillService extends AccessibilityService { dialog.show(); } + private void setDialogType(AlertDialog dialog) { + //noinspection ConstantConditions + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + } else { + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); + } + } + @Override public void onInterrupt() {