Skip to content

Commit dcca639

Browse files
committed
ensure emulator is used before using remote config
1 parent 07dfb09 commit dcca639

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

firebase-config/firebase-config.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
implementation project(':firebase-abt')
5454
implementation project(':firebase-components')
5555
implementation project(':firebase-installations-interop')
56+
testImplementation project(path: ':firebase-config')
5657
runtimeOnly project(':firebase-installations')
5758

5859
implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.android.gms.tasks.Task;
2424
import com.google.android.gms.tasks.Tasks;
2525
import com.google.firebase.FirebaseApp;
26+
import com.google.firebase.FirebaseError;
27+
import com.google.firebase.FirebaseException;
2628
import com.google.firebase.abt.AbtException;
2729
import com.google.firebase.abt.FirebaseABTesting;
2830
import com.google.firebase.emulators.EmulatedServiceSettings;
@@ -550,8 +552,14 @@ public Task<Void> reset() {
550552
*
551553
* @param host the emulator host (for example, 10.0.2.2)
552554
* @param port the emulator port (for example, 9299)
555+
*
556+
* @exception FirebaseRemoteConfigClientException Thrown when useEmulator is called after a fetch.
553557
*/
554-
public void useEmulator(@NonNull String host, int port) {
558+
public void useEmulator(@NonNull String host, int port) throws FirebaseRemoteConfigClientException {
559+
if (this.frcMetadata.getInfo().getLastFetchStatus() != LAST_FETCH_STATUS_NO_FETCH_YET) {
560+
throw new FirebaseRemoteConfigClientException(
561+
"Cannot connect to emulator after a fetch has been made.");
562+
}
555563
fetchHandler.setEmulatedServiceSettings(new EmulatedServiceSettings(host, port));
556564
}
557565

0 commit comments

Comments
 (0)