File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
firebase-installations/src/main/java/com/google/firebase/installations Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -146,14 +146,22 @@ private void preConditionChecks() {
146146 Preconditions .checkNotEmpty (getApplicationId ());
147147 Preconditions .checkNotEmpty (getProjectIdentifier ());
148148 Preconditions .checkNotEmpty (getApiKey ());
149+ Preconditions .checkArgument (
150+ Utils .isValidAppIdFormat (getApplicationId ()),
151+ "Please set your Application ID. A valid Firebase App ID is required to communicate "
152+ + "with Firebase server APIs: It identifies your application with Firebase."
153+ + "Please refer to https://firebase.google.com/support/privacy/init-options." );
154+ Preconditions .checkArgument (
155+ Utils .isValidApiKeyFormat (getApiKey ()),
156+ "Please set a valid API key. A Firebase API key is required to communicate with "
157+ + "Firebase server APIs: It authenticates your project with Google."
158+ + "Please refer to https://firebase.google.com/support/privacy/init-options." );
149159 }
150160
151161 /** Returns the Project Id or Project Number for the Firebase Project. */
152162 @ Nullable
153163 String getProjectIdentifier () {
154- return TextUtils .isEmpty (firebaseApp .getOptions ().getProjectId ())
155- ? firebaseApp .getOptions ().getGcmSenderId ()
156- : firebaseApp .getOptions ().getProjectId ();
164+ return firebaseApp .getOptions ().getProjectId ();
157165 }
158166
159167 /**
Original file line number Diff line number Diff line change 1515package com .google .firebase .installations ;
1616
1717import android .text .TextUtils ;
18+ import androidx .annotation .Nullable ;
1819import com .google .firebase .installations .local .PersistedInstallationEntry ;
1920import java .util .concurrent .TimeUnit ;
21+ import java .util .regex .Pattern ;
2022
2123/** Util methods used for {@link FirebaseInstallations} */
2224class Utils {
2325 public static final long AUTH_TOKEN_EXPIRATION_BUFFER_IN_SECS = TimeUnit .HOURS .toSeconds (1 );
26+ private static final String APP_ID_IDENTIFICATION_SUBSTRING = ":" ;
27+ private static final Pattern API_KEY_FORMAT = Pattern .compile ("\\ AA[\\ w-]{38}\\ z" );
2428
2529 /**
2630 * Checks if the FIS Auth token is expired or going to expire in next 1 hour {@link
@@ -41,4 +45,12 @@ public boolean isAuthTokenExpired(PersistedInstallationEntry entry) {
4145 public long currentTimeInSecs () {
4246 return TimeUnit .MILLISECONDS .toSeconds (System .currentTimeMillis ());
4347 }
48+
49+ static boolean isValidAppIdFormat (@ Nullable String appId ) {
50+ return appId .contains (APP_ID_IDENTIFICATION_SUBSTRING );
51+ }
52+
53+ static boolean isValidApiKeyFormat (@ Nullable String apiKey ) {
54+ return API_KEY_FORMAT .matcher (apiKey ).matches ();
55+ }
4456}
You can’t perform that action at this time.
0 commit comments