`setDynamicShortcuts()` is called from the Activity main thread
メンテナーはふだん 7 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1時間未満
- 初心者へのやさしさ
- 74/100
調査の方向性
呼び出しは app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt の checkShortcuts() にあり、onResume() から約133行目で到達します。同じ Activity 内の既存の ensureBackgroundThread { ... } ブロックの使われ方を確認し、shortcutManager.dynamicShortcuts = ... の代入だけをバックグラウンドのディスパッチャーに移してください。代入がメインスレッドで実行されなくなり、ショートカットの一覧が変わらず、アプリがビルドできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hi, I'm working on a research prototype static analyzer targeting Kotlin-based Android apps, and running it against this repo. It detected a small threading issue.
Checklist
- I can reproduce the bug with the latest version given here.
- I made sure that there are no existing issues - open or closed - to which I could contribute my information.
- I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
- I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
- I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
- This issue contains only one bug.
- I have read and understood the contribution guidelines.
Affected app version
Trunk
Checked file:
app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt
What I found
In MainActivity, onResume() calls checkShortcuts(). Inside checkShortcuts(), the stopwatch shortcut is published like this:
shortcutManager.dynamicShortcuts = listOf(stopWatchShortcutInfo)
This property setter calls ShortcutManager.setDynamicShortcuts(...). Android's API documentation warns that this method may take several seconds to complete and should only be called from a worker thread.
Verified bug trace
org.fossify.clock.activities.MainActivity.onResume()
-> checkShortcuts()
-> MainActivity.kt, around line 133:
shortcutManager.dynamicShortcuts = listOf(stopWatchShortcutInfo)
-> Kotlin property setter calls:
ShortcutManager.setDynamicShortcuts(List<ShortcutInfo>)
-> platform shortcut state is updated through ShortcutManager
-> documented as potentially taking several seconds
-> call is reached from the Activity main-thread lifecycle path
-> possible UI stall / delayed startup / ANR risk
I did not see a worker-thread boundary around this specific shortcut publishing call. There is an ensureBackgroundThread { ... } used elsewhere in the same Activity for alarm rescheduling, but not around shortcutManager.dynamicShortcuts.
Why I think this is worth changing
This probably does not fail every time, and it may be fast on many devices. The problem is that the platform API is documented as potentially slow, and the work may depend on system/launcher behavior. If it takes longer than expected, it can block UI drawing and input handling.
Suggested change
Move just the publishing call to a worker thread:
val shortcuts = listOf(stopWatchShortcutInfo)
lifecycleScope.launch(Dispatchers.IO) {
shortcutManager.dynamicShortcuts = shortcuts
}
This keeps the UI thread free while preserving the same shortcut behavior.
Reference
Android documents ShortcutManager#setDynamicShortcuts(...) as a potentially slow call:
This method may take several seconds to complete, so it should only be called from a worker thread.
- 主要言語
- Kotlin
- スター
- 706
- フォーク
- 73
- 平均マージ
- 5日 17時間
- マージ済み PR(30日)
- 8
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FossifyOrg/Clock のほかの issue
-
feature request needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
FossifyOrg/Clock#504 · コメント 1 件 ·
メンテナーはふだん 7 日以内に返信
-
feature request needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
FossifyOrg/Clock#492 ·
メンテナーはふだん 7 日以内に返信
-
feature request needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
FossifyOrg/Clock#491 ·
メンテナーはふだん 7 日以内に返信
-
bug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
FossifyOrg/Clock#448 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 7 日以内に返信
-
feature request needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
FossifyOrg/Clock#446 ·
メンテナーはふだん 7 日以内に返信
FossifyOrg/Clock の issue をすべて見る
似ている issue
-
[BUG] Navigation drawer drops library-name suffixes without ellipsis (1.0.8, NVIDIA Shield)対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
damontecres/Wholphin#2069 ·
メンテナーはふだん 1 日以内に返信
-
Android (vision-camera-location): HybridLocationManager never quits its HandlerThread on disposeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
margelo/react-native-vision-camera#4217 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
saisaharsh3/Leftovers#13 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 67/100
navikt/esyfo-narmesteleder#700 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
nightscout/AndroidAPS#5280 ·
メンテナーはふだん 1 日以内に返信