1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-03 00:53:27 +00:00

add tools page for autofill service

This commit is contained in:
Kyle Spearrin
2017-11-27 17:27:11 -05:00
parent 9bbddd6aeb
commit 783c4d104c
17 changed files with 222 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
using Android.App;
using Android.Views.Autofill;
using Bit.App.Abstractions;
using System.Linq;
using AndroidApp = Android.App.Application;
@@ -13,14 +14,27 @@ namespace Bit.Android.Services
public string Build => AndroidApp.Context.ApplicationContext.PackageManager
.GetPackageInfo(AndroidApp.Context.PackageName, 0).VersionCode.ToString();
public bool AutofillServiceEnabled => AutofillRunning();
public bool AutofillAccessibilityServiceEnabled => AutofillAccessibilityRunning();
public bool AutofillServiceEnabled => AutofillEnabled();
private bool AutofillRunning()
private bool AutofillAccessibilityRunning()
{
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"));
}
private bool AutofillEnabled()
{
if(global::Android.OS.Build.VERSION.SdkInt < global::Android.OS.BuildVersionCodes.O)
{
return false;
}
var activity = (MainActivity)Xamarin.Forms.Forms.Context;
var afm = (AutofillManager)activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)));
return afm.IsEnabled;
}
}
}

View File

@@ -407,5 +407,13 @@ namespace Bit.Android.Services
ActivityCompat.RequestPermissions(CrossCurrentActivity.Current.Activity, new string[] { permission },
Constants.SelectFilePermissionRequestCode);
}
public void OpenAutofillSettings()
{
var activity = (MainActivity)Forms.Context;
var intent = new Intent(Settings.ActionRequestSetAutofillService);
intent.SetData(global::Android.Net.Uri.Parse("package:com.x8bit.bitwarden"));
activity.StartActivity(intent);
}
}
}

View File

@@ -1,6 +1,7 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views.Autofill;
using Bit.App.Abstractions;
namespace Bit.Android.Services
@@ -44,5 +45,18 @@ namespace Bit.Android.Services
}
public bool NfcEnabled => Utilities.NfcEnabled();
public bool HasCamera => Xamarin.Forms.Forms.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCamera);
public bool AutofillServiceSupported => AutofillSupported();
private bool AutofillSupported()
{
if(Build.VERSION.SdkInt < BuildVersionCodes.O)
{
return false;
}
var activity = (MainActivity)Xamarin.Forms.Forms.Context;
var afm = (AutofillManager)activity.GetSystemService(Java.Lang.Class.FromType(typeof(AutofillManager)));
return afm.IsAutofillSupported;
}
}
}