|
14 | 14 |
|
15 | 15 | package com.google.firebase.installations.local;
|
16 | 16 |
|
| 17 | +import android.util.Log; |
17 | 18 | import androidx.annotation.NonNull;
|
18 | 19 | import com.google.firebase.FirebaseApp;
|
19 | 20 | import java.io.ByteArrayOutputStream;
|
|
33 | 34 | public class PersistedInstallation {
|
34 | 35 | private File dataFile;
|
35 | 36 | @NonNull private final FirebaseApp firebaseApp;
|
| 37 | + private static final String TAG = "PersistedInstallation"; |
36 | 38 |
|
37 | 39 | // Registration Status of each persisted fid entry
|
38 | 40 | // 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) {
|
81 | 83 | }
|
82 | 84 |
|
83 | 85 | private File getDataFile() {
|
84 |
| - |
85 | 86 | if (dataFile == null) {
|
86 | 87 | synchronized (this) {
|
87 | 88 | if (dataFile == null) {
|
88 | 89 | // Different FirebaseApp in the same Android application should have the same application
|
89 | 90 | // context and same dir path
|
90 | 91 | dataFile =
|
| 92 | + new File( |
| 93 | + firebaseApp.getApplicationContext().getNoBackupFilesDir(), |
| 94 | + SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json"); |
| 95 | + if (dataFile.exists()) { |
| 96 | + return dataFile; |
| 97 | + } |
| 98 | + // Data associated with FID shouldn't be stored in backup directory. Hence if the FID data |
| 99 | + // is present in the backup directory you move it to the non backup directory. |
| 100 | + File dataFileBackup = |
91 | 101 | new File(
|
92 | 102 | firebaseApp.getApplicationContext().getFilesDir(),
|
93 | 103 | SETTINGS_FILE_NAME_PREFIX + "." + firebaseApp.getPersistenceKey() + ".json");
|
| 104 | + if (dataFileBackup.exists()) { |
| 105 | + if (!dataFileBackup.renameTo(dataFile)) { |
| 106 | + Log.e( |
| 107 | + TAG, |
| 108 | + "Unable to move the file from back up to non back up directory", |
| 109 | + new IOException("Unable to move the file from back up to non back up directory")); |
| 110 | + return dataFileBackup; |
| 111 | + } |
| 112 | + } |
94 | 113 | }
|
95 | 114 | }
|
96 | 115 | }
|
|
0 commit comments