Better way of checking for autofill sevrice running

This commit is contained in:
Kyle Spearrin 2017-02-17 23:22:02 -05:00
parent b435256911
commit d53ea584ba
2 changed files with 12 additions and 16 deletions

View file

@ -19,7 +19,6 @@ namespace Bit.Android
private const string BitwardenPackage = "com.x8bit.bitwarden";
private const string BitwardenWebsite = "bitwarden.com";
public static bool Enabled { get; set; } = false;
private static Dictionary<string, Browser> SupportedBrowsers => new List<Browser>
{
new Browser("com.android.chrome", "url_bar"),
@ -54,7 +53,6 @@ namespace Bit.Android
public override void OnAccessibilityEvent(AccessibilityEvent e)
{
Enabled = true;
var root = RootInActiveWindow;
if(string.IsNullOrWhiteSpace(e.PackageName) || e.PackageName == SystemUiPackage ||
root?.PackageName != e.PackageName)
@ -116,18 +114,6 @@ namespace Bit.Android
}
protected override void OnServiceConnected()
{
base.OnServiceConnected();
Enabled = true;
}
public override void OnDestroy()
{
base.OnDestroy();
Enabled = false;
}
private void CancelNotification()
{
var notificationManager = ((NotificationManager)GetSystemService(NotificationService));

View file

@ -1,4 +1,6 @@
using Bit.App.Abstractions;
using Android.App;
using Bit.App.Abstractions;
using System.Linq;
using AndroidApp = Android.App.Application;
namespace Bit.Android.Services
@ -11,6 +13,14 @@ namespace Bit.Android.Services
public string Build => AndroidApp.Context.ApplicationContext.PackageManager
.GetPackageInfo(AndroidApp.Context.PackageName, 0).VersionCode.ToString();
public bool AutofillServiceEnabled => AutofillService.Enabled;
public bool AutofillServiceEnabled => AutofillRunning();
private bool AutofillRunning()
{
var manager = ((ActivityManager)Xamarin.Forms.Forms.Context.GetSystemService("activity"));
var services = manager.GetRunningServices(int.MaxValue);
return services.Any(s => s.Process.ToLowerInvariant().Contains("bitwarden") &&
s.Service.ClassName.ToLowerInvariant().Contains("autofill"));
}
}
}