mirror of
https://github.com/bitwarden/android.git
synced 2025-03-07 23:16:00 +03:00
Cleanup hacks because of Intent LaunchedFromHistory bug
This commit is contained in:
parent
749508871b
commit
c7af81bf0c
4 changed files with 36 additions and 66 deletions
|
@ -51,39 +51,37 @@ namespace Bit.Android
|
|||
if(data == null)
|
||||
{
|
||||
LastCredentials = null;
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
else
|
||||
{
|
||||
if(data.GetStringExtra("canceled") != null)
|
||||
try
|
||||
{
|
||||
if(data.GetStringExtra("canceled") != null)
|
||||
{
|
||||
LastCredentials = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var uri = data.GetStringExtra("uri");
|
||||
var username = data.GetStringExtra("username");
|
||||
var password = data.GetStringExtra("password");
|
||||
|
||||
LastCredentials = new AutofillCredentials
|
||||
{
|
||||
Username = username,
|
||||
Password = password,
|
||||
Uri = uri,
|
||||
LastUri = _lastQueriedUri
|
||||
};
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
LastCredentials = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var uri = data.GetStringExtra("uri");
|
||||
var username = data.GetStringExtra("username");
|
||||
var password = data.GetStringExtra("password");
|
||||
}
|
||||
|
||||
LastCredentials = new AutofillCredentials
|
||||
{
|
||||
Username = username,
|
||||
Password = password,
|
||||
Uri = uri,
|
||||
LastUri = _lastQueriedUri
|
||||
};
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
LastCredentials = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, "SetMainPage");
|
||||
Finish();
|
||||
}
|
||||
Finish();
|
||||
}
|
||||
|
||||
private void LaunchMainActivity(Intent callingIntent, int requestCode)
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Bit.Android
|
|||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
var uri = Intent.GetStringExtra("uri");
|
||||
var uri = Intent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory) ? null : Intent.GetStringExtra("uri");
|
||||
if(Intent.HasExtra("uri"))
|
||||
{
|
||||
Intent.RemoveExtra("uri");
|
||||
|
@ -99,7 +99,6 @@ namespace Bit.Android
|
|||
|
||||
private void ReturnCredentials(VaultListPageModel.Login login)
|
||||
{
|
||||
App.App.FromAutofillService = true;
|
||||
Intent data = new Intent();
|
||||
if(login == null)
|
||||
{
|
||||
|
|
|
@ -34,9 +34,6 @@ namespace Bit.App
|
|||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private readonly ILocalizeService _localizeService;
|
||||
private readonly IAppInfoService _appInfoService;
|
||||
private CancellationTokenSource _setMainPageCancellationTokenSource = null;
|
||||
|
||||
public static bool FromAutofillService { get; set; } = false;
|
||||
|
||||
public App(
|
||||
string uri,
|
||||
|
@ -68,7 +65,6 @@ namespace Bit.App
|
|||
SetCulture();
|
||||
SetStyles();
|
||||
|
||||
FromAutofillService = !string.IsNullOrWhiteSpace(_uri);
|
||||
if(authService.IsAuthenticated && _uri != null)
|
||||
{
|
||||
MainPage = new ExtendedNavigationPage(new VaultAutofillListLoginsPage(_uri));
|
||||
|
@ -98,9 +94,9 @@ namespace Bit.App
|
|||
Device.BeginInvokeOnMainThread(() => Logout(args));
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Application, int>(Current, "SetMainPage", (sender, ms) =>
|
||||
MessagingCenter.Subscribe<Application>(Current, "SetMainPage", (sender) =>
|
||||
{
|
||||
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource, ms);
|
||||
SetMainPageFromAutofill();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -109,7 +105,7 @@ namespace Bit.App
|
|||
// Handle when your app starts
|
||||
await CheckLockAsync(false);
|
||||
|
||||
if(!FromAutofillService)
|
||||
if(string.IsNullOrWhiteSpace(_uri))
|
||||
{
|
||||
var lastBuild = _settings.GetValueOrDefault<string>(LastBuildKey);
|
||||
if(lastBuild == null || lastBuild != _appInfoService.Build)
|
||||
|
@ -129,7 +125,7 @@ namespace Bit.App
|
|||
// Handle when your app sleeps
|
||||
Debug.WriteLine("OnSleep");
|
||||
|
||||
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource, 500);
|
||||
SetMainPageFromAutofill();
|
||||
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
||||
{
|
||||
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
|
||||
|
@ -159,38 +155,15 @@ namespace Bit.App
|
|||
}
|
||||
}
|
||||
|
||||
private CancellationTokenSource SetMainPageFromAutofill(CancellationTokenSource previousCts, int delay)
|
||||
private void SetMainPageFromAutofill()
|
||||
{
|
||||
if(Device.OS != TargetPlatform.Android)
|
||||
if(Device.OS != TargetPlatform.Android || string.IsNullOrWhiteSpace(_uri))
|
||||
{
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
previousCts?.Cancel();
|
||||
if(!FromAutofillService || string.IsNullOrWhiteSpace(_uri))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(delay);
|
||||
if(cts.Token.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
MainPage = new MainPage();
|
||||
});
|
||||
|
||||
_uri = null;
|
||||
FromAutofillService = false;
|
||||
}, cts.Token);
|
||||
|
||||
return cts;
|
||||
MainPage = new MainPage();
|
||||
_uri = null;
|
||||
}
|
||||
|
||||
private async Task IncrementalSyncAsync()
|
||||
|
|
|
@ -262,7 +262,7 @@ namespace Bit.App.Pages
|
|||
private void ClickedItem(object sender, EventArgs e)
|
||||
{
|
||||
_page.GoogleAnalyticsService.TrackExtensionEvent("Closed", _page.Uri.StartsWith("http") ? "Website" : "App");
|
||||
MessagingCenter.Send(Application.Current, "SetMainPage", 0);
|
||||
MessagingCenter.Send(Application.Current, "SetMainPage");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue