Add password protection feature to the app

This closes #446
This commit is contained in:
Ensar Sarajčić 2023-06-30 09:29:36 +02:00
parent af9143f46e
commit 143aaece4b
4 changed files with 62 additions and 6 deletions

View File

@ -21,7 +21,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.USE_FINGERPRINT"
android:name="android.permission.USE_BIOMETRIC"
tools:node="remove" />
<queries>
@ -55,9 +55,9 @@
android:name=".activities.ThreadActivity"
android:configChanges="orientation"
android:exported="false"
android:launchMode="singleTop"
android:parentActivityName=".activities.MainActivity"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop" />
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activities.NewConversationActivity"

View File

@ -62,6 +62,14 @@ class MainActivity : SimpleActivity() {
updateMaterialActivityViews(main_coordinator, conversations_list, useTransparentNavigation = true, useTopSearchMenu = true)
if (savedInstanceState == null) {
handleAppPasswordProtection {
if (!it) {
finish()
}
}
}
if (checkAppSideloading()) {
return
}
@ -636,6 +644,7 @@ class MainActivity : SimpleActivity() {
showErrorToast(e)
}
}
else -> toast(R.string.invalid_file_format)
}
}

View File

@ -5,9 +5,7 @@ import android.content.Intent
import android.os.Build
import android.os.Bundle
import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity
import com.simplemobiletools.commons.dialogs.ChangeDateTimeFormatDialog
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.dialogs.*
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
@ -49,6 +47,7 @@ class SettingsActivity : SimpleActivity() {
setupGroupMessageAsMMS()
setupLockScreenVisibility()
setupMMSFileSizeLimit()
setupAppPasswordProtection()
updateTextColors(settings_nested_scrollview)
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
@ -244,6 +243,28 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupAppPasswordProtection() {
settings_app_password_protection.isChecked = config.isAppPasswordProtectionOn
settings_app_password_protection_holder.setOnClickListener {
val tabToShow = if (config.isAppPasswordProtectionOn) config.appProtectionType else SHOW_ALL_TABS
SecurityDialog(this, config.appPasswordHash, tabToShow) { hash, type, success ->
if (success) {
val hasPasswordProtection = config.isAppPasswordProtectionOn
settings_app_password_protection.isChecked = !hasPasswordProtection
config.isAppPasswordProtectionOn = !hasPasswordProtection
config.appPasswordHash = if (hasPasswordProtection) "" else hash
config.appProtectionType = type
if (config.isAppPasswordProtectionOn) {
val confirmationTextId = if (config.appProtectionType == PROTECTION_FINGERPRINT)
R.string.fingerprint_setup_successfully else R.string.protection_setup_successfully
ConfirmationDialog(this, "", confirmationTextId, R.string.ok, 0) { }
}
}
}
}
}
private fun getMMSFileLimitText() = getString(
when (config.mmsFileSizeLimit) {
FILE_SIZE_100_KB -> R.string.mms_file_size_limit_100kb

View File

@ -341,6 +341,32 @@
tools:text="@string/mms_file_size_limit_none" />
</RelativeLayout>
<include
android:id="@+id/settings_outgoing_messages_divider"
layout="@layout/divider" />
<TextView
android:id="@+id/settings_security_label"
style="@style/SettingsSectionLabelStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/security" />
<RelativeLayout
android:id="@+id/settings_app_password_protection_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_app_password_protection"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password_protect_whole_app" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>