summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/backup/DialerBackupAgent.java
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2017-02-22 16:32:36 -0800
committerEric Erfanian <erfanian@google.com>2017-03-01 09:56:52 -0800
commitccca31529c07970e89419fb85a9e8153a5396838 (patch)
treea7034c0a01672b97728c13282a2672771cd28baa /java/com/android/dialer/backup/DialerBackupAgent.java
parente7ae4624ba6f25cb8e648db74e0d64c0113a16ba (diff)
Update dialer sources.
Test: Built package and system image. This change clobbers the old source, and is an export from an internal Google repository. The internal repository was forked form Android in March, and this change includes modifications since then, to near the v8 release. Since the fork, we've moved code from monolithic to independent modules. In addition, we've switched to Blaze/Bazel as the build sysetm. This export, however, still uses make. New dependencies have been added: - Dagger - Auto-Value - Glide - Libshortcutbadger Going forward, development will still be in Google3, and the Gerrit release will become an automated export, with the next drop happening in ~ two weeks. Android.mk includes local modifications from ToT. Abridged changelog: Bug fixes ● Not able to mute, add a call when using Phone app in multiwindow mode ● Double tap on keypad triggering multiple key and tones ● Reported spam numbers not showing as spam in the call log ● Crash when user tries to block number while Phone app is not set as default ● Crash when user picks a number from search auto-complete list Visual Voicemail (VVM) improvements ● Share Voicemail audio via standard exporting mechanisms that support file attachment (email, MMS, etc.) ● Make phone number, email and web sites in VVM transcript clickable ● Set PIN before declining VVM Terms of Service {Carrier} ● Set client type for outbound visual voicemail SMS {Carrier} New incoming call and incall UI on older devices (Android M) ● Updated Phone app icon ● New incall UI (large buttons, button labels) ● New and animated Answer/Reject gestures Accessibility ● Add custom answer/decline call buttons on answer screen for touch exploration accessibility services ● Increase size of touch target ● Add verbal feedback when a Voicemail fails to load ● Fix pressing of Phone buttons while in a phone call using Switch Access ● Fix selecting and opening contacts in talkback mode ● Split focus for ‘Learn More’ link in caller id & spam to help distinguish similar text Other ● Backup & Restore for App Preferences ● Prompt user to enable Wi-Fi calling if the call ends due to out of service and Wi-Fi is connected ● Rename “Dialpad” to “Keypad” ● Show "Private number" for restricted calls ● Delete unused items (vcard, add contact, call history) from Phone menu Change-Id: I2a7e53532a24c21bf308bf0a6d178d7ddbca4958
Diffstat (limited to 'java/com/android/dialer/backup/DialerBackupAgent.java')
-rw-r--r--java/com/android/dialer/backup/DialerBackupAgent.java276
1 files changed, 276 insertions, 0 deletions
diff --git a/java/com/android/dialer/backup/DialerBackupAgent.java b/java/com/android/dialer/backup/DialerBackupAgent.java
new file mode 100644
index 000000000..391a93f29
--- /dev/null
+++ b/java/com/android/dialer/backup/DialerBackupAgent.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2016 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.annotation.TargetApi;
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.FullBackupDataOutput;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Build.VERSION_CODES;
+import android.os.ParcelFileDescriptor;
+import android.provider.CallLog;
+import android.provider.CallLog.Calls;
+import android.provider.VoicemailContract;
+import android.provider.VoicemailContract.Voicemails;
+import android.util.Pair;
+import com.android.dialer.backup.nano.VoicemailInfo;
+import com.android.dialer.common.Assert;
+import com.android.dialer.common.ConfigProviderBindings;
+import com.android.dialer.common.LogUtil;
+import com.android.dialer.logging.Logger;
+import com.android.dialer.logging.nano.DialerImpression;
+import com.android.dialer.telecom.TelecomUtil;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+
+/**
+ * The Dialer backup agent to backup voicemails, and files under files, shared prefs and databases
+ */
+public class DialerBackupAgent extends BackupAgent {
+ // File names suffix for backup/restore.
+ private static final String VOICEMAIL_BACKUP_FILE_SUFFIX = "_voicemail_backup.proto";
+ // File name formats for backup. It looks like 000000_voicemail_backup.proto, 0000001...
+ private static final String VOICEMAIL_BACKUP_FILE_FORMAT = "%06d" + VOICEMAIL_BACKUP_FILE_SUFFIX;
+ // Order by Date entries from database. We start backup from the newest.
+ private static final String ORDER_BY_DATE = "date DESC";
+ // Voicemail Uri Column
+ public static final String VOICEMAIL_URI = "voicemail_uri";
+ // Voicemail packages to backup
+ public static final String VOICEMAIL_SOURCE_PACKAGE = "com.android.phone";
+
+ private long voicemailsBackedupSoFar = 0;
+ private long sizeOfVoicemailsBackedupSoFar = 0;
+ private boolean maxVoicemailBackupReached = false;
+
+ /**
+ * onBackup is used for Key/Value backup. Since we are using Dolly/Android Auto backup, we do not
+ * need to implement this method and Dolly should not be calling this. Instead Dolly will be
+ * calling onFullBackup.
+ */
+ @Override
+ public void onBackup(
+ ParcelFileDescriptor parcelFileDescriptor,
+ BackupDataOutput backupDataOutput,
+ ParcelFileDescriptor parcelFileDescriptor1)
+ throws IOException {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_BACKUP);
+ Assert.fail("Android Backup should not call DialerBackupAgent.onBackup");
+ }
+
+ /**
+ * onRestore is used for Key/Value restore. Since we are using Dolly/Android Auto backup/restore,
+ * we do not need to implement this method as Dolly should not be calling this method. Instead
+ * onFileRestore will be called by Dolly.
+ */
+ @Override
+ public void onRestore(
+ BackupDataInput backupDataInput, int i, ParcelFileDescriptor parcelFileDescriptor)
+ throws IOException {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_RESTORE);
+ Assert.fail("Android Backup should not call DialerBackupAgent.onRestore");
+ }
+
+ @TargetApi(VERSION_CODES.M)
+ @Override
+ public void onFullBackup(FullBackupDataOutput data) throws IOException {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_FULL_BACKUP);
+ LogUtil.i("DialerBackupAgent.onFullBackup", "performing dialer backup");
+ boolean autoBackupEnabled =
+ ConfigProviderBindings.get(this).getBoolean("enable_autobackup", true);
+ boolean vmBackupEnabled =
+ ConfigProviderBindings.get(this).getBoolean("enable_vm_backup", false);
+
+ if (autoBackupEnabled) {
+ if (!maxVoicemailBackupReached && vmBackupEnabled) {
+ voicemailsBackedupSoFar = 0;
+ sizeOfVoicemailsBackedupSoFar = 0;
+
+ LogUtil.i("DialerBackupAgent.onFullBackup", "autoBackup is enabled");
+ ContentResolver contentResolver = getContentResolver();
+ int limit = 1000;
+
+ Uri uri =
+ TelecomUtil.getCallLogUri(this)
+ .buildUpon()
+ .appendQueryParameter(Calls.LIMIT_PARAM_KEY, Integer.toString(limit))
+ .build();
+
+ LogUtil.i("DialerBackupAgent.onFullBackup", "backing up from: " + uri);
+
+ try (Cursor cursor =
+ contentResolver.query(
+ uri,
+ null,
+ String.format(
+ "(%s = ? AND deleted = 0 AND %s = ?)", Calls.TYPE, Voicemails.SOURCE_PACKAGE),
+ new String[] {
+ Integer.toString(CallLog.Calls.VOICEMAIL_TYPE), VOICEMAIL_SOURCE_PACKAGE
+ },
+ ORDER_BY_DATE,
+ null)) {
+
+ if (cursor == null) {
+ LogUtil.i("DialerBackupAgent.onFullBackup", "cursor was null");
+ return;
+ }
+
+ LogUtil.i("DialerBackupAgent.onFullBackup", "cursor count: " + cursor.getCount());
+ if (cursor.moveToFirst()) {
+ int fileNum = 0;
+ do {
+ backupRow(
+ data, cursor, String.format(Locale.US, VOICEMAIL_BACKUP_FILE_FORMAT, fileNum++));
+ } while (cursor.moveToNext() && !maxVoicemailBackupReached);
+ } else {
+ LogUtil.i("DialerBackupAgent.onFullBackup", "cursor.moveToFirst failed");
+ }
+ }
+ }
+ LogUtil.i(
+ "DialerBackupAgent.onFullBackup",
+ "vm files backed up: %d, vm size backed up:%d, "
+ + "max vm backup reached:%b, vm backup enabled:%b",
+ voicemailsBackedupSoFar,
+ sizeOfVoicemailsBackedupSoFar,
+ maxVoicemailBackupReached,
+ vmBackupEnabled);
+ super.onFullBackup(data);
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_FULL_BACKED_UP);
+ } else {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_BACKUP_DISABLED);
+ LogUtil.i("DialerBackupAgent.onFullBackup", "autoBackup is disabled");
+ }
+ }
+
+ private void backupRow(FullBackupDataOutput data, Cursor cursor, String fileName)
+ throws IOException {
+
+ VoicemailInfo cursorRowInProto =
+ DialerBackupUtils.convertVoicemailCursorRowToProto(cursor, getContentResolver());
+
+ File file = new File(getFilesDir(), fileName);
+ DialerBackupUtils.writeProtoToFile(file, cursorRowInProto);
+
+ if (sizeOfVoicemailsBackedupSoFar + file.length()
+ > DialerBackupUtils.maxVoicemailSizeToBackup) {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_MAX_VM_BACKUP_REACHED);
+ maxVoicemailBackupReached = true;
+ file.delete();
+ return;
+ }
+
+ backupFile(file, data);
+ }
+
+ // TODO: Write to FullBackupDataOutput directly (b/33849960)
+ private void backupFile(File file, FullBackupDataOutput data) throws IOException {
+ try {
+ super.fullBackupFile(file, data);
+ sizeOfVoicemailsBackedupSoFar = sizeOfVoicemailsBackedupSoFar + file.length();
+ voicemailsBackedupSoFar++;
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_VOICEMAIL_BACKED_UP);
+ LogUtil.i("DialerBackupAgent.backupFile", "file backed up:" + file.getAbsolutePath());
+ } finally {
+ file.delete();
+ }
+ }
+
+ // Being tracked in b/33839952
+ @Override
+ public void onQuotaExceeded(long backupDataBytes, long quotaBytes) {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_QUOTA_EXCEEDED);
+ LogUtil.i("DialerBackupAgent.onQuotaExceeded", "does nothing");
+ }
+
+ @TargetApi(VERSION_CODES.M)
+ @Override
+ public void onRestoreFile(
+ ParcelFileDescriptor data, long size, File destination, int type, long mode, long mtime)
+ throws IOException {
+ LogUtil.i("DialerBackupAgent.onRestoreFile", "size:" + size + " destination: " + destination);
+
+ String fileName = destination.getName();
+ LogUtil.i("DialerBackupAgent.onRestoreFile", "file name: " + fileName);
+
+ if (ConfigProviderBindings.get(this).getBoolean("enable_autobackup", true)) {
+ if (fileName.endsWith(VOICEMAIL_BACKUP_FILE_SUFFIX)
+ && ConfigProviderBindings.get(this).getBoolean("enable_vm_restore", true)) {
+ if (DialerBackupUtils.canRestoreVoicemails(getContentResolver(), this)) {
+ try {
+ super.onRestoreFile(data, size, destination, type, mode, mtime);
+ restoreVoicemail(destination);
+ destination.delete();
+ } catch (IOException e) {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_RESTORE_IO_EXCEPTION);
+ LogUtil.e(
+ "DialerBackupAgent.onRestoreFile",
+ "could not restore voicemail - IOException: ",
+ e);
+ }
+ } else {
+ LogUtil.i(
+ "DialerBackupAgent.onRestoreFile", "build does not support restoring voicemails");
+ }
+
+ } else {
+ super.onRestoreFile(data, size, destination, type, mode, mtime);
+ LogUtil.i("DialerBackupAgent.onRestoreFile", "restored: " + fileName);
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_RESTORED_FILE);
+ }
+ } else {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_RESTORE_DISABLED);
+ LogUtil.i("DialerBackupAgent.onRestoreFile", "autoBackup is disabled");
+ }
+ }
+
+ @Override
+ public void onRestoreFinished() {
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_ON_RESTORE_FINISHED);
+ LogUtil.i("DialerBackupAgent.onRestoreFinished", "do nothing");
+ }
+
+ @TargetApi(VERSION_CODES.M)
+ private void restoreVoicemail(File file) throws IOException {
+ Pair<ContentValues, byte[]> pair =
+ DialerBackupUtils.convertVoicemailProtoFileToContentValueAndAudioBytes(
+ file, getApplicationContext());
+
+ if (pair == null) {
+ LogUtil.i("DialerBackupAgent.restoreVoicemail", "not restoring VM due to duplicate");
+ Logger.get(this)
+ .logImpression(DialerImpression.Type.BACKUP_ON_RESTORE_VM_DUPLICATE_NOT_RESTORING);
+ return;
+ }
+
+ // TODO: Uniquely identify backup agent as the creator of this voicemail b/34084298
+ try (OutputStream restoreStream =
+ getContentResolver()
+ .openOutputStream(
+ getContentResolver()
+ .insert(VoicemailContract.Voicemails.CONTENT_URI, pair.first))) {
+ DialerBackupUtils.copyAudioBytesToContentUri(pair.second, restoreStream);
+ Logger.get(this).logImpression(DialerImpression.Type.BACKUP_RESTORED_VOICEMAIL);
+ }
+ }
+}