Skip to content

Commit

Permalink
aw: Fix metrics service unbinding when not bound
Browse files Browse the repository at this point in the history
We are seeing crash reports indicating that an unbind
is happening when the service is not registered.

The hypothesis for this are the OS is somehow calling
onServiceConnected twice. We will protect against posting
a task if we have already done it once.

(cherry picked from commit b881e81)

Bug: 1427985
Change-Id: Ib481f2399449d49262ebc77fed1ad43f418f8e44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4373762
Commit-Queue: Rupert Wiser <bewise@chromium.org>
Commit-Queue: Richard Coles <torne@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1122625}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4373792
Reviewed-by: Krishna Govind <govind@chromium.org>
Owners-Override: Krishna Govind <govind@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5677@{#6}
Cr-Branched-From: 2c16a35-refs/heads/main@{#1122213}
  • Loading branch information
Rupert Ben Wiser authored and Krishna Govind committed Mar 27, 2023
1 parent c5b0691 commit d7d7986
Showing 1 changed file with 6 additions and 0 deletions.
Expand Up @@ -95,6 +95,7 @@ private static class MetricsLogUploaderServiceConnection implements ServiceConne
private final boolean mUseDefaultUploadQos;
private final @NonNull byte[] mData;
private final CompletableFuture<Integer> mResult;
private final AtomicBoolean mPosted = new AtomicBoolean();

public MetricsLogUploaderServiceConnection(boolean useDefaultUploadQos,
@NonNull byte[] data, @NonNull CompletableFuture<Integer> resultFuture) {
Expand All @@ -105,6 +106,11 @@ public MetricsLogUploaderServiceConnection(boolean useDefaultUploadQos,

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// We want to avoid re-posting if the service connection dies
// and reconnects.
if (mPosted.getAndSet(true)) {
return;
}
// onServiceConnected is called on the app main looper so post it to a background thread
// for execution. No need to enforce the order in which the logs are sent to the service
// as this isn't required/enforced by UMA.
Expand Down

0 comments on commit d7d7986

Please sign in to comment.