yubioath-flutter/lib/android/management/state.dart

66 lines
1.9 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
2024-03-25 19:46:31 +03:00
* Copyright (C) 2022,2024 Yubico.
2022-10-04 13:12:54 +03:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-03-16 12:37:52 +03:00
import 'dart:async';
2024-03-22 16:23:38 +03:00
import 'package:flutter/services.dart';
2022-03-16 12:37:52 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/models.dart';
import '../../app/state.dart';
import '../../management/models.dart';
2022-03-16 12:37:52 +03:00
import '../../management/state.dart';
2024-03-22 16:23:38 +03:00
const _methods = MethodChannel('android.management.methods');
final androidManagementState = AsyncNotifierProvider.autoDispose
.family<ManagementStateNotifier, DeviceInfo, DevicePath>(
_AndroidManagementStateNotifier.new,
2022-03-16 12:37:52 +03:00
);
class _AndroidManagementStateNotifier extends ManagementStateNotifier {
@override
FutureOr<DeviceInfo> build(DevicePath devicePath) {
// Make sure to rebuild if currentDevice changes (as on reboot)
ref.watch(currentDeviceProvider);
2022-03-16 12:37:52 +03:00
return Completer<DeviceInfo>().future;
}
2022-03-16 12:37:52 +03:00
@override
2022-05-05 13:40:56 +03:00
Future<void> setMode(
{required int interfaces,
int challengeResponseTimeout = 0,
int? autoEjectTimeout}) async {}
2022-03-16 12:37:52 +03:00
@override
Future<void> writeConfig(DeviceConfig config,
{String currentLockCode = '',
String newLockCode = '',
bool reboot = false}) async {
if (reboot) {
state = const AsyncValue.loading();
2022-03-16 12:37:52 +03:00
}
ref.read(attachedDevicesProvider.notifier).refresh();
2022-03-16 12:37:52 +03:00
}
2024-02-02 15:52:22 +03:00
@override
2024-03-22 16:23:38 +03:00
Future<void> deviceReset() async {
await _methods.invokeMethod('deviceReset');
2024-02-02 15:52:22 +03:00
}
2022-03-16 12:37:52 +03:00
}