Skip to content

fix: use getLaunchIntentForPackage for alarm source filtering#21

Merged
wassupluke merged 1 commit into
mainfrom
feature/alarm-widget-font-size
Apr 3, 2026
Merged

fix: use getLaunchIntentForPackage for alarm source filtering#21
wassupluke merged 1 commit into
mainfrom
feature/alarm-widget-font-size

Conversation

@wassupluke
Copy link
Copy Markdown
Owner

@wassupluke wassupluke commented Apr 3, 2026

Summary

  • isUserFacingApp() used queryIntentActivities with MATCH_DEFAULT_ONLY, which requires CATEGORY_DEFAULT in the target's intent filter
  • Standard launcher activities only declare CATEGORY_LAUNCHER (not CATEGORY_DEFAULT), so the query always returned empty — alarm widget showed "No alarm" for every clock app including Google Clock
  • Replaced with getLaunchIntentForPackage(), Android's built-in API for this check, already used in both widgets' tap-action resolution

Test plan

  • ./gradlew :app:compileDebugKotlin passes
  • Set an alarm in Google Clock (or device default clock app), confirm alarm widget displays the alarm time instead of "No alarm"
  • With no alarm set, confirm widget still shows "No alarm"

Summary by Sourcery

Bug Fixes:

  • Fix alarm widget incorrectly showing "No alarm" for valid clock apps by updating the user-facing app detection logic.

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.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 3, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces 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 getLaunchIntentForPackage

sequenceDiagram
    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
Loading

Class diagram for AlarmWidgetReceiver with updated isUserFacingApp

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Replace custom intent-query based user-facing app detection with getLaunchIntentForPackage-based check.
  • Remove manual construction of ACTION_MAIN/CATEGORY_LAUNCHER intent filtered via MATCH_DEFAULT_ONLY.
  • Delete isUserFacingApp implementation that used queryIntentActivities on the package manager.
  • Introduce a simplified isUserFacingApp implementation that returns true when PackageManager.getLaunchIntentForPackage(packageName) is non-null.
app/src/main/java/com/wassupluke/widgets/widget/AlarmWidgetReceiver.kt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@wassupluke wassupluke merged commit b77ef3c into main Apr 3, 2026
3 checks passed
@wassupluke wassupluke deleted the feature/alarm-widget-font-size branch April 3, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant