Skip to content

Commit fe558c7

Browse files
committed
Migrate executors in fad/in-app-feedback
1 parent 233dead commit fe558c7

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
6565
private final SignInStorage signInStorage;
6666
private final ReleaseIdentifier releaseIdentifier;
6767
private final ScreenshotTaker screenshotTaker;
68-
private final Executor taskExecutor;
68+
private final Executor blockingExecutor;
6969
private final FirebaseAppDistributionNotificationsManager notificationsManager;
7070

7171
private final Object cachedNewReleaseLock = new Object();
@@ -95,7 +95,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
9595
@NonNull FirebaseAppDistributionLifecycleNotifier lifecycleNotifier,
9696
@NonNull ReleaseIdentifier releaseIdentifier,
9797
@NonNull ScreenshotTaker screenshotTaker,
98-
@NonNull Executor taskExecutor) {
98+
@NonNull Executor blockingExecutor) {
9999
this.firebaseApp = firebaseApp;
100100
this.testerSignInManager = testerSignInManager;
101101
this.newReleaseFetcher = newReleaseFetcher;
@@ -105,7 +105,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
105105
this.releaseIdentifier = releaseIdentifier;
106106
this.lifecycleNotifier = lifecycleNotifier;
107107
this.screenshotTaker = screenshotTaker;
108-
this.taskExecutor = taskExecutor;
108+
this.blockingExecutor = blockingExecutor;
109109
this.notificationsManager =
110110
new FirebaseAppDistributionNotificationsManager(firebaseApp.getApplicationContext());
111111
lifecycleNotifier.addOnActivityDestroyedListener(this::onActivityDestroyed);
@@ -324,13 +324,13 @@ public void startFeedback(@NonNull CharSequence infoText) {
324324
screenshotTaker
325325
.takeScreenshot()
326326
.addOnFailureListener(
327-
taskExecutor,
327+
blockingExecutor,
328328
e -> {
329329
LogWrapper.getInstance().w("Failed to take screenshot for feedback", e);
330330
doStartFeedback(infoText, null);
331331
})
332332
.addOnSuccessListener(
333-
taskExecutor, screenshotUri -> doStartFeedback(infoText, screenshotUri));
333+
blockingExecutor, screenshotUri -> doStartFeedback(infoText, screenshotUri));
334334
}
335335

