Do not show shortcuts if a PIN code is set

This commit is contained in:
Benoit Marty 2021-10-27 15:24:24 +02:00
parent 3a81c10062
commit 6f577d8232
2 changed files with 14 additions and 7 deletions

1
changelog.d/4170.bugfix Normal file
View File

@ -0,0 +1 @@
Do not show shortcuts if a PIN code is set

View File

@ -22,6 +22,7 @@ import android.os.Build
import androidx.core.content.getSystemService
import androidx.core.content.pm.ShortcutManagerCompat
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.features.pin.PinCodeStore
import io.reactivex.disposables.Disposable
import io.reactivex.disposables.Disposables
import org.matrix.android.sdk.api.session.room.RoomSortOrder
@ -35,7 +36,8 @@ import javax.inject.Inject
class ShortcutsHandler @Inject constructor(
private val context: Context,
private val shortcutCreator: ShortcutCreator,
private val activeSessionHolder: ActiveSessionHolder
private val activeSessionHolder: ActiveSessionHolder,
private val pinCodeStore: PinCodeStore
) {
fun observeRoomsAndBuildShortcuts(): Disposable {
@ -61,7 +63,6 @@ class ShortcutsHandler @Inject constructor(
}
}
private fun removeDeadShortcut(roomIds: List<String>) {
val deadShortcutIds = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_DYNAMIC)
.map { it.id }
@ -79,12 +80,17 @@ class ShortcutsHandler @Inject constructor(
}
private fun createShortcuts(rooms: List<RoomSummary>) {
val shortcuts = rooms.mapIndexed { index, room ->
shortcutCreator.create(room, index)
}
if (pinCodeStore.getEncodedPin() != null) {
// No shortcut in this case (privacy)
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
} else {
val shortcuts = rooms.mapIndexed { index, room ->
shortcutCreator.create(room, index)
}
shortcuts.forEach { shortcut ->
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
shortcuts.forEach { shortcut ->
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
}
}
}