Skip to content

Commit c8d3206

Browse files
committed
fix: implement WAKE_LOCK to prevent Freecess/MARs freezing
- Added WAKE_LOCK permission to AndroidManifest.xml - Acquire PARTIAL_WAKE_LOCK in onCreate() to prevent process freezing - Release wake lock in onDestroy() for battery efficiency - Fix for Samsung battery optimization freezing CleverKeys process - Service shows mHasMainConnection=false - investigating connection issue Issue: Android Freecess/MARs was freezing CleverKeys preventing keyboard rendering Solution: PARTIAL_WAKE_LOCK prevents system from treating IME as freezable background app
1 parent 1cf5704 commit c8d3206

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
66
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
77
<uses-permission android:name="android.permission.INTERNET"/>
8+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
89

910
<!-- Storage permissions - deprecated on Android 11+ (API 30+), use scoped storage instead -->
1011
<!-- These are only needed for Android 10 and below -->

src/main/kotlin/tribixbite/keyboard2/CleverKeysService.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class CleverKeysService : InputMethodService(),
117117
)
118118
}
119119

120+
// Wake lock to prevent Android Freecess/MARs from freezing IME process
121+
// Fix: Keyboard not rendering because process was being frozen by Samsung battery optimization
122+
private var wakeLock: android.os.PowerManager.WakeLock? = null
123+
120124
// Core components with null safety
121125
private var keyboardView: Keyboard2View? = null
122126
private var neuralEngine: NeuralSwipeEngine? = null
@@ -258,6 +262,21 @@ class CleverKeysService : InputMethodService(),
258262
super.onCreate()
259263
logD("CleverKeys service starting...")
260264

265+
// Acquire wake lock to prevent Freecess/MARs from freezing the process
266+
// Fix: Android was freezing CleverKeys preventing onCreateInputView() from being called
267+
try {
268+
val powerManager = getSystemService(android.content.Context.POWER_SERVICE) as android.os.PowerManager
269+
wakeLock = powerManager.newWakeLock(
270+
android.os.PowerManager.PARTIAL_WAKE_LOCK,
271+
"CleverKeys::IMEWakeLock"
272+
).apply {
273+
acquire()
274+
logD("✅ Wake lock acquired - process won't be frozen by battery optimization")
275+
}
276+
} catch (e: Exception) {
277+
logE("⚠️ Failed to acquire wake lock - keyboard may be frozen by battery optimization", e)
278+
}
279+
261280
// Initialize lifecycle for Compose support (REQUIRED)
262281
savedStateRegistryController.performRestore(null)
263282
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
@@ -283,6 +302,19 @@ class CleverKeysService : InputMethodService(),
283302
super.onDestroy()
284303
logD("CleverKeys service stopping...")
285304

305+
// Release wake lock to save battery
306+
try {
307+
wakeLock?.let {
308+
if (it.isHeld) {
309+
it.release()
310+
logD("✅ Wake lock released")
311+
}
312+
}
313+
wakeLock = null
314+
} catch (e: Exception) {
315+
logE("⚠️ Failed to release wake lock", e)
316+
}
317+
286318
// Handle lifecycle destruction for Compose support
287319
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
288320
logD("✅ Lifecycle destroyed")

0 commit comments

Comments
 (0)