diff --git a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt index d0e4c938cd..75f61a7b01 100644 --- a/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/FragmentModule.kt @@ -89,6 +89,7 @@ import im.vector.app.features.settings.VectorSettingsHelpAboutFragment import im.vector.app.features.settings.VectorSettingsLabsFragment import im.vector.app.features.settings.VectorSettingsNotificationPreferenceFragment import im.vector.app.features.settings.VectorSettingsNotificationsTroubleshootFragment +import im.vector.app.features.settings.VectorSettingsPinFragment import im.vector.app.features.settings.VectorSettingsPreferencesFragment import im.vector.app.features.settings.VectorSettingsSecurityPrivacyFragment import im.vector.app.features.settings.account.deactivation.DeactivateAccountFragment @@ -284,6 +285,11 @@ interface FragmentModule { @FragmentKey(VectorSettingsLabsFragment::class) fun bindVectorSettingsLabsFragment(fragment: VectorSettingsLabsFragment): Fragment + @Binds + @IntoMap + @FragmentKey(VectorSettingsPinFragment::class) + fun bindVectorSettingsPinFragment(fragment: VectorSettingsPinFragment): Fragment + @Binds @IntoMap @FragmentKey(PushRulesFragment::class) diff --git a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt index a2930c6129..0216ec512e 100644 --- a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt +++ b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt @@ -28,7 +28,6 @@ import im.vector.app.core.platform.VectorBaseActivity class PinActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedActivity { companion object { - const val PIN_REQUEST_CODE = 17890 fun newIntent(context: Context, args: PinArgs): Intent { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPinFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPinFragment.kt new file mode 100644 index 0000000000..e8f3e51b4f --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsPinFragment.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.settings + +import android.content.Intent +import androidx.lifecycle.lifecycleScope +import androidx.preference.Preference +import androidx.preference.SwitchPreference +import im.vector.app.R +import im.vector.app.features.navigation.Navigator +import im.vector.app.features.pin.PinActivity +import im.vector.app.features.pin.PinCodeStore +import im.vector.app.features.pin.PinLocker +import im.vector.app.features.pin.PinMode +import javax.inject.Inject + +class VectorSettingsPinFragment @Inject constructor( + private val pinLocker: PinLocker, + private val pinCodeStore: PinCodeStore, + private val navigator: Navigator +) : VectorSettingsBaseFragment() { + + override var titleRes = R.string.settings_security_application_protection_screen_title + override val preferenceXmlRes = R.xml.vector_settings_pin + + private val usePinCodePref by lazy { + findPreference(VectorPreferences.SETTINGS_SECURITY_USE_PIN_CODE_FLAG)!! + } + + override fun bindPref() { + refreshPinCodeStatus() + } + + private fun refreshPinCodeStatus() { + lifecycleScope.launchWhenResumed { + val hasPinCode = pinCodeStore.hasEncodedPin() + usePinCodePref.isChecked = hasPinCode + usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener { + val pinMode = if (hasPinCode) { + PinMode.DELETE + } else { + PinMode.CREATE + } + navigator.openPinCode(this@VectorSettingsPinFragment, pinMode) + true + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == PinActivity.PIN_REQUEST_CODE) { + pinLocker.unlock() + refreshPinCodeStatus() + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt index ff824733ae..532ab39eb3 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt @@ -29,7 +29,6 @@ import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat import androidx.core.view.isVisible -import androidx.lifecycle.lifecycleScope import androidx.preference.Preference import androidx.preference.PreferenceCategory import androidx.preference.SwitchPreference @@ -53,11 +52,6 @@ import im.vector.app.features.crypto.keys.KeysExporter import im.vector.app.features.crypto.keys.KeysImporter import im.vector.app.features.crypto.keysbackup.settings.KeysBackupManageActivity import im.vector.app.features.crypto.recover.BootstrapBottomSheet -import im.vector.app.features.navigation.Navigator -import im.vector.app.features.pin.PinActivity -import im.vector.app.features.pin.PinCodeStore -import im.vector.app.features.pin.PinLocker -import im.vector.app.features.pin.PinMode import im.vector.app.features.raw.wellknown.ElementWellKnownMapper import im.vector.app.features.raw.wellknown.isE2EByDefault import im.vector.app.features.themes.ThemeUtils @@ -76,10 +70,7 @@ import javax.inject.Inject class VectorSettingsSecurityPrivacyFragment @Inject constructor( private val vectorPreferences: VectorPreferences, - private val pinLocker: PinLocker, - private val activeSessionHolder: ActiveSessionHolder, - private val pinCodeStore: PinCodeStore, - private val navigator: Navigator + private val activeSessionHolder: ActiveSessionHolder ) : VectorSettingsBaseFragment() { override var titleRes = R.string.settings_security_and_privacy @@ -128,10 +119,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( findPreference(VectorPreferences.SETTINGS_ENCRYPTION_NEVER_SENT_TO_PREFERENCE_KEY)!! } - private val usePinCodePref by lazy { - findPreference(VectorPreferences.SETTINGS_SECURITY_USE_PIN_CODE_FLAG)!! - } - override fun onCreateRecyclerView(inflater: LayoutInflater?, parent: ViewGroup?, savedInstanceState: Bundle?): RecyclerView { return super.onCreateRecyclerView(inflater, parent, savedInstanceState).also { // Insert animation are really annoying the first time the list is shown @@ -265,8 +252,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } } - refreshPinCodeStatus() - refreshXSigningStatus() secureBackupPreference.icon = activity?.let { @@ -351,9 +336,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( }) } } - } else if (requestCode == PinActivity.PIN_REQUEST_CODE) { - pinLocker.unlock() - refreshPinCodeStatus() } else if (requestCode == REQUEST_E2E_FILE_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { importKeys(data) @@ -361,22 +343,6 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor( } } - private fun refreshPinCodeStatus() { - lifecycleScope.launchWhenResumed { - val hasPinCode = pinCodeStore.hasEncodedPin() - usePinCodePref.isChecked = hasPinCode - usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener { - val pinMode = if (hasPinCode) { - PinMode.DELETE - } else { - PinMode.CREATE - } - navigator.openPinCode(this@VectorSettingsSecurityPrivacyFragment, pinMode) - true - } - } - } - private fun refreshKeysManagementSection() { // If crypto is not enabled parent section will be removed // TODO notice that this will not work when no network diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 61580a66d4..1ea92edcee 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -2566,6 +2566,9 @@ Reset pin New pin To reset your PIN, you\'ll need to re-login and create a new one. + Protect access to the application. + Protect access to the application using pin code and biometrics. + Configure protection Enable PIN If you want to reset your PIN, tap Forgot PIN to logout and reset. Confirm PIN to disable PIN diff --git a/vector/src/main/res/xml/vector_settings_pin.xml b/vector/src/main/res/xml/vector_settings_pin.xml new file mode 100644 index 0000000000..2969a93b53 --- /dev/null +++ b/vector/src/main/res/xml/vector_settings_pin.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/vector/src/main/res/xml/vector_settings_security_privacy.xml b/vector/src/main/res/xml/vector_settings_security_privacy.xml index 9cd629251e..75256a5ead 100644 --- a/vector/src/main/res/xml/vector_settings_security_privacy.xml +++ b/vector/src/main/res/xml/vector_settings_security_privacy.xml @@ -117,18 +117,19 @@ + + - - \ No newline at end of file