Skip to content

Commit a6a4a19

Browse files
committed
Wrap updated params in a ConfigUpdate object.
1 parent eb9c9fa commit a6a4a19

File tree

8 files changed

+57
-21
lines changed

8 files changed

+57
-21
lines changed

firebase-config/api.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// Signature format: 2.0
22
package com.google.firebase.remoteconfig {
33

4+
@com.google.auto.value.AutoValue public abstract class ConfigUpdate {
5+
ctor public ConfigUpdate();
6+
method @NonNull public static com.google.firebase.remoteconfig.ConfigUpdate create(@NonNull java.util.Set<java.lang.String>);
7+
}
8+
49
public interface ConfigUpdateListener {
510
method public void onError(@NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException);
6-
method public void onUpdate(@NonNull java.util.Set<java.lang.String>);
11+
method public void onUpdate(@NonNull com.google.firebase.remoteconfig.ConfigUpdate);
712
}
813

914
public interface ConfigUpdateListenerRegistration {

firebase-config/firebase-config.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ dependencies {
5858
implementation 'com.google.firebase:firebase-measurement-connector:18.0.0'
5959
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
6060

61+
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.6'
6162
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
6263

64+
annotationProcessor 'com.google.auto.value:auto-value:1.6.6'
65+
6366
javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'
6467

6568
testImplementation 'org.mockito:mockito-core:2.25.0'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.google.firebase.remoteconfig;
2+
3+
import androidx.annotation.NonNull;
4+
import com.google.auto.value.AutoValue;
5+
import java.util.Set;
6+
7+
/**
8+
* Information about the updated config passed to the {@code onUpdate} callback of {@link
9+
* ConfigUpdateListener}.
10+
*/
11+
@AutoValue
12+
public abstract class ConfigUpdate {
13+
@NonNull
14+
public static ConfigUpdate create(@NonNull Set<String> updatedParams) {
15+
return new AutoValue_ConfigUpdate(updatedParams);
16+
}
17+
18+
/**
19+
* Parameter keys whose values have been updated from the currently activated values. Includes
20+
* keys that are added, deleted, and whose value, value source, or metadata has changed.
21+
*/
22+
@NonNull
23+
abstract Set<String> getUpdatedParams();
24+
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package com.google.firebase.remoteconfig;
1616

1717
import androidx.annotation.NonNull;
18-
19-
import java.util.Set;
2018
import javax.annotation.Nonnull;
2119

2220
/**
@@ -29,11 +27,10 @@ public interface ConfigUpdateListener {
2927
* Callback for when a new config has been automatically fetched from the backend and has changed
3028
* from the activated config.
3129
*
32-
* @param updatedParams The set of parameter keys changed from the currently activated values.
33-
* Includes keys that are: added; deleted; and whose value, value source, or metadata has
34-
* changed.
30+
* @param configUpdate A {@link ConfigUpdate} with information about the updated config, including
31+
* the set of updated parameters.
3532
*/
36-
void onUpdate(@NonNull Set<String> updatedParams);
33+
void onUpdate(@NonNull ConfigUpdate configUpdate);
3734

3835
/**
3936
* Callback for when an error occurs while listening for or fetching a config update.

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import androidx.annotation.VisibleForTesting;
2222
import com.google.android.gms.tasks.Task;
2323
import com.google.android.gms.tasks.Tasks;
24+
import com.google.firebase.remoteconfig.ConfigUpdate;
2425
import com.google.firebase.remoteconfig.ConfigUpdateListener;
2526
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
2627
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
@@ -77,9 +78,9 @@ private synchronized void propagateErrors(FirebaseRemoteConfigException exceptio
7778
}
7879
}
7980

80-
private synchronized void executeAllListenerCallbacks(Set<String> updatedParams) {
81+
private synchronized void executeAllListenerCallbacks(ConfigUpdate configUpdate) {
8182
for (ConfigUpdateListener listener : eventListeners) {
82-
listener.onUpdate(updatedParams);
83+
listener.onUpdate(configUpdate);
8384
}
8485
}
8586

@@ -116,7 +117,7 @@ public void listenForNotifications() {
116117
}
117118

118119
// TODO: Factor ConfigUpdateListener out of internal retry logic.
119-
retryCallback.onUpdate(new HashSet<>());
120+
retryCallback.onUpdate(ConfigUpdate.create(new HashSet<>()));
120121
executorService.shutdownNow();
121122
try {
122123
executorService.awaitTermination(3L, TimeUnit.SECONDS);
@@ -252,7 +253,8 @@ public synchronized Task<Void> fetchLatestConfig(int remainingAttempts, long tar
252253
return Tasks.forResult(null);
253254
}
254255

255-
executeAllListenerCallbacks(updatedParams);
256+
ConfigUpdate configUpdate = ConfigUpdate.create(updatedParams);
257+
executeAllListenerCallbacks(configUpdate);
256258
return Tasks.forResult(null);
257259
});
258260
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import androidx.annotation.NonNull;
2020
import com.google.firebase.FirebaseApp;
2121
import com.google.firebase.installations.FirebaseInstallationsApi;
22+
import com.google.firebase.remoteconfig.ConfigUpdate;
2223
import com.google.firebase.remoteconfig.ConfigUpdateListener;
2324
import com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration;
2425
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
@@ -162,7 +163,7 @@ public void remove() {
162163
public static class EmptyConfigUpdateListener implements ConfigUpdateListener {
163164

164165
@Override
165-
public void onUpdate(Set<String> updatedParams) {}
166+
public void onUpdate(ConfigUpdate configUpdate) {}
166167

167168
@Override
168169
public void onError(@NonNull FirebaseRemoteConfigException error) {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.firebase.FirebaseApp;
3333
import com.google.firebase.installations.FirebaseInstallationsApi;
3434
import com.google.firebase.installations.InstallationTokenResult;
35+
import com.google.firebase.remoteconfig.ConfigUpdate;
3536
import com.google.firebase.remoteconfig.ConfigUpdateListener;
3637
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
3738
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
@@ -292,7 +293,7 @@ public synchronized ConfigAutoFetch startAutoFetch(HttpURLConnection httpURLConn
292293
ConfigUpdateListener retryCallback =
293294
new ConfigUpdateListener() {
294295
@Override
295-
public void onUpdate(Set<String> updatedParams) {
296+
public void onUpdate(ConfigUpdate configUpdate) {
296297
closeRealtimeHttpStream();
297298
retryHTTPConnection();
298299
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static com.google.firebase.remoteconfig.internal.Personalization.EXTERNAL_PERSONALIZATION_ID_PARAM;
2929
import static com.google.firebase.remoteconfig.testutil.Assert.assertTrue;
3030
import static org.mockito.ArgumentMatchers.anyString;
31+
import static org.mockito.ArgumentMatchers.argThat;
3132
import static org.mockito.ArgumentMatchers.eq;
3233
import static org.mockito.Matchers.any;
3334
import static org.mockito.Mockito.doAnswer;
@@ -304,8 +305,8 @@ public void setUp() throws Exception {
304305
ConfigUpdateListener listener =
305306
new ConfigUpdateListener() {
306307
@Override
307-
public void onUpdate(Set<String> changedParams) {
308-
mockOnUpdateListener.onUpdate(changedParams);
308+
public void onUpdate(ConfigUpdate configUpdate) {
309+
mockOnUpdateListener.onUpdate(configUpdate);
309310
}
310311

311312
@Override
@@ -332,7 +333,7 @@ public void onError(@NonNull FirebaseRemoteConfigException error) {
332333
mockActivatedCache,
333334
listeners,
334335
mockRetryListener,
335-
scheduledExecutorService);
336+
scheduledExecutorService);
336337
configRealtimeHttpClient =
337338
new ConfigRealtimeHttpClient(
338339
firebaseApp,
@@ -342,7 +343,7 @@ public void onError(@NonNull FirebaseRemoteConfigException error) {
342343
context,
343344
"firebase",
344345
listeners,
345-
scheduledExecutorService);
346+
scheduledExecutorService);
346347
}
347348

348349
@Test
@@ -1189,7 +1190,7 @@ public void realtime_stream_listen_and_retry_success() throws Exception {
11891190
when(mockFetchHandler.fetch(0)).thenReturn(Tasks.forResult(realtimeFetchedContainerResponse));
11901191
configAutoFetch.listenForNotifications();
11911192

1192-
verify(mockRetryListener).onUpdate(new HashSet<>());
1193+
verify(mockRetryListener).onUpdate(any());
11931194
}
11941195

11951196
@Test
@@ -1318,7 +1319,8 @@ public void realtime_stream_autofetch_success() throws Exception {
13181319
flushScheduledTasks();
13191320

13201321
Set<String> updatedParams = Sets.newHashSet("realtime_param");
1321-
verify(mockOnUpdateListener).onUpdate(updatedParams);
1322+
verify(mockOnUpdateListener)
1323+
.onUpdate(argThat(configUpdate -> configUpdate.getUpdatedParams().equals(updatedParams)));
13221324
}
13231325

13241326
@Test
@@ -1333,7 +1335,8 @@ public void realtime_autofetchBeforeActivate_callsOnUpdateWithAllFetchedParams()
13331335
flushScheduledTasks();
13341336

13351337
Set<String> updatedParams = Sets.newHashSet("string_param", "long_param", "realtime_param");
1336-
verify(mockOnUpdateListener).onUpdate(updatedParams);
1338+
verify(mockOnUpdateListener)
1339+
.onUpdate(argThat(configUpdate -> configUpdate.getUpdatedParams().equals(updatedParams)));
13371340
}
13381341

13391342
@Test
@@ -1441,7 +1444,7 @@ private void flushScheduledTasks() throws InterruptedException {
14411444
private ConfigUpdateListener generateEmptyRealtimeListener() {
14421445
return new ConfigUpdateListener() {
14431446
@Override
1444-
public void onUpdate(Set<String> updatedParams) {}
1447+
public void onUpdate(ConfigUpdate configUpdate) {}
14451448

14461449
@Override
14471450
public void onError(@NonNull FirebaseRemoteConfigException error) {}

0 commit comments

Comments
 (0)