Add start workers in LaunchActivity#6720
Conversation
|
@jpelgrom I'm struggling here to find a nice way to work with this and I need more context.
From my point of view it is also not the responsibility of the Screen to start the workers. I can modify the start function to not take any I'm curious about your opinion here. |
Test Results 232 files 240 suites 9m 53s ⏱️ For more details on these failures, see this check. Results for commit 6af7901. ♻️ This comment has been updated with latest results. |
I think the goal the current behavior is trying to achieve is simply more updates for sensors / a way to kickstart any workers that the system may have suspended, as it is unlikely they will be delayed when the app is actively being used. That means tying it to the entrypoint for users -> WebViewActivity. (@dshokouhi might know more history here.) Following that logic, it isn't really about the specific screen but rather the entire app being opened or hidden (lifecycle). I kind of understand what you're trying to do with the ViewModel taking no context, but could you spell it out? There are still tons of Android-specific functions that exist and need context so I'm not sure it can be completely avoided forever, and to do everything in Compose where you have a context feels like misuse. ViewModel doesn't need to know about onResume/onStart but we could want functions called on those lifecycle events. If multiple things need to happen on onStart I'm not opposed to simply creating a function named onStart in the ViewModel to make it easier to manage 🤷. |
|
Yes we do have an app importance sensor that needs to update if the app is in foreground or what not. That's why the on pause and on resume calls are there. It should be on the settings activity as well iirc |
|
@jpelgrom we could potentially move the logic within the ViewModel but I'm not sure if it relevant here, it would force us to pass the context or change how we start the workers. |
There was a problem hiding this comment.
Pull request overview
This PR updates LaunchActivity (the app’s navigation entry Activity) to start the same background workers that are currently started from WebViewActivity, so sensor updates and the persistent WebSocket worker are initiated when the app resumes.
Changes:
- Start
SensorWorkerand scheduleWebsocketManagerfromLaunchActivity.onResume() - Trigger an immediate sensor refresh via
SensorReceiver.updateAllSensors()fromLaunchActivity.onPause() - Expand
LaunchActivityKDoc to describe these lifecycle behaviors
|
Moving it into LaunchActivity means that, at least as long as the WebViewActivity is used, these two updates + the update in WebViewActivity launch trigger very shortly after another because you transition in and out of LaunchActivity almost immediately. Maybe put these behind the feature flag as well? |
| @Test | ||
| fun `Given activity pauses without finishing then all sensors are updated`() { | ||
| ActivityScenario.launch(LaunchActivity::class.java).use { scenario -> | ||
| scenario.moveToState(Lifecycle.State.STARTED) // triggers onPause |
There was a problem hiding this comment.
This makes no sense to me, and I wouldn't be surprised if it turns out to be flaky. The documentation mentions (including emphasis!):
Started state for a LifecycleOwner. For an android.app.Activity, this state is reached in two cases:
- after android.app.Activity.onStart call;
- right before android.app.Activity.onPause call.
There was a problem hiding this comment.
Love the Google inconsistency... /s
In that case OK, no objection and it seems like the right way to test this.
* Introduce WebViewAction and enforce EvaluateScriptUsage (home-assistant#6713) * Introduce WebViewActions and enforce EvaluateScriptUsage * Apply Copilot feedback * Update app/src/main/kotlin/io/homeassistant/companion/android/frontend/WebViewAction.kt Co-authored-by: Joris Pelgröm <[email protected]> --------- Co-authored-by: Joris Pelgröm <[email protected]> * Update github/codeql-action action to v4.35.2 (home-assistant#6728) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update ruby/setup-ruby action to v1.302.0 (home-assistant#6731) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Bump changelog_master.xml for weekly release 2026.4.5 (home-assistant#6730) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Handle missing client certificate chooser activity (home-assistant#6716) * Add support for Gesture in FrontendScreen (home-assistant#6714) --------- Co-authored-by: Joris Pelgröm <[email protected]> * Update lokalise/lokalise-pull-action action to v5.2.1 (home-assistant#6724) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Enable cookie in FrontendScreen (home-assistant#6715) * Update dependency io.sentry:sentry-android-core to v8.39.1 (home-assistant#6732) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Update fastlane to 2.233.0 (home-assistant#6737) * Allow artifacts update for Ruby with renovate (home-assistant#6738) * Add support for NFC write in FrontendScreen (home-assistant#6719) * Add support for NFC write in FrontendScreen * Apply suggestions * Apply suggestion and improve NfcSetupActivity * Renovate: split Compose screenshot updates from other com.android updates (home-assistant#6743) * Update runConfigurations to work properly on Android 17 (home-assistant#6740) * Update com.android.* (home-assistant#6675) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Remove Trigger workflow step from Renovate lockfile worflow (home-assistant#6747) * Remove unnecessary permissions for actions (home-assistant#6748) * Adjust LaunchActivity configChanges flags (home-assistant#6751) * Ignore Chromium keystore disk write strict mode issue (home-assistant#6758) * Add start workers in LaunchActivity (home-assistant#6720) * Introduce check location disabled usecase and show Changelog on LaunchActivity (home-assistant#6734) * Add support for Zoom in FrontendScreen (home-assistant#6739) * Allow observeChanges on LocalStorate * Update dependency sh.calvin.reorderable:reorderable to v3.1.0 (home-assistant#6761) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Initialize Timber before Application.onCreate (home-assistant#6757) * Disable microwakeword test on wearOS (home-assistant#6766) * Add lint rule for webview evaluate javascript (home-assistant#6741) * Configure Composer diagnostic stacktrace (home-assistant#6764) * Ignore JobService leak in InstrumentationTest for API23 (home-assistant#6765) --------- Co-authored-by: Joris Pelgröm <[email protected]> * Update ruby/setup-ruby action to v1.304.0 (home-assistant#6770) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update ruby/setup-ruby action to v1.305.0 (home-assistant#6772) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency ruby to v4.0.3 (home-assistant#6762) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Lock file maintenance (home-assistant#6783) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Bump changelog_master.xml for weekly release 2026.4.6 (home-assistant#6778) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Update dependency io.sentry:sentry-android-core to v8.40.0 (home-assistant#6775) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Update dependency androidx.navigation:navigation-testing to v2.9.8 (home-assistant#6776) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Update org.jetbrains.kotlin.* (home-assistant#6774) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Update androidx.compose.* (home-assistant#6777) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Update com.android.* (home-assistant#6769) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Remove the use of Dispachers.Default in AppLockViewModel (home-assistant#6784) * Fix compose unit test and kotlin configuration after update (home-assistant#6785) --------- Co-authored-by: Joris Pelgröm <[email protected]> * Honor user-installed CAs in OkHttp trust store (home-assistant#6753) --------- Co-authored-by: Timothy <[email protected]> Co-authored-by: Copilot <[email protected]> * Add support for JSConfirm dialog in FrontendScreen (home-assistant#6749) * Fix resize cast for ExoPlayer in WebViewActivity causing blank player (home-assistant#6767) * Fix resize cast for ExoPlayer in WebViewActivity causing blank player * Use Double instead of Float * Enable fullscreen support at the LaunchActivity level (home-assistant#6759) * Enable fullscreen support at the LaunchActivity level * Add missing tests * Update ruby/setup-ruby action to v1.306.0 (home-assistant#6789) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Setup emulator WTF (home-assistant#6768) --------- Co-authored-by: Joris Pelgröm <[email protected]> * Add file chooser capability to FrontendScreen (home-assistant#6755) * Use a queue to handle FileChooserRequest --------- Co-authored-by: Copilot <[email protected]> * Adjust PermissionManager to use awaitResult (home-assistant#6787) * Update Gradle to v9.5.0 (home-assistant#6796) * Update Gradle to v9.5.0 * Update wrapper: gradlew wrapper --gradle-version 9.5.0 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Bump changelog_master.xml for weekly release 2026.5.1 (home-assistant#6795) * Bump changelog_master.xml for weekly release 2026.5.1 * Empty commit for CI --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Lock file maintenance (home-assistant#6802) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Bump changelog_master.xml for weekly release 2026.5.2 (home-assistant#6800) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Use OIDC to authenticate on Emulator.wtf (home-assistant#6803) * Add HTTP basic auth dialog to FrontendScreen (home-assistant#6750) * Introduce HACheckbox * Fix WebViewActivity leak via Handler.postDelayed in waitForConnection (home-assistant#5453) (home-assistant#6791) --------- Co-authored-by: jim-daf <[email protected]> Co-authored-by: Timothy <[email protected]> * Add app lock feature to FrontendScreen (home-assistant#6756) * Add Blur overlay to LaunchActivity * Migrate to AppLockStateManager * Fix leak of WebMessageListener by properly removing it in onDestroy (home-assistant#6805) --------- Co-authored-by: Joris Pelgröm <[email protected]> * Update lokalise/lokalise-pull-action action to v5.2.2 (home-assistant#6807) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update github/codeql-action action to v4.35.3 (home-assistant#6808) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Add ExoPlayer support for FrontendScreen from frontend request (home-assistant#6771) * Introduce FrontendExoPlayerManager * Allow HAApp to make fullscreen request to the LaunchActivity * Add support for ExoPlayer in FrontendScreen * Use Double for resize * Use ktx * Fix unit test * Fix tests * Apply Copilot feedbacks * Apply last suggestions * Apply suggestions on tests * Bump Gradle actions to 6.1.0 and use basic cache provider (home-assistant#6811) * Update aboutlibraries to v14.1.0 (home-assistant#6809) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Add support for custom view in FrontendScreen (home-assistant#6790) Instanciate the HAWebChromeClient from Compose to get the custom view * Support for auto play video in FrontendScreen (home-assistant#6806) * Support for auto play video in FrontendScreen * Adjust logic to address Copilot concern * Update app/src/main/kotlin/io/homeassistant/companion/android/frontend/FrontendViewModel.kt Co-authored-by: Joris Pelgröm <[email protected]> * Make observeChanges support multiples keys * Move entirely to LocalStorage --------- Co-authored-by: Joris Pelgröm <[email protected]> * Update com.android.* (home-assistant#6820) * Update com.android.* * Update dependency lockfiles * Empty commit for CI --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Update androidx.compose.* (home-assistant#6823) * Update androidx.compose.* * Update dependency lockfiles * Empty commit for CI --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Update dependency com.google.android.gms:play-services-wearable to v20 (home-assistant#6797) * Update dependency com.google.android.gms:play-services-wearable to v20 * Update dependency lockfiles * Empty commit for CI --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Update github/codeql-action action to v4.35.4 (home-assistant#6830) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Lock file maintenance (home-assistant#6833) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update dependency com.google.firebase:firebase-bom to v34.13.0 (home-assistant#6831) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Bump changelog_master.xml for weekly release 2026.5.3 (home-assistant#6827) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Update org.jetbrains.kotlin.* to v1.11.0 (home-assistant#6832) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Introduce RequestAccurateLocationReceiver and restrict LocationSensorManager export (home-assistant#6837) Introduce RequestAcurateLocationReceiver to stop exporting LocationSensorManager * Update aboutlibraries to v14.2.0 (home-assistant#6828) * Update aboutlibraries to v14.2.0 * Update dependency lockfiles * Empty commit for CI --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Update dependency com.slack.lint.compose:compose-lint-checks to v1.4.3 (home-assistant#6825) * Update dependency com.slack.lint.compose:compose-lint-checks to v1.4.3 * Update dependency lockfiles * Empty commit for CI --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Joris Pelgröm <[email protected]> * Restore HTTP 404/410 handling for updating registration (home-assistant#6835) * Update dependency io.sentry:sentry-android-core to v8.41.0 (home-assistant#6826) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Move the debug flag for WebView into the Application and Settings (home-assistant#6813) * Update androidx.* (home-assistant#6824) --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Timothy <[email protected]> * Add Improv external bus messages models (home-assistant#6817) * Fix crash on start in release due to WebView remote debug pref (home-assistant#6841) * Add support for PiP for FrontendScreen (home-assistant#6812) * Deprecated the old Material Design 2 theme to avoid using it (home-assistant#6815) * Deprecated the old Material Design 2 theme to avoid using it * Remove Autofix * Add action to open Settings View from Automotive main screen (home-assistant#6834) * Migrate TagReaderActivity to use BottomSheet and add confirmation buttons (home-assistant#6814) * Support next.home-assistant.io in Debug * Make TagReaderActivity standalone and translucent * Add preference to stored allowed tag and clearing in dev settings * Introduce PainterResourceUtil to load app icon --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]> Co-authored-by: Joris Pelgröm <[email protected]> * Update emulator wtf actions (home-assistant#6843) * isDrivingDistracted --------- Co-authored-by: Timothy <[email protected]> Co-authored-by: Joris Pelgröm <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Runye Zhang <[email protected]> Co-authored-by: Dimitris Dafnis <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Joris Pelgröm <[email protected]> Co-authored-by: jim-daf <[email protected]>


Summary
Replicate the start workers from the
WebViewActivitywithin theLaunchActivity. It does replicate exactly the existing behavior, it is not gated behindWipFeaturebecause it just triggers a second update of the sensor which is acceptable.Checklist
Any other notes