Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/mdm-biometrical-unlock] MDM setting for Biometrical Unlock #1058

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ownCloudAppFramework/AppLock Settings/AppLockSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ extern OCClassSettingsKey OCClassSettingsKeyPasscodeEnforced;
extern OCClassSettingsKey OCClassSettingsKeyRequiredPasscodeDigits;
extern OCClassSettingsKey OCClassSettingsKeyMaximumPasscodeDigits;
extern OCClassSettingsKey OCClassSettingsKeyPasscodeLockDelay;
extern OCClassSettingsKey OCClassSettingsKeyPasscodeUseBiometricalUnlock;

NS_ASSUME_NONNULL_END
20 changes: 18 additions & 2 deletions ownCloudAppFramework/AppLock Settings/AppLockSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ + (OCClassSettingsIdentifier)classSettingsIdentifier
return (@{
OCClassSettingsKeyPasscodeEnforced : @(NO),
OCClassSettingsKeyRequiredPasscodeDigits : @(4),
OCClassSettingsKeyMaximumPasscodeDigits : @(6)
OCClassSettingsKeyMaximumPasscodeDigits : @(6),
OCClassSettingsKeyPasscodeUseBiometricalUnlock : @(NO)
});
}

Expand Down Expand Up @@ -86,6 +87,13 @@ + (OCClassSettingsMetadataCollection)classSettingsMetadata
OCClassSettingsMetadataKeyDescription : @"Number of seconds before the lock snaps and the passcode is requested again.",
OCClassSettingsMetadataKeyStatus : OCClassSettingsKeyStatusAdvanced,
OCClassSettingsMetadataKeyCategory : @"Passcode"
},

OCClassSettingsKeyPasscodeUseBiometricalUnlock : @{
OCClassSettingsMetadataKeyType : OCClassSettingsMetadataTypeBoolean,
OCClassSettingsMetadataKeyDescription : @"Controls wether the biometrical unlock will be enabled automatically.",
OCClassSettingsMetadataKeyStatus : OCClassSettingsKeyStatusAdvanced,
OCClassSettingsMetadataKeyCategory : @"Passcode"
}
});
}
Expand Down Expand Up @@ -120,7 +128,14 @@ - (void)setLockDelay:(NSInteger)lockDelay

- (BOOL)biometricalSecurityEnabled
{
return ([_userDefaults boolForKey:@"security-settings-use-biometrical"]);
NSNumber *useBiometricalUnlock;

if ((useBiometricalUnlock = [_userDefaults objectForKey:@"security-settings-use-biometrical"]) != nil)
{
return (useBiometricalUnlock.boolValue);
}

return ([[self classSettingForOCClassSettingsKey:OCClassSettingsKeyPasscodeUseBiometricalUnlock] boolValue]);
}

- (void)setBiometricalSecurityEnabled:(BOOL)biometricalSecurityEnabled
Expand Down Expand Up @@ -174,3 +189,4 @@ - (BOOL)lockDelayUserSettable
OCClassSettingsKey OCClassSettingsKeyRequiredPasscodeDigits = @"requiredPasscodeDigits";
OCClassSettingsKey OCClassSettingsKeyMaximumPasscodeDigits = @"maximumPasscodeDigits";
OCClassSettingsKey OCClassSettingsKeyPasscodeLockDelay = @"lockDelay";
OCClassSettingsKey OCClassSettingsKeyPasscodeUseBiometricalUnlock = @"use-biometrical-unlock";
38 changes: 25 additions & 13 deletions ownCloudAppShared/AppLock/PasscodeSetupCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,36 @@ public class PasscodeSetupCoordinator {

public func showSuggestBiometricalUnlockUI() {
if let biometricalSecurityName = LAContext().supportedBiometricsAuthenticationName() {
let alertController = UIAlertController(title: biometricalSecurityName, message: String(format:"Unlock using %@?".localized, biometricalSecurityName), preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "Enable".localized, style: .default, handler: { _ in
PasscodeSetupCoordinator.isBiometricalSecurityEnabled = true
if AppLockSettings.shared.biometricalSecurityEnabled {
self.passcodeViewController?.dismiss(animated: true, completion: {
self.completionHandler?(false)
})
}))
if AppLockManager.supportedOnDevice {
AppLockManager.shared.showLockscreenIfNeeded()
}
} else {
let alertController = UIAlertController(title: biometricalSecurityName, message: String(format:"Unlock using %@?".localized, biometricalSecurityName), preferredStyle: .alert)

alertController.addAction(UIAlertAction(title: "Disable".localized, style: .cancel, handler: { _ in
PasscodeSetupCoordinator.isBiometricalSecurityEnabled = false
self.passcodeViewController?.dismiss(animated: true, completion: {
self.completionHandler?(false)
})
}))
alertController.addAction(UIAlertAction(title: "Enable".localized, style: .default, handler: { _ in
PasscodeSetupCoordinator.isBiometricalSecurityEnabled = true
self.passcodeViewController?.dismiss(animated: true, completion: {
self.completionHandler?(false)
})
if AppLockManager.supportedOnDevice {
AppLockManager.shared.showLockscreenIfNeeded()
}
}))

alertController.addAction(UIAlertAction(title: "Disable".localized, style: .cancel, handler: { _ in
PasscodeSetupCoordinator.isBiometricalSecurityEnabled = false
self.passcodeViewController?.dismiss(animated: true, completion: {
self.completionHandler?(false)
})
}))

self.passcodeViewController?.present(alertController, animated: true, completion: {
})
self.passcodeViewController?.present(alertController, animated: true, completion: {
})
}
} else {
self.passcodeViewController?.dismiss(animated: true, completion: {
self.completionHandler?(false)
Expand Down