Skip to content

Fix FIS ID duplication issue from backup data #7096

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firebase-installations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Unreleased

* [fixed] Mitigated FIS ID duplication issue from backup data. (#7025)

# 18.0.0
* [changed] Bump internal dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this part to reduce duplicatoin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by this? this initialization is different from the one below

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;
}
}
}
}
}
Expand Down