mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 02:18:27 +03:00
Check blacklist before showing overlay (#730)
This commit is contained in:
parent
558b10499b
commit
7a6fe5ed5f
1 changed files with 48 additions and 4 deletions
|
@ -28,6 +28,10 @@ namespace Bit.Droid.Accessibility
|
|||
private const string BitwardenPackage = "com.x8bit.bitwarden";
|
||||
private const string BitwardenWebsite = "vault.bitwarden.com";
|
||||
|
||||
private IStorageService _storageService;
|
||||
private DateTime? _lastSettingsReload = null;
|
||||
private TimeSpan _settingsReloadSpan = TimeSpan.FromMinutes(1);
|
||||
private HashSet<string> _blacklistedUris;
|
||||
private AccessibilityNodeInfo _anchorNode = null;
|
||||
private int _lastAnchorX = 0;
|
||||
private int _lastAnchorY = 0;
|
||||
|
@ -69,6 +73,8 @@ namespace Bit.Droid.Accessibility
|
|||
|
||||
// AccessibilityHelpers.PrintTestData(RootInActiveWindow, e);
|
||||
|
||||
LoadServices();
|
||||
var settingsTask = LoadSettingsAsync();
|
||||
AccessibilityNodeInfo root = null;
|
||||
|
||||
switch(e.EventType)
|
||||
|
@ -211,7 +217,23 @@ namespace Bit.Droid.Accessibility
|
|||
}
|
||||
|
||||
var uri = AccessibilityHelpers.GetUri(root);
|
||||
if(string.IsNullOrWhiteSpace(uri))
|
||||
var fillable = !string.IsNullOrWhiteSpace(uri);
|
||||
if(fillable)
|
||||
{
|
||||
if(_blacklistedUris != null && _blacklistedUris.Any())
|
||||
{
|
||||
if(Uri.TryCreate(uri, UriKind.Absolute, out var parsedUri) && parsedUri.Scheme.StartsWith("http"))
|
||||
{
|
||||
fillable = !_blacklistedUris.Contains(
|
||||
string.Format("{0}://{1}", parsedUri.Scheme, parsedUri.Host));
|
||||
}
|
||||
else
|
||||
{
|
||||
fillable = !_blacklistedUris.Contains(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!fillable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -363,5 +385,27 @@ namespace Bit.Droid.Accessibility
|
|||
}
|
||||
return _launcherPackageNames.Contains(eventPackageName);
|
||||
}
|
||||
|
||||
private void LoadServices()
|
||||
{
|
||||
if(_storageService == null)
|
||||
{
|
||||
_storageService = ServiceContainer.Resolve<IStorageService>("storageService");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadSettingsAsync()
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
if(_lastSettingsReload == null || (now - _lastSettingsReload.Value) > _settingsReloadSpan)
|
||||
{
|
||||
_lastSettingsReload = now;
|
||||
var uris = await _storageService.GetAsync<List<string>>(Constants.AutofillBlacklistedUrisKey);
|
||||
if(uris != null)
|
||||
{
|
||||
_blacklistedUris = new HashSet<string>(uris);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue