-
Notifications
You must be signed in to change notification settings - Fork 624
Remove synchronized blocks from ApkInstaller #4486
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
Conversation
Generated by 🚫 Danger |
Coverage Report 1Affected Products
Test Logs |
Size Report 1Affected Products
Test Logs |
Startup Time Report 1Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS. Startup time comparison between the CI merge commit (c2e4d4d) and the base commit (a28c43e) are not available. No macrobenchmark data found for the base commit (a28c43e). Analysis for the CI merge commit (c2e4d4d) can be found at: |
8432a15
to
e452ad6
Compare
e452ad6
to
ec13be6
Compare
@@ -84,12 +69,9 @@ private void startInstallActivity(String path, Activity currentActivity) { | |||
} | |||
|
|||
void trySetInstallTaskError() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this still need to be called "try"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do you one better: this method doesn't even need to exist! It's only called once so I'm going to inline it.
* Constructor for a {@link TaskCompletionSourceCache} that controls access using its own | ||
* sequential executor backed by the given base executor. | ||
* | ||
* @param baseExecutor Executor (typically {@link Lightweight}) to back the sequential executor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases where this should not (or is not) the "lightweight" executor?
If so, I think it should be documented which circumstances require a different executor. Does it depend on what TaskCompletionSourceProducer.produce()
does?
If not, maybe change "typically" to "always" and annotate the consturctor parameter accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It does depend on what TaskCompletionSourceProducer.produce()
does. I've reworded it.
@@ -144,5 +145,12 @@ static <T> UpdateTask onSuccessUpdateTask( | |||
return updateTask; | |||
} | |||
|
|||
/** Set a {@link TaskCompletionSource} to be resolved with the result of another {@link Task}. */ | |||
static <T> void shadowTask(TaskCompletionSource<T> taskCompletionSource, Task<T> task) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should this be a method on TaskCompletionSource
itself?
If so, can/should it use the TaskCompletionsSource
's executor instead of the "direct" one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TaskCompletionSource is provided by the play-services library, so we can't add it there (although we could file a feature request).
Also just a note: TaskCompletionSource
doesn't actually have its own executor. When you set a result on it, it passes that through to the underlying TaskImpl
, which executes any handlers on the executors that were specified when they were added. Using direct executor here ensures that any handlers that were themselves added using a direct executor will behave as expected: they'll be executed on the thread that set the result. (I'll add a note to that effect).
private final Object installTaskLock = new Object(); | ||
|
||
ApkInstaller(FirebaseAppDistributionLifecycleNotifier lifeCycleNotifier) { | ||
ApkInstaller( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this constructor be annotated with @VisibleForTesting
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
this(FirebaseAppDistributionLifecycleNotifier.getInstance()); | ||
} | ||
|
||
void onActivityStarted(@Nullable Activity activity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was literally doing nothing
public void | ||
setCurrentActivity_appInForegroundAfterAnInstallAttempt_installIntentOnCurrentActivity() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was testing the onActivityStarted()
that I removed.
firebaseAppDistribution.signOutTester(); | ||
awaitAsyncOperations(backgroundExecutor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed this test was flaky without this, which makes sense since the update to SharedPreferences happens on the background thread.
private final Object installTaskLock = new Object(); | ||
|
||
ApkInstaller(FirebaseAppDistributionLifecycleNotifier lifeCycleNotifier) { | ||
ApkInstaller( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
@@ -84,12 +69,9 @@ private void startInstallActivity(String path, Activity currentActivity) { | |||
} | |||
|
|||
void trySetInstallTaskError() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do you one better: this method doesn't even need to exist! It's only called once so I'm going to inline it.
* Constructor for a {@link TaskCompletionSourceCache} that controls access using its own | ||
* sequential executor backed by the given base executor. | ||
* | ||
* @param baseExecutor Executor (typically {@link Lightweight}) to back the sequential executor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. It does depend on what TaskCompletionSourceProducer.produce()
does. I've reworded it.
@@ -144,5 +145,12 @@ static <T> UpdateTask onSuccessUpdateTask( | |||
return updateTask; | |||
} | |||
|
|||
/** Set a {@link TaskCompletionSource} to be resolved with the result of another {@link Task}. */ | |||
static <T> void shadowTask(TaskCompletionSource<T> taskCompletionSource, Task<T> task) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TaskCompletionSource is provided by the play-services library, so we can't add it there (although we could file a feature request).
Also just a note: TaskCompletionSource
doesn't actually have its own executor. When you set a result on it, it passes that through to the underlying TaskImpl
, which executes any handlers on the executors that were specified when they were added. Using direct executor here ensures that any handlers that were themselves added using a direct executor will behave as expected: they'll be executed on the thread that set the result. (I'll add a note to that effect).
* Remove synchronized blocks from ApkInstaller * Fix broken test * Address Kai's feedback
* Remove synchronized blocks from ApkInstaller * Fix broken test * Address Kai's feedback
* Remove synchronized blocks from ApkInstaller * Fix broken test * Address Kai's feedback
* Remove synchronized blocks from ApkInstaller * Fix broken test * Address Kai's feedback
Uses a
TaskCompletionSourceCache
, which allows caching tasks which can then be resolved later in a thread-safe manner.