Skip to content

Commit 738043c

Browse files
committed
Merge branch 'master' of github.com:firebase/firebase-android-sdk into nullFixFis
2 parents 86044a4 + 5ea6635 commit 738043c

File tree

31 files changed

+380
-102
lines changed

31 files changed

+380
-102
lines changed

firebase-common/api.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
package com.google.firebase {
33

44
public class FirebaseApp {
5+
method public void enableEmulators(@NonNull com.google.firebase.emulators.EmulatorSettings);
56
method @NonNull public android.content.Context getApplicationContext();
67
method @NonNull public static java.util.List<com.google.firebase.FirebaseApp> getApps(@NonNull android.content.Context);
8+
method @NonNull public com.google.firebase.emulators.EmulatorSettings getEmulatorSettings();
79
method @NonNull public static com.google.firebase.FirebaseApp getInstance();
810
method @NonNull public static com.google.firebase.FirebaseApp getInstance(@NonNull String);
911
method @NonNull public String getName();
@@ -47,6 +49,30 @@ package com.google.firebase {
4749

4850
}
4951

52+
package com.google.firebase.emulators {
53+
54+
public final class EmulatedServiceSettings {
55+
ctor public EmulatedServiceSettings(@NonNull String, int);
56+
method @NonNull public String getHost();
57+
method public int getPort();
58+
}
59+
60+
public final class EmulatorSettings {
61+
field public static final com.google.firebase.emulators.EmulatorSettings DEFAULT;
62+
}
63+
64+
public static final class EmulatorSettings.Builder {
65+
ctor public EmulatorSettings.Builder();
66+
method @NonNull public com.google.firebase.emulators.EmulatorSettings.Builder addEmulatedService(@NonNull com.google.firebase.emulators.FirebaseEmulator, @NonNull com.google.firebase.emulators.EmulatedServiceSettings);
67+
method @NonNull public com.google.firebase.emulators.EmulatorSettings build();
68+
}
69+
70+
public final class FirebaseEmulator {
71+
method @NonNull public String getName();
72+
}
73+
74+
}
75+
5076
package com.google.firebase.provider {
5177

5278
public class FirebaseInitProvider extends android.content.ContentProvider {

firebase-common/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
version=19.3.1
1+
version=19.4.0
22
latestReleasedVersion=19.3.0
33
android.enableUnitTestBinaryResources=true

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ public FirebaseOptions getOptions() {
149149
/**
150150
* Returns the specified {@link EmulatorSettings} or a default.
151151
*
152-
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented
153-
*
154-
* @hide
152+
* <p>Calling this method "freezes" the emulator settings and future calls to enableEmulators on
153+
* the same FirebaseApp instance will fail.
155154
*/
156155
@NonNull
157156
public EmulatorSettings getEmulatorSettings() {
@@ -330,10 +329,7 @@ public static FirebaseApp initializeApp(
330329
* com.google.firebase.emulators.EmulatedServiceSettings} for {@link FirebaseDatabase#EMULATOR},
331330
* then calls to Cloud Firestore will communicate with the emulator rather than production.
332331
*
333-
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented
334-
*
335332
* @param emulatorSettings the emulator settings for all services.
336-
* @hide
337333
*/
338334
public void enableEmulators(@NonNull EmulatorSettings emulatorSettings) {
339335
checkNotDeleted();

firebase-common/src/main/java/com/google/firebase/emulators/EmulatedServiceSettings.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
/**
2020
* Settings to connect a single Firebase service to a local emulator.
2121
*
22-
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented
23-
*
2422
* @see EmulatorSettings
25-
* @hide
2623
*/
2724
public final class EmulatedServiceSettings {
2825

@@ -34,6 +31,7 @@ public EmulatedServiceSettings(@NonNull String host, int port) {
3431
this.port = port;
3532
}
3633

34+
@NonNull
3735
public String getHost() {
3836
return host;
3937
}

firebase-common/src/main/java/com/google/firebase/emulators/EmulatorSettings.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
* Settings that control which Firebase services should access a local emulator, rather than
2626
* production.
2727
*
28-
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented
29-
*
3028
* @see com.google.firebase.FirebaseApp#enableEmulators(EmulatorSettings)
31-
* @hide
3229
*/
3330
public final class EmulatorSettings {
3431

firebase-common/src/main/java/com/google/firebase/emulators/FirebaseEmulator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
/**
2020
* Identifier Firebase services that can be emulated using the Firebase Emulator Suite.
2121
*
22-
* <p>TODO(samstern): Un-hide this once Firestore, Database, and Functions are implemented
23-
*
2422
* @see com.google.firebase.FirebaseApp#enableEmulators(EmulatorSettings)
2523
* @see EmulatorSettings
2624
* @see EmulatedServiceSettings
27-
* @hide
2825
*/
2926
public final class FirebaseEmulator {
3027

@@ -36,14 +33,15 @@ public final class FirebaseEmulator {
3633
* @hide
3734
*/
3835
@NonNull
39-
public static FirebaseEmulator forName(String name) {
36+
public static FirebaseEmulator forName(@NonNull String name) {
4037
return new FirebaseEmulator(name);
4138
}
4239

43-
private FirebaseEmulator(String name) {
40+
private FirebaseEmulator(@NonNull String name) {
4441
this.name = name;
4542
}
4643

44+
@NonNull
4745
public String getName() {
4846
return name;
4947
}

firebase-config/ktx/src/test/kotlin/com/google/firebase/remoteconfig/ktx/RemoteConfigTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import org.robolectric.RuntimeEnvironment
3939
import org.mockito.Mockito.mock
4040
import org.mockito.Mockito.`when`
4141

42-
const val APP_ID = "APP_ID"
43-
const val API_KEY = "API_KEY"
42+
const val APP_ID = "1:14368190084:android:09cb977358c6f241"
43+
const val API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567"
4444

4545
const val EXISTING_APP = "existing"
4646

firebase-config/src/androidTest/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigIntegrationTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050

5151
@RunWith(AndroidJUnit4.class)
5252
public class FirebaseRemoteConfigIntegrationTest {
53-
private static final String API_KEY = "api_key";
53+
private static final String API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567";
5454
private static final String APP_ID = "1:14368190084:android:09cb977358c6f241";
55+
private static final String PROJECT_ID = "fake-frc-test-id";
5556

5657
@Mock private ConfigCacheClient mockFetchedCache;
5758
@Mock private ConfigCacheClient mockActivatedCache;
@@ -84,7 +85,11 @@ public void setUp() {
8485
FirebaseApp firebaseApp =
8586
FirebaseApp.initializeApp(
8687
context,
87-
new FirebaseOptions.Builder().setApiKey(API_KEY).setApplicationId(APP_ID).build());
88+
new FirebaseOptions.Builder()
89+
.setApiKey(API_KEY)
90+
.setApplicationId(APP_ID)
91+
.setProjectId(PROJECT_ID)
92+
.build());
8893

8994
// Catch all to avoid NPEs (the getters should never return null).
9095
when(mockFetchedCache.get()).thenReturn(Tasks.forResult(null));

firebase-config/src/main/java/com/google/firebase/remoteconfig/RemoteConfigConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public final class RemoteConfigConstants {
3131
/**
3232
* Keys of fields in the Fetch request body that the client sends to the Firebase Remote Config
3333
* server.
34+
*
35+
* <p>{@code INSTANCE_ID} and {@code INSTANCE_ID_TOKEN} are legacy names for the fields that used
36+
* to be populated by the IID SDK. The fields have been replaced by the installation ID and
37+
* installation auth token, respectively, which are fetched from the FIS SDK.
3438
*/
3539
@StringDef({
3640
RequestFieldKey.INSTANCE_ID,

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigFetchHttpClient.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public class ConfigFetchHttpClient {
7878
private static final String X_ANDROID_PACKAGE_HEADER = "X-Android-Package";
7979
private static final String X_ANDROID_CERT_HEADER = "X-Android-Cert";
8080
private static final String X_GOOGLE_GFE_CAN_RETRY = "X-Google-GFE-Can-Retry";
81+
private static final String INSTALLATIONS_AUTH_TOKEN_HEADER =
82+
"X-Goog-Firebase-Installations-Auth";
8183

8284
private final Context context;
8385
private final String appId;
@@ -149,9 +151,9 @@ HttpURLConnection createHttpURLConnection() throws FirebaseRemoteConfigException
149151
*
150152
* @param urlConnection a {@link HttpURLConnection} created by a call to {@link
151153
* #createHttpURLConnection}.
152-
* @param instanceId the Firebase Instance ID that identifies a Firebase App Instance.
153-
* @param instanceIdToken a valid Firebase Instance ID Token that authenticates a Firebase App
154-
* Instance.
154+
* @param installationId the Firebase installation ID that identifies a Firebase App Instance.
155+
* @param installationAuthToken a valid Firebase installation auth token that authenticates a
156+
* Firebase App Instance.
155157
* @param analyticsUserProperties a map of Google Analytics User Properties and the device's
156158
* corresponding values.
157159
* @param lastFetchETag the ETag returned by the last successful fetch call to the FRC server. The
@@ -164,20 +166,20 @@ HttpURLConnection createHttpURLConnection() throws FirebaseRemoteConfigException
164166
@Keep
165167
FetchResponse fetch(
166168
HttpURLConnection urlConnection,
167-
String instanceId,
168-
String instanceIdToken,
169+
String installationId,
170+
String installationAuthToken,
169171
Map<String, String> analyticsUserProperties,
170172
String lastFetchETag,
171173
Map<String, String> customHeaders,
172174
Date currentTime)
173175
throws FirebaseRemoteConfigException {
174-
setUpUrlConnection(urlConnection, lastFetchETag, customHeaders);
176+
setUpUrlConnection(urlConnection, lastFetchETag, installationAuthToken, customHeaders);
175177

176178
String fetchResponseETag;
177179
JSONObject fetchResponse;
178180
try {
179181
byte[] requestBody =
180-
createFetchRequestBody(instanceId, instanceIdToken, analyticsUserProperties)
182+
createFetchRequestBody(installationId, installationAuthToken, analyticsUserProperties)
181183
.toString()
182184
.getBytes("utf-8");
183185
setFetchRequestBody(urlConnection, requestBody);
@@ -212,7 +214,10 @@ FetchResponse fetch(
212214
}
213215

214216
private void setUpUrlConnection(
215-
HttpURLConnection urlConnection, String lastFetchEtag, Map<String, String> customHeaders) {
217+
HttpURLConnection urlConnection,
218+
String lastFetchEtag,
219+
String installationAuthToken,
220+
Map<String, String> customHeaders) {
216221
urlConnection.setDoOutput(true);
217222
urlConnection.setConnectTimeout((int) SECONDS.toMillis(connectTimeoutInSeconds));
218223
urlConnection.setReadTimeout((int) SECONDS.toMillis(readTimeoutInSeconds));
@@ -221,15 +226,16 @@ private void setUpUrlConnection(
221226
// change in the Fetch Response since the last fetch call.
222227
urlConnection.setRequestProperty(IF_NONE_MATCH_HEADER, lastFetchEtag);
223228

224-
setCommonRequestHeaders(urlConnection);
229+
setCommonRequestHeaders(urlConnection, installationAuthToken);
225230
setCustomRequestHeaders(urlConnection, customHeaders);
226231
}
227232

228233
private String getFetchUrl(String projectNumber, String namespace) {
229234
return String.format(FETCH_REGEX_URL, projectNumber, namespace);
230235
}
231236

232-
private void setCommonRequestHeaders(HttpURLConnection urlConnection) {
237+
private void setCommonRequestHeaders(
238+
HttpURLConnection urlConnection, String installationAuthToken) {
233239
urlConnection.setRequestProperty(API_KEY_HEADER, apiKey);
234240

235241
// Headers required for Android API Key Restrictions.
@@ -239,6 +245,9 @@ private void setCommonRequestHeaders(HttpURLConnection urlConnection) {
239245
// Header to denote request is retryable on the server.
240246
urlConnection.setRequestProperty(X_GOOGLE_GFE_CAN_RETRY, "yes");
241247

248+
// Header for FIS auth token
249+
urlConnection.setRequestProperty(INSTALLATIONS_AUTH_TOKEN_HEADER, installationAuthToken);
250+
242251
// Headers to denote that the request body is a JSONObject.
243252
urlConnection.setRequestProperty("Content-Type", "application/json");
244253
urlConnection.setRequestProperty("Accept", "application/json");
@@ -278,16 +287,19 @@ private String getFingerprintHashForPackage() {
278287
* serialized as a JSON.
279288
*/
280289
private JSONObject createFetchRequestBody(
281-
String instanceId, String instanceIdToken, Map<String, String> analyticsUserProperties)
290+
String installationId,
291+
String installationAuthToken,
292+
Map<String, String> analyticsUserProperties)
282293
throws FirebaseRemoteConfigClientException {
283294
Map<String, Object> requestBodyMap = new HashMap<>();
284295

285-
if (instanceId == null) {
286-
throw new FirebaseRemoteConfigClientException("Fetch failed: Firebase instance id is null.");
296+
if (installationId == null) {
297+
throw new FirebaseRemoteConfigClientException(
298+
"Fetch failed: Firebase installation id is null.");
287299
}
288-
requestBodyMap.put(INSTANCE_ID, instanceId);
300+
requestBodyMap.put(INSTANCE_ID, installationId);
289301

290-
requestBodyMap.put(INSTANCE_ID_TOKEN, instanceIdToken);
302+
requestBodyMap.put(INSTANCE_ID_TOKEN, installationAuthToken);
291303
requestBodyMap.put(APP_ID, appId);
292304

293305
Locale locale = context.getResources().getConfiguration().locale;

firebase-config/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
shadows = {ShadowPreconditions.class})
8585
public final class FirebaseRemoteConfigTest {
8686
private static final String APP_ID = "1:14368190084:android:09cb977358c6f241";
87-
private static final String API_KEY = "api_key";
87+
private static final String API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567";
88+
private static final String PROJECT_ID = "fake-frc-test-id";
8889

8990
private static final String FIREPERF_NAMESPACE = "fireperf";
9091

@@ -1220,6 +1221,11 @@ private static FirebaseApp initializeFirebaseApp(Context context) {
12201221
FirebaseApp.clearInstancesForTest();
12211222

12221223
return FirebaseApp.initializeApp(
1223-
context, new FirebaseOptions.Builder().setApiKey(API_KEY).setApplicationId(APP_ID).build());
1224+
context,
1225+
new FirebaseOptions.Builder()
1226+
.setApiKey(API_KEY)
1227+
.setApplicationId(APP_ID)
1228+
.setProjectId(PROJECT_ID)
1229+
.build());
12241230
}
12251231
}

firebase-config/src/test/java/com/google/firebase/remoteconfig/RemoteConfigComponentTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
@RunWith(RobolectricTestRunner.class)
5959
@Config(manifest = Config.NONE)
6060
public class RemoteConfigComponentTest {
61-
private static final String API_KEY = "api_key";
61+
private static final String API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567";
6262
private static final String APP_ID = "1:14368190084:android:09cb977358c6f241";
6363
private static final String DUMMY_API_KEY = "api_key";
64+
private static final String PROJECT_ID = "fake-frc-test-id";
6465

6566
@Mock private FirebaseApp mockFirebaseApp;
6667
@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
@@ -237,6 +238,11 @@ private static FirebaseApp initializeFirebaseApp(Context context) {
237238
FirebaseApp.clearInstancesForTest();
238239

239240
return FirebaseApp.initializeApp(
240-
context, new FirebaseOptions.Builder().setApiKey(API_KEY).setApplicationId(APP_ID).build());
241+
context,
242+
new FirebaseOptions.Builder()
243+
.setApiKey(API_KEY)
244+
.setApplicationId(APP_ID)
245+
.setProjectId(PROJECT_ID)
246+
.build());
241247
}
242248
}

0 commit comments

Comments
 (0)