Skip to content

Commit 578e845

Browse files
authored
Merge pull request #442 from qwertyfinger/fix-biometric-permanent-lock
Remove note protection if biometric id is no longer available
2 parents a66c723 + e099ba6 commit 578e845

File tree

7 files changed

+65
-39
lines changed

7 files changed

+65
-39
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ android {
5656
}
5757

5858
dependencies {
59-
implementation 'com.github.SimpleMobileTools:Simple-Commons:dc3f4b619e'
59+
implementation 'com.github.SimpleMobileTools:Simple-Commons:8979ca8187'
6060
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
6161
implementation 'androidx.documentfile:documentfile:1.0.1'
6262

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
android:name="android.hardware.faketouch"
1212
android:required="false" />
1313

14-
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
15-
1614
<application
1715
android:name=".App"
1816
android:allowBackup="true"

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.shouldBeUnlocked(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.shouldBeUnlocked(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.shouldBeUnlocked(this)) {
131133
updateCurrentNote(note)
132134
} else {
133135
performSecurityCheck(

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

Lines changed: 11 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,10 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
120122
}
121123

122124
override fun checkLockState() {
125+
if (note == null) {
126+
return
127+
}
128+
123129
view.apply {
124130
checklist_content_holder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
125131
checklist_fab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)

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

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

178178
override fun checkLockState() {
179+
if (note == null) {
180+
return
181+
}
182+
179183
view.apply {
180184
notes_counter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
181185
notes_scrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
@@ -263,11 +267,13 @@ class TextFragment : NoteFragment() {
263267
text.removeSpan(span)
264268
}
265269

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

273279
fun redo() {
@@ -285,11 +291,13 @@ class TextFragment : NoteFragment() {
285291
text.removeSpan(o)
286292
}
287293

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

295303
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 shouldBeUnlocked(context: Context): Boolean {
45+
return protectionType == PROTECTION_FINGERPRINT && !context.isBiometricIdAvailable()
46+
}
4047
}

0 commit comments

Comments
 (0)