Skip to content

Commit 0db2cab

Browse files
authored
Firebase Segmentation SDK switches to depend on FIS, from depending on IID (#1400)
* Add Firebase Segmentation SDK and some skeleton code in Firebase Android SDK (#514) * Add Firebase Segmentation SDK and some skeleton code in Firebase Android SDK * Add Firebase Segmentation SDK and some skeleton code in Firebase Android SDK * Address comments #1 * Address comments #1 * Address comments #2 * [Firebase Segmentation] Add custom installation id cache layer and tests for it. (#524) * Add type arguments in StorageTaskManager (#517) * Output artifact list during local publishing. (#515) This effort replaces #494. * Implement Firebase segmentation SDK device local cache * fix functions (#523) * fix functions * update minsdk version * remove idea * Set test type to release only in CI. (#522) * Set test type to release only in CI. This fixes Android Studio issue, where it is impossible to run integration tests in debug mode. Additionally move build type configuration to FirebaseLibraryPlugin to avoid projects.all configuration in gradle. * Add comment back. * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Minor fix to error message to match the admin sdk. (#525) * Minor fix to error message to match the admin sdk. In particular, it *is* allowed to have slashes, etc in field paths. * Added clean task to smoke tests. (#527) This change allows the smoke tests to clean all build variants created by the infrastructure. * Update deps to post-androidx gms versions. (#526) * Update deps to post-androidx gms versions. Additionally configure sources.jar for SDKs. * Update functions-ktx deps * Fix versions. * unbump fiam version in fiamui-app * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Copy firebase-firestore-ktx dependencies on firestore into its own subfolder (#528) * Wrap shared pref commit in a async task. * Address comments * Bump firestore version for release (#530) Additionally fix pom filter to exclude multidex from deps. * Google format fix * Fix some deprecations (#533) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * package refactor (#534) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. (#545) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. (#573) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK changes (#673) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK 1. Clean up http client response code. 2. When updateCustomInstallationId is called, on non-retryable server errors, the SDK should clean up the local cache. Instead, for retryable errors, SDK can keep the local cache for retrying update later. * Restrict Firebase API key to Android app package name. (#690) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK 1. Clean up http client response code. 2. When updateCustomInstallationId is called, on non-retryable server errors, the SDK should clean up the local cache. Instead, for retryable errors, SDK can keep the local cache for retrying update later. * Restrict Firebase API key to Android app package name. * Arete floc (#691) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK 1. Clean up http client response code. 2. When updateCustomInstallationId is called, on non-retryable server errors, the SDK should clean up the local cache. Instead, for retryable errors, SDK can keep the local cache for retrying update later. * Restrict Firebase API key to Android app package name. * Explicitly add internet permission * Disable registrar test for FirebaseSegmentation. (#1050) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK 1. Clean up http client response code. 2. When updateCustomInstallationId is called, on non-retryable server errors, the SDK should clean up the local cache. Instead, for retryable errors, SDK can keep the local cache for retrying update later. * Restrict Firebase API key to Android app package name. * Explicitly add internet permission * Disable registrar test for FirebaseSegmentation. * Replace the custom installation id cache SharedPref implementation by file implementation. (#1056) * Implement Firebase segmentation SDK device local cache * [Firebase Segmentation] Add custom installation id cache layer and tests for it. * Add test for updating cache * Switch to use SQLiteOpenHelper * Switch to use SharedPreferences from SQLite. * Change the cache class to be singleton * Wrap shared pref commit in a async task. * Address comments * Google format fix * Replace some deprecated code. * Package refactor * nit * nit * Add the state machine of updating custom installation id in the local cache and update to Firebase Segmentation backend. CL also contains unit tests. (The http client is not implemented yet.) * minor format fix * Address comments #1 * Http client in Firebase Segmentation SDK to call backend service. * Revert unintentional change * Fix connected device test * Fix connected device test * 1. Add a few annotations to make java code Kotlin friendly 2. Some fixes for the http request format * Fix java format * Fix API version * Change the segmentation API implementation to synchronous and put the entire synchronous code block in async task. * Fix a async getResult race issue. * OkHttpClient -> HttpsUrlConnection * Use gzip for compressing content and fix ourput stream memory leak risk. * Addressed a few comments * FirebaseSegmentation SDK 1. Clean up http client response code. 2. When updateCustomInstallationId is called, on non-retryable server errors, the SDK should clean up the local cache. Instead, for retryable errors, SDK can keep the local cache for retrying update later. * Restrict Firebase API key to Android app package name. * Explicitly add internet permission * Disable registrar test for FirebaseSegmentation. * Disable test lab * Add api info for segmentation API * [FLoC] Replace the custom installation id cache SharedPref implementation by file implementation. * [FLoC] Change FLoC instrumental tests to be unit tests. (#1058) * [FLoC] Change FLoC instrumental tests to be unit tests. * Hide non-public classes. * Firebase Segmentation SDK switches to depend on FIS. * Add FIS as a runtime dependency * minor formatting
1 parent ab8a693 commit 0db2cab

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

firebase-segmentation/firebase-segmentation.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ android {
4040
dependencies {
4141
implementation project(':firebase-common')
4242
implementation project(':firebase-components')
43-
44-
implementation('com.google.firebase:firebase-iid:17.0.3') {
45-
exclude group: "com.google.firebase", module: "firebase-common"
46-
}
43+
implementation project(':firebase-installations-interop')
44+
runtimeOnly project(':firebase-installations')
4745

4846
implementation 'androidx.appcompat:appcompat:1.1.0'
4947
implementation 'androidx.multidex:multidex:2.0.1'
50-
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
48+
implementation 'com.google.android.gms:play-services-tasks:17.0.2'
5149

5250
compileOnly "com.google.auto.value:auto-value-annotations:1.6.5"
5351
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=17.1.1
1+
version=17.2.0

firebase-segmentation/src/main/java/com/google/firebase/segmentation/FirebaseSegmentation.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import com.google.android.gms.tasks.Task;
2222
import com.google.android.gms.tasks.Tasks;
2323
import com.google.firebase.FirebaseApp;
24-
import com.google.firebase.iid.FirebaseInstanceId;
25-
import com.google.firebase.iid.InstanceIdResult;
24+
import com.google.firebase.installations.FirebaseInstallationsApi;
25+
import com.google.firebase.installations.InstallationTokenResult;
2626
import com.google.firebase.segmentation.SetCustomInstallationIdException.Status;
2727
import com.google.firebase.segmentation.local.CustomInstallationIdCache;
2828
import com.google.firebase.segmentation.local.CustomInstallationIdCacheEntryValue;
@@ -38,26 +38,26 @@ public class FirebaseSegmentation {
3838
public static final String TAG = "FirebaseSegmentation";
3939

4040
private final FirebaseApp firebaseApp;
41-
private final FirebaseInstanceId firebaseInstanceId;
41+
private final FirebaseInstallationsApi firebaseInstallationsApi;
4242
private final CustomInstallationIdCache localCache;
4343
private final SegmentationServiceClient backendServiceClient;
4444
private final Executor executor;
4545

46-
FirebaseSegmentation(FirebaseApp firebaseApp) {
46+
FirebaseSegmentation(FirebaseApp firebaseApp, FirebaseInstallationsApi firebaseInstallationsApi) {
4747
this(
4848
firebaseApp,
49-
FirebaseInstanceId.getInstance(firebaseApp),
49+
firebaseInstallationsApi,
5050
new CustomInstallationIdCache(firebaseApp),
5151
new SegmentationServiceClient(firebaseApp.getApplicationContext()));
5252
}
5353

5454
FirebaseSegmentation(
5555
FirebaseApp firebaseApp,
56-
FirebaseInstanceId firebaseInstanceId,
56+
FirebaseInstallationsApi firebaseInstallationsApi,
5757
CustomInstallationIdCache localCache,
5858
SegmentationServiceClient backendServiceClient) {
5959
this.firebaseApp = firebaseApp;
60-
this.firebaseInstanceId = firebaseInstanceId;
60+
this.firebaseInstallationsApi = firebaseInstallationsApi;
6161
this.localCache = localCache;
6262
this.backendServiceClient = backendServiceClient;
6363
this.executor = Executors.newFixedThreadPool(4);
@@ -82,7 +82,7 @@ public static FirebaseSegmentation getInstance() {
8282
*/
8383
@NonNull
8484
public static FirebaseSegmentation getInstance(@NonNull FirebaseApp app) {
85-
Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp.");
85+
Preconditions.checkArgument(app != null, "Null is not a valid value " + "of FirebaseApp.");
8686
return app.get(FirebaseSegmentation.class);
8787
}
8888

@@ -125,46 +125,43 @@ private Void updateCustomInstallationId(String customInstallationId)
125125
return null;
126126
}
127127

128-
InstanceIdResult instanceIdResult;
128+
String fid;
129+
InstallationTokenResult installationTokenResult;
129130
try {
130-
instanceIdResult = Tasks.await(firebaseInstanceId.getInstanceId());
131+
fid = Tasks.await(firebaseInstallationsApi.getId());
132+
// No need to force refresh token.
133+
installationTokenResult = Tasks.await(firebaseInstallationsApi.getToken(false));
131134
} catch (ExecutionException | InterruptedException e) {
132135
throw new SetCustomInstallationIdException(
133-
Status.CLIENT_ERROR, "Failed to get Firebase instance id");
136+
Status.CLIENT_ERROR, "Failed to get Firebase installation ID and token");
134137
}
135138

136139
boolean firstUpdateCacheResult =
137140
localCache.insertOrUpdateCacheEntry(
138141
CustomInstallationIdCacheEntryValue.create(
139-
customInstallationId,
140-
instanceIdResult.getId(),
141-
CustomInstallationIdCache.CacheStatus.PENDING_UPDATE));
142+
customInstallationId, fid, CustomInstallationIdCache.CacheStatus.PENDING_UPDATE));
142143

143144
if (!firstUpdateCacheResult) {
144145
throw new SetCustomInstallationIdException(
145146
Status.CLIENT_ERROR, "Failed to update client side cache");
146147
}
147148

148149
// Start requesting backend when first cache updae is done.
149-
String iid = instanceIdResult.getId();
150-
String iidToken = instanceIdResult.getToken();
151150
Code backendRequestResult =
152151
backendServiceClient.updateCustomInstallationId(
153152
Utils.getProjectNumberFromAppId(firebaseApp.getOptions().getApplicationId()),
154153
firebaseApp.getOptions().getApiKey(),
155154
customInstallationId,
156-
iid,
157-
iidToken);
155+
fid,
156+
installationTokenResult.getToken());
158157

159158
boolean finalUpdateCacheResult;
160159
switch (backendRequestResult) {
161160
case OK:
162161
finalUpdateCacheResult =
163162
localCache.insertOrUpdateCacheEntry(
164163
CustomInstallationIdCacheEntryValue.create(
165-
customInstallationId,
166-
instanceIdResult.getId(),
167-
CustomInstallationIdCache.CacheStatus.SYNCED));
164+
customInstallationId, fid, CustomInstallationIdCache.CacheStatus.SYNCED));
168165
break;
169166
case UNAUTHORIZED:
170167
localCache.clear();
@@ -212,32 +209,33 @@ private Void updateCustomInstallationId(String customInstallationId)
212209
*/
213210
@WorkerThread
214211
private Void clearCustomInstallationId() throws SetCustomInstallationIdException {
215-
InstanceIdResult instanceIdResult;
212+
String fid;
213+
InstallationTokenResult installationTokenResult;
216214
try {
217-
instanceIdResult = Tasks.await(firebaseInstanceId.getInstanceId());
215+
fid = Tasks.await(firebaseInstallationsApi.getId());
216+
// No need to force refresh token.
217+
installationTokenResult = Tasks.await(firebaseInstallationsApi.getToken(false));
218218
} catch (ExecutionException | InterruptedException e) {
219219
throw new SetCustomInstallationIdException(
220-
Status.CLIENT_ERROR, "Failed to get Firebase instance id");
220+
Status.CLIENT_ERROR, "Failed to get Firebase installation ID and token");
221221
}
222222

223223
boolean firstUpdateCacheResult =
224224
localCache.insertOrUpdateCacheEntry(
225225
CustomInstallationIdCacheEntryValue.create(
226-
"", instanceIdResult.getId(), CustomInstallationIdCache.CacheStatus.PENDING_CLEAR));
226+
"", fid, CustomInstallationIdCache.CacheStatus.PENDING_CLEAR));
227227

