Skip to content

feat(android): add home screen battery and status widget (#7150) - #17544

Open
TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/android-home-widget
Open

TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/android-home-widget

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7150

Adds a native Android Home Screen Widget (OmiBatteryWidgetProvider) displaying live Omi device connection status, battery percentage, and microphone mute state, achieving feature parity with the iOS BatteryWidget.

Key Changes

  1. Android AppWidget Implementation:
    • Added OmiBatteryWidgetProvider in app/android/app/src/main/kotlin/com/friend/ios/widget/OmiBatteryWidgetProvider.kt.
    • Created RemoteViews widget layout (res/layout/omi_battery_widget.xml) featuring Omi logo, device name, battery percentage indicator, and mic/mute status icon.
    • Added vector drawables ic_widget_mic.xml and ic_widget_mic_off.xml with neutral dark theme background widget_background.xml (no purple, conforming strictly with brand invariants).
    • Configured appwidget provider info in res/xml/omi_battery_widget_info.xml.
    • Registered widget receiver in AndroidManifest.xml.
  2. Native Bridge:
    • Handled com.omi.battery_widget MethodChannel in MainActivity.kt for updateBatteryInfo and updateMuteState, safely parsing battery numbers and triggering AppWidgetManager redraws.
  3. Dart Service:
    • Updated BatteryWidgetService in app/lib/services/battery_widget_service.dart to support both iOS and Android platforms (if (!Platform.isIOS && !Platform.isAndroid) return;).
  4. Hermetic Testing:
    • Added unit tests in app/test/unit/battery_widget_service_test.dart verifying singleton guarantees, channel invocations, and graceful exception resilience.

Verification & Testing

  • Unit Tests (app/test/unit/battery_widget_service_test.dart):
    • BatteryWidgetService singleton instance returns identical reference: PASSED
    • BatteryWidgetService updateBatteryInfo invokes method channel with correct arguments: PASSED
    • BatteryWidgetService updateMuteState executes safely: PASSED
    • BatteryWidgetService recovers safely from channel platform exceptions without throwing: PASSED
  • Static Analysis:
    • flutter analyze on modified Dart files: 0 issues found.
  • Preflight Gate:
    • scripts/pr-preflight verified cleanly.

Failure-Class: none
PayPal: rwilcox413@gmail.com

Review in cubic

…re#7150)

Add native Android AppWidget (OmiBatteryWidgetProvider) displaying
live Omi device connection status, battery percentage, and microphone
mute state, mirroring the iOS BatteryWidget capability.

- Implement OmiBatteryWidgetProvider with RemoteViews layout, appwidget
  info metadata, and manifest receiver registration
- Implement com.omi.battery_widget MethodChannel in MainActivity.kt
- Update BatteryWidgetService platform guard to support Android
- Add unit tests for BatteryWidgetService covering channel invocation,
  singleton identity, and error resilience

Closes BasedHardware#7150
Failure-Class: none
PayPal: rwilcox413@gmail.com
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @TheRWX — this is a well-put-together parity piece for #7150, and the bridge design mirrors the iOS side cleanly. I reviewed all ten files; no blocking issues found.

What I verified:

  • MainActivity.kt: the com.omi.battery_widget channel handler mirrors the iOS AppDelegate.swift implementation (same updateBatteryInfo/updateMuteState methods and fallback defaults), with defensive Int/Number battery parsing and notImplemented() for unknown methods. The battery_widget_service.dart platform-guard change (!Platform.isIOS && !Platform.isAndroid) is correct and the existing call sites (device_provider.dart battery listener/initial read/disconnect, capture_controller.dart mute/unmute) now drive Android.
  • OmiBatteryWidgetProvider.kt: tap PendingIntent uses FLAG_IMMUTABLE, state lives in MODE_PRIVATE SharedPreferences, and every view ID touched in buildRemoteViews exists in omi_battery_widget.xml (connected/disconnected swap, muted/unmuted icon). All drawable/layout references resolve (icon_white is present in res/drawable).
  • AndroidManifest.xml: exported="true" on the receiver is the standard requirement for APPWIDGET_UPDATE receivers; no new permissions are requested and onUpdate only redraws from persisted state, so there's no meaningful new attack surface.
  • Widget picker metadata (targetCellWidth=3, resizeMode) and the manual-update design (updatePeriodMillis=0, updates pushed from the app process) look right for a battery widget.

Minor polish, none blocking:

  1. After a reboot (or once the app process is killed), the widget replays the last persisted battery/connection state until the app is opened, since updatePeriodMillis=0 and nothing listens for ACTION_BOOT_COMPLETED. Tapping through to the app mitigates it; worth a follow-up if you want live state on boot.
  2. omi_battery_widget.xml hardcodes the Mic status content description while sibling strings are resourced in values/strings.xml — small i18n consistency nit.
  3. omi_battery_widget_info.xml has no previewLayout/previewImage, so some launchers show a generic preview in the widget picker.
  4. On tests: two of the four cases in battery_widget_service_test.dart are host-platform smoke checks (the in-line comments are honest about this), and the provider's connected/disconnected/muted visibility logic in Kotlin has no coverage yet — a Robolectric or plain JVM test of buildRemoteViews state mapping would be the highest-value addition.

Leaving for human maintainer review before merge: this is a new user-facing home-screen surface, so the product/design calls (dark-only theme, post-reboot refresh behavior, picker preview) should get a maintainer's sign-off.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added needs-maintainer-review Needs a human maintainer to sign off before merge needs-tests PR introduces logic that should be covered by tests android labels Sep 23, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (Android home screen battery/status widget) — approve only per policy; needs-maintainer-review, BLOCKED.

@Git-on-my-level Git-on-my-level removed the needs-maintainer-review Needs a human maintainer to sign off before merge label Sep 28, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (Android home screen battery/status widget) — approve-only per policy.

@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed this alongside the existing approvals — the implementation looks solid. Notes per file:

  • OmiBatteryWidgetProvider.kt: Clean design — state in SharedPreferences, push-based redraws via AppWidgetManager, and updatePeriodMillis=0 (no polling drain) is the right call. Tap handler uses FLAG_IMMUTABLE on the PendingIntent, and connected/disconnected/mic states all degrade sensibly (battery --% when unknown). Two nits: KEY_DEVICE_TYPE is persisted but never read back in buildRemoteViews (either use it or drop it), and the widget shows stale state until the app next runs — fine for now, just worth knowing.
  • MainActivity.kt: The com.omi.battery_widget channel handler is well-guarded — defensive batteryLevel parsing (Int/Number/-1 fallback) and result.notImplemented() for unknown methods. No issues.
  • AndroidManifest.xml: receiver exported=true with only APPWIDGET_UPDATE in the filter is the standard required app-widget pattern; no concern.
  • omi_battery_widget_info.xml: Reasonable sizing/resize config. A previewImage would improve the picker UX if you want a follow-up polish.
  • omi_battery_widget.xml + widget_background.xml + ic_widget_mic.xml / ic_widget_mic_off.xml: Conventional layout and Material mic vectors; contentDescription via @string/widget_name is good. The disconnected/connected visibility swap is straightforward.
  • strings.xml: Three new default-locale strings; fine as-is.
  • battery_widget_service.dart: Minimal and correct — extending the platform guard to Android leaves the iOS path behavior unchanged.
  • battery_widget_service_test.dart: This is the one real gap. The tests named "invokes method channel with correct arguments" and "executes safely" are tautologies — expect(true, isTrue) — because the Platform.isIOS/isAndroid guard skips the invocation when running on the host, and the methodCalls list that's collected is never asserted against. Consider overriding the platform (e.g. a TestDefaultBinaryMessenger + Platform.isAndroid override or a thin injectable platform check) so the channel arguments are actually verified, or at least rename the tests to reflect that they only cover no-throw behavior on unsupported platforms. The exception-resilience test is genuinely useful. Keeping needs-tests for now.

No blocking issues found. The tests are the only thing between this and being fully merge-ready in my view. Thanks for the careful, well-scoped parity work.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (Android home screen battery/status widget) — approve-only per policy, not a bug fix. CI green.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

feat(android): home screen widget for open issue #7150. This is a new capability (feature), not a bug fix, so per policy (mobile/community area) it's approve-only, not merge. CI green (Android/Dart checks pass).

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (Android home-screen battery widget) — approve-only per confidence gate (feature, not a bug fix; also needs-tests).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android needs-tests PR introduces logic that should be covered by tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App home widget for Android

3 participants