mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 00:02:58 +03:00
autofill intent fixes
This commit is contained in:
parent
5bce95a686
commit
be9db2930f
4 changed files with 18 additions and 44 deletions
|
@ -94,8 +94,10 @@ namespace Bit.Android
|
||||||
}
|
}
|
||||||
|
|
||||||
var intent = new Intent(this, typeof(MainActivity));
|
var intent = new Intent(this, typeof(MainActivity));
|
||||||
intent.PutExtra("uri", _lastQueriedUri);
|
if(!callingIntent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
|
||||||
intent.PutExtra("ts", Java.Lang.JavaSystem.CurrentTimeMillis());
|
{
|
||||||
|
intent.PutExtra("uri", _lastQueriedUri);
|
||||||
|
}
|
||||||
StartActivityForResult(intent, requestCode);
|
StartActivityForResult(intent, requestCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace Bit.Android
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(e.EventType)
|
switch(e.EventType)
|
||||||
{
|
{
|
||||||
case EventTypes.WindowContentChanged:
|
case EventTypes.WindowContentChanged:
|
||||||
|
@ -77,13 +77,8 @@ namespace Bit.Android
|
||||||
if(passwordNodes.Any())
|
if(passwordNodes.Any())
|
||||||
{
|
{
|
||||||
var uri = GetUri(root);
|
var uri = GetUri(root);
|
||||||
if(uri != null)
|
if(uri != null && !uri.Contains(BitwardenWebsite))
|
||||||
{
|
{
|
||||||
if(uri.Contains(BitwardenWebsite))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
|
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
|
||||||
{
|
{
|
||||||
var allEditTexts = GetWindowNodes(root, e, n => EditText(n));
|
var allEditTexts = GetWindowNodes(root, e, n => EditText(n));
|
||||||
|
@ -252,18 +247,18 @@ namespace Bit.Android
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<AccessibilityNodeInfo> GetWindowNodes(AccessibilityNodeInfo n,
|
private IEnumerable<AccessibilityNodeInfo> GetWindowNodes(AccessibilityNodeInfo n,
|
||||||
AccessibilityEvent e, Func<AccessibilityNodeInfo, bool> p)
|
AccessibilityEvent e, Func<AccessibilityNodeInfo, bool> condition)
|
||||||
{
|
{
|
||||||
if(n != null)
|
if(n != null)
|
||||||
{
|
{
|
||||||
if(n.WindowId == e.WindowId && !(n.ViewIdResourceName?.StartsWith(SystemUiPackage) ?? false) && p(n))
|
if(n.WindowId == e.WindowId && !(n.ViewIdResourceName?.StartsWith(SystemUiPackage) ?? false) && condition(n))
|
||||||
{
|
{
|
||||||
yield return n;
|
yield return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < n.ChildCount; i++)
|
for(int i = 0; i < n.ChildCount; i++)
|
||||||
{
|
{
|
||||||
foreach(var node in GetWindowNodes(n.GetChild(i), e, p))
|
foreach(var node in GetWindowNodes(n.GetChild(i), e, condition))
|
||||||
{
|
{
|
||||||
yield return node;
|
yield return node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,22 +28,7 @@ namespace Bit.Android
|
||||||
|
|
||||||
protected override void OnCreate(Bundle bundle)
|
protected override void OnCreate(Bundle bundle)
|
||||||
{
|
{
|
||||||
string uri = null;
|
var uri = Intent.GetStringExtra("uri");
|
||||||
if(!Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory) && Intent.HasExtra("uri") && Intent.HasExtra("ts"))
|
|
||||||
{
|
|
||||||
var tsDiff = Java.Lang.JavaSystem.CurrentTimeMillis() - Intent.GetLongExtra("ts", 0);
|
|
||||||
if(tsDiff < 5000)
|
|
||||||
{
|
|
||||||
uri = Intent.GetStringExtra("uri");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to clear intent for future
|
|
||||||
Intent.ReplaceExtras(new Bundle());
|
|
||||||
Intent.SetAction(string.Empty);
|
|
||||||
Intent.SetData(null);
|
|
||||||
Intent.SetFlags(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!Resolver.IsSet)
|
if(!Resolver.IsSet)
|
||||||
{
|
{
|
||||||
MainApplication.SetIoc(Application);
|
MainApplication.SetIoc(Application);
|
||||||
|
@ -134,8 +119,7 @@ namespace Bit.Android
|
||||||
{
|
{
|
||||||
Parent.SetResult(Result.Ok, data);
|
Parent.SetResult(Result.Ok, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagingCenter.Send(Xamarin.Forms.Application.Current, "SetMainPage");
|
|
||||||
Finish();
|
Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ namespace Bit.App
|
||||||
private const string LastBuildKey = "LastBuild";
|
private const string LastBuildKey = "LastBuild";
|
||||||
|
|
||||||
private string _uri;
|
private string _uri;
|
||||||
private DateTime _lastMainPageSet = DateTime.MinValue;
|
|
||||||
private readonly IDatabaseService _databaseService;
|
private readonly IDatabaseService _databaseService;
|
||||||
private readonly IConnectivity _connectivity;
|
private readonly IConnectivity _connectivity;
|
||||||
private readonly IUserDialogs _userDialogs;
|
private readonly IUserDialogs _userDialogs;
|
||||||
|
@ -93,11 +92,6 @@ namespace Bit.App
|
||||||
{
|
{
|
||||||
Logout(args);
|
Logout(args);
|
||||||
});
|
});
|
||||||
|
|
||||||
MessagingCenter.Subscribe<Application>(Current, "SetMainPage", (sender) =>
|
|
||||||
{
|
|
||||||
SetMainPageFromAutofill();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async override void OnStart()
|
protected async override void OnStart()
|
||||||
|
@ -165,15 +159,14 @@ namespace Bit.App
|
||||||
{
|
{
|
||||||
if(Device.OS == TargetPlatform.Android && !string.IsNullOrWhiteSpace(_uri))
|
if(Device.OS == TargetPlatform.Android && !string.IsNullOrWhiteSpace(_uri))
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
Task.Run(() =>
|
||||||
if((now - _lastMainPageSet).Seconds <= 1)
|
|
||||||
{
|
{
|
||||||
return;
|
Device.BeginInvokeOnMainThread(() =>
|
||||||
}
|
{
|
||||||
|
Current.MainPage = new MainPage();
|
||||||
_lastMainPageSet = now;
|
_uri = null;
|
||||||
Device.BeginInvokeOnMainThread(() => MainPage = new MainPage());
|
});
|
||||||
_uri = null;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue