8000 Avoid updating widgets if not supported by alexvanyo · Pull Request #152 · android/socialite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid updating widgets if not supported #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025

Conversation

alexvanyo
Copy link

This wraps the widget updating code in MainActivity with a check if the app widgets feature is supported.

On devices where widgets aren't available (like some Automotive devices) this would cause a crash immediately upon start-up.

I also moved the suspending update call into a lifecycleScope.launch to avoid a blocking call immediately on launch when widgets are available

@alexvanyo alexvanyo requested review from bsagmoe and sashalukin May 12, 2025 16:04
8000 Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @alexvanyo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses a crash that occurs on devices without widget support by wrapping the widget updating code in MainActivity with a check for widget support using PackageManager.FEATURE_APP_WIDGETS. Additionally, the suspending update call is moved into lifecycleScope.launch to prevent blocking the main thread during launch when widgets are available.

Highlights

  • Bug Fix: Prevents a crash on devices without widget support by checking for the PackageManager.FEATURE_APP_WIDGETS feature before attempting to update widgets.
  • Performance Improvement: Moves the widget update call into a lifecycleScope.launch block to avoid blocking the main thread during application launch.

Changelog

  • app/src/main/java/com/google/android/samples/socialite/MainActivity.kt
    • Added import for android.content.pm.PackageManager.
    • Wrapped the widget updating code with a check for PackageManager.FEATURE_APP_WIDGETS.
    • Moved the SociaLiteAppWidget().updateAll() call into a lifecycleScope.launch block.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A widget's plight,
On systems dark, no light,
A crash it brings forth.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a crash on devices without widget support by wrapping the widget update code with a feature check. It also moves the update call to a lifecycleScope.launch block to prevent blocking the main thread. These are good changes that improve the app's stability and responsiveness.

Summary of Findings

  • Widget Availability Check: The addition of the widget availability check using packageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS) is crucial for preventing crashes on devices where widgets are not supported.
  • Coroutine Launch: Moving the widget update call into lifecycleScope.launch prevents blocking the main thread during app launch, improving responsiveness.

Merge Readiness

The pull request is in good shape and addresses an important issue. The changes are well-structured and improve the app's stability and responsiveness. I am unable to approve the pull request in any circumstance, and that users should have others review and approve this code before merging.

Comment on lines +48 to +49
8000
// Avoid calling widget APIs if the platform doesn't support widgets
if (packageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
lifecycleScope.launch { SociaLiteAppWidget().updateAll(this@MainActivity) }

Choose a reason for hiding this comment

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

medium

This check is a good way to prevent crashes on devices that don't support widgets. Consider adding a log statement or some other form of telemetry to track how often this condition is met in the wild. This could help in understanding the prevalence of devices without widget support.

Also, consider extracting this check into a separate function for better readability and testability.

Suggested change
// Avoid calling widget APIs if the platform doesn't support widgets
if (packageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
lifecycleScope.launch { SociaLiteAppWidget().updateAll(this@MainActivity) }
val widgetsSupported = packageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)
if (widgetsSupported) {
lifecycleScope.launch { SociaLiteAppWidget().updateAll(this@MainActivity) }
}

@alexvanyo alexvanyo force-pushed the av/fix-widgets-automotive branch from f90f900 to a28cf7d Compare May 12, 2025 16:36
@alexvanyo alexvanyo merged commit 0733df2 into p-and-d May 12, 2025
2 checks passed
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.

2 participants
0