Merge "Add CTS test for VectorDrawable size"
diff --git a/build/module_test_config.mk b/build/module_test_config.mk
index 7c0695a..cb65061 100644
--- a/build/module_test_config.mk
+++ b/build/module_test_config.mk
@@ -18,7 +18,7 @@
 	$(call copy-file-to-target)
 # Have the module name depend on the module test config, so it gets generated
 # when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_module_test_config)
+$(my_all_targets) : $(cts_module_test_config)
 endif
 # clear var
 LOCAL_CTS_MODULE_CONFIG :=
diff --git a/build/support_package.mk b/build/support_package.mk
index 16a254e..c971609 100644
--- a/build/support_package.mk
+++ b/build/support_package.mk
@@ -33,4 +33,4 @@
   $(eval cts_support_apks += $(installed)))
 
 # Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_support_apks)
+$(my_all_targets) : $(cts_support_apks)
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/DirectBootHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/DirectBootHostTest.java
index 4983119..ed673ba 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/DirectBootHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/DirectBootHostTest.java
@@ -173,7 +173,7 @@
                     getDevice().executeShellCommand("sm set-emulate-fbe false");
                     getDevice().waitForDeviceOnline();
                 } else {
-                    getDevice().nonBlockingReboot();
+                    getDevice().rebootUntilOnline();
                 }
                 waitForBootCompleted();
             }
diff --git a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
index 531511c..f00592f 100644
--- a/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
+++ b/hostsidetests/appsecurity/test-apps/EncryptionApp/src/com/android/cts/encryptionapp/EncryptionAppTest.java
@@ -161,6 +161,14 @@
         view.click();
         mDevice.waitForIdle();
 
+        // Yes, we really want "none" if prompted again
+        view = new UiObject(new UiSelector()
+                .resourceId("com.android.settings:id/lock_none"));
+        if (view.waitForExists(TIMEOUT)) {
+            view.click();
+            mDevice.waitForIdle();
+        }
+
         // Yes, we really want to
         view = new UiObject(new UiSelector()
                 .resourceId("android:id/button1"));
diff --git a/hostsidetests/appsecurity/test-apps/ExternalStorageApp/src/com/android/cts/externalstorageapp/ExternalStorageTest.java b/hostsidetests/appsecurity/test-apps/ExternalStorageApp/src/com/android/cts/externalstorageapp/ExternalStorageTest.java
index 6030f1c..13b7bcb 100644
--- a/hostsidetests/appsecurity/test-apps/ExternalStorageApp/src/com/android/cts/externalstorageapp/ExternalStorageTest.java
+++ b/hostsidetests/appsecurity/test-apps/ExternalStorageApp/src/com/android/cts/externalstorageapp/ExternalStorageTest.java
@@ -128,8 +128,12 @@
                     getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "meow");
 
             final long id = dm.enqueue(new Request(source).setDestinationUri(Uri.fromFile(target)));
-            receiver.waitForDownloadComplete(30 * DateUtils.SECOND_IN_MILLIS, id);
-            assertSuccessfulDownload(id, target);
+            try {
+                receiver.waitForDownloadComplete(30 * DateUtils.SECOND_IN_MILLIS, id);
+                assertSuccessfulDownload(id, target);
+            } finally {
+                dm.remove(id);
+            }
         } finally {
             mContext.unregisterReceiver(receiver);
         }
diff --git a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
index c2c6d0f..d1f1036 100644
--- a/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
+++ b/hostsidetests/appsecurity/test-apps/PrivilegedUpdateApp/Android.mk
@@ -63,7 +63,7 @@
   $(eval cts_support_apks += $(installed)))
 
 # Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_support_apks)
+$(my_all_targets) : $(cts_support_apks)
 
 
 ###########################################################
@@ -94,4 +94,4 @@
   $(eval cts_support_apks += $(installed)))
 
 # Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_support_apks)
+$(my_all_targets) : $(cts_support_apks)
diff --git a/hostsidetests/jdwpsecurity/app/Android.mk b/hostsidetests/jdwpsecurity/app/Android.mk
index 6c7845c..d20e43a 100644
--- a/hostsidetests/jdwpsecurity/app/Android.mk
+++ b/hostsidetests/jdwpsecurity/app/Android.mk
@@ -28,5 +28,5 @@
 	$(copy-file-to-target)
 
 # Have the module name depend on the cts files; so the cts files get generated when you run mm/mmm/mma/mmma.
-$(my_register_name) : $(cts_library_jar)
+$(my_all_targets) : $(cts_library_jar)
 
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
index 3b50cf3..282e624 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
@@ -21,6 +21,7 @@
 import android.app.UiAutomation;
 import android.test.ActivityInstrumentationTestCase2;
 import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.accessibility.AccessibilityWindowInfo;
 
 import java.util.List;
