Skip to content

Commit a2faa71

Browse files
author
Andrii Chubko
committed
Remove note protection if biometric id is no longer available
This check is done to avoid user not being able to unlock the note if he removes biometric id from phone settings.
1 parent e9131ca commit a2faa71

File tree

5 files changed

+60
-36
lines changed

5 files changed

+60
-36
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ class MainActivity : SimpleActivity() {
316316
}
317317

318318
private fun initViewPager(wantedNoteId: Long? = null) {
319-
NotesHelper(this).getNotes {
320-
mNotes = it
319+
NotesHelper(this).getNotes { notes ->
320+
notes.filter { it.isBiometricLockUnavailable(this) }
321+
.forEach(::removeProtection)
322+
323+
mNotes = notes
321324
invalidateOptionsMenu()
322325
mCurrentNote = mNotes[0]
323326
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
@@ -1084,19 +1087,21 @@ class MainActivity : SimpleActivity() {
10841087
performSecurityCheck(
10851088
protectionType = mCurrentNote.protectionType,
10861089
requiredHash = mCurrentNote.protectionHash,
1087-
successCallback = { _, _ -> removeProtection() }
1090+
successCallback = { _, _ -> removeProtection(mCurrentNote) }
10881091
)
10891092
}
10901093

1091-
private fun removeProtection() {
1092-
mCurrentNote.protectionHash = ""
1093-
mCurrentNote.protectionType = PROTECTION_NONE
1094-
NotesHelper(this).insertOrUpdateNote(mCurrentNote) {
1095-
getCurrentFragment()?.apply {
1096-
shouldShowLockedContent = true
1097-
checkLockState()
1094+
private fun removeProtection(note: Note) {
1095+
note.protectionHash = ""
1096+
note.protectionType = PROTECTION_NONE
1097+
NotesHelper(this).insertOrUpdateNote(note) {
1098+
if (note == mCurrentNote) {
1099+
getCurrentFragment()?.apply {
1100+
shouldShowLockedContent = true
1101+
checkLockState()
1102+
}
1103+
invalidateOptionsMenu()
10981104
}
1099-
invalidateOptionsMenu()
11001105
}
11011106
}
11021107

app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,18 @@ class WidgetConfigureActivity : SimpleActivity() {
104104

105105
if (mNotes.size == 1 && note == null) {
106106
note = mNotes.first()
107-
performSecurityCheck(
108-
protectionType = note.protectionType,
109-
requiredHash = note.protectionHash,
110-
successCallback = { _, _ -> updateCurrentNote(note) },
111-
failureCallback = { finish() }
112-
)
113-
} else {
114-
if (note != null) {
107+
if (note.isBiometricLockUnavailable(this)) {
115108
updateCurrentNote(note)
109+
} else {
110+
performSecurityCheck(
111+
protectionType = note.protectionType,
112+
requiredHash = note.protectionHash,
113+
successCallback = { _, _ -> updateCurrentNote(note) },
114+
failureCallback = { finish() }
115+
)
116116
}
117+
} else if (note != null) {
118+
updateCurrentNote(note)
117119
}
118120
}
119121
}
@@ -127,7 +129,7 @@ class WidgetConfigureActivity : SimpleActivity() {
127129
RadioGroupDialog(this, items, mCurrentNoteId.toInt()) {
128130
val selectedId = it as Int
129131
val note = mNotes.firstOrNull { it.id!!.toInt() == selectedId } ?: return@RadioGroupDialog
130-
if (note.protectionType == PROTECTION_NONE) {
132+
if (note.protectionType == PROTECTION_NONE || note.isBiometricLockUnavailable(this)) {
131133
updateCurrentNote(note)
132134
} else {
133135
performSecurityCheck(

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
7878
items.clear()
7979

8080
note.value.split("\n").map { it.trim() }.filter { it.isNotBlank() }.forEachIndexed { index, value ->
81-
items.add(ChecklistItem(
82-
id = index,
83-
title = value,
84-
isDone = false
85-
))
81+
items.add(
82+
ChecklistItem(
83+
id = index,
84+
title = value,
85+
isDone = false
86+
)
87+
)
8688
}
8789

8890
saveChecklist()
@@ -120,6 +122,8 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
120122
}
121123

122124
override fun checkLockState() {
125+
if (note == null) return
126+
123127
view.apply {
124128
checklist_content_holder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
125129
checklist_fab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class TextFragment : NoteFragment() {
176176
fun removeTextWatcher() = view.text_note_view.removeTextChangedListener(textWatcher)
177177

178178
override fun checkLockState() {
179+
if (note == null) return
180+
179181
view.apply {
180182
notes_counter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
181183
notes_scrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
@@ -263,11 +265,13 @@ class TextFragment : NoteFragment() {
263265
text.removeSpan(span)
264266
}
265267

266-
Selection.setSelection(text, if (edit.before == null) {
267-
start
268-
} else {
269-
start + edit.before.length
270-
})
268+
Selection.setSelection(
269+
text, if (edit.before == null) {
270+
start
271+
} else {
272+
start + edit.before.length
273+
}
274+
)
271275
}
272276

273277
fun redo() {
@@ -285,11 +289,13 @@ class TextFragment : NoteFragment() {
285289
text.removeSpan(o)
286290
}
287291

288-
Selection.setSelection(text, if (edit.after == null) {
289-
start
290-
} else {
291-
start + edit.after.length
292-
})
292+
Selection.setSelection(
293+
text, if (edit.after == null) {
294+
start
295+
} else {
296+
start + edit.after.length
297+
}
298+
)
293299
}
294300

295301
fun isUndoAvailable() = textHistory.position > 0

app/src/main/kotlin/com/simplemobiletools/notes/pro/models/Note.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import androidx.room.ColumnInfo
66
import androidx.room.Entity
77
import androidx.room.Index
88
import androidx.room.PrimaryKey
9+
import com.simplemobiletools.commons.extensions.isBiometricIdAvailable
10+
import com.simplemobiletools.commons.helpers.PROTECTION_FINGERPRINT
911
import com.simplemobiletools.commons.helpers.PROTECTION_NONE
1012
import java.io.File
1113

@@ -17,7 +19,8 @@ data class Note(
1719
@ColumnInfo(name = "type") var type: Int,
1820
@ColumnInfo(name = "path") var path: String,
1921
@ColumnInfo(name = "protection_type") var protectionType: Int,
20-
@ColumnInfo(name = "protection_hash") var protectionHash: String) {
22+
@ColumnInfo(name = "protection_hash") var protectionHash: String
23+
) {
2124

2225
fun getNoteStoredValue(context: Context): String? {
2326
return if (path.isNotEmpty()) {
@@ -37,4 +40,8 @@ data class Note(
3740
}
3841

3942
fun isLocked() = protectionType != PROTECTION_NONE
43+
44+
fun isBiometricLockUnavailable(context: Context): Boolean {
45+
return protectionType == PROTECTION_FINGERPRINT && !context.isBiometricIdAvailable()
46+
}
4047
}

0 commit comments

Comments
 (0)