Skip to content

Commit

Permalink
fix: IntentReceiver was re-registered in TextInputManager
Browse files Browse the repository at this point in the history
This may leak the receiver registered in TrimeInputMethodService, which leads to a potential crash.
  • Loading branch information
WhiredPlanck committed Apr 13, 2024
1 parent 03701a3 commit 6084661
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ open class TrimeInputMethodService : LifecycleInputMethodService() {
}

override fun onDestroy() {
if (mIntentReceiver != null) mIntentReceiver!!.unregisterReceiver(this)
mIntentReceiver?.unregisterReceiver(this)
mIntentReceiver = null
InputFeedbackManager.destroy()
inputView = null
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.osfans.trime.data.AppPrefs
import com.osfans.trime.data.schema.SchemaManager
import com.osfans.trime.data.theme.EventManager
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.broadcast.IntentReceiver
import com.osfans.trime.ime.core.Speech
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.Keycode
Expand Down Expand Up @@ -59,7 +58,6 @@ class TextInputManager(
KeyboardView.OnKeyboardActionListener,
Candidate.EventListener {
private val prefs get() = AppPrefs.defaultInstance()
private var intentReceiver: IntentReceiver? = null
private var rimeNotificationJob: Job? = null

val locales = Array(2) { Locale.getDefault() }
Expand Down Expand Up @@ -101,11 +99,6 @@ class TextInputManager(
*/
override fun onCreate() {
super.onCreate()

intentReceiver =
IntentReceiver().also {
it.registerReceiver(trime)
}
rimeNotificationJob =
rime.run { notificationFlow }
.onEach(::handleRimeNotification)
Expand Down Expand Up @@ -135,9 +128,6 @@ class TextInputManager(
* Cancels all coroutines and cleans up.
*/
override fun onDestroy() {
intentReceiver?.unregisterReceiver(trime)
intentReceiver = null

rimeNotificationJob?.cancel()
rimeNotificationJob = null
instance = null
Expand Down

0 comments on commit 6084661

Please sign in to comment.