@@ -103,8 +104,9 @@
                         .getWindows();
                 // Wait for a window state changed event with our window showing
                 for (int i = 0; i < windows.size(); i++) {
-                    if (windows.get(i).getRoot().getPackageName()
-                            .equals(getActivity().getPackageName())) {
+                    AccessibilityNodeInfo root = windows.get(i).getRoot();
+                    if ((root != null) &&
+                            root.getPackageName().equals(getActivity().getPackageName())) {
                         return (event.getEventType()
                                 == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
                     }
diff --git a/tests/tests/graphics/res/drawable/animated_state_list_with_avd.xml b/tests/tests/graphics/res/drawable/animated_state_list_with_avd.xml
new file mode 100644
index 0000000..7a2d3c2
--- /dev/null
+++ b/tests/tests/graphics/res/drawable/animated_state_list_with_avd.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * 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.
+ -->
+
+<animated-selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+            android:state_focused="true"
+            android:id="@+id/focused"
+            android:drawable="@drawable/red" />
+    <item
+            android:state_checked="false"
+            android:id="@+id/unchecked"
+            android:drawable="@drawable/black" />
+    <transition
+            android:fromId="@+id/unchecked"
+            android:toId="@+id/focused">
+        <!--empty avd -->
+        <animated-vector
+            android:drawable="@drawable/vector_drawable_grouping_1" >
+        </animated-vector>
+    </transition>
+    <transition
+            android:fromId="@+id/focused"
+            android:toId="@+id/unchecked">
+        <animated-vector
+                android:drawable="@drawable/vector_drawable_grouping_1" >
+            <target
+                    android:name="sun"
+                    android:animation="@anim/animation_grouping_1_01" />
+            <target
+                    android:name="earth"
+                    android:animation="@anim/animation_grouping_1_01" />
+        </animated-vector>
+    </transition>
+    <item
+            android:state_checked="true"
+            android:drawable="@drawable/blue" />
+    <item
+            android:state_activated="true"
+            android:drawable="@drawable/yellow" />
+</animated-selector>
\ No newline at end of file
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedStateListDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedStateListDrawableTest.java
index 8797fef..f8cd816 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedStateListDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/AnimatedStateListDrawableTest.java
@@ -250,6 +250,16 @@
         assertEquals(4, asldState.getChildCount());
     }
 
+    @Test
+    public void testParsingTransitionDefinedWithAVD() {
+        AnimatedStateListDrawable asld = (AnimatedStateListDrawable) mContext.getDrawable(
+                R.drawable.animated_state_list_with_avd);
+        DrawableContainerState asldState = (DrawableContainerState) asld.getConstantState();
+        // Ensure that everything defined in xml after the definition of a transition with AVD is
+        // parsed by checking the total drawables parsed.
+        assertEquals(6, asldState.getChildCount());
+    }
+
     public abstract class MockTransition extends MockDrawable implements Animatable, Animatable2 {
         private HashSet<AnimationCallback> mCallbacks = new HashSet<>();
 
diff --git a/tests/tests/print/src/android/print/cts/PrintJobTest.java b/tests/tests/print/src/android/print/cts/PrintJobTest.java
index 0c88e6e4..f3081fb 100644
--- a/tests/tests/print/src/android/print/cts/PrintJobTest.java
+++ b/tests/tests/print/src/android/print/cts/PrintJobTest.java
@@ -22,6 +22,7 @@
 import android.print.PrintAttributes.Resolution;
 import android.print.PrintDocumentAdapter;
 import android.print.PrintJobInfo;
+import android.print.PrintManager;
 import android.print.PrinterCapabilitiesInfo;
 import android.print.PrinterId;
 import android.print.PrinterInfo;
@@ -321,27 +322,64 @@
                     assertEquals(0, printJob.getAdvancedIntOption(VALID_STRING_KEY));
                 });
 
+        final int[] callCount = new int[1];
+
         CustomPrintOptionsActivity.setCallBack(
                 (printJob, printer) -> {
-                    PrintJobInfo.Builder printJobBuilder = new PrintJobInfo.Builder(printJob);
+                    if (callCount[0] == 0) {
+                        PrintJobInfo.Builder printJobBuilder = new PrintJobInfo.Builder(printJob);
 
-                    try {
-                        printJobBuilder.putAdvancedOption(null, STRING_VALUE);
-                        throw new RuntimeException("Should not be able to use a null key");
-                    } catch (NullPointerException e) {
-                        // expected
+                        try {
+                            printJobBuilder.putAdvancedOption(null, STRING_VALUE);
+                            throw new RuntimeException("Should not be able to use a null key");
+                        } catch (NullPointerException e) {
+                            // expected
+                        }
+
+                        // Second put overrides the first
+                        printJobBuilder.putAdvancedOption(VALID_STRING_KEY, "something");
+                        printJobBuilder.putAdvancedOption(VALID_STRING_KEY, STRING_VALUE);
+
+                        printJobBuilder.putAdvancedOption(VALID_INT_KEY, "something");
+                        printJobBuilder.putAdvancedOption(VALID_INT_KEY, INT_VALUE);
+
+                        printJobBuilder.putAdvancedOption(VALID_NULL_KEY, null);
+
+                        // Rotate the media size to force adapter to write again
+                        PrintAttributes.Builder attributeBuilder = new PrintAttributes.Builder();
+                        attributeBuilder.setMediaSize(printJob.getAttributes().getMediaSize()
+                                .asLandscape());
+                        attributeBuilder.setResolution(printJob.getAttributes().getResolution());
+                        attributeBuilder.setDuplexMode(printJob.getAttributes().getDuplexMode());
+                        attributeBuilder.setColorMode(printJob.getAttributes().getColorMode());
+                        attributeBuilder.setMinMargins(printJob.getAttributes().getMinMargins());
+
+                        printJobBuilder.setAttributes(attributeBuilder.build());
+
+                        return printJobBuilder.build();
+                    } else {
+                        // Check that options are readable
+                        assertTrue(printJob.hasAdvancedOption(VALID_STRING_KEY));
+                        assertEquals(STRING_VALUE,
+                                printJob.getAdvancedStringOption(VALID_STRING_KEY));
+
+                        assertFalse(printJob.hasAdvancedOption(INVALID_STRING_KEY));
+                        assertNull(printJob.getAdvancedStringOption(INVALID_STRING_KEY));
+
+                        assertTrue(printJob.hasAdvancedOption(VALID_INT_KEY));
+                        assertEquals(INT_VALUE, printJob.getAdvancedIntOption(VALID_INT_KEY));
+
+                        assertTrue(printJob.hasAdvancedOption(VALID_NULL_KEY));
+                        assertNull(printJob.getAdvancedStringOption(VALID_NULL_KEY));
+
+                        assertFalse(printJob.hasAdvancedOption(INVALID_INT_KEY));
+                        assertEquals(0, printJob.getAdvancedIntOption(INVALID_INT_KEY));
+
+                        assertNull(printJob.getAdvancedStringOption(VALID_INT_KEY));
+                        assertEquals(0, printJob.getAdvancedIntOption(VALID_STRING_KEY));
+
+                        return null;
                     }
-
-                    // Second put overrides the first
-                    printJobBuilder.putAdvancedOption(VALID_STRING_KEY, "something");
-                    printJobBuilder.putAdvancedOption(VALID_STRING_KEY, STRING_VALUE);
-
-                    printJobBuilder.putAdvancedOption(VALID_INT_KEY, "something");
-                    printJobBuilder.putAdvancedOption(VALID_INT_KEY, INT_VALUE);
-
-                    printJobBuilder.putAdvancedOption(VALID_NULL_KEY, null);
-
-                    return printJobBuilder.build();
                 });
 
         // Configure the print services.
@@ -354,9 +392,42 @@
         PrintDocumentAdapter adapter = createDefaultPrintDocumentAdapter(1);
 
         // Start printing.
-        print(adapter);
+        print(adapter, "advancedOption");
+
+        waitForWriteAdapterCallback(1);
+
         openPrintOptions();
         openCustomPrintOptions();
+
+        waitForWriteAdapterCallback(2);
+
+        callCount[0]++;
+
+        // The advanced option should not be readable from the activity
+        getActivity().getSystemService(PrintManager.class).getPrintJobs().stream()
+                .filter(printJob -> printJob.getInfo().getLabel().equals("advancedOption"))
+                .forEach(printJob -> {
+                    assertFalse(printJob.getInfo().hasAdvancedOption(VALID_STRING_KEY));
+                    assertEquals(null,
+                            printJob.getInfo().getAdvancedStringOption(VALID_STRING_KEY));
+
+                    assertFalse(printJob.getInfo().hasAdvancedOption(INVALID_STRING_KEY));
+                    assertNull(printJob.getInfo().getAdvancedStringOption(INVALID_STRING_KEY));
+
+                    assertFalse(printJob.getInfo().hasAdvancedOption(VALID_INT_KEY));
+                    assertEquals(0, printJob.getInfo().getAdvancedIntOption(VALID_INT_KEY));
+
+                    assertFalse(printJob.getInfo().hasAdvancedOption(VALID_NULL_KEY));
+                    assertNull(printJob.getInfo().getAdvancedStringOption(VALID_NULL_KEY));
+
+                    assertFalse(printJob.getInfo().hasAdvancedOption(INVALID_INT_KEY));
+                    assertEquals(0, printJob.getInfo().getAdvancedIntOption(INVALID_INT_KEY));
+
+                    assertNull(printJob.getInfo().getAdvancedStringOption(VALID_INT_KEY));
+                    assertEquals(0, printJob.getInfo().getAdvancedIntOption(VALID_STRING_KEY));
+                });
+
+        openCustomPrintOptions();
         clickPrintButton();
 
         // Wait for print job to be queued