1
0
mirror of https://github.com/bitwarden/mobile.git synced 2025-01-07 18:58:35 +01:00
bitwarden-mobile/src/Android/AutofillService.cs

45 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.AccessibilityServices;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Views.Accessibility;
using Android.Widget;
namespace Bit.Android
{
//[Service(Permission = "android.permission.BIND_ACCESSIBILITY_SERVICE", Label = "bitwarden")]
//[IntentFilter(new string[] { "android.accessibilityservice.AccessibilityService" })]
//[MetaData("android.accessibilityservice", Resource = "@xml/accessibilityservice")]
public class AutofillService : AccessibilityService
{
public override void OnAccessibilityEvent(AccessibilityEvent e)
{
var eventType = e.EventType;
switch(eventType)
{
case EventTypes.ViewTextSelectionChanged:
if(e.Source.Password && string.IsNullOrWhiteSpace(e.Source.Text))
{
var bundle = new Bundle();
bundle.PutCharSequence(AccessibilityNodeInfo.ActionArgumentSetTextCharsequence, "mypassword");
e.Source.PerformAction(global::Android.Views.Accessibility.Action.SetText, bundle);
}
break;
default:
break;
}
}
public override void OnInterrupt()
{
}
}
}