diff --git a/firebase-installations/CHANGELOG.md b/firebase-installations/CHANGELOG.md index ecf23d70e18..c4ab514a082 100644 --- a/firebase-installations/CHANGELOG.md +++ b/firebase-installations/CHANGELOG.md @@ -1,5 +1,5 @@ # Unreleased - +* [fixed] Mitigated FIS ID duplication issue from backup data. (#7025) # 18.0.0 * [changed] Bump internal dependencies diff --git a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java index 854637c9679..8d6da3404aa 100644 --- a/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java +++ b/firebase-installations/src/main/java/com/google/firebase/installations/local/PersistedInstallation.java @@ -14,6 +14,7 @@ package com.google.firebase.installations.local; +import android.util.Log; import androidx.annotation.NonNull; import com.google.firebase.FirebaseApp; import java.io.ByteArrayOutputStream; @@ -33,6 +34,7 @@ public class PersistedInstallation { private File dataFile; @NonNull private final FirebaseApp firebaseApp; + private static final String TAG = "PersistedInstallation"; // Registration Status of each persisted fid entry // NOTE: never change the ordinal of the enum values because the enum values are written to @@ -81,16 +83,33 @@ public PersistedInstallation(@NonNull FirebaseApp firebaseApp) { } private File getDataFile() { - if (dataFile == null) { synchronized (this) { if (dataFile == null) { // Different FirebaseApp in the same Android application should have the same application // context and same dir path dataFile = + new File( + firebaseApp.getApplicationContext().getNoBackupFilesDir(), + SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); + if (dataFile.exists()) { + return dataFile; + } + // Data associated with FID shouldn't be stored in backup directory. Hence if the FID data + // is present in the backup directory you move it to the non backup directory. + File dataFileBackup = new File( firebaseApp.getApplicationContext().getFilesDir(), SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); + if (dataFileBackup.exists()) { + if (!dataFileBackup.renameTo(dataFile)) { + Log.e( + TAG, + "Unable to move the file from back up to non back up directory", + new IOException("Unable to move the file from back up to non back up directory")); + return dataFileBackup; + } + } } } }