1919import android .content .Context ;
2020import android .content .pm .PackageManager .NameNotFoundException ;
2121import android .util .Log ;
22+
2223import androidx .annotation .IntDef ;
2324import androidx .annotation .NonNull ;
2425import androidx .annotation .VisibleForTesting ;
26+
2527import com .google .android .gms .common .util .AndroidUtilsLight ;
2628import com .google .android .gms .common .util .Hex ;
2729import com .google .android .gms .tasks .Tasks ;
3133import com .google .firebase .appcheck .FirebaseAppCheck ;
3234import com .google .firebase .heartbeatinfo .HeartBeatController ;
3335import com .google .firebase .inject .Provider ;
36+
3437import java .io .BufferedOutputStream ;
3538import java .io .BufferedReader ;
3639import java .io .IOException ;
4144import java .lang .annotation .RetentionPolicy ;
4245import java .net .HttpURLConnection ;
4346import java .net .URL ;
47+ import java .nio .charset .StandardCharsets ;
48+
4449import org .json .JSONException ;
4550
4651/**
@@ -57,9 +62,10 @@ public class NetworkClient {
5762 "https://firebaseappcheck.googleapis.com/v1/projects/%s/apps/%s:exchangePlayIntegrityToken?key=%s" ;
5863 private static final String PLAY_INTEGRITY_CHALLENGE_URL_TEMPLATE =
5964 "https://firebaseappcheck.googleapis.com/v1/projects/%s/apps/%s:generatePlayIntegrityChallenge?key=%s" ;
65+ private static final String RECAPTCHA_ENTERPRISE_URL_TEMPLATE =
66+ "https://firebaseappcheck.googleapis.com/v1/projects/%s/apps/%s:exchangeRecaptchaEnterpriseToken?key=%s" ;
6067 private static final String CONTENT_TYPE = "Content-Type" ;
6168 private static final String APPLICATION_JSON = "application/json" ;
62- private static final String UTF_8 = "UTF-8" ;
6369 @ VisibleForTesting static final String X_FIREBASE_CLIENT = "X-Firebase-Client" ;
6470 @ VisibleForTesting static final String X_ANDROID_PACKAGE = "X-Android-Package" ;
6571 @ VisibleForTesting static final String X_ANDROID_CERT = "X-Android-Cert" ;
@@ -71,12 +77,13 @@ public class NetworkClient {
7177 private final Provider <HeartBeatController > heartBeatControllerProvider ;
7278
7379 @ Retention (RetentionPolicy .SOURCE )
74- @ IntDef ({UNKNOWN , DEBUG , PLAY_INTEGRITY })
80+ @ IntDef ({UNKNOWN , DEBUG , PLAY_INTEGRITY , RECAPTCHA_ENTERPRISE })
7581 public @interface AttestationTokenType {}
7682
7783 public static final int UNKNOWN = 0 ;
7884 public static final int DEBUG = 2 ;
7985 public static final int PLAY_INTEGRITY = 3 ;
86+ public static final int RECAPTCHA_ENTERPRISE = 4 ;
8087
8188 public NetworkClient (@ NonNull FirebaseApp firebaseApp ) {
8289 this (
@@ -172,7 +179,7 @@ private String makeNetworkRequest(
172179 ? urlConnection .getInputStream ()
173180 : urlConnection .getErrorStream ();
174181 StringBuilder response = new StringBuilder ();
175- try (BufferedReader reader = new BufferedReader (new InputStreamReader (in , UTF_8 ))) {
182+ try (BufferedReader reader = new BufferedReader (new InputStreamReader (in , StandardCharsets . UTF_8 ))) {
176183 String line ;
177184 while ((line = reader .readLine ()) != null ) {
178185 response .append (line );
@@ -236,6 +243,8 @@ private static String getUrlTemplate(@AttestationTokenType int tokenType) {
236243 return DEBUG_EXCHANGE_URL_TEMPLATE ;
237244 case PLAY_INTEGRITY :
238245 return PLAY_INTEGRITY_EXCHANGE_URL_TEMPLATE ;
246+ case RECAPTCHA_ENTERPRISE :
247+ return RECAPTCHA_ENTERPRISE_URL_TEMPLATE ;
239248 default :
240249 throw new IllegalArgumentException ("Unknown token type." );
241250 }
0 commit comments