Skip to content

Commit 628b221

Browse files
committed
fix fis issue
1 parent 2bfc0a5 commit 628b221

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.installations.local;
1616

17+
import android.util.Log;
1718
import androidx.annotation.NonNull;
1819
import com.google.firebase.FirebaseApp;
1920
import java.io.ByteArrayOutputStream;
@@ -33,6 +34,7 @@
3334
public class PersistedInstallation {
3435
private File dataFile;
3536
@NonNull private final FirebaseApp firebaseApp;
37+
private static final String TAG = "PersistedInstallation";
3638

3739
// Registration Status of each persisted fid entry
3840
// NOTE: never change the ordinal of the enum values because the enum values are written to
@@ -81,17 +83,41 @@ public PersistedInstallation(@NonNull FirebaseApp firebaseApp) {
8183
}
8284

8385
private File getDataFile() {
84-
8586
if (dataFile == null) {
8687
synchronized (this) {
8788
if (dataFile == null) {
8889
// Different FirebaseApp in the same Android application should have the same application
8990
// context and same dir path
9091
dataFile =
9192
new File(
92-
firebaseApp.getApplicationContext().getFilesDir(),
93+
firebaseApp.getApplicationContext().getNoBackupFilesDir(),
94+
SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json");
95+
}
96+
}
97+
} else {
98+
try {
99+
String noBackUpFilePath =
100+
firebaseApp.getApplicationContext().getNoBackupFilesDir().getCanonicalPath();
101+
if (dataFile.getCanonicalPath().startsWith(noBackUpFilePath)) {
102+
return dataFile;
103+
} else {
104+
// Move the file to the no back up directory.
105+
File dataFileNonBackup =
106+
new File(
107+
firebaseApp.getApplicationContext().getNoBackupFilesDir(),
93108
SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json");
109+
110+
if (!dataFile.renameTo(dataFileNonBackup)) {
111+
Log.e(
112+
TAG,
113+
"Unable to move the file from back up to non back up directory",
114+
new IOException("Unable to move the file from back up to non back up directory"));
115+
} else {
116+
dataFile = dataFileNonBackup;
117+
}
94118
}
119+
} catch (IOException e) {
120+
Log.e(TAG, "Error copying data file to non back up directory", e);
95121
}
96122
}
97123

0 commit comments

Comments
 (0)