summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/backup
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-08-09 15:37:50 -0700
committerEric Erfanian <erfanian@google.com>2017-08-09 15:37:50 -0700
commit9bdb503274a292741ece14215c1545d6bcb0e67f (patch)
tree36d9989aff397b3fe2f5cd61f9bcbcfb5c838dbd /java/com/android/dialer/backup
parent2d6eb93719acd833b4a0b9c1d48a222d5522a835 (diff)
Implement Dialer K/V Backup and Restore.
This CL ensures that Restore works correctly (to unblock us for ODR system image). As restore happens on the system image and the logic cannot be updated via PlayStore, this CL is time sensitive, to ensure we can get it into the ODR system drop. This CL only backups com.android.dialer.app_preferences.xml for now, but can always be changed to update more shared preference files when needed via an playstore update. Since we are using PersistentBackupAgentHelper, we don't have to worry about not being able to restore additional backed up shared preference files from the future, as PersistentBackupAgentHelper will allow us to restore all the shared preferences that were ever backed up via Key/Value. Currently I added an end to end unit test, and tested restore via "adb shell bmgr restore com.google.android.dialer", which restored the stored data sets. A follow up CL will include additional files to backup and impression logging. Bug: 64363054 Test: DialerPersistentBackupAgentTest PiperOrigin-RevId: 164524465 Change-Id: I5bd65215a42744ba4149a9359e443679306b6cc0
Diffstat (limited to 'java/com/android/dialer/backup')
-rw-r--r--java/com/android/dialer/backup/AndroidManifest.xml25
-rw-r--r--java/com/android/dialer/backup/DialerPersistentBackupAgent.java72
2 files changed, 97 insertions, 0 deletions
diff --git a/java/com/android/dialer/backup/AndroidManifest.xml b/java/com/android/dialer/backup/AndroidManifest.xml
new file mode 100644
index 000000000..84992c0ee
--- /dev/null
+++ b/java/com/android/dialer/backup/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<!--
+ ~ Copyright (C) 2017 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dialer.backup">
+
+
+ <!-- Android backup service key -->
+ <!-- https://developer.android.com/google/backup/signup.html -->
+ <meta-data
+ android:name="com.google.android.backup.api_key"
+ android:value="AEdPqrEAAAAIn3-Y3JKit1mrzfvcdbVhUiJn2ICtKfhGYLy0Bg"/>
+</manifest> \ No newline at end of file
diff --git a/java/com/android/dialer/backup/DialerPersistentBackupAgent.java b/java/com/android/dialer/backup/DialerPersistentBackupAgent.java
new file mode 100644
index 000000000..dfe4ea301
--- /dev/null
+++ b/java/com/android/dialer/backup/DialerPersistentBackupAgent.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.dialer.backup;
+
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.os.ParcelFileDescriptor;
+import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
+import android.util.ArrayMap;
+import com.android.dialer.common.Assert;
+import com.android.dialer.common.LogUtil;
+import com.google.android.libraries.backup.BackupKeyPredicate;
+import com.google.android.libraries.backup.BackupKeyPredicates;
+import com.google.android.libraries.backup.PersistentBackupAgentHelper;
+import java.io.IOException;
+import java.util.Map;
+
+/** Implementation of Key/Value Backup that powers Dialer's backup and restore. */
+public class DialerPersistentBackupAgent extends PersistentBackupAgentHelper {
+
+ private static final String DEFAULT_SHARED_PREFS_NAME = "com.google.android.dialer_preferences";
+
+ @NonNull private final String sharedPrefsName;
+
+ @VisibleForTesting(otherwise = VisibleForTesting.NONE)
+ DialerPersistentBackupAgent(@NonNull String sharedPreferenceName) {
+ this.sharedPrefsName = Assert.isNotNull(sharedPreferenceName);
+ }
+
+ public DialerPersistentBackupAgent() {
+ this(DEFAULT_SHARED_PREFS_NAME);
+ }
+
+ @Override
+ public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor stateFile)
+ throws IOException {
+ LogUtil.i("DialerPersistentBackupAgent.onRestore", "restore from version: " + appVersionCode);
+ super.onRestore(data, appVersionCode, stateFile);
+ }
+
+ @Override
+ public void onBackup(
+ ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState)
+ throws IOException {
+ LogUtil.i("DialerPersistentBackupAgent.onBackup", "onBackup being performed");
+ super.onBackup(oldState, data, newState);
+ }
+
+ @Override
+ public Map<String, BackupKeyPredicate> getBackupSpecification() {
+ LogUtil.i(
+ "DialerPersistentBackupAgent.getBackupSpecification",
+ "file being backed up: " + sharedPrefsName);
+ Map<String, BackupKeyPredicate> backupSpecification = new ArrayMap<>();
+ backupSpecification.put(sharedPrefsName, BackupKeyPredicates.alwaysTrue());
+ return backupSpecification;
+ }
+}