Browse Source

Add setting to show lockscreen

Vishnu Mohandas 4 years ago
parent
commit
088b73eb70

+ 2 - 2
android/app/src/main/kotlin/io/ente/photos/MainActivity.kt

@@ -1,6 +1,6 @@
 package io.ente.photos
 
-import io.flutter.embedding.android.FlutterActivity;
+import io.flutter.embedding.android.FlutterFragmentActivity;
 
-class MainActivity : FlutterActivity() {
+class MainActivity : FlutterFragmentActivity() {
 }

+ 13 - 0
lib/core/configuration.dart

@@ -42,6 +42,7 @@ class Configuration {
   static const secretKeyKey = "secret_key";
   static const keyAttributesKey = "key_attributes";
   static const keyShouldBackupOverMobileData = "should_backup_over_mobile_data";
+  static const keyShouldShowLockScreen = "should_show_lock_screen";
   static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
 
   SharedPreferences _preferences;
@@ -336,4 +337,16 @@ class Configuration {
       SyncService.instance.sync();
     }
   }
+
+  bool shouldShowLockScreen() {
+    if (_preferences.containsKey(keyShouldShowLockScreen)) {
+      return _preferences.getBool(keyShouldShowLockScreen);
+    } else {
+      return false;
+    }
+  }
+
+  Future<void> setShouldShowLockScreen(bool value) {
+    return _preferences.setBool(keyShouldShowLockScreen, value);
+  }
 }

+ 48 - 0
lib/ui/settings_page.dart

@@ -7,8 +7,10 @@ import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter_email_sender/flutter_email_sender.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
+import 'package:local_auth/local_auth.dart';
 import 'package:package_info_plus/package_info_plus.dart';
 import 'package:path_provider/path_provider.dart';
+import 'package:photos/utils/auth_util.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/services/billing_service.dart';
@@ -37,6 +39,7 @@ class SettingsPage extends StatelessWidget {
   Widget _getBody() {
     final contents = [
       BackupSettingsWidget(),
+      SecuritySectionWidget(),
       SupportSectionWidget(),
       InfoSectionWidget(),
       AccountSectionWidget(),
@@ -252,6 +255,51 @@ class _BackedUpFoldersWidgetState extends State<BackedUpFoldersWidget> {
   }
 }
 
+class SecuritySectionWidget extends StatefulWidget {
+  SecuritySectionWidget({Key key}) : super(key: key);
+
+  @override
+  _SecuritySectionWidgetState createState() => _SecuritySectionWidgetState();
+}
+
+class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
+  @override
+  void initState() {
+    super.initState();
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      child: Column(
+        children: [
+          Padding(padding: EdgeInsets.all(12)),
+          SettingsSectionTitle("security"),
+          Container(
+            height: 36,
+            child: Row(
+              mainAxisAlignment: MainAxisAlignment.spaceBetween,
+              children: [
+                Text("lockscreen"),
+                Switch(
+                  value: Configuration.instance.shouldShowLockScreen(),
+                  onChanged: (value) async {
+                    final result = await requestAuthentication();
+                    if (result) {
+                      Configuration.instance.setShouldShowLockScreen(value);
+                      setState(() {});
+                    }
+                  },
+                ),
+              ],
+            ),
+          ),
+        ],
+      ),
+    );
+  }
+}
+
 class SettingsSectionTitle extends StatelessWidget {
   final String title;
   const SettingsSectionTitle(this.title, {Key key}) : super(key: key);

+ 20 - 0
lib/utils/auth_util.dart

@@ -0,0 +1,20 @@
+import 'package:local_auth/auth_strings.dart';
+import 'package:local_auth/local_auth.dart';
+
+Future<bool> requestAuthentication() async {
+  return await LocalAuthentication().authenticate(
+      localizedReason: "please authenticate to view your memories",
+      androidAuthStrings: AndroidAuthMessages(
+        biometricHint: "verify identity",
+        biometricNotRecognized: "not recognized, try again",
+        biometricRequiredTitle: "biometric required",
+        biometricSuccess: "successfully verified",
+        cancelButton: "cancel",
+        deviceCredentialsRequiredTitle: "device credentials required",
+        deviceCredentialsSetupDescription: "device credentials required",
+        goToSettingsButton: "go to settings",
+        goToSettingsDescription:
+            "authentication is not setup on your device, go to Settings > Security to set it up",
+        signInTitle: "authentication required",
+      ));
+}