Skip to content

Commit a5ffdd3

Browse files
committed
Reading iid store only for default firebase app
1 parent bce4059 commit a5ffdd3

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

firebase-installations/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package com.google.firebase.installations {
2626
package com.google.firebase.installations.local {
2727

2828
public class IidStore {
29-
ctor public IidStore(@NonNull FirebaseApp);
29+
ctor public IidStore();
3030
method @Nullable public String readIid();
3131
}
3232

firebase-installations/src/main/java/com/google/firebase/installations/FirebaseInstallations.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class FirebaseInstallations implements FirebaseInstallationsApi {
7474
new FirebaseInstallationServiceClient(firebaseApp.getApplicationContext()),
7575
new PersistedInstallation(firebaseApp),
7676
new Utils(DefaultClock.getInstance()),
77-
new IidStore(firebaseApp));
77+
new IidStore());
7878
}
7979

8080
FirebaseInstallations(
@@ -226,11 +226,9 @@ private final void doRegistration() {
226226
// New FID needs to be created
227227
if (persistedInstallationEntry.isNotGenerated()) {
228228

229-
// Read the existing iid for this firebase installation
230-
String fid = iidStore.readIid();
231-
if (fid == null) {
232-
fid = utils.createRandomFid();
233-
}
229+
// For a default firebase installation read the existing iid. For other custom firebase
230+
// installations create a new fid
231+
String fid = readExistingIidOrCreateFid();
234232
persistFid(fid);
235233
persistedInstallationEntry = persistedInstallation.readPersistedInstallationEntryValue();
236234
}
@@ -287,6 +285,19 @@ private final void doRegistration() {
287285
}
288286
}
289287

288+
private String readExistingIidOrCreateFid() {
289+
// Check if this firebase app is the default (first initialized) instance
290+
if (!firebaseApp.equals(FirebaseApp.getInstance())) {
291+
return utils.createRandomFid();
292+
}
293+
// For a default firebase installation, read the existing iid from shared prefs
294+
String fid = iidStore.readIid();
295+
if (fid == null) {
296+
fid = utils.createRandomFid();
297+
}
298+
return fid;
299+
}
300+
290301
private void persistFid(String fid) throws FirebaseInstallationsException {
291302
boolean firstUpdateCacheResult =
292303
persistedInstallation.insertOrUpdatePersistedInstallationEntry(

firebase-installations/src/main/java/com/google/firebase/installations/local/IidStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public class IidStore {
3939
@GuardedBy("iidPrefs")
4040
private final SharedPreferences iidPrefs;
4141

42-
public IidStore(@NonNull FirebaseApp firebaseApp) {
42+
public IidStore() {
4343
// Different FirebaseApp in the same Android application should have the same application
4444
// context and same dir path. We only read existing Iids for the default firebase application.
4545
iidPrefs =
46-
firebaseApp
46+
FirebaseApp.getInstance()
4747
.getApplicationContext()
4848
.getSharedPreferences(IID_SHARED_PREFS_NAME, Context.MODE_PRIVATE);
4949
}

0 commit comments

Comments
 (0)