-
Notifications
You must be signed in to change notification settings - Fork 625
Adding a FidListener that propagates fid changes to the clients. #2195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
ada672b
f7fb021
6c5a1eb
28e81ab
7a83a77
43ed01b
56c7b85
c276010
16cc4d1
3d5b112
0e45a10
78d2468
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.installations.internal; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
/** | ||
* Provides a call-back interface {@link FidListener} that updates on Fid changes. | ||
* | ||
* @hide | ||
*/ | ||
public interface FidListener { | ||
/** | ||
* This method gets invoked when a Fid changes. | ||
* | ||
* @param fid represents the newly generated installation id. | ||
*/ | ||
void onFidChanged(@NonNull String fid); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||||||||||||
// Copyright 2020 Google LLC | ||||||||||||||||||||
// | ||||||||||||||||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||
// you may not use this file except in compliance with the License. | ||||||||||||||||||||
// You may obtain a copy of the License at | ||||||||||||||||||||
// | ||||||||||||||||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||
// | ||||||||||||||||||||
// Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||
// See the License for the specific language governing permissions and | ||||||||||||||||||||
// limitations under the License. | ||||||||||||||||||||
|
||||||||||||||||||||
package com.google.firebase.installations.internal; | ||||||||||||||||||||
|
||||||||||||||||||||
/** | ||||||||||||||||||||
* Interface for un-registering a previously registered listener. | ||||||||||||||||||||
* | ||||||||||||||||||||
* @hide | ||||||||||||||||||||
*/ | ||||||||||||||||||||
public interface HandleFidListener { | ||||||||||||||||||||
ankitaj224 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
|
||||||||||||||||||||
/** | ||||||||||||||||||||
* Unregisters a previously registered {@link FidListener}. | ||||||||||||||||||||
* | ||||||||||||||||||||
* @hide | ||||||||||||||||||||
*/ | ||||||||||||||||||||
void unregister(FidListener fidListener); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The handle is supposed to represent a registration so it shouldn't take a listener as a parameter. For an example see Lines 17 to 25 in c7d3073
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PTAL. Thanks |
||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.installations; | ||
|
||
import androidx.annotation.NonNull; | ||
import com.google.firebase.installations.internal.FidListener; | ||
|
||
class FakeFidListener implements FidListener { | ||
private String currentFid; | ||
|
||
@Override | ||
public void onFidChanged(@NonNull String fid) { | ||
currentFid = fid; | ||
} | ||
|
||
public String getLatestFid() { | ||
return currentFid; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ public class FirebaseInstallationsTest { | |
@Mock private RandomFidGenerator mockFidGenerator; | ||
|
||
public static final String TEST_FID_1 = "cccccccccccccccccccccc"; | ||
public static final String TEST_FID_2 = "dccccccccccccccccccccd"; | ||
|
||
public static final String TEST_PROJECT_ID = "777777777777"; | ||
|
||
|
@@ -453,6 +454,40 @@ public void testReadToken_withJsonformatting() { | |
assertThat(iidStore.readToken(), equalTo("thetoken")); | ||
} | ||
|
||
@Test | ||
public void testFidListener_fidChanged_successful() throws Exception { | ||
when(mockIidStore.readIid()).thenReturn(null); | ||
when(mockIidStore.readToken()).thenReturn(null); | ||
when(mockBackend.createFirebaseInstallation( | ||
anyString(), anyString(), anyString(), anyString(), any())) | ||
.thenReturn( | ||
TEST_INSTALLATION_RESPONSE | ||
.toBuilder() | ||
.setUri("/projects/" + TEST_PROJECT_ID + "/installations/" + TEST_FID_2) | ||
.setFid(TEST_FID_2) | ||
.build()); | ||
|
||
FakeFidListener fidListener = new FakeFidListener(); | ||
// Register the FidListener | ||
firebaseInstallations.registerFidListener(fidListener); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider adding a test for removing a registration as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this test to check the removing registration code as well. PTAL. Thanks |
||
|
||
// Do the actual getId() call under test. | ||
// Confirm both that it returns the expected ID, as does reading the prefs from storage. | ||
TestOnCompleteListener<String> onCompleteListener = new TestOnCompleteListener<>(); | ||
Task<String> task = firebaseInstallations.getId(); | ||
task.addOnCompleteListener(executor, onCompleteListener); | ||
String fid = onCompleteListener.await(); | ||
assertWithMessage("getId Task failed.").that(fid).isEqualTo(TEST_FID_1); | ||
|
||
// Waiting for Task that registers FID on the FIS Servers | ||
executor.awaitTermination(500, TimeUnit.MILLISECONDS); | ||
PersistedInstallationEntry entry = persistedInstallation.readPersistedInstallationEntryValue(); | ||
assertThat(entry.getFirebaseInstallationId(), equalTo(TEST_FID_2)); | ||
|
||
// Verify FidListener receives fid changes. | ||
assertThat(fidListener.getLatestFid(), equalTo(TEST_FID_2)); | ||
} | ||
|
||
@Test | ||
public void testGetId_migrateIid_successful() throws Exception { | ||
when(mockIidStore.readIid()).thenReturn(TEST_INSTANCE_ID_1); | ||
|
Uh oh!
There was an error while loading. Please reload this page.