mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 09:58:27 +03:00
WIP on accessibility service
This commit is contained in:
parent
2c446f939e
commit
ea1aafbab2
4 changed files with 40 additions and 15 deletions
|
@ -123,6 +123,18 @@ namespace Bit.Android
|
|||
{
|
||||
uri = string.Concat("http://", uri);
|
||||
}
|
||||
else if(Build.VERSION.SdkInt <= BuildVersionCodes.KitkatWatch)
|
||||
{
|
||||
var parts = uri.Split(new string[] { ". " }, StringSplitOptions.None);
|
||||
if(parts.Length > 1)
|
||||
{
|
||||
var urlPart = parts.FirstOrDefault(p => p.StartsWith("http"));
|
||||
if(urlPart != null)
|
||||
{
|
||||
uri = urlPart.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uri;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:accessibilityEventTypes="typeAllMask"
|
||||
android:accessibilityFeedbackType="feedbackSpoken"
|
||||
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
|
||||
android:accessibilityFeedbackType="feedbackGeneric"
|
||||
android:accessibilityFlags="flagDefault"
|
||||
android:notificationTimeout="100"
|
||||
android:canRetrieveWindowContent="true"/>
|
|
@ -14,6 +14,7 @@ using Acr.UserDialogs;
|
|||
using XLabs.Ioc;
|
||||
using System.Reflection;
|
||||
using Bit.App.Resources;
|
||||
using System.Threading;
|
||||
|
||||
namespace Bit.App
|
||||
{
|
||||
|
@ -30,6 +31,7 @@ namespace Bit.App
|
|||
private readonly ILockService _lockService;
|
||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||
private readonly ILocalizeService _localizeService;
|
||||
private CancellationTokenSource _setMainPageCancellationTokenSource = null;
|
||||
|
||||
public static bool FromAutofillService { get; set; } = false;
|
||||
|
||||
|
@ -91,9 +93,9 @@ namespace Bit.App
|
|||
Device.BeginInvokeOnMainThread(() => Logout(args));
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<Application>(Current, "SetMainPage", async (sender) =>
|
||||
MessagingCenter.Subscribe<Application>(Current, "SetMainPage", (sender) =>
|
||||
{
|
||||
await SetMainPageFromAutofill();
|
||||
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -112,7 +114,7 @@ namespace Bit.App
|
|||
// Handle when your app sleeps
|
||||
Debug.WriteLine("OnSleep");
|
||||
|
||||
await SetMainPageFromAutofill(true);
|
||||
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource);
|
||||
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
||||
{
|
||||
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
|
||||
|
@ -142,27 +144,38 @@ namespace Bit.App
|
|||
}
|
||||
}
|
||||
|
||||
private async Task SetMainPageFromAutofill(bool skipAlreadyOnCheck = false)
|
||||
private CancellationTokenSource SetMainPageFromAutofill(CancellationTokenSource previousCts)
|
||||
{
|
||||
if(Device.OS != TargetPlatform.Android)
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
var alreadyOnMainPage = MainPage as MainPage;
|
||||
if(!skipAlreadyOnCheck && alreadyOnMainPage != null)
|
||||
previousCts?.Cancel();
|
||||
if(!FromAutofillService || string.IsNullOrWhiteSpace(_uri))
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if(FromAutofillService || !string.IsNullOrWhiteSpace(_uri))
|
||||
var cts = new CancellationTokenSource();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// delay some so that we dont see the screen change as autofill closes
|
||||
await Task.Delay(1000);
|
||||
if(cts.Token.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
MainPage = new MainPage();
|
||||
});
|
||||
|
||||
_uri = null;
|
||||
FromAutofillService = false;
|
||||
}
|
||||
}, cts.Token);
|
||||
|
||||
return cts;
|
||||
}
|
||||
|
||||
private async Task IncrementalSyncAsync()
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Bit.App.Pages
|
|||
{
|
||||
_uri = uriString;
|
||||
Uri uri;
|
||||
if(!Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out uri) ||
|
||||
if(!Uri.TryCreate(uriString, UriKind.Absolute, out uri) ||
|
||||
!DomainName.TryParse(uri.Host, out _domainName))
|
||||
{
|
||||
if(uriString != null && uriString.StartsWith(Constants.AndroidAppProtocol))
|
||||
|
|
Loading…
Reference in a new issue