From 628b221c908a9b72aa61cf9d95dba30abb79f94d Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 2 Jul 2025 14:54:31 -0400 Subject: [PATCH 1/5] fix fis issue --- .../local/PersistedInstallation.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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..d18214d76f7 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,7 +83,6 @@ public PersistedInstallation(@NonNull FirebaseApp firebaseApp) { } private File getDataFile() { - if (dataFile == null) { synchronized (this) { if (dataFile == null) { @@ -89,9 +90,34 @@ private File getDataFile() { // context and same dir path dataFile = new File( - firebaseApp.getApplicationContext().getFilesDir(), + firebaseApp.getApplicationContext().getNoBackupFilesDir(), + SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); + } + } + } else { + try { + String noBackUpFilePath = + firebaseApp.getApplicationContext().getNoBackupFilesDir().getCanonicalPath(); + if (dataFile.getCanonicalPath().startsWith(noBackUpFilePath)) { + return dataFile; + } else { + // Move the file to the no back up directory. + File dataFileNonBackup = + new File( + firebaseApp.getApplicationContext().getNoBackupFilesDir(), SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); + + if (!dataFile.renameTo(dataFileNonBackup)) { + 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")); + } else { + dataFile = dataFileNonBackup; + } } + } catch (IOException e) { + Log.e(TAG, "Error copying data file to non back up directory", e); } } From 5a6fc9bbd412e1c16fcf4376cd573ecd02e7a776 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 2 Jul 2025 15:01:06 -0400 Subject: [PATCH 2/5] update --- firebase-installations/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-installations/CHANGELOG.md b/firebase-installations/CHANGELOG.md index ecf23d70e18..120641a4c3f 100644 --- a/firebase-installations/CHANGELOG.md +++ b/firebase-installations/CHANGELOG.md @@ -1,5 +1,5 @@ # Unreleased - +* [fixed] Fix FIS ID duplication issue from backup data. (#7025) # 18.0.0 * [changed] Bump internal dependencies From 8f3a211bbfe28e5fefc19e9941a1067cba6da17b Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 2 Jul 2025 15:32:16 -0400 Subject: [PATCH 3/5] use synchronized --- .../local/PersistedInstallation.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) 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 d18214d76f7..e26492bb2db 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 @@ -95,29 +95,31 @@ private File getDataFile() { } } } else { - try { - String noBackUpFilePath = - firebaseApp.getApplicationContext().getNoBackupFilesDir().getCanonicalPath(); - if (dataFile.getCanonicalPath().startsWith(noBackUpFilePath)) { - return dataFile; - } else { - // Move the file to the no back up directory. - File dataFileNonBackup = - new File( - firebaseApp.getApplicationContext().getNoBackupFilesDir(), - SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); - - if (!dataFile.renameTo(dataFileNonBackup)) { - 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")); + synchronized (this) { + try { + String noBackUpFilePath = + firebaseApp.getApplicationContext().getNoBackupFilesDir().getCanonicalPath(); + if (dataFile.getCanonicalPath().startsWith(noBackUpFilePath)) { + return dataFile; } else { - dataFile = dataFileNonBackup; + // Move the file to the no back up directory. + File dataFileNonBackup = + new File( + firebaseApp.getApplicationContext().getNoBackupFilesDir(), + SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); + + if (!dataFile.renameTo(dataFileNonBackup)) { + 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")); + } else { + dataFile = dataFileNonBackup; + } } + } catch (IOException e) { + Log.e(TAG, "Error copying data file to non back up directory", e); } - } catch (IOException e) { - Log.e(TAG, "Error copying data file to non back up directory", e); } } From dac0a8941ad934c1d882398bd97d71b5a4f28726 Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Wed, 2 Jul 2025 15:40:18 -0400 Subject: [PATCH 4/5] Address comments --- .../local/PersistedInstallation.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) 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 e26492bb2db..1aeac992f18 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 @@ -92,33 +92,21 @@ private File getDataFile() { new File( firebaseApp.getApplicationContext().getNoBackupFilesDir(), SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); - } - } - } else { - synchronized (this) { - try { - String noBackUpFilePath = - firebaseApp.getApplicationContext().getNoBackupFilesDir().getCanonicalPath(); - if (dataFile.getCanonicalPath().startsWith(noBackUpFilePath)) { + if (dataFile.exists()) { return dataFile; - } else { - // Move the file to the no back up directory. - File dataFileNonBackup = - new File( - firebaseApp.getApplicationContext().getNoBackupFilesDir(), - SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); - - if (!dataFile.renameTo(dataFileNonBackup)) { + } + 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")); - } else { - dataFile = dataFileNonBackup; } } - } catch (IOException e) { - Log.e(TAG, "Error copying data file to non back up directory", e); } } } From 2ca1c0dd5da06fed35d413fc03cf353e971a08dd Mon Sep 17 00:00:00 2001 From: VinayGuthal Date: Thu, 3 Jul 2025 11:06:05 -0400 Subject: [PATCH 5/5] update --- firebase-installations/CHANGELOG.md | 2 +- .../firebase/installations/local/PersistedInstallation.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/firebase-installations/CHANGELOG.md b/firebase-installations/CHANGELOG.md index 120641a4c3f..c4ab514a082 100644 --- a/firebase-installations/CHANGELOG.md +++ b/firebase-installations/CHANGELOG.md @@ -1,5 +1,5 @@ # Unreleased -* [fixed] Fix FIS ID duplication issue from backup data. (#7025) +* [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 1aeac992f18..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 @@ -95,6 +95,8 @@ private File getDataFile() { 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(), @@ -105,6 +107,7 @@ private File getDataFile() { 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; } } }