Added isDeviceLocked extension

This commit is contained in:
merkost 2023-05-29 21:35:35 +10:00
parent 0b3bf0a750
commit 9fba023443
1 changed files with 9 additions and 13 deletions

View File

@ -1,15 +1,12 @@
package com.simplemobiletools.keyboard.extensions package com.simplemobiletools.keyboard.extensions
import android.app.KeyguardManager
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.view.LayoutInflater import android.view.*
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
@ -25,19 +22,18 @@ import com.simplemobiletools.keyboard.interfaces.ClipsDao
val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext)
val Context.safeStorageContext: Context val Context.safeStorageContext: Context
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) {
val deviceContext = createDeviceProtectedStorageContext() val deviceStorageContext = createDeviceProtectedStorageContext()
deviceContext deviceStorageContext
} else { } else {
this this
} }
val Context.isDeviceLocked: Boolean
get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
val Context.clipsDB: ClipsDao val Context.clipsDB: ClipsDao
get() = if (isDeviceLocked) { get() = ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao()
ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao()
} else {
ClipsDatabase.getInstance(applicationContext).ClipsDao()
}
fun Context.getCurrentClip(): String? { fun Context.getCurrentClip(): String? {
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)