Merge tag 'android-6.0.1_r3' into 601r3

Android 6.0.1 release 3

* tag 'android-6.0.1_r3':
  Add a check for full-memory-backup user awareness.

Change-Id: I0a657569d55f0edd620ae86e318886bdce9d2941
diff --git a/Android.mk b/Android.mk
index b2681b2..356e001 100644
--- a/Android.mk
+++ b/Android.mk
@@ -11,7 +11,7 @@
 # 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
similarity index 95%
rename from src/com/android/providers/calllogbackup/CallLogBackupAgent.java
rename to 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 @@
 
     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 @@
 
     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 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 @@
     @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 @@
         }
     }
 
+    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
similarity index 65%
rename from src/com/android/providers/calllogbackup/CallLogChangeReceiver.java
rename to 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
similarity index 97%
rename from tests/src/com/android/providers/calllogbackup/CallLogBackupAgentTest.java
rename to 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.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
similarity index 97%
rename from tests/src/com/android/providers/calllogbackup/MockitoHelper.java
rename to 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;