From 8cab8a3c793950e633b69ee41e7a5e0cb5042f69 Mon Sep 17 00:00:00 2001 From: merkost Date: Thu, 15 Jun 2023 16:23:11 +1000 Subject: [PATCH 1/2] Fixed directBoot crashes --- .../kotlin/com/simplemobiletools/keyboard/App.kt | 4 ++-- .../simplemobiletools/keyboard/extensions/Context.kt | 12 ++++++++---- .../com/simplemobiletools/keyboard/helpers/Config.kt | 6 +++--- .../keyboard/views/MyKeyboardView.kt | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt index 55c2d87..91418e6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt @@ -4,12 +4,12 @@ import android.app.Application import androidx.emoji2.bundled.BundledEmojiCompatConfig import androidx.emoji2.text.EmojiCompat import com.simplemobiletools.commons.extensions.checkUseEnglish -import com.simplemobiletools.keyboard.extensions.isDeviceLocked +import com.simplemobiletools.keyboard.extensions.isDeviceInDirectBootMode class App : Application() { override fun onCreate() { super.onCreate() - if (!isDeviceLocked) { + if (!isDeviceInDirectBootMode) { checkUseEnglish() } setupEmojiCompat() diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 9f2f28d..9ca9e8c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -1,10 +1,10 @@ package com.simplemobiletools.keyboard.extensions -import android.app.KeyguardManager import android.content.ClipboardManager import android.content.Context import android.graphics.Color import android.os.IBinder +import android.os.UserManager import android.view.* import android.widget.TextView import androidx.appcompat.app.AlertDialog @@ -19,17 +19,21 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao + val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context - get() = if (isNougatPlus() && isDeviceLocked) { + get() = if (isNougatPlus() && isDeviceInDirectBootMode) { createDeviceProtectedStorageContext() } else { this } -val Context.isDeviceLocked: Boolean - get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked +val Context.isDeviceInDirectBootMode: Boolean + get() { + val userManager = getSystemService(Context.USER_SERVICE) as UserManager + return isNougatPlus() && userManager.isUserUnlocked + } val Context.clipsDB: ClipsDao get() = ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao() diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt index 42fd98f..11344c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt @@ -2,9 +2,9 @@ package com.simplemobiletools.keyboard.helpers import android.content.Context import com.simplemobiletools.commons.helpers.BaseConfig -import com.simplemobiletools.keyboard.extensions.isDeviceLocked +import com.simplemobiletools.keyboard.extensions.isDeviceInDirectBootMode import com.simplemobiletools.keyboard.extensions.safeStorageContext -import java.util.* +import java.util.Locale class Config(context: Context) : BaseConfig(context) { companion object { @@ -44,7 +44,7 @@ class Config(context: Context) : BaseConfig(context) { set(showClipboardContent) = prefs.edit().putBoolean(SHOW_CLIPBOARD_CONTENT, showClipboardContent).apply() var showNumbersRow: Boolean - get() = if (!context.isDeviceLocked) { + get() = if (!context.isDeviceInDirectBootMode) { prefs.getBoolean(SHOW_NUMBERS_ROW, false) } else { true diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index d14051e..8bbcbc8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -226,7 +226,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt() mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt() - with (context.safeStorageContext) { + with(context.safeStorageContext) { mTextColor = getProperTextColor() mBackgroundColor = getProperBackgroundColor() mPrimaryColor = getProperPrimaryColor() @@ -431,7 +431,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut pinned_clipboard_items.applyColorFilter(mTextColor) clipboard_clear.applyColorFilter(mTextColor) - toolbar_holder.beInvisibleIf(context.isDeviceLocked) + toolbar_holder.beInvisibleIf(context.isDeviceInDirectBootMode) } mClipboardManagerHolder?.apply { From af0f05c299fc702e689f4609f3e08626888ed099 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Thu, 15 Jun 2023 09:19:51 +0200 Subject: [PATCH 2/2] fixing a check --- .../com/simplemobiletools/keyboard/extensions/Context.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 2fd461a..e57df65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -19,7 +19,6 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao - val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context @@ -32,7 +31,7 @@ val Context.safeStorageContext: Context val Context.isDeviceInDirectBootMode: Boolean get() { val userManager = getSystemService(Context.USER_SERVICE) as UserManager - return isNougatPlus() && userManager.isUserUnlocked + return isNougatPlus() && !userManager.isUserUnlocked } val Context.clipsDB: ClipsDao