336336
@Override
@@ -369,18 +369,19 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
369369
testerSignInManager
370370
.signInTester()
371371
.addOnFailureListener(
372-
taskExecutor,
372+
blockingExecutor,
373373
e -> {
374374
feedbackInProgress.set(false);
375375
LogWrapper.getInstance()
376376
.e("Failed to sign in tester. Could not collect feedback.", e);
377377
})
378378
.onSuccessTask(
379-
taskExecutor,
379+
blockingExecutor,
380380
unused ->
381381
releaseIdentifier
382382
.identifyRelease()
383383
.addOnFailureListener(
384+
blockingExecutor,
384385
e -> {
385386
feedbackInProgress.set(false);
386387
LogWrapper.getInstance().e("Failed to identify release", e);
@@ -391,11 +392,12 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
391392
.show();
392393
})
393394
.onSuccessTask(
394-
taskExecutor,
395+
blockingExecutor,
395396
releaseName ->
396397
// in development-mode the releaseName might be null
397398
launchFeedbackActivity(releaseName, infoText, screenshotUri)
398399
.addOnFailureListener(
400+
blockingExecutor,
399401
e -> {
400402
feedbackInProgress.set(false);
401403
LogWrapper.getInstance()

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionRegistrar.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import androidx.annotation.Keep;
2121
import androidx.annotation.NonNull;
2222
import com.google.firebase.FirebaseApp;
23+
import com.google.firebase.annotations.concurrent.Background;
2324
import com.google.firebase.annotations.concurrent.Blocking;
2425
import com.google.firebase.appdistribution.FirebaseAppDistribution;
2526
import com.google.firebase.components.Component;
@@ -33,10 +34,9 @@
3334
import java.util.Arrays;
3435
import java.util.List;
3536
import java.util.concurrent.Executor;
36-
import java.util.concurrent.Executors;
3737

3838
/**
39-
* Registers FirebaseAppDistribution.
39+
* Registers FirebaseAppDistribution and related components.
4040
*
4141
* @hide
4242
*/
@@ -48,21 +48,27 @@ public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
4848

4949
@Override
5050
public @NonNull List<Component<?>> getComponents() {
51+
Qualified<Executor> backgroundExecutor = Qualified.qualified(Background.class, Executor.class);
5152
Qualified<Executor> blockingExecutor = Qualified.qualified(Blocking.class, Executor.class);
5253
return Arrays.asList(
5354
Component.builder(FirebaseAppDistribution.class)
5455
.name(LIBRARY_NAME)
5556
.add(Dependency.required(FirebaseApp.class))
5657
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class))
58+
.add(Dependency.required(backgroundExecutor))
5759
.add(Dependency.required(blockingExecutor))
58-
.factory(c -> buildFirebaseAppDistribution(c, c.get(blockingExecutor)))
60+
.factory(
61+
c ->
62+
buildFirebaseAppDistribution(
63+
c, c.get(backgroundExecutor), c.get(blockingExecutor)))
5964
// construct FirebaseAppDistribution instance on startup so we can register for
6065
// activity lifecycle callbacks before the API is called
6166
.alwaysEager()
6267
.build(),
6368
Component.builder(FeedbackSender.class)
6469
.add(Dependency.required(FirebaseApp.class))
6570
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class))
71+
.add(Dependency.required(backgroundExecutor))
6672
.add(Dependency.required(blockingExecutor))
6773
.factory(c -> buildFeedbackSender(c, c.get(blockingExecutor)))
6874
.build(),
@@ -86,7 +92,7 @@ private FeedbackSender buildFeedbackSender(
8692
// TODO(b/258264924): Migrate to go/firebase-android-executors
8793
@SuppressLint("ThreadPoolCreation")
8894
private FirebaseAppDistribution buildFirebaseAppDistribution(
89-
ComponentContainer container, Executor blockingExecutor) {
95+
ComponentContainer container, Executor backgroundExecutor, Executor blockingExecutor) {
9096
FirebaseApp firebaseApp = container.get(FirebaseApp.class);
9197
Context context = firebaseApp.getApplicationContext();
9298
Provider<FirebaseInstallationsApi> firebaseInstallationsApiProvider =
@@ -112,8 +118,8 @@ private FirebaseAppDistribution buildFirebaseAppDistribution(
112118
signInStorage,
113119
lifecycleNotifier,
114120
releaseIdentifier,
115-
new ScreenshotTaker(firebaseApp, lifecycleNotifier),
116-
Executors.newSingleThreadExecutor());
121+
new ScreenshotTaker(firebaseApp, lifecycleNotifier, backgroundExecutor),
122+
blockingExecutor);
117123

118124
if (context instanceof Application) {
119125
Application firebaseApplication = (Application) context;

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/ScreenshotTaker.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.firebase.appdistribution.impl;
1616

17-
import android.annotation.SuppressLint;
1817
import android.annotation.TargetApi;
1918
import android.app.Activity;
2019
import android.content.Context;
@@ -37,7 +36,6 @@
3736
import java.io.FileOutputStream;
3837
import java.io.IOException;
3938
import java.util.concurrent.Executor;
40-
import java.util.concurrent.Executors;
4139

4240
/** A class that takes screenshots of the host app. */
4341
class ScreenshotTaker {
@@ -47,23 +45,15 @@ class ScreenshotTaker {
4745

4846
private final FirebaseApp firebaseApp;
4947
private final FirebaseAppDistributionLifecycleNotifier lifecycleNotifier;
50-
private final Executor taskExecutor;
48+
private final Executor backgroundExecutor;
5149

52-
// TODO(b/258264924): Migrate to go/firebase-android-executors
53-
@SuppressLint("ThreadPoolCreation")
54-
ScreenshotTaker(
55-
FirebaseApp firebaseApp, FirebaseAppDistributionLifecycleNotifier lifecycleNotifier) {
56-
this(firebaseApp, lifecycleNotifier, Executors.newSingleThreadExecutor());
57-
}
58-
59-
@VisibleForTesting
6050
ScreenshotTaker(
6151
FirebaseApp firebaseApp,
6252
FirebaseAppDistributionLifecycleNotifier lifecycleNotifier,
63-
Executor taskExecutor) {
53+
Executor backgroundExecutor) {
6454
this.firebaseApp = firebaseApp;
6555
this.lifecycleNotifier = lifecycleNotifier;
66-
this.taskExecutor = taskExecutor;
56+
this.backgroundExecutor = backgroundExecutor;
6757
}
6858

6959
/**
@@ -81,7 +71,7 @@ Task<Uri> takeScreenshot() {
8171
/** Deletes any previously taken screenshot. */
8272
Task<Void> deleteScreenshot() {
8373
return TaskUtils.runAsyncInTask(
84-
taskExecutor,
74+
backgroundExecutor,
8575
() -> {
8676
firebaseApp.getApplicationContext().deleteFile(SCREENSHOT_FILE_NAME);
8777
return null;
@@ -157,7 +147,7 @@ private Task<Uri> writeToFile(@Nullable Bitmap bitmap) {
157147
return Tasks.forResult(null);
158148
}
159149
return TaskUtils.runAsyncInTask(
160-
taskExecutor,
150+
backgroundExecutor,
161151
() -> {
162152
try (FileOutputStream outputStream = openFileOutputStream()) {
163153
// PNG is a lossless format, the compression factor (100) is ignored

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/SignInStorage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class SignInStorage {
3030
this.signInSharedPreferences =
3131
new Lazy(
3232
() ->
33+
// TODO(lkellogg): This constructs a SharedPreferences object, which touches disk
34+
// and therefore should be run on a @Background executor. This could ideally be
35+
// done by a new shared component.
3336
applicationContext.getSharedPreferences(
3437
SIGNIN_PREFERENCES_NAME, Context.MODE_PRIVATE));
3538
}

0 commit comments

Comments
 (0)