Skip to content

Commit d30f896

Browse files
Minor refactoring and renaming changes.
1 parent 65c3492 commit d30f896

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private synchronized boolean isEventListenersEmpty() {
8989
return this.eventListeners.isEmpty();
9090
}
9191

92-
public void setBackgroundState(boolean backgroundState) {
93-
isInBackground = backgroundState;
92+
public void setIsInBackground(boolean isInBackground) {
93+
this.isInBackground = isInBackground;
9494
}
9595

9696
private String parseAndValidateConfigUpdateMessage(String message) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public synchronized ConfigUpdateListenerRegistration addRealtimeConfigUpdateList
9191
}
9292

9393
public synchronized void setBackgroundState(boolean isInBackground) {
94-
configRealtimeHttpClient.setRealtimeBackgroundState(isInBackground);
94+
configRealtimeHttpClient.setIsInBackground(isInBackground);
9595
if (!isInBackground) {
9696
beginRealtime();
9797
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public class ConfigRealtimeHttpClient {
115115
private final Random random;
116116
private final Clock clock;
117117
private final ConfigSharedPrefsClient sharedPrefsClient;
118+
private final Object backgroundLock;
118119

119120
public ConfigRealtimeHttpClient(
120121
FirebaseApp firebaseApp,
@@ -149,6 +150,7 @@ public ConfigRealtimeHttpClient(
149150
this.sharedPrefsClient = sharedPrefsClient;
150151
this.isRealtimeDisabled = false;
151152
this.isInBackground = false;
153+
this.backgroundLock = new Object();
152154
}
153155

154156
private static String extractProjectNumberFromAppId(String gmpAppId) {
@@ -395,22 +397,20 @@ public void run() {
395397
}
396398
}
397399

398-
public void setRealtimeBackgroundState(boolean backgroundState) {
400+
public void setIsInBackground(boolean isInBackground) {
399401
// Make changes in synchronized block so only one thread sets the background state and calls
400402
// disconnect.
401-
synchronized (isInBackground) {
402-
isInBackground = backgroundState;
403+
synchronized (backgroundLock) {
404+
this.isInBackground = isInBackground;
403405

404406
// Propagate to ConfigAutoFetch as well.
405407
if (configAutoFetch != null) {
406-
configAutoFetch.setBackgroundState(backgroundState);
408+
configAutoFetch.setIsInBackground(isInBackground);
407409
}
408-
// Close the connection if the app is in the background and their is an active
410+
// Close the connection if the app is in the background and there is an active
409411
// HttpUrlConnection.
410-
if (isInBackground) {
411-
if (httpURLConnection != null) {
412-
httpURLConnection.disconnect();
413-
}
412+
if (isInBackground && httpURLConnection != null) {
413+
httpURLConnection.disconnect();
414414
}
415415
}
416416
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void onError(@NonNull FirebaseRemoteConfigException error) {
352352
listeners,
353353
mockRetryListener,
354354
scheduledExecutorService);
355-
configAutoFetch.setBackgroundState(false);
355+
configAutoFetch.setIsInBackground(false);
356356
realtimeSharedPrefsClient =
357357
new ConfigSharedPrefsClient(
358358
context.getSharedPreferences("test_file", Context.MODE_PRIVATE));
@@ -1528,7 +1528,7 @@ public void realtime_stream_listen_backgrounded_disconnects() throws Exception {
15281528
.closeRealtimeHttpConnection(any(InputStream.class), any(InputStream.class));
15291529
when(mockHttpURLConnection.getResponseCode()).thenReturn(200);
15301530
configRealtimeHttpClientSpy.beginRealtimeHttpStream();
1531-
configRealtimeHttpClientSpy.setRealtimeBackgroundState(true);
1531+
configRealtimeHttpClientSpy.setIsInBackground(true);
15321532
flushScheduledTasks();
15331533

15341534
verify(mockHttpURLConnection, times(1)).disconnect();

0 commit comments

Comments
 (0)