Configured storage for direct boot mode

This commit is contained in:
merkost 2023-05-26 12:26:18 +10:00
parent 1b15a52fcb
commit fc6bee9df7
4 changed files with 18 additions and 6 deletions

View File

@ -25,7 +25,6 @@
<activity <activity
android:name=".activities.SplashActivity" android:name=".activities.SplashActivity"
android:directBootAware="true"
android:exported="false" android:exported="false"
android:theme="@style/SplashTheme" /> android:theme="@style/SplashTheme" />

View File

@ -4,7 +4,6 @@ import android.content.Context
import androidx.room.Database import androidx.room.Database
import androidx.room.Room import androidx.room.Room
import androidx.room.RoomDatabase import androidx.room.RoomDatabase
import com.simplemobiletools.commons.extensions.safeStorageContext
import com.simplemobiletools.keyboard.interfaces.ClipsDao import com.simplemobiletools.keyboard.interfaces.ClipsDao
import com.simplemobiletools.keyboard.models.Clip import com.simplemobiletools.keyboard.models.Clip
@ -20,7 +19,7 @@ abstract class ClipsDatabase : RoomDatabase() {
if (db == null) { if (db == null) {
synchronized(ClipsDatabase::class) { synchronized(ClipsDatabase::class) {
if (db == null) { if (db == null) {
db = Room.databaseBuilder(context.applicationContext.safeStorageContext, ClipsDatabase::class.java, "clips.db").build() db = Room.databaseBuilder(context, ClipsDatabase::class.java, "clips.db").build()
db!!.openHelper.setWriteAheadLoggingEnabled(true) db!!.openHelper.setWriteAheadLoggingEnabled(true)
} }
} }

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.keyboard.extensions
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.IBinder import android.os.IBinder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -21,9 +22,21 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase
import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.helpers.*
import com.simplemobiletools.keyboard.interfaces.ClipsDao import com.simplemobiletools.keyboard.interfaces.ClipsDao
val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.config: Config get() = Config.newInstance(applicationContext)
val Context.clipsDB: ClipsDao get() = ClipsDatabase.getInstance(applicationContext).ClipsDao() val Context.safeStorageContext: Context
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
createDeviceProtectedStorageContext()
} else {
this
}
val Context.clipsDB: ClipsDao
get() = if (isDeviceLocked) {
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)

View File

@ -2,11 +2,12 @@ package com.simplemobiletools.keyboard.helpers
import android.content.Context import android.content.Context
import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.keyboard.extensions.safeStorageContext
import java.util.* import java.util.*
class Config(context: Context) : BaseConfig(context) { class Config(context: Context) : BaseConfig(context) {
companion object { companion object {
fun newInstance(context: Context) = Config(context) fun newInstance(context: Context) = Config(context.safeStorageContext)
} }
var vibrateOnKeypress: Boolean var vibrateOnKeypress: Boolean