fix: use getLaunchIntentForPackage for alarm source filtering#21
Merged
Conversation
isUserFacingApp used queryIntentActivities with MATCH_DEFAULT_ONLY, which requires CATEGORY_DEFAULT in the target's intent filter. Standard launcher activities only declare CATEGORY_LAUNCHER, so the query always returned empty — making the alarm widget show "No alarm" for every clock app including Google Clock. Replace with getLaunchIntentForPackage, which is Android's built-in API for this check and is already used in both widgets' tap-action code.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces the custom user-facing app check in AlarmWidgetReceiver with Android's built-in getLaunchIntentForPackage() to correctly identify launcher apps for alarm source filtering and fix the widget always showing "No alarm". Sequence diagram for updated alarm source filtering using getLaunchIntentForPackagesequenceDiagram
actor User
participant HomeScreen as HomeScreenWidget
participant AlarmWidgetReceiver
participant Context
participant PackageManager
participant ClockApp as ClockAppPackage
User->>HomeScreen: Add alarm widget / refresh widget
HomeScreen->>AlarmWidgetReceiver: onUpdate(...)
AlarmWidgetReceiver->>Context: getPackageManager()
Context-->>AlarmWidgetReceiver: PackageManager
AlarmWidgetReceiver->>PackageManager: getLaunchIntentForPackage(clockAppPackageName)
PackageManager-->>AlarmWidgetReceiver: Intent or null
alt User-facing app detected
AlarmWidgetReceiver->>ClockApp: Query next scheduled alarm
ClockApp-->>AlarmWidgetReceiver: Next alarm time
AlarmWidgetReceiver-->>HomeScreen: Render widget with alarm time
else Not user-facing app or no alarm
AlarmWidgetReceiver-->>HomeScreen: Render widget with text No alarm
end
Class diagram for AlarmWidgetReceiver with updated isUserFacingAppclassDiagram
class GlanceAppWidgetReceiver
class AlarmWidgetReceiver {
+onReceive(context: Context, intent: Intent) : Unit
+onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) : Unit
-isUserFacingApp(context: Context, packageName: String) : Boolean
}
class Context {
+packageManager: PackageManager
}
class PackageManager {
+getLaunchIntentForPackage(packageName: String) : Intent
}
class Intent {
+action: String
+categories: Set~String~
+setPackage(packageName: String) : Intent
+addCategory(category: String) : Intent
}
GlanceAppWidgetReceiver <|-- AlarmWidgetReceiver
Context --> PackageManager : uses
AlarmWidgetReceiver --> Context : uses
AlarmWidgetReceiver --> PackageManager : calls
PackageManager --> Intent : returns
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isUserFacingApp()usedqueryIntentActivitieswithMATCH_DEFAULT_ONLY, which requiresCATEGORY_DEFAULTin the target's intent filterCATEGORY_LAUNCHER(notCATEGORY_DEFAULT), so the query always returned empty — alarm widget showed "No alarm" for every clock app including Google ClockgetLaunchIntentForPackage(), Android's built-in API for this check, already used in both widgets' tap-action resolutionTest plan
./gradlew :app:compileDebugKotlinpassesSummary by Sourcery
Bug Fixes: