Skip to content

Commit 77e0831

Browse files
authored
Merge 3aacd2b into a2261d8
2 parents a2261d8 + 3aacd2b commit 77e0831

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private static String formatId(@NonNull String id) {
104104
@Override
105105
@NonNull
106106
public synchronized InstallIds getInstallIds() {
107-
CrashlyticsWorkers.checkBackgroundThread();
108107
if (!shouldRefresh()) {
109108
return installIds;
110109
}
@@ -183,7 +182,7 @@ private String readCachedCrashlyticsInstallId(SharedPreferences prefs) {
183182
*/
184183
@NonNull
185184
public FirebaseInstallationId fetchTrueFid(boolean validate) {
186-
CrashlyticsWorkers.checkBackgroundThread(); // This fetch blocks, never do it on main.
185+
CrashlyticsWorkers.checkNotMainThread(); // This fetch blocks, never do it on main.
187186
String fid = null;
188187
String authToken = null;
189188

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/concurrency/CrashlyticsWorkers.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.firebase.crashlytics.internal.concurrency
1818

19+
import android.os.Build
20+
import android.os.Looper
1921
import com.google.firebase.crashlytics.internal.Logger
2022
import java.util.concurrent.ExecutorService
2123

@@ -59,6 +61,12 @@ class CrashlyticsWorkers(
5961
/** When enabled, failed preconditions will cause assertion errors for debugging. */
6062
@JvmStatic var enforcement: Boolean = false
6163

64+
@JvmStatic
65+
fun checkNotMainThread() =
66+
checkThread(::isNotMainThread) {
67+
"Must not be called on a main thread, was called on $threadName."
68+
}
69+
6270
@JvmStatic
6371
fun checkBlockingThread() =
6472
checkThread(::isBlockingThread) {
@@ -71,6 +79,13 @@ class CrashlyticsWorkers(
7179
"Must be called on a background thread, was called on $threadName."
7280
}
7381

82+
private fun isNotMainThread() =
83+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
84+
!Looper.getMainLooper().isCurrentThread
85+
} else {
86+
Looper.getMainLooper() != Looper.myLooper()
87+
}
88+
7489
private fun isBlockingThread() = threadName.contains("Firebase Blocking Thread #")
7590

7691
private fun isBackgroundThread() = threadName.contains("Firebase Background Thread #")

0 commit comments

Comments
 (0)