diff options
author | Santos Cordon <santoscordon@google.com> | 2015-10-09 12:50:27 -0700 |
---|---|---|
committer | Santos Cordon <santoscordon@google.com> | 2015-10-13 16:43:16 -0700 |
commit | 349e0f4b527d73ed575d4c33eed1e99599e5acf6 (patch) | |
tree | a133d2e148f3f985d12bd4f9c05792cfad175f8f | |
parent | a172ae826f3e53c637d239a354acd0a0dd9f40be (diff) | |
download | android_packages_providers_CallLogProvider-349e0f4b527d73ed575d4c33eed1e99599e5acf6.tar.gz android_packages_providers_CallLogProvider-349e0f4b527d73ed575d4c33eed1e99599e5acf6.tar.bz2 android_packages_providers_CallLogProvider-349e0f4b527d73ed575d4c33eed1e99599e5acf6.zip |
Add a check for full-memory-backup user awareness.
Also, update the package name of CallLogBackupAgent.
Bug: 24783945
Change-Id: Iccf88af058260bc94ac6837868c4da692427f464
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | src/com/android/calllogbackup/CallLogBackupAgent.java (renamed from src/com/android/providers/calllogbackup/CallLogBackupAgent.java) | 27 | ||||
-rw-r--r-- | src/com/android/calllogbackup/CallLogChangeReceiver.java (renamed from src/com/android/providers/calllogbackup/CallLogChangeReceiver.java) | 19 | ||||
-rw-r--r-- | tests/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java (renamed from tests/src/com/android/providers/calllogbackup/CallLogBackupAgentTest.java) | 6 | ||||
-rw-r--r-- | tests/src/com/android/calllogbackup/MockitoHelper.java (renamed from tests/src/com/android/providers/calllogbackup/MockitoHelper.java) | 2 |
7 files changed, 51 insertions, 15 deletions
@@ -11,7 +11,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) # leaving out code which is tested by other means (e.g. static libraries) that # would dilute the coverage results. These options do not affect regular # production builds. -LOCAL_EMMA_COVERAGE_FILTER := +com.android.providers.calllogbackup.* +LOCAL_EMMA_COVERAGE_FILTER := +com.android.calllogbackup.* LOCAL_PACKAGE_NAME := CallLogBackup LOCAL_CERTIFICATE := shared diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1ee54f0..2a1aadb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,5 +1,5 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.providers.calllogbackup" + package="com.android.calllogbackup" android:sharedUserId="android.uid.shared" android:sharedUserLabel="@string/sharedUserLabel"> @@ -10,7 +10,7 @@ android:usesCleartextTraffic="false"> <meta-data android:name="com.google.android.backup.api_key" - android:value="AEdPqrEAAAAISbHhhUji6KZyyjz4I8-MdBqlnoiTJoFAEUHHzA" /> + android:value="AEdPqrEAAAAIVhVYJjcc4bozis7qBfzzgREFk3nIkWGNc5VaRg" /> <receiver android:name="CallLogChangeReceiver" android:permission="android.permission.SEND_CALL_LOG_CHANGE"> diff --git a/src/com/android/providers/calllogbackup/CallLogBackupAgent.java b/src/com/android/calllogbackup/CallLogBackupAgent.java index f939d8c..a6f7c85 100644 --- a/src/com/android/providers/calllogbackup/CallLogBackupAgent.java +++ b/src/com/android/calllogbackup/CallLogBackupAgent.java @@ -14,19 +14,21 @@ * limitations under the License */ -package com.android.providers.calllogbackup; +package com.android.calllogbackup; import android.app.backup.BackupAgent; import android.app.backup.BackupDataInput; import android.app.backup.BackupDataOutput; import android.content.ComponentName; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.os.ParcelFileDescriptor; import android.os.UserHandle; import android.os.UserManager; import android.provider.CallLog; import android.provider.CallLog.Calls; +import android.provider.Settings; import android.telecom.PhoneAccountHandle; import android.util.Log; @@ -96,6 +98,8 @@ public class CallLogBackupAgent extends BackupAgent { private static final String TAG = "CallLogBackupAgent"; + private static final String USER_FULL_DATA_BACKUP_AWARE = "user_full_data_backup_aware"; + /** Current version of CallLogBackup. Used to track the backup format. */ @VisibleForTesting static final int VERSION = 1002; @@ -109,6 +113,7 @@ public class CallLogBackupAgent extends BackupAgent { static final int END_OEM_DATA_MARKER = 0x60061E; + private static final String[] CALL_LOG_PROJECTION = new String[] { CallLog.Calls._ID, CallLog.Calls.DATE, @@ -130,6 +135,13 @@ public class CallLogBackupAgent extends BackupAgent { public void onBackup(ParcelFileDescriptor oldStateDescriptor, BackupDataOutput data, ParcelFileDescriptor newStateDescriptor) throws IOException { + if (shouldPreventBackup(this)) { + if (isDebug()) { + Log.d(TAG, "Skipping onBackup"); + } + return; + } + // Get the list of the previous calls IDs which were backed up. DataInputStream dataInput = new DataInputStream( new FileInputStream(oldStateDescriptor.getFileDescriptor())); @@ -157,6 +169,13 @@ public class CallLogBackupAgent extends BackupAgent { @Override public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException { + if (shouldPreventBackup(this)) { + if (isDebug()) { + Log.d(TAG, "Skipping restore"); + } + return; + } + if (isDebug()) { Log.d(TAG, "Performing Restore"); } @@ -486,6 +505,12 @@ public class CallLogBackupAgent extends BackupAgent { } } + static boolean shouldPreventBackup(Context context) { + // Check to see that the user is full-data aware before performing calllog backup. + return Settings.Secure.getInt( + context.getContentResolver(), USER_FULL_DATA_BACKUP_AWARE, 0) == 0; + } + private static boolean isDebug() { return Log.isLoggable(TAG, Log.DEBUG); } diff --git a/src/com/android/providers/calllogbackup/CallLogChangeReceiver.java b/src/com/android/calllogbackup/CallLogChangeReceiver.java index dbd7b00..eaebe5f 100644 --- a/src/com/android/providers/calllogbackup/CallLogChangeReceiver.java +++ b/src/com/android/calllogbackup/CallLogChangeReceiver.java @@ -14,27 +14,38 @@ * limitations under the License */ -package com.android.providers.calllogbackup; +package com.android.calllogbackup; import android.app.backup.BackupManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.provider.Settings; +import android.util.Log; /** * Call Log Change Broadcast Receiver. Receives an intent when the call log provider changes * so that it triggers backup accordingly. */ public class CallLogChangeReceiver extends BroadcastReceiver { - + private static final String TAG = "CallLogChangeReceiver"; + private static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE); private static final String ACTION_CALL_LOG_CHANGE = "android.intent.action.CALL_LOG_CHANGE"; /** ${inheritDoc} */ @Override public void onReceive(Context context, Intent intent) { if (ACTION_CALL_LOG_CHANGE.equals(intent.getAction())) { - BackupManager bm = new BackupManager(context); - bm.dataChanged(); + + if (CallLogBackupAgent.shouldPreventBackup(context)) { + // User is not full-backup-data aware so we skip calllog backup until they are. + if (VDBG) { + Log.v(TAG, "Skipping call log backup due to lack of full-data check."); + } + } else { + BackupManager bm = new BackupManager(context); + bm.dataChanged(); + } } } diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 285bb46..357df4f 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -15,7 +15,7 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.android.providers.calllogbackup.tests" + package="com.android.calllogbackup.tests" android:sharedUserId="android.uid.shared"> <application> @@ -27,10 +27,10 @@ all other applications via the command: "adb shell itr". The "itr" command will find all tests declared by all applications. If you want to run just these tests on their own then use the command: - "adb shell am instrument -w com.android.providers.calllogbackup.tests/android.test.InstrumentationTestRunner" + "adb shell am instrument -w com.android.calllogbackup.tests/android.test.InstrumentationTestRunner" --> <instrumentation android:name="android.test.InstrumentationTestRunner" - android:targetPackage="com.android.providers.calllogbackup" + android:targetPackage="com.android.calllogbackup" android:label="CallLog Backup Tests"> </instrumentation> diff --git a/tests/src/com/android/providers/calllogbackup/CallLogBackupAgentTest.java b/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java index 53ad162..4564195 100644 --- a/tests/src/com/android/providers/calllogbackup/CallLogBackupAgentTest.java +++ b/tests/src/com/android/calllogbackup/CallLogBackupAgentTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.providers.calllogbackup; +package com.android.calllogbackup; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -25,8 +25,8 @@ import android.app.backup.BackupDataOutput; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; -import com.android.providers.calllogbackup.CallLogBackupAgent.Call; -import com.android.providers.calllogbackup.CallLogBackupAgent.CallLogBackupState; +import com.android.calllogbackup.CallLogBackupAgent.Call; +import com.android.calllogbackup.CallLogBackupAgent.CallLogBackupState; import org.mockito.InOrder; import org.mockito.Matchers; diff --git a/tests/src/com/android/providers/calllogbackup/MockitoHelper.java b/tests/src/com/android/calllogbackup/MockitoHelper.java index 778f142..25407d0 100644 --- a/tests/src/com/android/providers/calllogbackup/MockitoHelper.java +++ b/tests/src/com/android/calllogbackup/MockitoHelper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.providers.calllogbackup; +package com.android.calllogbackup; import android.util.Log; |