Skip to content

Commit b5ce88c

Browse files
committed
ensure emulator is used before using remote config
1 parent e4ffb7b commit b5ce88c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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;
@@ -580,8 +582,14 @@ public ConfigUpdateListenerRegistration addOnConfigUpdateListener(
580582
*
581583
* @param host the emulator host (for example, 10.0.2.2)
582584
* @param port the emulator port (for example, 9299)
585+
*
586+
* @exception FirebaseRemoteConfigClientException Thrown when useEmulator is called after a fetch.
583587
*/
584-
public void useEmulator(@NonNull String host, int port) {
588+
public void useEmulator(@NonNull String host, int port) throws FirebaseRemoteConfigClientException {
589+
if (this.frcMetadata.getInfo().getLastFetchStatus() != LAST_FETCH_STATUS_NO_FETCH_YET) {
590+
throw new FirebaseRemoteConfigClientException(
591+
"Cannot connect to emulator after a fetch has been made.");
592+
}
585593
fetchHandler.setEmulatedServiceSettings(new EmulatedServiceSettings(host, port));
586594
}
587595

0 commit comments

Comments
 (0)