|
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,17 +83,41 @@ 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 = |
91 | 92 | 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(), |
93 | 108 | 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 | + } |
94 | 118 | } |
| 119 | + } catch (IOException e) { |
| 120 | + Log.e(TAG, "Error copying data file to non back up directory", e); |
95 | 121 | } |
96 | 122 | } |
97 | 123 |
|
|
0 commit comments