From 739d5c48f2ec0f31d984a637eb2411c85afda6d2 Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sun, 15 Nov 2026 21:01:30 +0530 Subject: [PATCH 1/2] fix(lint): make the default locale explicit in String.format Behavior is unchanged, numbers are still formatted for the device locale. --- .../keyboard/settings/dialogs/SoundPackDownloadDialog.kt | 3 ++- .../helium314/keyboard/settings/screens/AdvancedScreen.kt | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/dialogs/SoundPackDownloadDialog.kt b/app/src/main/java/helium314/keyboard/settings/dialogs/SoundPackDownloadDialog.kt index 975dce09e..7d45c2fca 100644 --- a/app/src/main/java/helium314/keyboard/settings/dialogs/SoundPackDownloadDialog.kt +++ b/app/src/main/java/helium314/keyboard/settings/dialogs/SoundPackDownloadDialog.kt @@ -59,6 +59,7 @@ import helium314.keyboard.latin.utils.prefs import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.util.Locale @Composable fun SoundPackDownloadDialog( @@ -362,7 +363,7 @@ fun SoundPackDownloadDialog( append("v${rPack.versionName} • ") if (rPack.sizeBytes > 0) { val kb = rPack.sizeBytes / 1024 - if (kb >= 1024) append(String.format("%.1f MB", kb / 1024f)) + if (kb >= 1024) append(String.format(Locale.getDefault(), "%.1f MB", kb / 1024f)) else append("$kb KB") } } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt index dcea19c49..1f226b9e7 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt @@ -73,6 +73,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.Spacer import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import java.util.Locale @Composable @@ -1095,7 +1096,7 @@ fun createAdvancedSettings(context: Context) = listOfNotNull( key = Settings.PREF_OFFLINE_TEMP, default = Defaults.PREF_OFFLINE_TEMP, range = 0.0f..2.0f, - description = { String.format("%.2f", it) } + description = { String.format(Locale.getDefault(), "%.2f", it) } ) // Top-P @@ -1104,7 +1105,7 @@ fun createAdvancedSettings(context: Context) = listOfNotNull( key = Settings.PREF_OFFLINE_TOP_P, default = Defaults.PREF_OFFLINE_TOP_P, range = 0.0f..1.0f, - description = { String.format("%.2f", it) } + description = { String.format(Locale.getDefault(), "%.2f", it) } ) // Top-K @@ -1122,7 +1123,7 @@ fun createAdvancedSettings(context: Context) = listOfNotNull( key = Settings.PREF_OFFLINE_MIN_P, default = Defaults.PREF_OFFLINE_MIN_P, range = 0.0f..1.0f, - description = { String.format("%.2f", it) } + description = { String.format(Locale.getDefault(), "%.2f", it) } ) // Show Thinking From fa47c84db03490a170322039ed11ffc541ef9a54 Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sun, 15 Nov 2026 21:01:30 +0530 Subject: [PATCH 2/2] fix(lint): remove dead SDK checks, fix unused intersect result and static service reference - drop SDK_INT checks that are always true with minSdk 23 - Rect.intersect leaves the rect unclipped when there is no overlap, so empty it (FloatingKeyboardManager, LatinIME touchable region) - AccessibilityUtils is a static singleton and held the LatinIME service, keep the application context instead - suppress StaticFieldLeak where the singleton already holds the application context - CustomSoundManager: BLE broadcast devices need API 33, not 31 --- .../accessibility/AccessibilityUtils.kt | 20 ++++----- .../keyboard/compat/BrowserDetector.kt | 7 +-- .../keyboard/compat/IsLockedCompat.kt | 4 +- .../clipboard/ClipboardHistoryView.kt | 6 +-- .../keyboard/emoji/SupportedEmojis.kt | 1 - .../latin/AudioAndHapticFeedbackManager.kt | 2 + .../keyboard/latin/FloatingKeyboardManager.kt | 14 ++---- .../helium314/keyboard/latin/InputView.kt | 4 +- .../java/helium314/keyboard/latin/LatinIME.kt | 2 +- .../keyboard/latin/RichInputMethodManager.kt | 2 + .../calculator/CalculatorHistoryManager.kt | 2 + .../keyboard/latin/cjk/CjkInputManager.kt | 2 + .../latin/permissions/PermissionsUtil.kt | 5 --- .../latin/sound/CustomSoundManager.kt | 43 +++++++------------ .../AndroidWordLevelSpellCheckerSession.kt | 24 +++++------ .../SuggestionStripLayoutHelper.kt | 10 +---- .../keyboard/latin/utils/NetworkUtils.kt | 20 +++------ .../keyboard/latin/voice/VoiceInputManager.kt | 34 ++++++--------- .../settings/screens/AppQuirksScreen.kt | 7 +-- .../keyboard/latin/utils/ProofreadService.kt | 34 ++++++--------- 20 files changed, 89 insertions(+), 154 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/accessibility/AccessibilityUtils.kt b/app/src/main/java/helium314/keyboard/accessibility/AccessibilityUtils.kt index ffdd9a8b3..0d869de50 100644 --- a/app/src/main/java/helium314/keyboard/accessibility/AccessibilityUtils.kt +++ b/app/src/main/java/helium314/keyboard/accessibility/AccessibilityUtils.kt @@ -6,6 +6,7 @@ package helium314.keyboard.accessibility +import android.annotation.SuppressLint import android.content.Context import android.media.AudioDeviceInfo.* import android.media.AudioManager @@ -34,7 +35,8 @@ class AccessibilityUtils private constructor() { private var mTypedWord: String? = null private fun initInternal(context: Context) { - mContext = context + // the instance is static, do not keep the service alive + mContext = context.applicationContext mAccessibilityManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager mAudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager } @@ -73,16 +75,11 @@ class AccessibilityUtils private constructor() { if (speakPassword) return false } // Always speak if the user is listening through headphones. - val listeningThroughHeadphones = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - @Suppress("deprecation") // no replacement available - mAudioManager.isWiredHeadsetOn || mAudioManager.isBluetoothA2dpOn - } else { - // try the same as the deprecated thing above, for what we can assume to be headphones - mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { - when (it.type) { - TYPE_WIRED_HEADSET, TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_SCO, TYPE_BLUETOOTH_A2DP, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET -> true - else -> false - } + // what we can assume to be headphones + val listeningThroughHeadphones = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { + when (it.type) { + TYPE_WIRED_HEADSET, TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_SCO, TYPE_BLUETOOTH_A2DP, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET -> true + else -> false } } return if (listeningThroughHeadphones) { @@ -196,6 +193,7 @@ class AccessibilityUtils private constructor() { private val TAG = AccessibilityUtils::class.java.simpleName private val CLASS = AccessibilityUtils::class.java.name private val PACKAGE = AccessibilityUtils::class.java.getPackage()?.name ?: "helium314.keyboard.accessibility" + @SuppressLint("StaticFieldLeak") // holds the application context val instance = AccessibilityUtils() /* * Setting this constant to {@code false} will disable all keyboard diff --git a/app/src/main/java/helium314/keyboard/compat/BrowserDetector.kt b/app/src/main/java/helium314/keyboard/compat/BrowserDetector.kt index 7020fb696..a03553159 100644 --- a/app/src/main/java/helium314/keyboard/compat/BrowserDetector.kt +++ b/app/src/main/java/helium314/keyboard/compat/BrowserDetector.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri -import android.os.Build import helium314.keyboard.latin.utils.Log import java.util.Collections @@ -44,11 +43,7 @@ object BrowserDetector { val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com")).apply { addCategory(Intent.CATEGORY_BROWSABLE) } - val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PackageManager.MATCH_ALL - } else { - 0 - } + val flags = PackageManager.MATCH_ALL val resolveInfos = appContext.packageManager.queryIntentActivities(intent, flags) for (info in resolveInfos) { val pkg = info.activityInfo?.packageName diff --git a/app/src/main/java/helium314/keyboard/compat/IsLockedCompat.kt b/app/src/main/java/helium314/keyboard/compat/IsLockedCompat.kt index c3e15cb52..34afd7369 100644 --- a/app/src/main/java/helium314/keyboard/compat/IsLockedCompat.kt +++ b/app/src/main/java/helium314/keyboard/compat/IsLockedCompat.kt @@ -18,10 +18,8 @@ fun refreshDeviceLocked(context: Context): Boolean { val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as? KeyguardManager val locked = if (keyguardManager == null) { false - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { - keyguardManager.isDeviceLocked } else { - keyguardManager.isKeyguardLocked + keyguardManager.isDeviceLocked } cachedDeviceLocked = locked lastLockCheckTime = SystemClock.elapsedRealtime() diff --git a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt index aa30dbf0d..8ab0e3875 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/clipboard/ClipboardHistoryView.kt @@ -263,10 +263,8 @@ class ClipboardHistoryView @JvmOverloads constructor( textView.overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS textView.isFocusable = false textView.isFocusableInTouchMode = false - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - textView.breakStrategy = android.text.Layout.BREAK_STRATEGY_SIMPLE - textView.hyphenationFrequency = android.text.Layout.HYPHENATION_FREQUENCY_NONE - } + textView.breakStrategy = android.text.Layout.BREAK_STRATEGY_SIMPLE + textView.hyphenationFrequency = android.text.Layout.HYPHENATION_FREQUENCY_NONE } private var pendingCursorListener: Pair? = null diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/SupportedEmojis.kt b/app/src/main/java/helium314/keyboard/keyboard/emoji/SupportedEmojis.kt index 0d94fe284..e037ab532 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/SupportedEmojis.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/SupportedEmojis.kt @@ -23,7 +23,6 @@ object SupportedEmojis { } private fun determineMaxSdk(context: Context) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return if (context.prefs().contains(Settings.PREF_EMOJI_MAX_SDK)) return val paint = Paint() (Settings.getInstance().customEmojiTypeface ?: Settings.getInstance().customTypeface) diff --git a/app/src/main/java/helium314/keyboard/latin/AudioAndHapticFeedbackManager.kt b/app/src/main/java/helium314/keyboard/latin/AudioAndHapticFeedbackManager.kt index f712c1aed..f6a278c70 100644 --- a/app/src/main/java/helium314/keyboard/latin/AudioAndHapticFeedbackManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/AudioAndHapticFeedbackManager.kt @@ -6,6 +6,7 @@ package helium314.keyboard.latin +import android.annotation.SuppressLint import android.content.Context import android.media.AudioManager import android.os.Build @@ -335,6 +336,7 @@ class AudioAndHapticFeedbackManager private constructor() { companion object { private const val MIN_GESTURE_HAPTIC_INTERVAL_MS = 40L + @SuppressLint("StaticFieldLeak") // holds the application context private val sInstance = AudioAndHapticFeedbackManager() fun getInstance(): AudioAndHapticFeedbackManager = sInstance diff --git a/app/src/main/java/helium314/keyboard/latin/FloatingKeyboardManager.kt b/app/src/main/java/helium314/keyboard/latin/FloatingKeyboardManager.kt index 5f0d45c7e..e33fff574 100644 --- a/app/src/main/java/helium314/keyboard/latin/FloatingKeyboardManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/FloatingKeyboardManager.kt @@ -162,7 +162,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME frame.getLocationInWindow(tempLocation) outRect.set(tempLocation[0], tempLocation[1], tempLocation[0] + frame.width, tempLocation[1] + frame.height) if (windowWidth > 0 && windowHeight > 0) { - outRect.intersect(0, 0, windowWidth, windowHeight) + if (!outRect.intersect(0, 0, windowWidth, windowHeight)) outRect.setEmpty() } return !outRect.isEmpty } @@ -246,9 +246,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME frame.background = bgDrawable frame.clipToOutline = true frame.outlineProvider = ViewOutlineProvider.BACKGROUND - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - frame.elevation = 8f * density - } + frame.elevation = 8f * density KeyboardSwitcher.getInstance().reloadKeyboard() @@ -309,9 +307,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME frame.outlineProvider = null frame.clipToOutline = false Settings.getValues().mColors.setBackground(frame, ColorType.MAIN_BACKGROUND) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - frame.elevation = 0f - } + frame.elevation = 0f (latinIME.mInputView as? InputView)?.updateBottomPadding() latinIME.mInputView?.post { latinIME.mInputView?.requestApplyInsets() } } @@ -404,9 +400,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME frame.outlineProvider = null frame.clipToOutline = false Settings.getValues().mColors.setBackground(frame, ColorType.MAIN_BACKGROUND) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - frame.elevation = 0f - } + frame.elevation = 0f } ResourceUtils.setFloatingKeyboardWidth(0) ResourceUtils.setFloatingKeyboardScale(0.0f) diff --git a/app/src/main/java/helium314/keyboard/latin/InputView.kt b/app/src/main/java/helium314/keyboard/latin/InputView.kt index aaf88a001..15fa6b5a7 100644 --- a/app/src/main/java/helium314/keyboard/latin/InputView.kt +++ b/app/src/main/java/helium314/keyboard/latin/InputView.kt @@ -52,11 +52,9 @@ class InputView @JvmOverloads constructor( if (mNavBarBottomInsets > 0) return mNavBarBottomInsets val insets = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { rootWindowInsets?.getInsets(WindowInsets.Type.navigationBars())?.bottom ?: 0 - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + } else { @Suppress("DEPRECATION") rootWindowInsets?.systemWindowInsetBottom ?: 0 - } else { - 0 // View.getRootWindowInsets needs API 23, the insets come from onApplyWindowInsets } if (insets > 0) { mNavBarBottomInsets = insets diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt index a77aa5564..c1e87271f 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.kt +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.kt @@ -1276,7 +1276,7 @@ class LatinIME : InputMethodService(), mTempLocation[1] + child.height ) if (windowWidth > 0 && windowHeight > 0) { - mTempRect.intersect(0, 0, windowWidth, windowHeight) + if (!mTempRect.intersect(0, 0, windowWidth, windowHeight)) mTempRect.setEmpty() } if (!mTempRect.isEmpty) { outRegion.op(mTempRect, Region.Op.UNION) diff --git a/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt b/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt index e169fcc60..4a956516c 100644 --- a/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/RichInputMethodManager.kt @@ -5,6 +5,7 @@ */ package helium314.keyboard.latin +import android.annotation.SuppressLint import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager @@ -401,6 +402,7 @@ class RichInputMethodManager private constructor() { private val TAG = RichInputMethodManager::class.java.simpleName private const val DEBUG = false + @SuppressLint("StaticFieldLeak") // holds the application context private val instance = RichInputMethodManager() fun getInstance(): RichInputMethodManager { diff --git a/app/src/main/java/helium314/keyboard/latin/calculator/CalculatorHistoryManager.kt b/app/src/main/java/helium314/keyboard/latin/calculator/CalculatorHistoryManager.kt index 86565b23c..6970b19be 100644 --- a/app/src/main/java/helium314/keyboard/latin/calculator/CalculatorHistoryManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/calculator/CalculatorHistoryManager.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only package helium314.keyboard.latin.calculator +import android.annotation.SuppressLint import android.content.Context import android.content.SharedPreferences import androidx.core.content.edit @@ -102,6 +103,7 @@ class CalculatorHistoryManager private constructor(private val context: Context) private const val PREF_CALCULATOR_HISTORY = "pref_calculator_history_json" private const val MAX_HISTORY_ITEMS = 30 + @SuppressLint("StaticFieldLeak") // holds the application context @Volatile private var instance: CalculatorHistoryManager? = null diff --git a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt index e2a7813a4..8a7a6c263 100644 --- a/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/cjk/CjkInputManager.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only package helium314.keyboard.latin.cjk +import android.annotation.SuppressLint import android.content.Context import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputConnection @@ -190,6 +191,7 @@ class CjkInputManager private constructor(private val context: Context) { companion object { private const val TAG = "CjkInputManager" + @SuppressLint("StaticFieldLeak") // holds the application context @Volatile private var instance: CjkInputManager? = null diff --git a/app/src/main/java/helium314/keyboard/latin/permissions/PermissionsUtil.kt b/app/src/main/java/helium314/keyboard/latin/permissions/PermissionsUtil.kt index 75948be47..07581abd5 100644 --- a/app/src/main/java/helium314/keyboard/latin/permissions/PermissionsUtil.kt +++ b/app/src/main/java/helium314/keyboard/latin/permissions/PermissionsUtil.kt @@ -8,7 +8,6 @@ package helium314.keyboard.latin.permissions import android.content.Context import android.content.pm.PackageManager -import android.os.Build import androidx.core.content.ContextCompat /** @@ -19,10 +18,6 @@ object PermissionsUtil { * Queries if al the permissions are granted for the given permission strings. */ fun checkAllPermissionsGranted(context: Context?, vararg permissions: String): Boolean { - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { - // For all pre-M devices, we should have all the permissions granted on install. - return true - } if (context == null) return false for (permission in permissions) { diff --git a/app/src/main/java/helium314/keyboard/latin/sound/CustomSoundManager.kt b/app/src/main/java/helium314/keyboard/latin/sound/CustomSoundManager.kt index 0b3055cd9..fce5b09aa 100644 --- a/app/src/main/java/helium314/keyboard/latin/sound/CustomSoundManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/sound/CustomSoundManager.kt @@ -93,36 +93,25 @@ class CustomSoundManager private constructor(private val appContext: Context) { private fun checkBluetoothAudioConnected(): Boolean { val audioManager = appContext.getSystemService(Context.AUDIO_SERVICE) as? AudioManager ?: return false - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - try { - audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { device -> - when (device.type) { - AudioDeviceInfo.TYPE_BLUETOOTH_A2DP, - AudioDeviceInfo.TYPE_BLUETOOTH_SCO, - AudioDeviceInfo.TYPE_HEARING_AID, - AudioDeviceInfo.TYPE_WIRED_HEADSET, - AudioDeviceInfo.TYPE_WIRED_HEADPHONES, - AudioDeviceInfo.TYPE_USB_HEADSET -> true - else -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - device.type == AudioDeviceInfo.TYPE_BLE_HEADSET || - device.type == AudioDeviceInfo.TYPE_BLE_SPEAKER || - device.type == AudioDeviceInfo.TYPE_BLE_BROADCAST - } else { - false - } - } + return try { + audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { device -> + when (device.type) { + AudioDeviceInfo.TYPE_BLUETOOTH_A2DP, + AudioDeviceInfo.TYPE_BLUETOOTH_SCO, + AudioDeviceInfo.TYPE_HEARING_AID, + AudioDeviceInfo.TYPE_WIRED_HEADSET, + AudioDeviceInfo.TYPE_WIRED_HEADPHONES, + AudioDeviceInfo.TYPE_USB_HEADSET -> true + else -> { + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + (device.type == AudioDeviceInfo.TYPE_BLE_HEADSET || + device.type == AudioDeviceInfo.TYPE_BLE_SPEAKER)) || + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && + device.type == AudioDeviceInfo.TYPE_BLE_BROADCAST) } } - } catch (e: Throwable) { - @Suppress("DEPRECATION") - try { - audioManager.isBluetoothA2dpOn || audioManager.isWiredHeadsetOn - } catch (_: Throwable) { - false - } } - } else { + } catch (e: Throwable) { @Suppress("DEPRECATION") try { audioManager.isBluetoothA2dpOn || audioManager.isWiredHeadsetOn diff --git a/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidWordLevelSpellCheckerSession.kt b/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidWordLevelSpellCheckerSession.kt index 759fd5e74..8707d04b0 100644 --- a/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidWordLevelSpellCheckerSession.kt +++ b/app/src/main/java/helium314/keyboard/latin/spellcheck/AndroidWordLevelSpellCheckerSession.kt @@ -66,19 +66,17 @@ abstract class AndroidWordLevelSpellCheckerSession( } override fun getLocale(): String? { - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - val imm = mService.applicationContext.getSystemService(InputMethodManager::class.java) - if (imm != null) { - val currentInputMethodSubtype = imm.currentInputMethodSubtype - if (currentInputMethodSubtype != null) { - val localeString = currentInputMethodSubtype.locale - if (!localeString.isNullOrEmpty()) { - return localeString - } - if ("dummy" == currentInputMethodSubtype.extraValue) { - val prefs = mService.prefs() - return SubtypeSettings.getSelectedSubtype(prefs).locale - } + val imm = mService.applicationContext.getSystemService(InputMethodManager::class.java) + if (imm != null) { + val currentInputMethodSubtype = imm.currentInputMethodSubtype + if (currentInputMethodSubtype != null) { + val localeString = currentInputMethodSubtype.locale + if (!localeString.isNullOrEmpty()) { + return localeString + } + if ("dummy" == currentInputMethodSubtype.extraValue) { + val prefs = mService.prefs() + return SubtypeSettings.getSelectedSubtype(prefs).locale } } } diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.kt b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.kt index d21f70b83..8c6f7c051 100644 --- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.kt +++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripLayoutHelper.kt @@ -508,14 +508,8 @@ internal class SuggestionStripLayoutHelper( } if (thumb != null && chipBg != null) { val layerDrawable = LayerDrawable(arrayOf(chipBg, thumb)).apply { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - setLayerGravity(1, Gravity.CENTER) - setLayerSize(1, thumbW, thumbH) - } else { - val padH = ((width - thumbW) / 2).coerceAtLeast(0) - val padV = 5.dpToPx(context.resources) - setLayerInset(1, padH, padV, padH, padV) - } + setLayerGravity(1, Gravity.CENTER) + setLayerSize(1, thumbW, thumbH) } wordView.background = layerDrawable } else if (thumb != null) { diff --git a/app/src/main/java/helium314/keyboard/latin/utils/NetworkUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/NetworkUtils.kt index 4f5dfd985..0fa357edf 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/NetworkUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/NetworkUtils.kt @@ -4,7 +4,6 @@ package helium314.keyboard.latin.utils import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities -import android.os.Build import java.net.NetworkInterface object NetworkUtils { @@ -14,21 +13,14 @@ object NetworkUtils { try { val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager if (cm != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val network = cm.activeNetwork - if (network != null) { - val capabilities = cm.getNetworkCapabilities(network) - if (capabilities != null) { - return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - } + val network = cm.activeNetwork + if (network != null) { + val capabilities = cm.getNetworkCapabilities(network) + if (capabilities != null) { + return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) } - return false - } else { - @Suppress("DEPRECATION") - val networkInfo = cm.activeNetworkInfo - @Suppress("DEPRECATION") - return networkInfo != null && networkInfo.isConnected } + return false } } catch (e: Throwable) { Log.w(TAG, "ConnectivityManager check failed", e) diff --git a/app/src/main/java/helium314/keyboard/latin/voice/VoiceInputManager.kt b/app/src/main/java/helium314/keyboard/latin/voice/VoiceInputManager.kt index 328838c8a..0dd824b51 100644 --- a/app/src/main/java/helium314/keyboard/latin/voice/VoiceInputManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/voice/VoiceInputManager.kt @@ -484,29 +484,19 @@ class VoiceInputManager( var record: AudioRecord? = null for (source in sources) { try { - val candidate = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val audioFormat = AudioFormat.Builder() - .setEncoding(AudioFormat.ENCODING_PCM_16BIT) - .setSampleRate(SAMPLE_RATE) - .setChannelMask(AudioFormat.CHANNEL_IN_MONO) - .build() - val builder = AudioRecord.Builder() - .setAudioSource(source) - .setAudioFormat(audioFormat) - .setBufferSizeInBytes(bufferSize) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - builder.setContext(ims) - } - builder.build() - } else { - AudioRecord( - source, - SAMPLE_RATE, - AudioFormat.CHANNEL_IN_MONO, - AudioFormat.ENCODING_PCM_16BIT, - bufferSize - ) + val audioFormat = AudioFormat.Builder() + .setEncoding(AudioFormat.ENCODING_PCM_16BIT) + .setSampleRate(SAMPLE_RATE) + .setChannelMask(AudioFormat.CHANNEL_IN_MONO) + .build() + val builder = AudioRecord.Builder() + .setAudioSource(source) + .setAudioFormat(audioFormat) + .setBufferSizeInBytes(bufferSize) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + builder.setContext(ims) } + val candidate = builder.build() if (candidate.state == AudioRecord.STATE_INITIALIZED) { Log.i(TAG, "AudioRecord initialized successfully with source: $source") record = candidate diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AppQuirksScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AppQuirksScreen.kt index 9c57709ba..94212ed9e 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AppQuirksScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AppQuirksScreen.kt @@ -4,7 +4,6 @@ package helium314.keyboard.settings.screens import android.content.Context import android.content.Intent import android.content.pm.PackageManager -import android.os.Build import android.view.inputmethod.EditorInfo import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -91,11 +90,7 @@ fun AppQuirksScreen( val intent = Intent(Intent.ACTION_MAIN).apply { addCategory(Intent.CATEGORY_LAUNCHER) } - val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PackageManager.MATCH_ALL - } else { - 0 - } + val flags = PackageManager.MATCH_ALL val resolveInfos = pm.queryIntentActivities(intent, flags) val appList = mutableListOf() val visited = mutableSetOf() diff --git a/app/src/standard/java/helium314/keyboard/latin/utils/ProofreadService.kt b/app/src/standard/java/helium314/keyboard/latin/utils/ProofreadService.kt index 020e3690d..57778819f 100644 --- a/app/src/standard/java/helium314/keyboard/latin/utils/ProofreadService.kt +++ b/app/src/standard/java/helium314/keyboard/latin/utils/ProofreadService.kt @@ -6,7 +6,6 @@ package helium314.keyboard.latin.utils import android.content.Context import android.content.SharedPreferences -import android.os.Build import android.os.Handler import android.os.Looper import androidx.security.crypto.EncryptedSharedPreferences @@ -45,25 +44,20 @@ class ProofreadService(private val context: Context) { } private val securePrefs: SharedPreferences by lazy { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - try { - val masterKey = MasterKey.Builder(context) - .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) - .build() - EncryptedSharedPreferences.create( - context, - PREFS_NAME, - masterKey, - EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, - EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM - ) - } catch (e: Exception) { - // Fallback to regular prefs if encryption fails - Log.w("ProofreadService", "Failed to create encrypted prefs, using regular prefs", e) - context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - } - } else { - // API 21-22 doesn't support EncryptedSharedPreferences + try { + val masterKey = MasterKey.Builder(context) + .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) + .build() + EncryptedSharedPreferences.create( + context, + PREFS_NAME, + masterKey, + EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, + EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM + ) + } catch (e: Exception) { + // Fallback to regular prefs if encryption fails + Log.w("ProofreadService", "Failed to create encrypted prefs, using regular prefs", e) context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) } }