29
29
import com .google .android .gms .common .util .AndroidUtilsLight ;
30
30
import com .google .android .gms .common .util .Hex ;
31
31
import com .google .android .gms .common .util .VisibleForTesting ;
32
- import com .google .firebase . heartbeatinfo . HeartBeatInfo ;
33
- import com .google .firebase .heartbeatinfo .HeartBeatInfo . HeartBeat ;
32
+ import com .google .android . gms . tasks . Tasks ;
33
+ import com .google .firebase .heartbeatinfo .HeartBeatController ;
34
34
import com .google .firebase .inject .Provider ;
35
35
import com .google .firebase .installations .FirebaseInstallationsException ;
36
36
import com .google .firebase .installations .FirebaseInstallationsException .Status ;
37
37
import com .google .firebase .installations .remote .InstallationResponse .ResponseCode ;
38
- import com .google .firebase .platforminfo .UserAgentPublisher ;
39
38
import java .io .BufferedReader ;
40
39
import java .io .IOException ;
41
40
import java .io .InputStream ;
46
45
import java .net .URL ;
47
46
import java .net .URLConnection ;
48
47
import java .nio .charset .Charset ;
48
+ import java .util .concurrent .ExecutionException ;
49
49
import java .util .regex .Pattern ;
50
50
import java .util .zip .GZIPOutputStream ;
51
51
import org .json .JSONException ;
@@ -88,8 +88,7 @@ public class FirebaseInstallationServiceClient {
88
88
/** Heartbeat tag for firebase installations. */
89
89
private static final String FIREBASE_INSTALLATIONS_ID_HEARTBEAT_TAG = "fire-installations-id" ;
90
90
91
- private static final String HEART_BEAT_HEADER = "x-firebase-client-log-type" ;
92
- private static final String USER_AGENT_HEADER = "x-firebase-client" ;
91
+ private static final String HEART_BEAT_HEADER = "x-firebase-client" ;
93
92
94
93
private static final String X_ANDROID_PACKAGE_HEADER_KEY = "X-Android-Package" ;
95
94
private static final String X_ANDROID_CERT_HEADER_KEY = "X-Android-Cert" ;
@@ -114,17 +113,13 @@ public class FirebaseInstallationServiceClient {
114
113
static final String PARSING_EXPIRATION_TIME_ERROR_MESSAGE = "Invalid Expiration Timestamp." ;
115
114
116
115
private final Context context ;
117
- private final Provider <UserAgentPublisher > userAgentPublisher ;
118
- private final Provider <HeartBeatInfo > heartbeatInfo ;
116
+ private final Provider <HeartBeatController > heartBeatProvider ;
119
117
private final RequestLimiter requestLimiter ;
120
118
121
119
public FirebaseInstallationServiceClient (
122
- @ NonNull Context context ,
123
- @ NonNull Provider <UserAgentPublisher > publisher ,
124
- @ NonNull Provider <HeartBeatInfo > heartbeatInfo ) {
120
+ @ NonNull Context context , @ NonNull Provider <HeartBeatController > heartBeatProvider ) {
125
121
this .context = context ;
126
- this .userAgentPublisher = publisher ;
127
- this .heartbeatInfo = heartbeatInfo ;
122
+ this .heartBeatProvider = heartBeatProvider ;
128
123
this .requestLimiter = new RequestLimiter ();
129
124
}
130
125
@@ -485,14 +480,16 @@ private HttpURLConnection openHttpURLConnection(URL url, String apiKey)
485
480
httpURLConnection .addRequestProperty (CONTENT_ENCODING_HEADER_KEY , GZIP_CONTENT_ENCODING );
486
481
httpURLConnection .addRequestProperty (CACHE_CONTROL_HEADER_KEY , CACHE_CONTROL_DIRECTIVE );
487
482
httpURLConnection .addRequestProperty (X_ANDROID_PACKAGE_HEADER_KEY , context .getPackageName ());
488
- if ((heartbeatInfo .get () != null ) && (userAgentPublisher .get () != null )) {
489
- HeartBeat heartbeat =
490
- heartbeatInfo .get ().getHeartBeatCode (FIREBASE_INSTALLATIONS_ID_HEARTBEAT_TAG );
491
- if (heartbeat != HeartBeat .NONE ) {
492
- httpURLConnection .addRequestProperty (
493
- USER_AGENT_HEADER , userAgentPublisher .get ().getUserAgent ());
483
+ HeartBeatController heartBeatController = heartBeatProvider .get ();
484
+ if (heartBeatController != null ) {
485
+ try {
494
486
httpURLConnection .addRequestProperty (
495
- HEART_BEAT_HEADER , Integer .toString (heartbeat .getCode ()));
487
+ HEART_BEAT_HEADER , Tasks .await (heartBeatController .getHeartBeatsHeader ()));
488
+ } catch (ExecutionException e ) {
489
+ Log .w (TAG , "Failed to get heartbeats header" , e );
490
+ } catch (InterruptedException e ) {
491
+ Thread .currentThread ().interrupt ();
492
+ Log .w (TAG , "Failed to get heartbeats header" , e );
496
493
}
497
494
}
498
495
httpURLConnection .addRequestProperty (X_ANDROID_CERT_HEADER_KEY , getFingerprintHashForPackage ());
0 commit comments