From bcc17d91bd931a323ca061730e112385164ea7dd Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Sat, 11 Feb 2023 06:50:52 +0100 Subject: [PATCH] fix potential crash on newer Android versions when trying to close notification drawer --- .../Properties/AndroidManifest_net.xml | 4 ++-- .../Properties/AndroidManifest_nonet.xml | 4 ++-- .../services/CopyToClipboardService.cs | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/keepass2android/Properties/AndroidManifest_net.xml b/src/keepass2android/Properties/AndroidManifest_net.xml index 4d54acfc..b008d5dd 100644 --- a/src/keepass2android/Properties/AndroidManifest_net.xml +++ b/src/keepass2android/Properties/AndroidManifest_net.xml @@ -1,7 +1,7 @@  diff --git a/src/keepass2android/Properties/AndroidManifest_nonet.xml b/src/keepass2android/Properties/AndroidManifest_nonet.xml index ee2d0df0..839d80be 100644 --- a/src/keepass2android/Properties/AndroidManifest_nonet.xml +++ b/src/keepass2android/Properties/AndroidManifest_nonet.xml @@ -1,7 +1,7 @@  diff --git a/src/keepass2android/services/CopyToClipboardService.cs b/src/keepass2android/services/CopyToClipboardService.cs index 18424a78..173d9bff 100644 --- a/src/keepass2android/services/CopyToClipboardService.cs +++ b/src/keepass2android/services/CopyToClipboardService.cs @@ -241,6 +241,7 @@ namespace keepass2android .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis()) .SetTicker(entryName + ": " + desc) .SetVisibility((int)Android.App.NotificationVisibility.Secret) + .SetAutoCancel(true) .SetContentIntent(pending); if (entryIcon != null) builder.SetLargeIcon(entryIcon); @@ -951,7 +952,9 @@ namespace keepass2android { CopyToClipboardService.CopyValueToClipboardWithTimeout(context, username, false); } - context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer + + CloseNotificationDrawer(context); + } else if (action.Equals(Intents.CopyPassword)) { @@ -960,7 +963,7 @@ namespace keepass2android { CopyToClipboardService.CopyValueToClipboardWithTimeout(context, password, true); } - context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer + CloseNotificationDrawer(context); } else if (action.Equals(Intents.CopyTotp)) { @@ -969,7 +972,7 @@ namespace keepass2android { CopyToClipboardService.CopyValueToClipboardWithTimeout(context, totp, true); } - context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer + CloseNotificationDrawer(context); } else if (action.Equals(Intents.CheckKeyboard)) { @@ -977,6 +980,11 @@ namespace keepass2android } } + private static void CloseNotificationDrawer(Context context) + { + if ((int)Build.VERSION.SdkInt < 31) //sending this intent is no longer allowed since Android 31 + context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer + } }; }