Snap for 7426904 from be3c102a0237e3ef8569b1485cc6572bba8b7c9b to sc-v2-release
Change-Id: Ief9cc23726d146878c8e4e7c9c45d5e2293b3ef1
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 31c2cfd..ac6ec2e 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -111,6 +111,7 @@
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.AtomicFile;
import android.util.Log;
import android.util.Pair;
import android.util.Xml;
@@ -3194,10 +3195,17 @@
@VisibleForTesting
boolean writeSimSettingsToInternalStorage(byte[] data) {
- File file = new File(getContext().getFilesDir(), BACKED_UP_SIM_SPECIFIC_SETTINGS_FILE);
- try (FileOutputStream fos = new FileOutputStream(file)) {
+ AtomicFile atomicFile = new AtomicFile(
+ new File(getContext().getFilesDir(), BACKED_UP_SIM_SPECIFIC_SETTINGS_FILE));
+ FileOutputStream fos = null;
+ try {
+ fos = atomicFile.startWrite();
fos.write(data);
+ atomicFile.finishWrite(fos);
} catch (IOException e) {
+ if (fos != null) {
+ atomicFile.failWrite(fos);
+ }
loge("Not able to create internal file with per-sim configs. Failed with error "
+ e);
return false;
@@ -3224,8 +3232,9 @@
return;
}
+ AtomicFile atomicFile = new AtomicFile(file);
PersistableBundle bundle = null;
- try (FileInputStream fis = new FileInputStream(file)) {
+ try (FileInputStream fis = atomicFile.openRead()) {
bundle = PersistableBundle.readFromStream(fis);
} catch (IOException e) {
loge("Failed to convert backed up per-sim configs to bundle. Stopping restore. "