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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
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,17 +83,41 @@ 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().getFilesDir(),
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

Copy link
Collaborator

Choose a reason for hiding this comment

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

The file name is the same, the only difference is the directory.

}
}
} 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);
}
}

Expand Down
Loading