mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Merge pull request #2181 from vector-im/feature/bma_pin_fix
PIN code: request PIN code if phone has been locked
This commit is contained in:
commit
a3570a69dd
3 changed files with 24 additions and 1 deletions
|
@ -5,7 +5,7 @@ Features ✨:
|
|||
-
|
||||
|
||||
Improvements 🙌:
|
||||
-
|
||||
- PIN code: request PIN code if phone has been locked
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fix Splash layout on small screens
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
package im.vector.app
|
||||
|
||||
import android.app.Application
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.res.Configuration
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
|
@ -92,6 +95,15 @@ class VectorApplication :
|
|||
// font thread handler
|
||||
private var fontThreadHandler: Handler? = null
|
||||
|
||||
private val powerKeyReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent) {
|
||||
if (intent.action == Intent.ACTION_SCREEN_OFF
|
||||
&& vectorPreferences.useFlagPinCode()) {
|
||||
pinLocker.screenIsOff()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
enableStrictModeIfNeeded()
|
||||
super.onCreate()
|
||||
|
@ -163,6 +175,12 @@ class VectorApplication :
|
|||
ProcessLifecycleOwner.get().lifecycle.addObserver(pinLocker)
|
||||
// This should be done as early as possible
|
||||
// initKnownEmojiHashSet(appContext)
|
||||
|
||||
applicationContext.registerReceiver(powerKeyReceiver, IntentFilter().apply {
|
||||
// Looks like i cannot receive OFF, if i don't have both ON and OFF
|
||||
addAction(Intent.ACTION_SCREEN_OFF)
|
||||
addAction(Intent.ACTION_SCREEN_ON)
|
||||
})
|
||||
}
|
||||
|
||||
private fun enableStrictModeIfNeeded() {
|
||||
|
|
|
@ -81,6 +81,11 @@ class PinLocker @Inject constructor(
|
|||
computeState()
|
||||
}
|
||||
|
||||
fun screenIsOff() {
|
||||
shouldBeLocked = true
|
||||
computeState()
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun entersForeground() {
|
||||
val timeElapsedSinceBackground = SystemClock.elapsedRealtime() - entersBackgroundTs
|
||||
|
|
Loading…
Reference in a new issue