Skip to content

Commit 1b758c6

Browse files
committed
Deprecate awaitEvenIfOnMain
1 parent ad7b591 commit 1b758c6

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public Task<Void> then(@Nullable Settings settings) throws Exception {
248248
try {
249249
// Never block on ODFs, in case they get triggered from the main thread.
250250
if (!isOnDemand) {
251+
//noinspection deprecation drain the worker instead.
251252
Utils.awaitEvenIfOnMainThread(handleUncaughtExceptionTask);
252253
}
253254
} catch (TimeoutException e) {
@@ -559,7 +560,6 @@ void doCloseSessions(SettingsProvider settingsProvider) {
559560
}
560561

561562
/**
562-
*
563563
* Not synchronized/locked. Must be executed from the executor service runs tasks in serial order
564564
*/
565565
private void doCloseSessions(

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/IdManager.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414

1515
package com.google.firebase.crashlytics.internal.common;
1616

17-
import static com.google.firebase.crashlytics.internal.common.Utils.awaitEvenIfOnMainThread;
17+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
1818

1919
import android.content.Context;
2020
import android.content.SharedPreferences;
2121
import android.os.Build;
2222
import androidx.annotation.NonNull;
23+
import com.google.android.gms.tasks.Tasks;
2324
import com.google.firebase.crashlytics.internal.Logger;
25+
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorkers;
2426
import com.google.firebase.installations.FirebaseInstallationsApi;
2527
import java.util.Locale;
2628
import java.util.Objects;
2729
import java.util.UUID;
2830
import java.util.regex.Pattern;
2931

3032
public class IdManager implements InstallIdProvider {
33+
private static final int TIMEOUT_MILLIS = 4_000;
3134

3235
public static final String DEFAULT_VERSION_NAME = "0.0";
3336

@@ -179,19 +182,22 @@ private String readCachedCrashlyticsInstallId(SharedPreferences prefs) {
179182
*/
180183
@NonNull
181184
public FirebaseInstallationId fetchTrueFid(boolean validate) {
185+
CrashlyticsWorkers.checkBackgroundThread(); // This fetch blocks, never do it on main.
182186
String fid = null;
183187
String authToken = null;
184188

185189
if (validate) {
186190
// Fetch the auth token first when requested, so the fid will be validated.
187191
try {
188-
authToken = awaitEvenIfOnMainThread(firebaseInstallations.getToken(false)).getToken();
192+
authToken =
193+
Tasks.await(firebaseInstallations.getToken(false), TIMEOUT_MILLIS, MILLISECONDS)
194+
.getToken();
189195
} catch (Exception ex) {
190196
Logger.getLogger().w("Error getting Firebase authentication token.", ex);
191197
}
192198
}
193199
try {
194-
fid = awaitEvenIfOnMainThread(firebaseInstallations.getId());
200+
fid = Tasks.await(firebaseInstallations.getId(), TIMEOUT_MILLIS, MILLISECONDS);
195201
} catch (Exception ex) {
196202
Logger.getLogger().w("Error getting Firebase installation id.", ex);
197203
}
@@ -213,7 +219,9 @@ private synchronized String createAndCacheCrashlyticsInstallId(
213219
return iid;
214220
}
215221

216-
/** @return the package name that identifies this App. */
222+
/**
223+
* @return the package name that identifies this App.
224+
*/
217225
public String getAppIdentifier() {
218226
return appIdentifier;
219227
}

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/Utils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
@SuppressWarnings({"ResultOfMethodCallIgnored", "UnusedReturnValue"})
2828
public final class Utils {
2929
/** Timeout in milliseconds for blocking on background threads. */
30-
private static final int BACKGROUND_TIMEOUT_MILLIS = 4_000;
30+
private static final int BACKGROUND_TIMEOUT_MILLIS = 5_000;
3131

3232
/** Timeout in milliseconds for blocking on the main thread. Be careful about ANRs. */
33-
private static final int MAIN_TIMEOUT_MILLIS = 2_750;
33+
private static final int MAIN_TIMEOUT_MILLIS = 4_000;
3434

3535
/**
3636
* Blocks until the given Task completes, and then returns the value the Task was resolved with,
@@ -44,7 +44,9 @@ public final class Utils {
4444
* @return the value that was returned by the task, if successful.
4545
* @throws InterruptedException if the method was interrupted
4646
* @throws TimeoutException if the method timed out while waiting for the task.
47+
* @deprecated Don't use this. Drain the worker instead.
4748
*/
49+
@Deprecated
4850
public static <T> T awaitEvenIfOnMainThread(Task<T> task)
4951
throws InterruptedException, TimeoutException {
5052
CountDownLatch latch = new CountDownLatch(1);

0 commit comments

Comments
 (0)