[mob][photos] Lockscreen Fixes (#2398)

This commit is contained in:
Ashil
2024-07-11 15:54:37 +05:30
committed by GitHub
4 changed files with 56 additions and 25 deletions

View File

@@ -21,7 +21,11 @@ class LocalAuthenticationService {
) async {
if (await _isLocalAuthSupportedOnDevice()) {
AppLock.of(context)!.setEnabled(false);
final result = await requestAuthentication(context, infoMessage);
final result = await requestAuthentication(
context,
infoMessage,
isAuthenticatingForInAppChange: true,
);
AppLock.of(context)!.setEnabled(
await Configuration.instance.shouldShowLockScreen(),
);
@@ -39,15 +43,17 @@ class LocalAuthenticationService {
BuildContext context,
String? savedPin,
String? savedPassword, {
bool isOnOpeningApp = false,
bool isAuthenticatingOnAppLaunch = false,
bool isAuthenticatingForInAppChange = false,
}) async {
if (savedPassword != null) {
final result = await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return LockScreenPassword(
isAuthenticating: true,
isOnOpeningApp: isOnOpeningApp,
isChangingLockScreenSettings: true,
isAuthenticatingForInAppChange: isAuthenticatingForInAppChange,
isAuthenticatingOnAppLaunch: isAuthenticatingOnAppLaunch,
authPass: savedPassword,
);
},
@@ -62,8 +68,9 @@ class LocalAuthenticationService {
MaterialPageRoute(
builder: (BuildContext context) {
return LockScreenPin(
isAuthenticating: true,
isOnOpeningApp: isOnOpeningApp,
isChangingLockScreenSettings: true,
isAuthenticatingForInAppChange: isAuthenticatingForInAppChange,
isAuthenticatingOnAppLaunch: isAuthenticatingOnAppLaunch,
authPin: savedPin,
);
},

View File

@@ -16,14 +16,24 @@ import "package:photos/utils/lock_screen_settings.dart";
class LockScreenPassword extends StatefulWidget {
const LockScreenPassword({
super.key,
this.isAuthenticating = false,
this.isOnOpeningApp = false,
this.isChangingLockScreenSettings = false,
this.isAuthenticatingOnAppLaunch = false,
this.isAuthenticatingForInAppChange = false,
this.authPass,
});
//Is false when setting a new password
final bool isAuthenticating;
final bool isOnOpeningApp;
/// [isChangingLockScreenSettings] Authentication required for changing lock screen settings.
/// Set to true when the app requires the user to authenticate before allowing
/// changes to the lock screen settings.
final bool isChangingLockScreenSettings;
/// [isAuthenticatingOnAppLaunch] Authentication required on app launch.
/// Set to true when the app requires the user to authenticate immediately upon opening.
final bool isAuthenticatingOnAppLaunch;
/// [isAuthenticatingForInAppChange] Authentication required for in-app changes (e.g., email, password).
/// Set to true when the app requires the to authenticate for sensitive actions like email, password changes.
final bool isAuthenticatingForInAppChange;
final String? authPass;
@override
State<LockScreenPassword> createState() => _LockScreenPasswordState();
@@ -155,7 +165,7 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
),
),
Text(
widget.isAuthenticating
widget.isChangingLockScreenSettings
? S.of(context).enterPassword
: S.of(context).setNewPassword,
textAlign: TextAlign.center,
@@ -201,7 +211,8 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
if (widget.authPass == base64Encode(hash)) {
await _lockscreenSetting.setInvalidAttemptCount(0);
widget.isOnOpeningApp
widget.isAuthenticatingOnAppLaunch ||
widget.isAuthenticatingForInAppChange
? Navigator.of(context).pop(true)
: Navigator.of(context).pushReplacement(
MaterialPageRoute(
@@ -210,7 +221,7 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
);
return true;
} else {
if (widget.isOnOpeningApp) {
if (widget.isAuthenticatingOnAppLaunch) {
invalidAttemptsCount++;
await _lockscreenSetting.setInvalidAttemptCount(invalidAttemptsCount);
if (invalidAttemptsCount > 4) {
@@ -224,7 +235,7 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
}
Future<void> _confirmPassword() async {
if (widget.isAuthenticating) {
if (widget.isChangingLockScreenSettings) {
await _confirmPasswordAuth(_passwordController.text);
return;
} else {

View File

@@ -18,14 +18,24 @@ import 'package:pinput/pinput.dart';
class LockScreenPin extends StatefulWidget {
const LockScreenPin({
super.key,
this.isAuthenticating = false,
this.isOnOpeningApp = false,
this.isChangingLockScreenSettings = false,
this.isAuthenticatingOnAppLaunch = false,
this.isAuthenticatingForInAppChange = false,
this.authPin,
});
//Is false when setting a new password
final bool isAuthenticating;
final bool isOnOpeningApp;
/// [isChangingLockScreenSettings] Authentication required for changing lock screen settings.
/// Set to true when the app requires the user to authenticate before allowing
/// changes to the lock screen settings.
final bool isChangingLockScreenSettings;
/// [isAuthenticatingOnAppLaunch] Authentication required on app launch.
/// Set to true when the app requires the user to authenticate immediately upon opening.
final bool isAuthenticatingOnAppLaunch;
/// [isAuthenticatingForInAppChange] Authentication required for in-app changes (e.g., email, password).
/// Set to true when the app requires the to authenticate for sensitive actions like email, password changes.
final bool isAuthenticatingForInAppChange;
final String? authPin;
@override
State<LockScreenPin> createState() => _LockScreenPinState();
@@ -62,7 +72,8 @@ class _LockScreenPinState extends State<LockScreenPin> {
if (widget.authPin == base64Encode(hash)) {
invalidAttemptsCount = 0;
await _lockscreenSetting.setInvalidAttemptCount(0);
widget.isOnOpeningApp
widget.isAuthenticatingOnAppLaunch ||
widget.isAuthenticatingForInAppChange
? Navigator.of(context).pop(true)
: Navigator.of(context).pushReplacement(
MaterialPageRoute(
@@ -81,7 +92,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
isPinValid = false;
});
if (widget.isOnOpeningApp) {
if (widget.isAuthenticatingOnAppLaunch) {
invalidAttemptsCount++;
await _lockscreenSetting.setInvalidAttemptCount(invalidAttemptsCount);
if (invalidAttemptsCount > 4) {
@@ -93,7 +104,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
}
Future<void> _confirmPin(String code) async {
if (widget.isAuthenticating) {
if (widget.isChangingLockScreenSettings) {
await confirmPinAuth(code);
return;
} else {
@@ -220,7 +231,7 @@ class _LockScreenPinState extends State<LockScreenPin> {
),
),
Text(
widget.isAuthenticating
widget.isChangingLockScreenSettings
? S.of(context).enterPin
: S.of(context).setNewPin,
style: textTheme.bodyBold,

View File

@@ -11,6 +11,7 @@ Future<bool> requestAuthentication(
BuildContext context,
String reason, {
bool isOpeningApp = false,
bool isAuthenticatingForInAppChange = false,
}) async {
Logger("AuthUtil").info("Requesting authentication");
await LocalAuthentication().stopAuthentication();
@@ -23,7 +24,8 @@ Future<bool> requestAuthentication(
context,
savedPin,
savedPassword,
isOnOpeningApp: isOpeningApp,
isAuthenticatingOnAppLaunch: isOpeningApp,
isAuthenticatingForInAppChange: isAuthenticatingForInAppChange,
);
} else {
return await LocalAuthentication().authenticate(