-
Notifications
You must be signed in to change notification settings - Fork 483
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
feat(ui): authenticate first when enabling security settings #991
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6f1b0d2
Improve biometric lock security and hide it on tv
IndusAryan 8e608bf
remove imports and redundancy
IndusAryan 6a2d0fd
Merge remote-tracking branch 'origin/master' into fixmetrics
IndusAryan 8ba2fb8
merge with upstream
IndusAryan bbcf024
merge with upstream #2
IndusAryan caf415a
fix some issues
IndusAryan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import androidx.core.view.isVisible | |
import androidx.fragment.app.FragmentActivity | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.PreferenceManager | ||
import androidx.preference.SwitchPreferenceCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser | ||
import com.lagradost.cloudstream3.CommonActivity.onDialogDismissedEvent | ||
|
@@ -30,6 +31,7 @@ import com.lagradost.cloudstream3.syncproviders.AuthAPI | |
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI | ||
import com.lagradost.cloudstream3.syncproviders.OAuth2API | ||
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR | ||
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE | ||
import com.lagradost.cloudstream3.ui.settings.Globals.TV | ||
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout | ||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref | ||
|
@@ -38,13 +40,20 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setTool | |
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar | ||
import com.lagradost.cloudstream3.utils.AppUtils.html | ||
import com.lagradost.cloudstream3.utils.BackupUtils | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.authCallback | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.biometricPrompt | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.deviceHasPasswordPinLock | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.isAuthEnabled | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.promptInfo | ||
import com.lagradost.cloudstream3.utils.BiometricAuthenticator.startBiometricAuthentication | ||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe | ||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialogText | ||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe | ||
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard | ||
import com.lagradost.cloudstream3.utils.UIHelper.setImage | ||
|
||
class SettingsAccount : PreferenceFragmentCompat() { | ||
class SettingsAccount : PreferenceFragmentCompat(), BiometricAuthenticator.BiometricAuthCallback { | ||
companion object { | ||
/** Used by nginx plugin too */ | ||
fun showLoginInfo( | ||
|
@@ -252,6 +261,31 @@ class SettingsAccount : PreferenceFragmentCompat() { | |
} | ||
} | ||
|
||
private fun updateAuthPreference(enabled: Boolean) { | ||
val biometricKey = getString(R.string.biometric_key) | ||
|
||
PreferenceManager.getDefaultSharedPreferences(context ?: requireContext()).edit() | ||
.putBoolean(biometricKey, enabled).apply() | ||
findPreference<SwitchPreferenceCompat>(biometricKey)?.isChecked = enabled | ||
} | ||
|
||
override fun onAuthenticationError() { | ||
updateAuthPreference(!isAuthEnabled(context ?: requireContext())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove requireContext |
||
} | ||
|
||
override fun onAuthenticationSuccess() { | ||
if (isAuthEnabled(context?: return)) { | ||
updateAuthPreference(true) | ||
BackupUtils.backup(activity) | ||
activity?.showBottomDialogText( | ||
getString(R.string.biometric_setting), | ||
getString(R.string.biometric_warning).html() | ||
) { onDialogDismissedEvent } | ||
} else { | ||
updateAuthPreference(false) | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setUpToolbar(R.string.category_account) | ||
|
@@ -262,23 +296,27 @@ class SettingsAccount : PreferenceFragmentCompat() { | |
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
hideKeyboard() | ||
setPreferencesFromResource(R.xml.settings_account, rootKey) | ||
// hide preference on tvs and emulators | ||
if (!isLayout(PHONE)) { | ||
getPref(R.string.biometric_key)?.isEnabled = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getPref(R.string.biometric_key)?.isEnabled = isLayout(PHONE) |
||
} | ||
|
||
getPref(R.string.biometric_key)?.setOnPreferenceClickListener { | ||
val authEnabled = PreferenceManager.getDefaultSharedPreferences( | ||
context ?: return@setOnPreferenceClickListener false | ||
) | ||
.getBoolean(getString(R.string.biometric_key), false) | ||
|
||
if (authEnabled) { | ||
BackupUtils.backup(activity) | ||
val title = activity?.getString(R.string.biometric_setting) | ||
val warning = activity?.getString(R.string.biometric_warning) | ||
activity?.showBottomDialogText( | ||
title as String, | ||
warning.html() | ||
) { onDialogDismissedEvent } | ||
val ctx = context ?: return@setOnPreferenceClickListener false | ||
|
||
if (deviceHasPasswordPinLock(ctx)) { | ||
startBiometricAuthentication( | ||
activity?: requireActivity(), | ||
R.string.biometric_authentication_title, | ||
false | ||
) | ||
promptInfo?.let { | ||
authCallback = this | ||
biometricPrompt?.authenticate(it) | ||
} | ||
} | ||
true | ||
|
||
false | ||
} | ||
|
||
val syncApis = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove requireContext