2017-02-18 07:22:02 +03:00
|
|
|
|
using Android.App;
|
2017-11-28 01:27:11 +03:00
|
|
|
|
using Android.Views.Autofill;
|
2017-02-18 07:22:02 +03:00
|
|
|
|
using Bit.App.Abstractions;
|
2017-12-22 19:23:03 +03:00
|
|
|
|
using Plugin.CurrentActivity;
|
2017-02-18 07:22:02 +03:00
|
|
|
|
using System.Linq;
|
2016-08-27 21:36:32 +03:00
|
|
|
|
using AndroidApp = Android.App.Application;
|
2016-07-24 06:50:08 +03:00
|
|
|
|
|
|
|
|
|
namespace Bit.Android.Services
|
|
|
|
|
{
|
|
|
|
|
public class AppInfoService : IAppInfoService
|
|
|
|
|
{
|
2016-08-27 21:36:32 +03:00
|
|
|
|
public string Version => AndroidApp.Context.ApplicationContext.PackageManager
|
|
|
|
|
.GetPackageInfo(AndroidApp.Context.PackageName, 0).VersionName;
|
2016-07-24 06:50:08 +03:00
|
|
|
|
|
2016-08-27 21:36:32 +03:00
|
|
|
|
public string Build => AndroidApp.Context.ApplicationContext.PackageManager
|
|
|
|
|
.GetPackageInfo(AndroidApp.Context.PackageName, 0).VersionCode.ToString();
|
2017-02-01 08:38:35 +03:00
|
|
|
|
|
2017-11-28 01:27:11 +03:00
|
|
|
|
public bool AutofillAccessibilityServiceEnabled => AutofillAccessibilityRunning();
|
|
|
|
|
public bool AutofillServiceEnabled => AutofillEnabled();
|
2017-02-18 07:22:02 +03:00
|
|
|
|
|
2017-11-28 01:27:11 +03:00
|
|
|
|
private bool AutofillAccessibilityRunning()
|
2017-02-18 07:22:02 +03:00
|
|
|
|
{
|
2017-12-22 19:23:03 +03:00
|
|
|
|
var manager = ((ActivityManager)CrossCurrentActivity.Current.Activity.GetSystemService("activity"));
|
2017-02-18 07:22:02 +03:00
|
|
|
|
var services = manager.GetRunningServices(int.MaxValue);
|
|
|
|
|
return services.Any(s => s.Process.ToLowerInvariant().Contains("bitwarden") &&
|
|
|
|
|
s.Service.ClassName.ToLowerInvariant().Contains("autofill"));
|
|
|
|
|
}
|
2017-11-28 01:27:11 +03:00
|
|
|
|
|
|
|
|
|
private bool AutofillEnabled()
|
|
|
|
|
{
|
|
|
|
|
if(global::Android.OS.Build.VERSION.SdkInt < global::Android.OS.BuildVersionCodes.O)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 19:23:03 +03:00
|
|
|
|
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
2017-11-28 01:27:11 +03:00
|
|
|
|
var afm = (AutofillManager)activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)));
|
|
|
|
|
return afm.IsEnabled;
|
|
|
|
|
}
|
2016-07-24 06:50:08 +03:00
|
|
|
|
}
|
|
|
|
|
}
|