14
14
15
15
package com .google .firebase .crashlytics .internal .common ;
16
16
17
- import static com . google . firebase . crashlytics . internal . common . Utils . awaitEvenIfOnMainThread ;
17
+ import static java . util . concurrent . TimeUnit . MILLISECONDS ;
18
18
19
19
import android .content .Context ;
20
20
import android .content .SharedPreferences ;
21
21
import android .os .Build ;
22
22
import androidx .annotation .NonNull ;
23
+ import com .google .android .gms .tasks .Tasks ;
23
24
import com .google .firebase .crashlytics .internal .Logger ;
25
+ import com .google .firebase .crashlytics .internal .concurrency .CrashlyticsWorkers ;
24
26
import com .google .firebase .installations .FirebaseInstallationsApi ;
25
27
import java .util .Locale ;
26
28
import java .util .Objects ;
27
29
import java .util .UUID ;
28
30
import java .util .regex .Pattern ;
29
31
30
32
public class IdManager implements InstallIdProvider {
33
+ private static final int TIMEOUT_MILLIS = 4_000 ;
31
34
32
35
public static final String DEFAULT_VERSION_NAME = "0.0" ;
33
36
@@ -179,19 +182,22 @@ private String readCachedCrashlyticsInstallId(SharedPreferences prefs) {
179
182
*/
180
183
@ NonNull
181
184
public FirebaseInstallationId fetchTrueFid (boolean validate ) {
185
+ CrashlyticsWorkers .checkBackgroundThread (); // This fetch blocks, never do it on main.
182
186
String fid = null ;
183
187
String authToken = null ;
184
188
185
189
if (validate ) {
186
190
// Fetch the auth token first when requested, so the fid will be validated.
187
191
try {
188
- authToken = awaitEvenIfOnMainThread (firebaseInstallations .getToken (false )).getToken ();
192
+ authToken =
193
+ Tasks .await (firebaseInstallations .getToken (false ), TIMEOUT_MILLIS , MILLISECONDS )
194
+ .getToken ();
189
195
} catch (Exception ex ) {
190
196
Logger .getLogger ().w ("Error getting Firebase authentication token." , ex );
191
197
}
192
198
}
193
199
try {
194
- fid = awaitEvenIfOnMainThread (firebaseInstallations .getId ());
200
+ fid = Tasks . await (firebaseInstallations .getId (), TIMEOUT_MILLIS , MILLISECONDS );
195
201
} catch (Exception ex ) {
196
202
Logger .getLogger ().w ("Error getting Firebase installation id." , ex );
197
203
}
@@ -213,7 +219,9 @@ private synchronized String createAndCacheCrashlyticsInstallId(
213
219
return iid ;
214
220
}
215
221
216
- /** @return the package name that identifies this App. */
222
+ /**
223
+ * @return the package name that identifies this App.
224
+ */
217
225
public String getAppIdentifier () {
218
226
return appIdentifier ;
219
227
}
0 commit comments