mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +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);
|
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;
|
return uri;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:accessibilityEventTypes="typeAllMask"
|
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
|
||||||
android:accessibilityFeedbackType="feedbackSpoken"
|
android:accessibilityFeedbackType="feedbackGeneric"
|
||||||
android:accessibilityFlags="flagDefault"
|
android:accessibilityFlags="flagDefault"
|
||||||
android:notificationTimeout="100"
|
android:notificationTimeout="100"
|
||||||
android:canRetrieveWindowContent="true"/>
|
android:canRetrieveWindowContent="true"/>
|
|
@ -14,6 +14,7 @@ using Acr.UserDialogs;
|
||||||
using XLabs.Ioc;
|
using XLabs.Ioc;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Bit.App.Resources;
|
using Bit.App.Resources;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Bit.App
|
namespace Bit.App
|
||||||
{
|
{
|
||||||
|
@ -30,6 +31,7 @@ namespace Bit.App
|
||||||
private readonly ILockService _lockService;
|
private readonly ILockService _lockService;
|
||||||
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
private readonly IGoogleAnalyticsService _googleAnalyticsService;
|
||||||
private readonly ILocalizeService _localizeService;
|
private readonly ILocalizeService _localizeService;
|
||||||
|
private CancellationTokenSource _setMainPageCancellationTokenSource = null;
|
||||||
|
|
||||||
public static bool FromAutofillService { get; set; } = false;
|
public static bool FromAutofillService { get; set; } = false;
|
||||||
|
|
||||||
|
@ -91,9 +93,9 @@ namespace Bit.App
|
||||||
Device.BeginInvokeOnMainThread(() => Logout(args));
|
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
|
// Handle when your app sleeps
|
||||||
Debug.WriteLine("OnSleep");
|
Debug.WriteLine("OnSleep");
|
||||||
|
|
||||||
await SetMainPageFromAutofill(true);
|
_setMainPageCancellationTokenSource = SetMainPageFromAutofill(_setMainPageCancellationTokenSource);
|
||||||
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
if(Device.OS == TargetPlatform.Android && !TopPageIsLock())
|
||||||
{
|
{
|
||||||
_settings.AddOrUpdateValue(Constants.LastActivityDate, DateTime.UtcNow);
|
_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)
|
if(Device.OS != TargetPlatform.Android)
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var alreadyOnMainPage = MainPage as MainPage;
|
previousCts?.Cancel();
|
||||||
if(!skipAlreadyOnCheck && alreadyOnMainPage != null)
|
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);
|
await Task.Delay(1000);
|
||||||
MainPage = new MainPage();
|
if(cts.Token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Device.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
MainPage = new MainPage();
|
||||||
|
});
|
||||||
|
|
||||||
_uri = null;
|
_uri = null;
|
||||||
FromAutofillService = false;
|
FromAutofillService = false;
|
||||||
}
|
}, cts.Token);
|
||||||
|
|
||||||
|
return cts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task IncrementalSyncAsync()
|
private async Task IncrementalSyncAsync()
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
_uri = uriString;
|
_uri = uriString;
|
||||||
Uri uri;
|
Uri uri;
|
||||||
if(!Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out uri) ||
|
if(!Uri.TryCreate(uriString, UriKind.Absolute, out uri) ||
|
||||||
!DomainName.TryParse(uri.Host, out _domainName))
|
!DomainName.TryParse(uri.Host, out _domainName))
|
||||||
{
|
{
|
||||||
if(uriString != null && uriString.StartsWith(Constants.AndroidAppProtocol))
|
if(uriString != null && uriString.StartsWith(Constants.AndroidAppProtocol))
|
||||||
|
|
Loading…
Reference in a new issue