display notifications to allow copying TOTP to clipboard when autofilling, closes #1072

This commit is contained in:
Philipp Crocoll
2020-02-15 03:55:43 +01:00
parent 7ba17b8552
commit e51999ea1f
4 changed files with 20 additions and 15 deletions

View File

@@ -92,7 +92,7 @@ namespace keepass2android
{ {
public const String KeyEntry = "entry"; public const String KeyEntry = "entry";
public const String KeyRefreshPos = "refresh_pos"; public const String KeyRefreshPos = "refresh_pos";
public const String KeyCloseAfterCreate = "close_after_create"; public const String KeyActivateKeyboard = "activate_keyboard";
public const String KeyGroupFullPath = "groupfullpath_key"; public const String KeyGroupFullPath = "groupfullpath_key";
public const int requestCodeBinaryFilename = 42376; public const int requestCodeBinaryFilename = 42376;
@@ -480,13 +480,13 @@ namespace keepass2android
internal void StartNotificationsService(bool closeAfterCreate) internal void StartNotificationsService(bool activateKeyboard)
{ {
Intent showNotIntent = new Intent(this, typeof (CopyToClipboardService)); Intent showNotIntent = new Intent(this, typeof (CopyToClipboardService));
showNotIntent.SetAction(Intents.ShowNotification); showNotIntent.SetAction(Intents.ShowNotification);
showNotIntent.PutExtra(KeyEntry, new ElementAndDatabaseId(App.Kp2a.CurrentDb, Entry).FullId); showNotIntent.PutExtra(KeyEntry, new ElementAndDatabaseId(App.Kp2a.CurrentDb, Entry).FullId);
_appTask.PopulatePasswordAccessServiceIntent(showNotIntent); _appTask.PopulatePasswordAccessServiceIntent(showNotIntent);
showNotIntent.PutExtra(KeyCloseAfterCreate, closeAfterCreate); showNotIntent.PutExtra(KeyActivateKeyboard, activateKeyboard);
StartService(showNotIntent); StartService(showNotIntent);
} }

View File

@@ -511,6 +511,7 @@ namespace keepass2android
{ {
ShowUserNotifications = ShowUserNotificationsMode.Always; ShowUserNotifications = ShowUserNotificationsMode.Always;
CloseAfterCreate = true; CloseAfterCreate = true;
ActivateKeyboard = true;
} }
public const String ShowUserNotificationsKey = "ShowUserNotifications"; public const String ShowUserNotificationsKey = "ShowUserNotifications";
@@ -520,14 +521,17 @@ namespace keepass2android
public ShowUserNotificationsMode ShowUserNotifications { get; set; } public ShowUserNotificationsMode ShowUserNotifications { get; set; }
public const String CloseAfterCreateKey = "CloseAfterCreate"; public const String CloseAfterCreateKey = "CloseAfterCreate";
public const String ActivateKeyboardKey = "ActivateKeyboard";
public bool CloseAfterCreate { get; set; } public bool CloseAfterCreate { get; set; }
public bool ActivateKeyboard { get; set; }
public override void Setup(Bundle b) public override void Setup(Bundle b)
{ {
ShowUserNotifications = (ShowUserNotificationsMode) GetIntFromBundle(b, ShowUserNotificationsKey, (int)ShowUserNotificationsMode.Always); ShowUserNotifications = (ShowUserNotificationsMode) GetIntFromBundle(b, ShowUserNotificationsKey, (int)ShowUserNotificationsMode.Always);
CloseAfterCreate = GetBoolFromBundle(b, CloseAfterCreateKey, true); CloseAfterCreate = GetBoolFromBundle(b, CloseAfterCreateKey, true);
ActivateKeyboard = GetBoolFromBundle(b, ActivateKeyboardKey, true);
} }
@@ -537,6 +541,7 @@ namespace keepass2android
{ {
yield return new StringExtra { Key = ShowUserNotificationsKey, Value = ((int)ShowUserNotifications).ToString() }; yield return new StringExtra { Key = ShowUserNotificationsKey, Value = ((int)ShowUserNotifications).ToString() };
yield return new StringExtra { Key = CloseAfterCreateKey, Value = CloseAfterCreate.ToString() }; yield return new StringExtra { Key = CloseAfterCreateKey, Value = CloseAfterCreate.ToString() };
yield return new StringExtra { Key = ActivateKeyboardKey, Value = ActivateKeyboard.ToString() };
} }
} }
@@ -550,7 +555,7 @@ namespace keepass2android
|| ((ShowUserNotifications == ShowUserNotificationsMode.WhenTotp) && new Kp2aTotp().TryGetAdapter(new PwEntryOutput(activity.Entry, App.Kp2a.CurrentDb)) != null)) || ((ShowUserNotifications == ShowUserNotificationsMode.WhenTotp) && new Kp2aTotp().TryGetAdapter(new PwEntryOutput(activity.Entry, App.Kp2a.CurrentDb)) != null))
{ {
//show the notifications //show the notifications
activity.StartNotificationsService(CloseAfterCreate); activity.StartNotificationsService(ActivateKeyboard);
} }
else else
{ {

View File

@@ -347,8 +347,8 @@ namespace keepass2android
if (intent.Action == Intents.ShowNotification) if (intent.Action == Intents.ShowNotification)
{ {
//first time opening the entry -> bring up the notifications //first time opening the entry -> bring up the notifications
bool closeAfterCreate = intent.GetBooleanExtra(EntryActivity.KeyCloseAfterCreate, false); bool activateKeyboard = intent.GetBooleanExtra(EntryActivity.KeyActivateKeyboard, false);
DisplayAccessNotifications(entry, closeAfterCreate, searchUrl); DisplayAccessNotifications(entry, activateKeyboard, searchUrl);
} }
else //UpdateKeyboard else //UpdateKeyboard
{ {
@@ -429,7 +429,7 @@ namespace keepass2android
public void DisplayAccessNotifications(PwEntryOutput entry, bool closeAfterCreate, string searchUrl) public void DisplayAccessNotifications(PwEntryOutput entry, bool activateKeyboard, string searchUrl)
{ {
var hadKeyboardData = ClearNotifications(); var hadKeyboardData = ClearNotifications();
@@ -483,7 +483,7 @@ namespace keepass2android
{ {
//switch rooted //switch rooted
bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false); bool onlySwitchOnSearch = prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key), false);
if (closeAfterCreate || (!onlySwitchOnSearch)) if (activateKeyboard || (!onlySwitchOnSearch))
{ {
ActivateKp2aKeyboard(); ActivateKp2aKeyboard();
} }
@@ -492,7 +492,7 @@ namespace keepass2android
{ {
//if the app is about to be closed again (e.g. after searching for a URL and returning to the browser: //if the app is about to be closed again (e.g. after searching for a URL and returning to the browser:
// automatically bring up the Keyboard selection dialog // automatically bring up the Keyboard selection dialog
if ((closeAfterCreate) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default))) if ((activateKeyboard) && prefs.GetBoolean(GetString(Resource.String.OpenKp2aKeyboardAutomatically_key), Resources.GetBoolean(Resource.Boolean.OpenKp2aKeyboardAutomatically_default)))
{ {
ActivateKp2aKeyboard(); ActivateKp2aKeyboard();
} }

View File

@@ -30,7 +30,7 @@ namespace keepass2android.services.Kp2aAutofill
//will return the results later //will return the results later
Intent i = new Intent(this, typeof(SelectCurrentDbActivity)); Intent i = new Intent(this, typeof(SelectCurrentDbActivity));
//don't show user notifications when an entry is opened. //don't show user notifications when an entry is opened.
var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp, AutoReturnFromQuery = autoReturnFromQuery }; var task = new SearchUrlTask() { UrlToSearchFor = requestedUrl, ShowUserNotifications = ShowUserNotificationsMode.WhenTotp, AutoReturnFromQuery = autoReturnFromQuery, ActivateKeyboard = false };
task.ToIntent(i); task.ToIntent(i);
return i; return i;
} }