This commit is contained in:
Adam Velebil 2022-11-28 11:44:55 +01:00
parent a908232744
commit 20c703b084
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
4 changed files with 38 additions and 19 deletions

View File

@ -19,11 +19,11 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:yubico_authenticator/android/init.dart';
import 'package:yubico_authenticator/android/keys.dart' as android_keys;
import 'package:yubico_authenticator/android/qr_scanner/qr_scanner_view.dart';
import 'package:yubico_authenticator/android/preferences.dart';
import 'package:yubico_authenticator/app/views/device_avatar.dart';
import 'package:yubico_authenticator/app/views/keys.dart' as app_keys;
import '../test_util.dart';
import 'constants.dart';
void _setShowBetaDialogPref(bool value) async {
SharedPreferences.setMockInitialValues({betaDialogPrefName: value});

View File

@ -20,4 +20,5 @@ const prefNfcOpenApp = 'prefNfcOpenApp';
const prefNfcBypassTouch = 'prefNfcBypassTouch';
const prefNfcCopyOtp = 'prefNfcCopyOtp';
const prefClipKbdLayout = 'prefClipKbdLayout';
const prefUsbOpenApp = 'prefUsbOpenApp';
const prefTheme = 'APP_STATE_THEME';

View File

@ -23,12 +23,7 @@ import '../../core/state.dart';
import '../../widgets/list_title.dart';
import '../../widgets/responsive_dialog.dart';
import '../keys.dart' as keys;
const String _prefNfcOpenApp = 'prefNfcOpenApp';
const String _prefNfcBypassTouch = 'prefNfcBypassTouch';
const String _prefNfcCopyOtp = 'prefNfcCopyOtp';
const String _prefClipKbdLayout = 'prefClipKbdLayout';
const String _prefUsbOpenApp = 'prefUsbOpenApp';
import '../preferences.dart';
// TODO: Get these from Android
const List<String> _keyboardLayouts = ['US', 'DE', 'DE-CH'];
@ -62,8 +57,8 @@ enum _TapAction {
}
static _TapAction load(SharedPreferences prefs) {
final launchApp = prefs.getBool(_prefNfcOpenApp) ?? true;
final copyOtp = prefs.getBool(_prefNfcCopyOtp) ?? false;
final launchApp = prefs.getBool(prefNfcOpenApp) ?? true;
final copyOtp = prefs.getBool(prefNfcCopyOtp) ?? false;
if (launchApp && copyOtp) {
return both;
}
@ -75,8 +70,8 @@ enum _TapAction {
}
void save(SharedPreferences prefs) {
prefs.setBool(_prefNfcOpenApp, this != copy);
prefs.setBool(_prefNfcCopyOtp, this != launch);
prefs.setBool(prefNfcOpenApp, this != copy);
prefs.setBool(prefNfcCopyOtp, this != launch);
}
}
@ -108,9 +103,9 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
final tapAction = _TapAction.load(prefs);
final clipKbdLayout =
prefs.getString(_prefClipKbdLayout) ?? _defaultClipKbdLayout;
final nfcBypassTouch = prefs.getBool(_prefNfcBypassTouch) ?? false;
final usbOpenApp = prefs.getBool(_prefUsbOpenApp) ?? false;
prefs.getString(prefClipKbdLayout) ?? _defaultClipKbdLayout;
final nfcBypassTouch = prefs.getBool(prefNfcBypassTouch) ?? false;
final usbOpenApp = prefs.getBool(prefUsbOpenApp) ?? false;
final themeMode = ref.watch(themeModeProvider);
final theme = Theme.of(context);
@ -148,7 +143,7 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
onTap: () async {
var newValue = await _selectKbdLayout(context, clipKbdLayout);
if (newValue != clipKbdLayout) {
await prefs.setString(_prefClipKbdLayout, newValue);
await prefs.setString(prefClipKbdLayout, newValue);
setState(() {});
}
},
@ -163,7 +158,7 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
value: nfcBypassTouch,
key: keys.nfcBypassTouchSetting,
onChanged: (value) {
prefs.setBool(_prefNfcBypassTouch, value);
prefs.setBool(prefNfcBypassTouch, value);
setState(() {});
}),
const ListTitle('USB options'),
@ -172,7 +167,7 @@ class _AndroidSettingsPageState extends ConsumerState<AndroidSettingsPage> {
value: usbOpenApp,
key: keys.usbOpenApp,
onChanged: (value) {
prefs.setBool(_prefUsbOpenApp, value);
prefs.setBool(prefUsbOpenApp, value);
setState(() {});
}),
const ListTitle('Appearance'),

View File

@ -23,11 +23,10 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:yubico_authenticator/android/keys.dart' as keys;
import 'package:yubico_authenticator/android/state.dart';
import 'package:yubico_authenticator/android/views/android_settings_page.dart';
import 'package:yubico_authenticator/android/preferences.dart';
import 'package:yubico_authenticator/app/state.dart';
import 'package:yubico_authenticator/core/state.dart';
import '../integration_test/android/constants.dart';
Widget createMaterialApp({required Widget child}) {
return MaterialApp(
localizationsDelegates: const [
@ -103,10 +102,16 @@ extension _WidgetTesterHelper on WidgetTester {
await pumpAndSettle();
}
Future<void> tapOpenAppOnUsb() async {
await tap(find.byKey(keys.usbOpenApp));
await pumpAndSettle();
}
ListTile themeModeListTile() =>
find.byKey(keys.themeModeSetting).evaluate().single.widget as ListTile;
Future<void> openAppThemeOptionSelection() async {
await ensureVisible(find.byKey(keys.themeModeSetting));
var widget = find.byKey(keys.themeModeSetting).hitTestable();
expect(widget, findsOneWidget);
await tap(widget);
@ -290,4 +295,22 @@ void main() {
expect(sharedPrefs.getString(prefTheme), equals('dark'));
});
});
testWidgets('Open app on USB', (WidgetTester tester) async {
SharedPreferences.setMockInitialValues({prefUsbOpenApp: false});
SharedPreferences sharedPrefs = await SharedPreferences.getInstance();
await tester.pumpWidget(androidWidget(
sharedPrefs: sharedPrefs,
child: widget,
));
// change to true
await tester.tapOpenAppOnUsb();
expect(sharedPrefs.getBool(prefUsbOpenApp), equals(true));
// change to false
await tester.tapOpenAppOnUsb();
expect(sharedPrefs.getBool(prefUsbOpenApp), equals(false));
});
}