@Test @Config(sdk = Build.VERSION_CODES.KITKAT ) public void fetch_localeUsesToStringBelowLollipop() throws Exception { String languageTag = "zh-Hant-TW"; String languageString = "zh_TW_#Hant"; context.getResources().getConfiguration().setLocale(Locale.forLanguageTag(languageTag)); setServerResponseTo(noChangeResponseBody, SECOND_ETAG); Map<String, String> userProperties = ImmutableMap.of("up1", "hello", "up2", "world"); fetch(FIRST_ETAG, userProperties); JSONObject requestBody = new JSONObject(fakeHttpURLConnection.getOutputStream().toString()); assertThat(requestBody.get(LANGUAGE_CODE)).isEqualTo(languageString); }
@Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); @VisibleForTesting long getConnectTimeoutInSeconds(); @VisibleForTesting long getReadTimeoutInSeconds(); }
ConfigFetchHttpClient { @Keep FetchResponse fetch( HttpURLConnection urlConnection, String installationId, String installationAuthToken, Map<String, String> analyticsUserProperties, String lastFetchETag, Map<String, String> customHeaders, Date currentTime) throws FirebaseRemoteConfigException { setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders); String fetchResponseETag; JSONObject fetchResponse; try { byte[] requestBody = createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties) .toString() .getBytes("utf-8"); setFetchRequestBody(urlConnection, requestBody); urlConnection.connect(); int responseCode = urlConnection.getResponseCode(); if (responseCode != 200) { throw new FirebaseRemoteConfigServerException( responseCode, urlConnection.getResponseMessage()); } fetchResponseETag = urlConnection.getHeaderField(ETAG_HEADER); fetchResponse = getFetchResponseBody(urlConnection); } catch (IOException | JSONException e) { throw new FirebaseRemoteConfigClientException( "The client had an error while calling the backend!", e); } finally { urlConnection.disconnect(); try { urlConnection.getInputStream().close(); } catch (IOException e) { } } if (!backendHasUpdates(fetchResponse)) { return FetchResponse.forBackendHasNoUpdates(currentTime); } ConfigContainer fetchedConfigs = extractConfigs(fetchResponse, currentTime); return FetchResponse.forBackendUpdatesFetched(fetchedConfigs, fetchResponseETag); } ConfigFetchHttpClient(
      Context context,
      String appId,
      String apiKey,
      String namespace,
      long connectTimeoutInSeconds,
      long readTimeoutInSeconds); @VisibleForTesting long getConnectTimeoutInSeconds(); @VisibleForTesting long getReadTimeoutInSeconds();  }