26
26
import androidx .annotation .NonNull ;
27
27
import androidx .annotation .VisibleForTesting ;
28
28
import com .google .android .gms .tasks .Task ;
29
- import com .google .android .gms .tasks .TaskCompletionSource ;
30
29
import com .google .firebase .FirebaseApp ;
31
30
import com .google .firebase .appdistribution .FirebaseAppDistribution ;
32
31
import com .google .firebase .appdistribution .FirebaseAppDistributionException ;
@@ -47,7 +46,6 @@ class ApkUpdater {
47
46
private static final String REQUEST_METHOD_GET = "GET" ;
48
47
private static final String DEFAULT_APK_FILE_NAME = "downloaded_release.apk" ;
49
48
50
- private TaskCompletionSource <File > downloadTaskCompletionSource ;
51
49
private final Executor blockingExecutor ; // Executor to run task listeners on a background thread
52
50
private final Context context ;
53
51
private final ApkInstaller apkInstaller ;
@@ -142,25 +140,11 @@ private void installApk(File file, boolean showDownloadNotificationManager) {
142
140
@ NonNull
143
141
Task <File > downloadApk (
144
142
@ NonNull AppDistributionReleaseInternal newRelease , boolean showNotification ) {
145
- if (downloadTaskCompletionSource != null
146
- && !downloadTaskCompletionSource .getTask ().isComplete ()) {
147
- return downloadTaskCompletionSource .getTask ();
148
- }
149
-
150
- downloadTaskCompletionSource = new TaskCompletionSource <>();
151
-
152
- blockingExecutor .execute (
153
- () -> {
154
- try {
155
- makeApkDownloadRequest (newRelease , showNotification );
156
- } catch (FirebaseAppDistributionException e ) {
157
- safeSetTaskException (downloadTaskCompletionSource , e );
158
- }
159
- });
160
- return downloadTaskCompletionSource .getTask ();
143
+ return TaskUtils .runAsyncInTask (
144
+ blockingExecutor , () -> makeApkDownloadRequest (newRelease , showNotification ));
161
145
}
162
146
163
- private void makeApkDownloadRequest (
147
+ private File makeApkDownloadRequest (
164
148
@ NonNull AppDistributionReleaseInternal newRelease , boolean showNotification )
165
149
throws FirebaseAppDistributionException {
166
150
String downloadUrl = newRelease .getDownloadUrl ();
@@ -197,7 +181,7 @@ private void makeApkDownloadRequest(
197
181
UpdateStatus .DOWNLOADED ,
198
182
showNotification ,
199
183
R .string .download_completed );
200
- safeSetTaskResult ( downloadTaskCompletionSource , apkFile ) ;
184
+ return apkFile ;
201
185
}
202
186
203
187
private static boolean isResponseSuccess (int responseCode ) {
0 commit comments