Skip to content

Commit

Permalink
Merge pull request #58 from nevissecurity/feature/NEVISACCESSAPP-6288-…
Browse files Browse the repository at this point in the history
…Camera-preview-fix

NEVISACCESSAPP-6288: Camera handling fix
  • Loading branch information
tamas-toth authored Nov 8, 2024
2 parents 41ab8c8 + f1e7576 commit 26fa675
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 40 deletions.
6 changes: 3 additions & 3 deletions lib/domain/model/error/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class BusinessException implements Exception {
BusinessException.missingDispatchTokenResponse()
: type = BusinessErrorType.missingDispatchTokenResponse;

BusinessException.missingOpenSettingsOperationForUser()
: type = BusinessErrorType.missingOpenSettingsOperationForUser;

BusinessException.credentialAuthenticatorNotFound()
: type = BusinessErrorType.credentialAuthenticatorNotFound;

BusinessException.registeredAccountsNotFound()
: type = BusinessErrorType.registeredAccountsNotFound;

BusinessException.cameraAccessDenied()
: type = BusinessErrorType.cameraAccessDenied;
}

class PinNotEnrolledException implements Exception {
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/model/error/error_message_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum BusinessErrorType {
invalidState,
missingCookie,
missingDispatchTokenResponse,
missingOpenSettingsOperationForUser,
credentialAuthenticatorNotFound,
registeredAccountsNotFound,
cameraAccessDenied,
}
7 changes: 2 additions & 5 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
},
"businessErrorTypeAccountsNotFound": "No accounts were found for the operation.",
"businessErrorTypeAuthenticatorNotFound": "No available authenticator found.",
"businessErrorTypeDispatchTargetNotFound": "No dispatch target was found for the operation.",
"businessErrorTypeCameraAccessDenied": "Camera access is denied. Please go to Settings and allow it.",
"businessErrorTypeDeviceInformationNotFound": "No device information was found.",
"businessErrorTypeInvalidState": "Invalid state.",
"businessErrorTypeMissingCookie": "No cookie was provided in the legacy login response.",
"businessErrorTypeMissingDispatchTokenResponse": "The returned URI did not have a dispatchTokenResponse query parameter.",
"businessErrorTypeMissingOpenSettingsOperationForUser": "No open settings operation found for the given user.",
"businessErrorTypeCredentialAuthenticatorNotFound": "Credential authenticator not found.",
"businessErrorTypeRegisteredAccountsNotFound": "There are no registered accounts.",
"selectAccountScreenTitle": "Select an account",
Expand All @@ -58,9 +58,6 @@
"authCloudApiRegistration": "Auth Cloud Api Registration",
"deleteAuthenticators": "Delete Authenticators",
"inBandRegister": "In-Band Register",
"cameraAccessDenied": "Please allow access to camera.",
"cameraAccessPermanentlyDenied": "Camera access is denied. Please go to settings and allow it.",
"cameraInitializationFailed": "Failed to initialize camera.",
"readQrCodeScreenTitle": "Read Qr Code",
"biometricPopUpTitle": "Biometric authentication required",
"biometricPopUpDescription": "Please use the default biometric method to identify yourself.",
Expand Down
8 changes: 6 additions & 2 deletions lib/ui/screens/home/home_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/c
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/home/home_event.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/home/home_state.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/select_account/navigation/select_account_parameter.dart';
import 'package:permission_handler/permission_handler.dart';

@injectable
class HomeBloc extends Bloc<HomeEvent, HomeState> {
Expand Down Expand Up @@ -154,8 +155,11 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
ReadQrCodeEvent event,
Emitter<HomeState> emit,
) async {
_globalNavigationManager.pushReadQrCode();
_yieldBasedOnCurrentState(emit);
if (await Permission.camera.request().isGranted) {
_globalNavigationManager.pushReadQrCode();
} else {
_errorHandler.handle(BusinessException.cameraAccessDenied());
}
}

Future<void> _handleDeregister(
Expand Down
26 changes: 1 addition & 25 deletions lib/ui/screens/read_qr_code/read_qr_code_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/read_qr_code/read_qr_code_bloc.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/screens/read_qr_code/read_qr_code_event.dart';
import 'package:nevis_mobile_authentication_sdk_example_app_flutter/ui/widgets/app_scaffold.dart';
Expand All @@ -30,7 +29,6 @@ class _ReadQrCodeScreenState extends State<ReadQrCodeScreen>
);

StreamSubscription<Object?>? _subscription;
PermissionStatus _permissionStatus = PermissionStatus.denied;
bool _isLoading = false;
bool _isBarcodeFound = false;

Expand All @@ -40,13 +38,6 @@ class _ReadQrCodeScreenState extends State<ReadQrCodeScreen>
WidgetsBinding.instance.addObserver(this);
_subscription = _controller.barcodes.listen(_handleBarcode);
unawaited(_controller.start());

_listenForPermissionStatus();
}

void _listenForPermissionStatus() async {
final status = await Permission.camera.request();
setState(() => _permissionStatus = status);
}

@override
Expand All @@ -55,23 +46,8 @@ class _ReadQrCodeScreenState extends State<ReadQrCodeScreen>
Widget content;
if (_isLoading) {
content = const Center(child: CircularProgressIndicator());
} else if (_permissionStatus == PermissionStatus.granted) {
content = _mobileScannerContent(localization);
} else if (_permissionStatus == PermissionStatus.denied) {
content = _textContent(
localization,
Colors.black,
localization.cameraAccessDenied,
);
} else if (_permissionStatus == PermissionStatus.permanentlyDenied) {
content = _textContent(localization, Colors.black,
localization.cameraAccessPermanentlyDenied);
} else {
content = _textContent(
localization,
Colors.black,
localization.cameraInitializationFailed,
);
content = _mobileScannerContent(localization);
}

return AppScaffold(
Expand Down
7 changes: 3 additions & 4 deletions lib/util/localization_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,19 @@ extension BusinessErrorTypeLocalizationExtension on BusinessErrorType {
case BusinessErrorType.authenticatorNotFound:
return localizations.businessErrorTypeAuthenticatorNotFound;
case BusinessErrorType.deviceInformationNotFound:
return localizations.businessErrorTypeDispatchTargetNotFound;
return localizations.businessErrorTypeDeviceInformationNotFound;
case BusinessErrorType.invalidState:
return localizations.businessErrorTypeInvalidState;
case BusinessErrorType.missingCookie:
return localizations.businessErrorTypeMissingCookie;
case BusinessErrorType.missingDispatchTokenResponse:
return localizations.businessErrorTypeMissingDispatchTokenResponse;
case BusinessErrorType.missingOpenSettingsOperationForUser:
return localizations
.businessErrorTypeMissingOpenSettingsOperationForUser;
case BusinessErrorType.credentialAuthenticatorNotFound:
return localizations.businessErrorTypeCredentialAuthenticatorNotFound;
case BusinessErrorType.registeredAccountsNotFound:
return localizations.businessErrorTypeRegisteredAccountsNotFound;
case BusinessErrorType.cameraAccessDenied:
return localizations.businessErrorTypeCameraAccessDenied;
}
}
}

0 comments on commit 26fa675

Please sign in to comment.