228228
if (!firstUpdateCacheResult) {
229229
throw new SetCustomInstallationIdException(
230230
Status.CLIENT_ERROR, "Failed to update client side cache");
231231
}
232232

233-
String iid = instanceIdResult.getId();
234-
String iidToken = instanceIdResult.getToken();
235233
Code backendRequestResult =
236234
backendServiceClient.clearCustomInstallationId(
237235
Utils.getProjectNumberFromAppId(firebaseApp.getOptions().getApplicationId()),
238236
firebaseApp.getOptions().getApiKey(),
239-
iid,
240-
iidToken);
237+
fid,
238+
installationTokenResult.getToken());
241239

242240
boolean finalUpdateCacheResult;
243241
switch (backendRequestResult) {

firebase-segmentation/src/main/java/com/google/firebase/segmentation/FirebaseSegmentationRegistrar.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.firebase.components.Component;
2020
import com.google.firebase.components.ComponentRegistrar;
2121
import com.google.firebase.components.Dependency;
22+
import com.google.firebase.installations.FirebaseInstallationsApi;
2223
import com.google.firebase.platforminfo.LibraryVersionComponent;
2324
import java.util.Arrays;
2425
import java.util.List;
@@ -32,7 +33,11 @@ public List<Component<?>> getComponents() {
3233
return Arrays.asList(
3334
Component.builder(FirebaseSegmentation.class)
3435
.add(Dependency.required(FirebaseApp.class))
35-
.factory(c -> new FirebaseSegmentation(c.get(FirebaseApp.class)))
36+
.add(Dependency.required(FirebaseInstallationsApi.class))
37+
.factory(
38+
c ->
39+
new FirebaseSegmentation(
40+
c.get(FirebaseApp.class), c.get(FirebaseInstallationsApi.class)))
3641
.build(),
3742
LibraryVersionComponent.create("fire-segmentation", BuildConfig.VERSION_NAME));
3843
}

firebase-segmentation/src/test/java/com/google/firebase/segmentation/FirebaseSegmentationTest.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import com.google.android.gms.tasks.Tasks;
2828
import com.google.firebase.FirebaseApp;
2929
import com.google.firebase.FirebaseOptions;
30-
import com.google.firebase.iid.FirebaseInstanceId;
31-
import com.google.firebase.iid.InstanceIdResult;
30+
import com.google.firebase.installations.FirebaseInstallationsApi;
31+
import com.google.firebase.installations.InstallationTokenResult;
3232
import com.google.firebase.segmentation.local.CustomInstallationIdCache;
3333
import com.google.firebase.segmentation.local.CustomInstallationIdCacheEntryValue;
3434
import com.google.firebase.segmentation.remote.SegmentationServiceClient;
@@ -44,17 +44,19 @@
4444
import org.junit.runner.RunWith;
4545
import org.junit.runners.MethodSorters;
4646
import org.mockito.Mock;
47+
import org.mockito.Mockito;
4748
import org.mockito.MockitoAnnotations;
4849
import org.robolectric.RobolectricTestRunner;
4950

5051
@RunWith(RobolectricTestRunner.class)
5152
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
5253
public class FirebaseSegmentationTest {
5354
private static final String CUSTOM_INSTALLATION_ID = "123";
54-
private static final String FIREBASE_INSTANCE_ID = "cAAAAAAAAAA";
55+
private static final String FIREBASE_INSTALLATION_ID = "fid_is_better_than_iid";
56+
private static final String FIREBASE_INSTALLATION_ID_TOKEN = "fis_token";
5557

5658
private FirebaseApp firebaseApp;
57-
@Mock private FirebaseInstanceId firebaseInstanceId;
59+
@Mock private FirebaseInstallationsApi firebaseInstallationsApi;
5860
@Mock private SegmentationServiceClient backendClientReturnsOk;
5961
@Mock private SegmentationServiceClient backendClientReturnsError;
6062

@@ -88,20 +90,33 @@ public void setUp() {
8890
when(backendClientReturnsError.clearCustomInstallationId(
8991
anyLong(), anyString(), anyString(), anyString()))
9092
.thenReturn(SegmentationServiceClient.Code.SERVER_ERROR);
91-
when(firebaseInstanceId.getInstanceId())
93+
when(firebaseInstallationsApi.getId()).thenReturn(Tasks.forResult(FIREBASE_INSTALLATION_ID));
94+
when(firebaseInstallationsApi.getToken(Mockito.anyBoolean()))
9295
.thenReturn(
9396
Tasks.forResult(
94-
new InstanceIdResult() {
97+
new InstallationTokenResult() {
9598
@NonNull
9699
@Override
97-
public String getId() {
98-
return FIREBASE_INSTANCE_ID;
100+
public String getToken() {
101+
return FIREBASE_INSTALLATION_ID_TOKEN;
99102
}
100103

101104
@NonNull
102105
@Override
103-
public String getToken() {
104-
return "iid_token";
106+
public long getTokenExpirationTimestamp() {
107+
return 0;
108+
}
109+
110+
@NonNull
111+
@Override
112+
public long getTokenCreationTimestamp() {
113+
return 0;
114+
}
115+
116+
@NonNull
117+
@Override
118+
public Builder toBuilder() {
119+
return null;
105120
}
106121
}));
107122
when(cacheReturnsError.insertOrUpdateCacheEntry(any())).thenReturn(false);
@@ -119,7 +134,7 @@ public void cleanUp() throws Exception {
119134
public void testUpdateCustomInstallationId_CacheOk_BackendOk() throws Exception {
120135
FirebaseSegmentation firebaseSegmentation =
121136
new FirebaseSegmentation(
122-
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsOk);
137+
firebaseApp, firebaseInstallationsApi, actualCache, backendClientReturnsOk);
123138

124139
// No exception, means success.
125140
TestOnCompleteListener<Void> onCompleteListener = new TestOnCompleteListener<>();
@@ -129,7 +144,7 @@ public void testUpdateCustomInstallationId_CacheOk_BackendOk() throws Exception
129144
assertNull(onCompleteListener.await());
130145
CustomInstallationIdCacheEntryValue entryValue = actualCache.readCacheEntryValue();
131146
assertThat(entryValue.getCustomInstallationId()).isEqualTo(CUSTOM_INSTALLATION_ID);
132-
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTANCE_ID);
147+
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTALLATION_ID);
133148
assertThat(entryValue.getCacheStatus()).isEqualTo(CustomInstallationIdCache.CacheStatus.SYNCED);
134149
}
135150

@@ -138,7 +153,7 @@ public void testUpdateCustomInstallationId_CacheOk_BackendError_Retryable()
138153
throws InterruptedException {
139154
FirebaseSegmentation firebaseSegmentation =
140155
new FirebaseSegmentation(
141-
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);
156+
firebaseApp, firebaseInstallationsApi, actualCache, backendClientReturnsError);
142157

143158
// Expect exception
144159
try {
@@ -157,7 +172,7 @@ public void testUpdateCustomInstallationId_CacheOk_BackendError_Retryable()
157172

158173
CustomInstallationIdCacheEntryValue entryValue = actualCache.readCacheEntryValue();
159174
assertThat(entryValue.getCustomInstallationId()).isEqualTo(CUSTOM_INSTALLATION_ID);
160-
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTANCE_ID);
175+
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTALLATION_ID);
161176
assertThat(entryValue.getCacheStatus())
162177
.isEqualTo(CustomInstallationIdCache.CacheStatus.PENDING_UPDATE);
163178
}
@@ -170,7 +185,7 @@ public void testUpdateCustomInstallationId_CacheOk_BackendError_NotRetryable()
170185
.thenReturn(SegmentationServiceClient.Code.CONFLICT);
171186
FirebaseSegmentation firebaseSegmentation =
172187
new FirebaseSegmentation(
173-
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);
188+
firebaseApp, firebaseInstallationsApi, actualCache, backendClientReturnsError);
174189

175190
// Expect exception
176191
try {
@@ -195,7 +210,7 @@ public void testUpdateCustomInstallationId_CacheOk_BackendError_NotRetryable()
195210
public void testUpdateCustomInstallationId_CacheError_BackendOk() throws InterruptedException {
196211
FirebaseSegmentation firebaseSegmentation =
197212
new FirebaseSegmentation(
198-
firebaseApp, firebaseInstanceId, cacheReturnsError, backendClientReturnsOk);
213+
firebaseApp, firebaseInstallationsApi, cacheReturnsError, backendClientReturnsOk);
199214

200215
// Expect exception
201216
try {
@@ -218,11 +233,11 @@ public void testClearCustomInstallationId_CacheOk_BackendOk() throws Exception {
218233
actualCache.insertOrUpdateCacheEntry(
219234
CustomInstallationIdCacheEntryValue.create(
220235
CUSTOM_INSTALLATION_ID,
221-
FIREBASE_INSTANCE_ID,
236+
FIREBASE_INSTALLATION_ID,
222237
CustomInstallationIdCache.CacheStatus.SYNCED));
223238
FirebaseSegmentation firebaseSegmentation =
224239
new FirebaseSegmentation(
225-
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsOk);
240+
firebaseApp, firebaseInstallationsApi, actualCache, backendClientReturnsOk);
226241

227242
// No exception, means success.
228243
TestOnCompleteListener<Void> onCompleteListener = new TestOnCompleteListener<>();
@@ -239,11 +254,11 @@ public void testClearCustomInstallationId_CacheOk_BackendError() throws Exceptio
239254
actualCache.insertOrUpdateCacheEntry(
240255
CustomInstallationIdCacheEntryValue.create(
241256
CUSTOM_INSTALLATION_ID,
242-
FIREBASE_INSTANCE_ID,
257+
FIREBASE_INSTALLATION_ID,
243258
CustomInstallationIdCache.CacheStatus.SYNCED));
244259
FirebaseSegmentation firebaseSegmentation =
245260
new FirebaseSegmentation(
246-
firebaseApp, firebaseInstanceId, actualCache, backendClientReturnsError);
261+
firebaseApp, firebaseInstallationsApi, actualCache, backendClientReturnsError);
247262

248263
// Expect exception
249264
try {
@@ -262,7 +277,7 @@ public void testClearCustomInstallationId_CacheOk_BackendError() throws Exceptio
262277

263278
CustomInstallationIdCacheEntryValue entryValue = actualCache.readCacheEntryValue();
264279
assertThat(entryValue.getCustomInstallationId().isEmpty()).isTrue();
265-
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTANCE_ID);
280+
assertThat(entryValue.getFirebaseInstanceId()).isEqualTo(FIREBASE_INSTALLATION_ID);
266281
assertThat(entryValue.getCacheStatus())
267282
.isEqualTo(CustomInstallationIdCache.CacheStatus.PENDING_CLEAR);
268283
}
@@ -271,7 +286,7 @@ public void testClearCustomInstallationId_CacheOk_BackendError() throws Exceptio
271286
public void testClearCustomInstallationId_CacheError_BackendOk() throws InterruptedException {
272287
FirebaseSegmentation firebaseSegmentation =
273288
new FirebaseSegmentation(
274-
firebaseApp, firebaseInstanceId, cacheReturnsError, backendClientReturnsOk);
289+
firebaseApp, firebaseInstallationsApi, cacheReturnsError, backendClientReturnsOk);
275290

276291
// Expect exception
277292
try {

0 commit comments

Comments
 (0)