Skip to content

Commit ac24fae

Browse files
authored
Enabling FIS network call timeout. (#827)
* Enabling FIS network call timeout. * Addressing Di's comments
1 parent aa73d95 commit ac24fae

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

firebase-installations/src/main/java/com/google/firebase/installations/remote/FirebaseInstallationServiceClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class FirebaseInstallationServiceClient {
5959
private static final String X_ANDROID_PACKAGE_HEADER_KEY = "X-Android-Package";
6060
private static final String X_ANDROID_CERT_HEADER_KEY = "X-Android-Cert";
6161

62+
private static final int NETWORK_TIMEOUT_MILLIS = 10000;
63+
6264
private final Context context;
6365

6466
public FirebaseInstallationServiceClient(@NonNull Context context) {
@@ -90,6 +92,8 @@ public InstallationResponse createFirebaseInstallation(
9092
apiKey));
9193

9294
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
95+
httpsURLConnection.setConnectTimeout(NETWORK_TIMEOUT_MILLIS);
96+
httpsURLConnection.setReadTimeout(NETWORK_TIMEOUT_MILLIS);
9397
httpsURLConnection.setDoOutput(true);
9498
httpsURLConnection.setRequestMethod("POST");
9599
httpsURLConnection.addRequestProperty(CONTENT_TYPE_HEADER_KEY, JSON_CONTENT_TYPE);
@@ -165,6 +169,8 @@ public void deleteFirebaseInstallation(
165169
apiKey));
166170

167171
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
172+
httpsURLConnection.setConnectTimeout(NETWORK_TIMEOUT_MILLIS);
173+
httpsURLConnection.setReadTimeout(NETWORK_TIMEOUT_MILLIS);
168174
httpsURLConnection.setDoOutput(true);
169175
httpsURLConnection.setRequestMethod("DELETE");
170176
httpsURLConnection.addRequestProperty("Authorization", "FIS_v2 " + refreshToken);
@@ -219,6 +225,8 @@ public InstallationTokenResult generateAuthToken(
219225
apiKey));
220226

221227
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
228+
httpsURLConnection.setConnectTimeout(NETWORK_TIMEOUT_MILLIS);
229+
httpsURLConnection.setReadTimeout(NETWORK_TIMEOUT_MILLIS);
222230
httpsURLConnection.setDoOutput(true);
223231
httpsURLConnection.setRequestMethod("POST");
224232
httpsURLConnection.addRequestProperty("Authorization", "FIS_v2 " + refreshToken);

0 commit comments

Comments
 (0)