From 826f3fef7049440251a00024bb9da5b9623c58d0 Mon Sep 17 00:00:00 2001 From: luckyrat Date: Thu, 9 Nov 2023 18:41:15 +0000 Subject: [PATCH] Enable Keyboard Autofill for recent Android versions --- android/app/src/main/AndroidManifest.xml | 3 ++ lib/widgets/settings.dart | 36 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f3f6fb1..85bd7cf 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -60,6 +60,9 @@ + { buildSignature: 'Unknown', ); + // ignore: unused_field + BaseDeviceInfo? _deviceInfo; + AndroidDeviceInfo? _androidDeviceInfo; + @override void initState() { super.initState(); unawaited(_initPackageInfo()); + unawaited(_initDeviceInfo()); } Future _initPackageInfo() async { @@ -459,6 +466,18 @@ class _AutofillStatusWidgetState extends State { } } + Future _initDeviceInfo() async { + final deviceInfoPlugin = DeviceInfoPlugin(); + final deviceInfo = await deviceInfoPlugin.deviceInfo; + final androidInfo = Platform.isAndroid ? await deviceInfoPlugin.androidInfo : null; + if (mounted) { + setState(() { + _deviceInfo = deviceInfo; + _androidDeviceInfo = androidInfo; + }); + } + } + @override Widget build(BuildContext context) { final str = S.of(context); @@ -513,6 +532,23 @@ class _AutofillStatusWidgetState extends State { }, ), ), + Visibility( + visible: widget.isEnabled && KeeVaultPlatform.isAndroid && (_androidDeviceInfo?.version.sdkInt ?? 0) >= 31, + child: SwitchSettingsTile( + settingKey: 'autofillServiceEnableIMEIntegration', + title: 'Show in keyboard', + subtitle: 'experimental feature', + defaultValue: true, + onChange: (value) async { + // We assume the autofill preference's SharedPreferences feature + // is in sync to begin with and always specify what the user has + // requested from our own preference so in the worst case, the + // user will have to toggle the switch a couple of times to + // resync and fix any broken behaviour. + await BlocProvider.of(context).setIMEIntegrationPreference(value); + }, + ), + ), ]), ), Divider(