diff --git a/app/src/main/java/com/bintianqi/owndroid/Auth.kt b/app/src/main/java/com/bintianqi/owndroid/Auth.kt index 6075013..ccad6a8 100644 --- a/app/src/main/java/com/bintianqi/owndroid/Auth.kt +++ b/app/src/main/java/com/bintianqi/owndroid/Auth.kt @@ -101,16 +101,21 @@ fun Auth(activity: FragmentActivity, callback: AuthenticationCallback, promptInf Button( onClick = { val bioManager = BiometricManager.from(context) - when(BiometricManager.BIOMETRIC_SUCCESS){ - bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) -> - promptInfo - .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG) - .setNegativeButtonText("Use password") - bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) -> - promptInfo - .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK) - .setNegativeButtonText("Use password") - else -> promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL) + val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE) + if(sharedPref.getBoolean("bio_auth", false)){ + when(BiometricManager.BIOMETRIC_SUCCESS){ + bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) -> + promptInfo + .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG) + .setNegativeButtonText("Use password") + bioManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK) -> + promptInfo + .setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_WEAK) + .setNegativeButtonText("Use password") + else -> promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL) + } + }else{ + promptInfo.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL) } authWithBiometricPrompt(activity, promptInfo.build(), callback) } diff --git a/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt b/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt index c2e0a3c..ba44883 100644 --- a/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt +++ b/app/src/main/java/com/bintianqi/owndroid/MainActivity.kt @@ -60,9 +60,14 @@ class MainActivity : FragmentActivity() { WindowCompat.setDecorFitsSystemWindows(window, false) super.onCreate(savedInstanceState) setContentView(R.layout.base) + val sharedPref = applicationContext.getSharedPreferences("data", Context.MODE_PRIVATE) val fragmentManager = supportFragmentManager val transaction = fragmentManager.beginTransaction() - transaction.add(R.id.base, AuthFragment(), "auth") + if(sharedPref.getBoolean("auth", false)){ + transaction.add(R.id.base, AuthFragment(), "auth") + }else{ + transaction.add(R.id.base, homeFragment, "home") + } transaction.commit() val locale = applicationContext.resources?.configuration?.locale zhCN = locale==Locale.SIMPLIFIED_CHINESE||locale==Locale.CHINESE||locale==Locale.CHINA diff --git a/app/src/main/java/com/bintianqi/owndroid/Setting.kt b/app/src/main/java/com/bintianqi/owndroid/Setting.kt index eb59a9a..2337fc9 100644 --- a/app/src/main/java/com/bintianqi/owndroid/Setting.kt +++ b/app/src/main/java/com/bintianqi/owndroid/Setting.kt @@ -14,9 +14,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.Scaffold import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.getValue +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource @@ -56,9 +54,10 @@ fun AppSetting(navCtrl:NavHostController, materialYou: MutableState, bl popExitTransition = Animations.navHostPopExitTransition, modifier = Modifier.padding(top = it.calculateTopPadding()) ){ - composable(route = "Home"){Home(localNavCtrl)} - composable(route = "Settings"){Settings(materialYou, blackTheme)} - composable(route = "About"){About()} + composable(route = "Home"){ Home(localNavCtrl) } + composable(route = "Theme"){ ThemeSettings(materialYou, blackTheme) } + composable(route = "Auth"){ AuthSettings() } + composable(route = "About"){ About() } } } } @@ -66,13 +65,14 @@ fun AppSetting(navCtrl:NavHostController, materialYou: MutableState, bl @Composable private fun Home(navCtrl: NavHostController){ Column(modifier = Modifier.fillMaxSize()){ - SubPageItem(R.string.setting,"",R.drawable.settings_fill0){navCtrl.navigate("Settings")} + SubPageItem(R.string.setting,"",R.drawable.settings_fill0){navCtrl.navigate("Theme")} + SubPageItem(R.string.security,"",R.drawable.settings_fill0){navCtrl.navigate("Auth")} SubPageItem(R.string.about,"",R.drawable.info_fill0){navCtrl.navigate("About")} } } @Composable -private fun Settings(materialYou:MutableState, blackTheme:MutableState){ +private fun ThemeSettings(materialYou:MutableState, blackTheme:MutableState){ val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) { if(VERSION.SDK_INT>=31){ @@ -98,6 +98,31 @@ private fun Settings(materialYou:MutableState, blackTheme:MutableState< } } +@Composable +private fun AuthSettings(){ + val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE) + var auth by remember{ mutableStateOf(sharedPref.getBoolean("auth",false)) } + Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) { + if(VERSION.SDK_INT>=30){ + SwitchItem( + R.string.lock_owndroid, "", null, + { auth }, + { + sharedPref.edit().putBoolean("auth",it).apply() + auth = sharedPref.getBoolean("auth",false) + } + ) + } + if(auth){ + SwitchItem( + R.string.enable_bio_auth, "", null, + { sharedPref.getBoolean("bio_auth",false) }, + { sharedPref.edit().putBoolean("bio_auth",it).apply() } + ) + } + } +} + @Composable private fun About(){ val myContext = LocalContext.current diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index bb31a11..0c73510 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -480,6 +480,9 @@ 源代码 纯黑夜间主题 需要打开夜间模式 + 安全 + 锁定OwnDroid + 使用生物识别 读取外部存储 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df0a295..44c4853 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -495,6 +495,9 @@ Source code Black theme Require dark mode on + Security + Lock OwnDroid + Auth with biometrics Read external storage