Skip to content

Commit

Permalink
Mark DeveloperUiService as foreground in onStartCommand
Browse files Browse the repository at this point in the history
The Webview DeveloperUiService is always started with
Context.startForegroundService, which requires services to then call
Service.startForeground within 5 seconds.

This CL moves that second call to onStartCommand to make sure it is
always called, as there are currently reports of it not being called in
time, which causes app crashes.

The javadoc change is replacing a } with a ).

Fixed: b/237496875
Fixed: 1330024
Change-Id: Iad43ee83bdd88e83c5a4d70a0971f0e87153fe60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3749201
Reviewed-by: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Commit-Queue: Peter Pakkenberg <pbirk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1025617}
  • Loading branch information
Peter Birk Pakkenberg authored and Chromium LUCI CQ committed Jul 19, 2022
1 parent 9302fba commit 50933b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void startDeveloperUiService(String webViewPackageName) {

/**
* Fetch the flag overrides from the developer mode ContentProvider. This should only be called
* if {@link #isDeveloperModeEnabled(String}} returns {@code true}, otherwise this may incur
* if {@link #isDeveloperModeEnabled(String)} returns {@code true}, otherwise this may incur
* unnecessary IPC or start up processes unnecessarily.
*
* @param webViewPackageName the package name of the WebView implementation to fetch the flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public void setFlagOverrides(Map overriddenFlags) {
}
};

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final int mode = super.onStartCommand(intent, flags, startId);
// Service is always expected to run in foreground, so mark as such when it is started.
// Subsequent calls will simply replace the foreground service notification.
markAsForegroundService();
return mode;
}

/**
* Static method to fetch the flag overrides. If this returns an empty map, this will
* asynchronously restart the Service to disable developer mode.
Expand Down Expand Up @@ -287,7 +296,6 @@ private void enableDeveloperMode() {
} else {
startService(intent);
}
markAsForegroundService();

ComponentName developerModeState =
new ComponentName(this, DeveloperModeUtils.DEVELOPER_MODE_STATE_COMPONENT);
Expand Down

0 comments on commit 50933b1

Please sign in to comment.