mirror of
https://github.com/bitwarden/mobile.git
synced 2025-03-09 12:49:10 +01:00
Cleanup hacks because of Intent LaunchedFromHistory bug
This commit is contained in:
parent
749508871b
commit
c7af81bf0c
@ -51,39 +51,37 @@ namespace Bit.Android
|
|||||||
if(data == null)
|
if(data == null)
|
||||||
{
|
{
|
||||||
LastCredentials = null;
|
LastCredentials = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
try
|
|
||||||
{
|
{
|
||||||
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;
|
LastCredentials = null;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
var uri = data.GetStringExtra("uri");
|
|
||||||
var username = data.GetStringExtra("username");
|
|
||||||
var password = data.GetStringExtra("password");
|
|
||||||
|
|
||||||
LastCredentials = new AutofillCredentials
|
Finish();
|
||||||
{
|
|
||||||
Username = username,
|
|
||||||
Password = password,
|
|
||||||
Uri = uri,
|
|
||||||
LastUri = _lastQueriedUri
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
LastCredentials = null;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, "SetMainPage");
|
|
||||||
Finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LaunchMainActivity(Intent callingIntent, int requestCode)
|
private void LaunchMainActivity(Intent callingIntent, int requestCode)
|
||||||
|
@ -28,7 +28,7 @@ namespace Bit.Android
|
|||||||
|
|
||||||
protected override void OnCreate(Bundle bundle)
|
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"))
|
if(Intent.HasExtra("uri"))
|
||||||
{
|
{
|
||||||
Intent.RemoveExtra("uri");
|
Intent.RemoveExtra("uri");
|
||||||
@ -99,7 +99,6 @@ namespace Bit.Android
|
|||||||
|
|
||||||
private void ReturnCredentials(VaultListPageModel.Login login)
|
private void ReturnCredentials(VaultListPageModel.Login login)
|
||||||
{
|
{
|
||||||
App.App.FromAutofillService = true;
|
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
if(login == null)
|
if(login == null)
|
||||||
{
|
{
|
||||||
|
@ -34,9 +34,6 @@ namespace Bit.App
|
|||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
private readonly ILocalizeService _localizeService;
|
private readonly ILocalizeService _localizeService;
|
||||||
private readonly IAppInfoService _appInfoService;
|
private readonly IAppInfoService _appInfoService;
|
||||||
private CancellationTokenSource _setMainPageCancellationTokenSource = null;
|
|
||||||
|
|
||||||
public static bool FromAutofillService { get; set; } = false;
|
|
||||||
|
|
||||||
public App(
|
public App(
|
||||||
string uri,
|
string uri,
|
||||||
@ -68,7 +65,6 @@ namespace Bit.App
|
|||||||
SetCulture();
|
SetCulture();
|
||||||
SetStyles();
|
SetStyles();
|
||||||
|
|
||||||
FromAutofillService = !string.IsNullOrWhiteSpace(_uri);
|
|
||||||
if(authService.IsAuthenticated && _uri != null)
|
if(authService.IsAuthenticated && _uri != null)
|
||||||
{
|
{
|
||||||
MainPage = new ExtendedNavigationPage(new VaultAutofillListLoginsPage(_uri));
|
MainPage = new ExtendedNavigationPage(new VaultAutofillListLoginsPage(_uri));
|
||||||
@ -98,9 +94,9 @@ namespace Bit.App
|
|||||||
Device.BeginInvokeOnMainThread(() => Logout(args));
|
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
|
// Handle when your app starts
|
||||||
await CheckLockAsync(false);
|
await CheckLockAsync(false);
|
||||||
|
|
||||||
if(!FromAutofillService)
|
if(string.IsNullOrWhiteSpace(_uri))
|
||||||
{
|
{
|
||||||
var lastBuild = _settings.GetValueOrDefault<string>(LastBuildKey);
|
var lastBuild = _settings.GetValueOrDefault<string>(LastBuildKey);
|
||||||
if(lastBuild == null || lastBuild != _appInfoService.Build)
|
if(lastBuild == null || lastBuild != _appInfoService.Build)
|
||||||
@ -129,7 +125,7 @@ namespace Bit.App
|
|||||||
// Handle when your app sleeps
|
// Handle when your app sleeps
|
||||||
Debug.WriteLine("OnSleep");
|
Debug.WriteLine("OnSleep");
|
||||||
|
|
||||||
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource, 500);
|
SetMainPageFromAutofill();
|
||||||
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
||||||
{
|
{
|
||||||
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
|
_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();
|
MainPage = new MainPage();
|
||||||
if(!FromAutofillService || string.IsNullOrWhiteSpace(_uri))
|
_uri = null;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task IncrementalSyncAsync()
|
private async Task IncrementalSyncAsync()
|
||||||
|
@ -262,7 +262,7 @@ namespace Bit.App.Pages
|
|||||||
private void ClickedItem(object sender, EventArgs e)
|
private void ClickedItem(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_page.GoogleAnalyticsService.TrackExtensionEvent("Closed", _page.Uri.StartsWith("http") ? "Website" : "App");
|
_page.GoogleAnalyticsService.TrackExtensionEvent("Closed", _page.Uri.StartsWith("http") ? "Website" : "App");
|
||||||
MessagingCenter.Send(Application.Current, "SetMainPage", 0);
|
MessagingCenter.Send(Application.Current, "SetMainPage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user