Merge "Add CtsVerifier tests for settings lockdowns" into mnc-dev
diff --git a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/ExternalStorageHostTest.java b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/ExternalStorageHostTest.java
index d74ec52..cb67c63 100644
--- a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/ExternalStorageHostTest.java
+++ b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/ExternalStorageHostTest.java
@@ -215,6 +215,10 @@
             // Verify they both have isolated view of storage
             runDeviceTests(MULTIUSER_PKG, MULTIUSER_CLASS, "testReadIsolatedStorage", owner);
             runDeviceTests(MULTIUSER_PKG, MULTIUSER_CLASS, "testReadIsolatedStorage", secondary);
+
+            // Verify they can't poke at each other
+            runDeviceTests(MULTIUSER_PKG, MULTIUSER_CLASS, "testUserIsolation", owner);
+            runDeviceTests(MULTIUSER_PKG, MULTIUSER_CLASS, "testUserIsolation", secondary);
         } finally {
             getDevice().uninstallPackage(MULTIUSER_PKG);
             removeUsersForTest(users);
diff --git a/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/src/com/android/cts/multiuserstorageapp/MultiUserStorageTest.java b/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/src/com/android/cts/multiuserstorageapp/MultiUserStorageTest.java
index ed84a66..d9f00d2 100644
--- a/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/src/com/android/cts/multiuserstorageapp/MultiUserStorageTest.java
+++ b/hostsidetests/appsecurity/test-apps/MultiUserStorageApp/src/com/android/cts/multiuserstorageapp/MultiUserStorageTest.java
@@ -16,6 +16,7 @@
 
 package com.android.cts.multiuserstorageapp;
 
+import static com.android.cts.externalstorageapp.CommonExternalStorageTest.assertDirNoAccess;
 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.getAllPackageSpecificPathsExceptObb;
 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.readInt;
 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.writeInt;
@@ -119,6 +120,24 @@
                 readInt(buildRawObbPath(FILE_OBB_SINGLETON)));
     }
 
+    /**
+     * Verify that we can't poke at storage of other users.
+     */
+    public void testUserIsolation() throws Exception {
+        final File myPath = Environment.getExternalStorageDirectory();
+        final int myId = android.os.Process.myUid() / 100000;
+        assertEquals(String.valueOf(myId), myPath.getName());
+
+        Log.d(TAG, "My path is " + myPath);
+        final File basePath = myPath.getParentFile();
+        for (int i = 0; i < 128; i++) {
+            if (i == myId) continue;
+
+            final File otherPath = new File(basePath, String.valueOf(i));
+            assertDirNoAccess(otherPath);
+        }
+    }
+
     private File buildApiObbPath(String file) {
         return new File(getContext().getObbDir(), file);
     }
diff --git a/tests/tests/assist/AndroidManifest.xml b/tests/tests/assist/AndroidManifest.xml
index c5772ad..b6cd684 100644
--- a/tests/tests/assist/AndroidManifest.xml
+++ b/tests/tests/assist/AndroidManifest.xml
@@ -28,6 +28,7 @@
           <intent-filter>
               <action android:name="android.intent.action.TEST_START_ACTIVITY_ASSIST_STRUCTURE" />
               <action android:name="android.intent.action.TEST_START_ACTIVITY_DISABLE_CONTEXT" />
+              <action android:name="android.intent.action.TEST_START_ACTIVITY_FLAG_SECURE" />
               <category android:name="android.intent.category.LAUNCHER" />
               <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
diff --git a/tests/tests/assist/common/src/android/assist/common/Utils.java b/tests/tests/assist/common/src/android/assist/common/Utils.java
index 1831182..bf051c0 100644
--- a/tests/tests/assist/common/src/android/assist/common/Utils.java
+++ b/tests/tests/assist/common/src/android/assist/common/Utils.java
@@ -15,18 +15,11 @@
  */
 package android.assist.common;
 
-import android.app.VoiceInteractor;
-import android.app.VoiceInteractor.PickOptionRequest.Option;
-import android.content.BroadcastReceiver;
+import android.R;
 import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
 import android.os.Bundle;
-import android.util.Log;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.concurrent.CountDownLatch;
 
 public class Utils {
     public static final String TESTCASE_TYPE = "testcase_type";
@@ -42,8 +35,10 @@
 
     public static final int TIMEOUT_MS = 2 * 1000; // TODO(awlee): what is the timeout
 
+    /** Test name suffixes */
     public static final String ASSIST_STRUCTURE = "ASSIST_STRUCTURE";
     public static final String DISABLE_CONTEXT = "DISABLE_CONTEXT";
+    public static final String FLAG_SECURE = "FLAG_SECURE";
 
     /**
      * The shim activity that starts the service associated with each test.
@@ -51,6 +46,7 @@
     public static final String getTestActivity(String testCaseType) {
         switch (testCaseType) {
             case ASSIST_STRUCTURE:
+            case FLAG_SECURE:
                 return "service.AssistStructureActivity";
             case DISABLE_CONTEXT:
                 return "service.DisableContextActivity";
@@ -65,8 +61,12 @@
     public static final ComponentName getTestAppComponent(String testCaseType) {
         switch (testCaseType) {
             case ASSIST_STRUCTURE:
+            case DISABLE_CONTEXT:
                 return new ComponentName(
                         "android.assist.testapp", "android.assist.testapp.TestApp");
+            case FLAG_SECURE:
+                return new ComponentName(
+                        "android.assist.testapp", "android.assist.testapp.SecureActivity");
             default:
                 return new ComponentName("","");
         }
@@ -90,19 +90,6 @@
         return buf.toString();
     }
 
-    public static final String toOptionsString(Option[] options) {
-        StringBuilder sb = new StringBuilder();
-        sb.append("{");
-        for (int i = 0; i < options.length; i++) {
-            if (i >= 1) {
-                sb.append(", ");
-            }
-            sb.append(options[i].getLabel());
-        }
-        sb.append("}");
-        return sb.toString();
-    }
-
     public static final void addErrorResult(final Bundle testinfo, final String msg) {
         testinfo.getStringArrayList(testinfo.getString(Utils.TESTCASE_TYPE))
             .add(TEST_ERROR + " " + msg);
diff --git a/tests/tests/assist/service/AndroidManifest.xml b/tests/tests/assist/service/AndroidManifest.xml
index 543568d..2c5206a 100644
--- a/tests/tests/assist/service/AndroidManifest.xml
+++ b/tests/tests/assist/service/AndroidManifest.xml
@@ -34,6 +34,7 @@
       <activity android:name=".AssistStructureActivity" >
           <intent-filter>
               <action android:name="android.intent.action.START_TEST_ASSIST_STRUCTURE" />
+              <action android:name="android.intent.action.START_TEST_FLAG_SECURE" />
               <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
       </activity>
diff --git a/tests/tests/assist/service/src/android/voiceinteraction/service/DisableContextActivity.java b/tests/tests/assist/service/src/android/voiceinteraction/service/DisableContextActivity.java
index 0db7ec1..52ba7ac 100644
--- a/tests/tests/assist/service/src/android/voiceinteraction/service/DisableContextActivity.java
+++ b/tests/tests/assist/service/src/android/voiceinteraction/service/DisableContextActivity.java
@@ -38,6 +38,7 @@
         super.onStart();
         Intent intent = new Intent();
         intent.setComponent(new ComponentName(this, MainInteractionService.class));
+        finish();
         ComponentName serviceName = startService(intent);
         Log.i(TAG, "Started service: " + serviceName);
     }
diff --git a/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionService.java b/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionService.java
index 684c817..85bd6ea 100644
--- a/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionService.java
+++ b/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionService.java
@@ -17,7 +17,6 @@
 package android.assist.service;
 
 import android.content.ComponentName;
-import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.service.voice.VoiceInteractionService;
diff --git a/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionSession.java b/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionSession.java
index 7b77ea0..9a835c2 100644
--- a/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionSession.java
+++ b/tests/tests/assist/service/src/android/voiceinteraction/service/MainInteractionSession.java
@@ -16,27 +16,19 @@
 
 package android.assist.service;
 
-import android.app.VoiceInteractor;
-import android.app.VoiceInteractor.Prompt;
 import android.app.assist.AssistContent;
 import android.app.assist.AssistStructure;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.graphics.Bitmap;
-import android.os.AsyncTask;
 import android.os.Bundle;
 import android.service.voice.VoiceInteractionSession;
-import android.service.voice.VoiceInteractionSession.ConfirmationRequest;
-import android.service.voice.VoiceInteractionSession.PickOptionRequest;
 import android.util.Log;
 
 import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
-import java.util.List;
 
 import android.assist.common.Utils;
-import android.webkit.URLUtil;
 
 public class MainInteractionSession extends VoiceInteractionSession {
     static final String TAG = "MainInteractionSession";
@@ -93,7 +85,7 @@
 
     @Override
     public void onHandleScreenshot(/*@Nullable*/ Bitmap screenshot) {
-        Log.i(TAG, "onHandleScreenshot");
+        Log.i(TAG, String.format("onHandleScreenshot - Screenshot: %s", screenshot));
         super.onHandleScreenshot(screenshot);
         ByteArrayOutputStream bs = new ByteArrayOutputStream();
         if (screenshot != null) {
diff --git a/tests/tests/assist/src/android/assist/TestStartActivity.java b/tests/tests/assist/src/android/assist/TestStartActivity.java
index c0549c6..df9b534 100644
--- a/tests/tests/assist/src/android/assist/TestStartActivity.java
+++ b/tests/tests/assist/src/android/assist/TestStartActivity.java
@@ -21,12 +21,9 @@
 import android.app.Activity;
 import android.content.Intent;
 import android.content.ComponentName;
-import android.content.Context;
 import android.os.Bundle;
 import android.util.Log;
 
-import android.assist.common.Utils;
-
 public class TestStartActivity extends Activity {
     static final String TAG = "TestStartActivity";
 
@@ -42,22 +39,21 @@
         Log.i(TAG, " in onResume");
     }
 
-    public void startTest(String testCaseType) {
-        Log.i(TAG, "Starting test activity for TestCaseType = " + testCaseType);
+    public void startTest(String testCaseName) {
+        Log.i(TAG, "Starting test activity for TestCaseType = " + testCaseName);
         Intent intent = new Intent();
-        intent.putExtra(Utils.TESTCASE_TYPE, testCaseType);
-        intent.setAction("android.intent.action.START_TEST_" + testCaseType);
+        intent.putExtra(Utils.TESTCASE_TYPE, testCaseName);
+        intent.setAction("android.intent.action.START_TEST_" + testCaseName);
         intent.setComponent(new ComponentName("android.assist.service",
-                "android.assist." + Utils.getTestActivity(testCaseType)));
+                "android.assist." + Utils.getTestActivity(testCaseName)));
         startActivity(intent);
     }
 
-    public void start3pApp() {
+    public void start3pApp(String testCaseName) {
         Intent intent = new Intent();
-        intent.setComponent(new ComponentName("android.assist.testapp",
-                "android.assist.testapp.TestApp"));
+        intent.setAction("android.intent.action.TEST_APP_" + testCaseName);
+        intent.setComponent(Utils.getTestAppComponent(testCaseName));
         startActivity(intent);
-
     }
 
     @Override protected void onPause() {
diff --git a/tests/tests/assist/src/android/assist/cts/AssistStructureTest.java b/tests/tests/assist/src/android/assist/cts/AssistStructureTest.java
index d113774..97ab290 100644
--- a/tests/tests/assist/src/android/assist/cts/AssistStructureTest.java
+++ b/tests/tests/assist/src/android/assist/cts/AssistStructureTest.java
@@ -16,25 +16,10 @@
 
 package android.assist.cts;
 
-import android.assist.TestStartActivity;
 import android.assist.common.Utils;
 
-import android.app.assist.AssistContent;
-import android.app.assist.AssistStructure;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.cts.util.SystemUtil;
-import android.os.Bundle;
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
+import android.provider.Settings;
 
-import java.lang.Exception;
-import java.lang.Override;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
 /**
  *  Test that the AssistStructure returned is properly formatted.
@@ -57,22 +42,11 @@
     }
 
     public void testAssistStructure() throws Exception {
-        // TODO(awlee): verify that the context/screenshot setting is on if appropriate
-        if (mAssistContent == null) {
-            fail("Received null assistBundle or assistContent.");
-            return;
-        }
-        if (mAssistBundle == null) {
-            fail("Received null assistBundle.");
-            return;
-        }
+        assertEquals("1", Settings.Secure.getString(
+            mContext.getContentResolver(), "assist_structure_enabled"));
 
-        if (mAssistStructure == null) {
-            fail("Received null assistStructure");
-            return;
-        } else {
-            verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE),
+        verifyAssistDataNullness(false, false, false, false);
+        verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE),
                     false /*FLAG_SECURE set*/);
-        }
     }
 }
\ No newline at end of file
diff --git a/tests/tests/assist/src/android/assist/cts/AssistTestBase.java b/tests/tests/assist/src/android/assist/cts/AssistTestBase.java
index b2ec739..e6d08cf 100644
--- a/tests/tests/assist/src/android/assist/cts/AssistTestBase.java
+++ b/tests/tests/assist/src/android/assist/cts/AssistTestBase.java
@@ -19,7 +19,6 @@
 import android.assist.TestStartActivity;
 import android.assist.common.Utils;
 
-import android.app.Activity;
 import android.app.assist.AssistContent;
 import android.app.assist.AssistStructure;
 import android.content.BroadcastReceiver;
@@ -27,9 +26,11 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.res.XmlResourceParser;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.os.Bundle;
+import android.provider.Settings;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.Log;
 
@@ -57,6 +58,11 @@
     protected void setUp() throws Exception {
         super.setUp();
         mContext = getInstrumentation().getTargetContext();
+        assertEquals("1", Settings.Secure.getString(
+            mContext.getContentResolver(), "assist_structure_enabled"));
+        assertEquals("1", Settings.Secure.getString(
+            mContext.getContentResolver(), "assist_screenshot_enabled"));
+        logContextAndScreenshotSetting();
     }
 
     @Override
@@ -71,7 +77,7 @@
         mTestName = testName;
         intent.setAction("android.intent.action.TEST_START_ACTIVITY_" + testName);
         intent.setComponent(new ComponentName(getInstrumentation().getContext(),
-                TestStartActivity.class));
+            TestStartActivity.class));
         setActivityIntent(intent);
         mTestActivity = getActivity();
     }
@@ -86,9 +92,9 @@
         }
         mReceiver = new TestResultsReceiver();
         mContext.registerReceiver(mReceiver,
-                new IntentFilter(Utils.BROADCAST_ASSIST_DATA_INTENT));
+            new IntentFilter(Utils.BROADCAST_ASSIST_DATA_INTENT));
 
-        mTestActivity.start3pApp();
+        mTestActivity.start3pApp(mTestName);
         mTestActivity.startTest(mTestName);
         if (!mLatch.await(Utils.TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
             fail("Failed to receive broadcast in " + Utils.TIMEOUT_MS + "msec");
@@ -97,6 +103,43 @@
         return true;
     }
 
+    /**
+     * Checks that the nullness of values are what we expect.
+     * @param isBundleNull True if assistBundle should be null.
+     * @param isStructureNull True if assistStructure should be null.
+     * @param isContentNull True if assistContent should be null.
+     * @param isScreenshotNull True if screenshot should be null.
+     */
+    protected void verifyAssistDataNullness(boolean isBundleNull, boolean isStructureNull,
+            boolean isContentNull, boolean isScreenshotNull) {
+
+        if ((mAssistContent == null) != isContentNull) {
+            fail(String.format("Should %s have been null - AssistContent: %s",
+                    isContentNull? "":"not", mAssistContent));
+        }
+
+        if ((mAssistStructure == null) != isStructureNull) {
+            fail(String.format("Should %s have been null - AssistStructure: %s",
+                isStructureNull ? "" : "not", mAssistStructure));
+        }
+
+        if ((mAssistBundle == null) != isBundleNull) {
+            fail(String.format("Should %s have been null - AssistBundle: %s",
+                    isBundleNull? "":"not", mAssistBundle));
+        }
+
+        if ((mScreenshot == null) != isScreenshotNull) {
+            fail(String.format("Should %s have been null - Screenshot: %s",
+                    isScreenshotNull? "":"not", mScreenshot));
+        }
+    }
+
+    /**
+     * Traverses and compares the view heirarchy of the backgroundApp and the view we expect.
+     *
+     * @param backgroundApp ComponentName of app the assistant is invoked upon
+     * @param isSecureWindow Denotes whether the activity has FLAG_SECURE set
+     */
     protected void verifyAssistStructure(ComponentName backgroundApp, boolean isSecureWindow) {
         // Check component name matches
         assertEquals(backgroundApp.flattenToString(),
@@ -106,10 +149,18 @@
         assertEquals(1, numWindows);
         for (int i = 0; i < numWindows; i++) {
             AssistStructure.ViewNode node = mAssistStructure.getWindowNodeAt(i).getRootViewNode();
-            // TODO: traverse view heirarchy and verify it matches what we expect
+            // TODO: Actually traverse the view heirarchy and verify it matches what we expect
+            // If isSecureWindow, will not have any children.
         }
     }
 
+    protected void logContextAndScreenshotSetting() {
+        Log.i(TAG, "Context is: " + Settings.Secure.getString(
+            mContext.getContentResolver(), "assist_structure_enabled"));
+        Log.i(TAG, "Screenshot is: " + Settings.Secure.getString(
+            mContext.getContentResolver(), "assist_screenshot_enabled"));
+    }
+
     class TestResultsReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/tests/tests/assist/src/android/assist/cts/DisableContextTest.java b/tests/tests/assist/src/android/assist/cts/DisableContextTest.java
index 6801737..9407ec5 100644
--- a/tests/tests/assist/src/android/assist/cts/DisableContextTest.java
+++ b/tests/tests/assist/src/android/assist/cts/DisableContextTest.java
@@ -53,8 +53,8 @@
         SystemUtil.runShellCommand(getInstrumentation(),
                 "settings put secure assist_structure_enabled 0");
         SystemUtil.runShellCommand(getInstrumentation(),
-                "settings put secure assist_screenshot_enabled 0");
-
+            "settings put secure assist_screenshot_enabled 0");
+        logContextAndScreenshotSetting();
         startTestActivity(TEST_CASE_TYPE);
         waitForBroadcast();
     }
@@ -64,20 +64,14 @@
         SystemUtil.runShellCommand(getInstrumentation(),
                 "settings put secure assist_structure_enabled 1");
         SystemUtil.runShellCommand(getInstrumentation(),
-                "settings put secure assist_screenshot_enabled 1");
+            "settings put secure assist_screenshot_enabled 1");
+        logContextAndScreenshotSetting();
         super.tearDown();
     }
 
     public void testContextAndScreenshotOff() throws Exception {
         // Both settings off
-        if (mAssistContent != null || mAssistBundle != null || mAssistStructure != null) {
-            fail(String.format("Should have all been null - Bundle: %s, Structure: %s, Content: %s",
-                    mAssistBundle, mAssistStructure, mAssistContent));
-        }
-
-        if (mScreenshot != null) {
-            fail(String.format("Should have been null - Screenshot: %s", mScreenshot));
-        }
+        verifyAssistDataNullness(true, true, true, true);
 
         // Screenshot off, context on
         SystemUtil.runShellCommand(getInstrumentation(),
@@ -86,29 +80,19 @@
             "settings put secure assist_screenshot_enabled 0");
         waitForBroadcast();
 
-        if (mScreenshot != null) {
-            fail(String.format("Should have been null - Screenshot: %s", mScreenshot));
-        }
+        logContextAndScreenshotSetting();
 
-        if (mAssistContent == null || mAssistBundle == null) {
-            fail(String.format("Should not have been null - Bundle: %s, Content: %s",
-                mAssistBundle, mAssistContent));
-        }
+        verifyAssistDataNullness(false, false, false, true);
 
         // Context off, screenshot on
         SystemUtil.runShellCommand(getInstrumentation(),
-            "settings put secure assist_screenshot_enabled 1");
-        SystemUtil.runShellCommand(getInstrumentation(),
             "settings put secure assist_structure_enabled 0");
+        SystemUtil.runShellCommand(getInstrumentation(),
+            "settings put secure assist_screenshot_enabled 1");
         waitForBroadcast();
 
-        if (mScreenshot == null) {
-            fail(String.format("Should not have been null - Screenshot: %s", mScreenshot));
-        }
+        logContextAndScreenshotSetting();
 
-        if (mAssistContent != null || mAssistBundle != null || mAssistStructure != null) {
-            fail(String.format("Should have all been null - Bundle: %s, Structure: %s, Content: %s",
-                mAssistBundle, mAssistStructure, mAssistContent));
-        }
+        verifyAssistDataNullness(true, true, true, false);
     }
 }
\ No newline at end of file
diff --git a/tests/tests/assist/src/android/assist/cts/FlagSecureTest.java b/tests/tests/assist/src/android/assist/cts/FlagSecureTest.java
new file mode 100644
index 0000000..0e79d9d
--- /dev/null
+++ b/tests/tests/assist/src/android/assist/cts/FlagSecureTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 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 android.assist.cts;
+
+import android.assist.common.Utils;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * Test we receive proper assist data (root assistStructure with no children) when the assistant is
+ * invoked on an app with FLAG_SECURE set.
+ */
+public class FlagSecureTest extends AssistTestBase {
+
+    static final String TAG = "DisableContextTest";
+
+    private static final String TEST_CASE_TYPE = Utils.FLAG_SECURE;
+
+    public FlagSecureTest() {
+        super();
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        startTestActivity(TEST_CASE_TYPE);
+        waitForBroadcast();
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testSecureActivity() throws Exception {
+        verifyAssistDataNullness(false, false, false, true);
+
+        // verify that we have only the root window and not its children.
+        verifyAssistStructure(Utils.getTestAppComponent(TEST_CASE_TYPE), true);
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/assist/testapp/AndroidManifest.xml b/tests/tests/assist/testapp/AndroidManifest.xml
index 5b16ed7..371ae7b 100644
--- a/tests/tests/assist/testapp/AndroidManifest.xml
+++ b/tests/tests/assist/testapp/AndroidManifest.xml
@@ -19,16 +19,25 @@
     package="android.assist.testapp">
 
     <application>
-      <uses-library android:name="android.test.runner" />
+        <uses-library android:name="android.test.runner" />
 
-      <activity android:name="TestApp"
+        <activity android:name="TestApp"
                 android:label="Assist Test App"
                 android:theme="@android:style/Theme.Material.Light">
           <intent-filter>
-              <action android:name="android.intent.action.TEST_APP" />
+              <action android:name="android.intent.action.TEST_APP_ASSIST_STRUCTURE" />
               <category android:name="android.intent.category.DEFAULT" />
               <category android:name="android.intent.category.VOICE" />
           </intent-filter>
-      </activity>
+        </activity>
+        <activity android:name="SecureActivity"
+                  android:label="Secure Test App"
+                  android:theme="@android:style/Theme.Material.Light">
+            <intent-filter>
+                <action android:name="android.intent.action.TEST_APP_FLAG_SECURE" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <category android:name="android.intent.category.VOICE" />
+            </intent-filter>
+        </activity>
     </application>
 </manifest>
diff --git a/tests/tests/assist/testapp/res/layout/voice_interaction_main.xml b/tests/tests/assist/testapp/res/layout/secure_app.xml
similarity index 100%
rename from tests/tests/assist/testapp/res/layout/voice_interaction_main.xml
rename to tests/tests/assist/testapp/res/layout/secure_app.xml
diff --git a/tests/tests/assist/testapp/res/layout/voice_interaction_main.xml b/tests/tests/assist/testapp/res/layout/test_app.xml
similarity index 100%
copy from tests/tests/assist/testapp/res/layout/voice_interaction_main.xml
copy to tests/tests/assist/testapp/res/layout/test_app.xml
diff --git a/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/SecureActivity.java b/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/SecureActivity.java
new file mode 100644
index 0000000..83f7549
--- /dev/null
+++ b/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/SecureActivity.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 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 android.assist.testapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+import android.view.WindowManager;
+
+public class SecureActivity extends Activity {
+    static final String TAG = "SecureActivity";
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Log.i(TAG, "SecureActivity created");
+        setContentView(R.layout.secure_app);
+        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
+            WindowManager.LayoutParams.FLAG_SECURE);
+    }
+}
\ No newline at end of file
diff --git a/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/TestApp.java b/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/TestApp.java
index 7fa9653..85a9342 100644
--- a/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/TestApp.java
+++ b/tests/tests/assist/testapp/src/android/voiceinteraction/testapp/TestApp.java
@@ -17,17 +17,9 @@
 package android.assist.testapp;
 
 import android.app.Activity;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
 
-import java.util.ArrayList;
-
-import android.assist.common.Utils;
-
 public class TestApp extends Activity {
     static final String TAG = "TestApp";
 
@@ -38,7 +30,7 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         Log.i(TAG, "TestApp created");
-        getLayoutInflater().inflate(R.layout.voice_interaction_main, null);
+        getLayoutInflater().inflate(R.layout.test_app, null);
     }
 
     @Override
diff --git a/tests/tests/hardware/Android.mk b/tests/tests/hardware/Android.mk
index 9523d87..9c26d8a 100644
--- a/tests/tests/hardware/Android.mk
+++ b/tests/tests/hardware/Android.mk
@@ -34,7 +34,7 @@
     src/android/hardware/cts/SensorIntegrationTests.java \
     src/android/hardware/cts/SensorBatchingTests.java \
     src/android/hardware/cts/SensorTest.java \
-    src/android/hardware/cts/SensorManagerStaticTest.java \
+    src/android/hardware/cts/SensorManagerStaticTest.java
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil
 
@@ -57,4 +57,4 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-include $(BUILD_CTS_PACKAGE)
\ No newline at end of file
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorParameterRangeTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorParameterRangeTest.java
new file mode 100644
index 0000000..4750b09
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorParameterRangeTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 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 android.hardware.cts;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.hardware.cts.helpers.SensorCtsHelper;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Test min-max frequency, max range parameters for sensors.
+ *
+ * <p>To execute these test cases, the following command can be used:</p>
+ * <pre>
+ * adb shell am instrument -e class android.hardware.cts.SensorParameterRangeTest \
+ *     -w com.android.cts.hardware/android.test.AndroidJUnitRunner
+ * </pre>
+ */
+public class SensorParameterRangeTest extends SensorTestCase {
+
+    private static final double ACCELEROMETER_MAX_RANGE = 8 * 9.81; // 8G
+    private static final int ACCELEROMETER_MIN_FREQUENCY = 5;
+    private static final int ACCELEROMETER_MAX_FREQUENCY = 200;
+
+    private static final double GYRO_MAX_RANGE = 1000/57.295; // 1000 degrees per sec.
+    private static final int GYRO_MIN_FREQUENCY = 5;
+    private static final int GYRO_MAX_FREQUENCY = 200;
+
+    private static final int MAGNETOMETER_MAX_RANGE = 900;   // micro telsa
+    private static final int MAGNETOMETER_MIN_FREQUENCY = 5;
+    private static final int MAGNETOMETER_MAX_FREQUENCY = 50;
+
+    private static final int PRESSURE_MAX_RANGE = 1100;     // hecto-pascal
+    private static final int PRESSURE_MIN_FREQUENCY = 1;
+    private static final int PRESSURE_MAX_FREQUENCY = 10;
+
+    private boolean mHasHifiSensors;
+    private SensorManager mSensorManager;
+
+    @Override
+    public void setUp() {
+        mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
+        mHasHifiSensors = getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_HIFI_SENSORS);
+    }
+
+    public void testAccelerometerRange() {
+        checkSensorRangeAndFrequency(
+                mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
+                ACCELEROMETER_MAX_RANGE,
+                ACCELEROMETER_MIN_FREQUENCY,
+                ACCELEROMETER_MAX_FREQUENCY);
+  }
+
+  public void testGyroscopeRange() {
+        checkSensorRangeAndFrequency(
+                mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE),
+                GYRO_MAX_RANGE,
+                GYRO_MIN_FREQUENCY,
+                GYRO_MAX_FREQUENCY);
+  }
+
+    public void testMagnetometerRange() {
+        checkSensorRangeAndFrequency(
+                mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
+                MAGNETOMETER_MAX_RANGE,
+                MAGNETOMETER_MIN_FREQUENCY,
+                MAGNETOMETER_MAX_FREQUENCY);
+    }
+
+    public void testPressureRange() {
+        checkSensorRangeAndFrequency(
+                mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE),
+                PRESSURE_MAX_RANGE,
+                PRESSURE_MIN_FREQUENCY,
+                PRESSURE_MAX_FREQUENCY);
+    }
+
+    private void checkSensorRangeAndFrequency(
+          Sensor sensor, double maxRange, int minFrequency, int maxFrequency) {
+        if (!mHasHifiSensors) return;
+        assertTrue(String.format("%s Range actual=%.2f expected=%.2f %s",
+                    sensor.getName(), sensor.getMaximumRange(), maxRange,
+                    SensorCtsHelper.getUnitsForSensor(sensor)),
+                sensor.getMaximumRange() >= maxRange);
+        double actualMinFrequency = SensorCtsHelper.getFrequency(sensor.getMaxDelay(),
+                TimeUnit.MICROSECONDS);
+        assertTrue(String.format("%s Min Frequency actual=%.2f expected=%dHz",
+                    sensor.getName(), actualMinFrequency, minFrequency), actualMinFrequency <=
+                minFrequency);
+
+        double actualMaxFrequency = SensorCtsHelper.getFrequency(sensor.getMinDelay(),
+                TimeUnit.MICROSECONDS);
+        assertTrue(String.format("%s Max Frequency actual=%.2f expected=%dHz",
+                    sensor.getName(), actualMaxFrequency, maxFrequency), actualMaxFrequency >=
+                maxFrequency);
+    }
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorSupportTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorSupportTest.java
new file mode 100644
index 0000000..2f25c8d
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorSupportTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2015 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 android.hardware.cts;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.test.AndroidTestCase;
+
+/**
+ * Checks if Hifi sensors are supported. When supported, checks individual support for
+ * Accelerometer, Gyroscope, Gyroscope_uncal, GeoMagneticField, MagneticField_uncal
+ * Pressure, RotationVector, SignificantMotion, StepDetector, StepCounter, TiltDetector.
+ *
+ * <p>To execute these test cases, the following command can be used:</p>
+ * <pre>
+ * adb shell am instrument -e class android.hardware.cts.SensorSupportTest \
+ *     -w com.android.cts.hardware/android.test.AndroidJUnitRunner
+ * </pre>
+ */
+public class SensorSupportTest extends AndroidTestCase {
+    private SensorManager mSensorManager;
+    private boolean mAreHifiSensorsSupported;
+
+    @Override
+    public void setUp() {
+        // Tests will only run if HIFI_SENSORS are supported.
+        mAreHifiSensorsSupported = getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_HIFI_SENSORS);
+        if (mAreHifiSensorsSupported) {
+            mSensorManager =
+                    (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
+        }
+    }
+
+    public void testSupportsAccelerometer() {
+        checkSupportsSensor(Sensor.TYPE_ACCELEROMETER);
+    }
+
+    public void testSupportsGyroscope() {
+        checkSupportsSensor(Sensor.TYPE_GYROSCOPE);
+    }
+
+    public void testSupportsGyroscopeUncalibrated() {
+        checkSupportsSensor(Sensor.TYPE_GYROSCOPE_UNCALIBRATED);
+    }
+
+    public void testSupportsGeoMagneticField() {
+        checkSupportsSensor(Sensor.TYPE_GEOMAGNETIC_ROTATION_VECTOR);
+    }
+
+    public void testSupportsMagneticFieldUncalibrated() {
+        checkSupportsSensor(Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED);
+    }
+
+    public void testSupportsPressure() {
+        checkSupportsSensor(Sensor.TYPE_PRESSURE);
+    }
+
+    public void testSupportsRotationVector() {
+        checkSupportsSensor(Sensor.TYPE_ROTATION_VECTOR);
+    }
+
+    public void testSupportsSignificantMotion() {
+        checkSupportsSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
+    }
+
+    public void testSupportsStepDetector() {
+        checkSupportsSensor(Sensor.TYPE_STEP_DETECTOR);
+    }
+
+    public void testSupportsStepCounter() {
+        checkSupportsSensor(Sensor.TYPE_STEP_COUNTER);
+    }
+
+    public void testSupportsTiltDetector() {
+        final int TYPE_TILT_DETECTOR = 22;
+        checkSupportsSensor(TYPE_TILT_DETECTOR);
+    }
+
+    private void checkSupportsSensor(int sensorType) {
+        if (mAreHifiSensorsSupported) {
+            assertTrue(mSensorManager.getDefaultSensor(sensorType) != null);
+        }
+    }
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
index 490e965..55465ac 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/SensorCtsHelper.java
@@ -15,6 +15,7 @@
  */
 package android.hardware.cts.helpers;
 
+import android.hardware.Sensor;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -259,4 +260,20 @@
             throw new IllegalStateException("Collection cannot be null or empty");
         }
     }
+
+    public static String getUnitsForSensor(Sensor sensor) {
+        switch(sensor.getType()) {
+            case Sensor.TYPE_ACCELEROMETER:
+                return "m/s^2";
+            case Sensor.TYPE_MAGNETIC_FIELD:
+            case Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED:
+                return "uT";
+            case Sensor.TYPE_GYROSCOPE:
+            case Sensor.TYPE_GYROSCOPE_UNCALIBRATED:
+                return "radians/sec";
+            case Sensor.TYPE_PRESSURE:
+                return "hPa";
+        };
+        return "";
+    }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
index 6633903..e5a5053 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/JitterVerification.java
@@ -18,6 +18,10 @@
 
 import junit.framework.Assert;
 
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import android.util.Log;
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorCtsHelper;
 import android.hardware.cts.helpers.SensorStats;
@@ -39,6 +43,8 @@
 
     // sensorType: threshold (% of expected period)
     private static final SparseIntArray DEFAULTS = new SparseIntArray(12);
+    // Max allowed jitter (in percentage).
+    private static final int THRESHOLD_PERCENT_FOR_HIFI_SENSORS = 1;
     static {
         // Use a method so that the @deprecation warning can be set for that method only
         setDefaults();
@@ -68,6 +74,11 @@
         if (threshold == -1) {
             return null;
         }
+        boolean hasHifiSensors = environment.getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_HIFI_SENSORS);
+        if (hasHifiSensors) {
+           threshold = THRESHOLD_PERCENT_FOR_HIFI_SENSORS;
+        }
         return new JitterVerification(threshold);
     }
 
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
index f7c2c53..20dd2d2 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/sensorverification/StandardDeviationVerification.java
@@ -18,10 +18,13 @@
 
 import junit.framework.Assert;
 
+import android.content.Context;
+import android.content.pm.PackageManager;
 import android.hardware.Sensor;
 import android.hardware.cts.helpers.SensorStats;
 import android.hardware.cts.helpers.TestSensorEnvironment;
 import android.hardware.cts.helpers.TestSensorEvent;
+import android.util.Log;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -66,7 +69,21 @@
         if (!DEFAULTS.containsKey(sensorType)) {
             return null;
         }
+        boolean hasHifiSensors = environment.getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_HIFI_SENSORS);
 
+        if (hasHifiSensors) {
+            // Max accelerometer deviation: 400uG/√Hz
+            DEFAULTS.put(Sensor.TYPE_ACCELEROMETER, new float[]{0.004f, 0.004f, 0.004f});
+            // Max gyro deviation: 0.014°/s/√Hz
+            float deviationInRadians = (float) (0.014f * (Math.PI / 180));
+            DEFAULTS.put(Sensor.TYPE_GYROSCOPE,
+                    new float[]{deviationInRadians,deviationInRadians, deviationInRadians});
+            // Max magnetometer deviation: 0.1uT/√Hz
+            DEFAULTS.put(Sensor.TYPE_MAGNETIC_FIELD, new float[]{0.1f, 0.1f, 0.1f});
+            // Max pressure deviation: 2Pa/√Hz
+            DEFAULTS.put(Sensor.TYPE_PRESSURE, new float[]{2.0f, 2.0f, 2.0f});
+        }
         return new StandardDeviationVerification(DEFAULTS.get(sensorType));
     }
 
@@ -107,9 +124,9 @@
             if (stdDevs[i] > mThreshold[i]) {
                 failed = true;
             }
-            stddevSb.append(String.format("%.2f", stdDevs[i]));
+            stddevSb.append(String.format("%.3f", stdDevs[i]));
             if (i != stdDevs.length - 1) stddevSb.append(", ");
-            expectedSb.append(String.format("<%.2f", mThreshold[i]));
+            expectedSb.append(String.format("<%.3f", mThreshold[i]));
             if (i != stdDevs.length - 1) expectedSb.append(", ");
         }
         if (stdDevs.length > 1) {
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerTest.java b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
index 5870005..ded0539 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
@@ -45,27 +45,24 @@
 import android.os.Vibrator;
 import android.provider.Settings;
 import android.provider.Settings.System;
-import android.test.InstrumentationTestCase;
+import android.test.AndroidTestCase;
 import android.view.SoundEffectConstants;
 
 import java.util.TreeMap;
 
-public class AudioManagerTest extends InstrumentationTestCase {
+public class AudioManagerTest extends AndroidTestCase {
 
     private final static int MP3_TO_PLAY = R.raw.testmp3;
     private final static long TIME_TO_PLAY = 2000;
-    private final static String APPOPS_OP_STR = "android:write_settings";
     private AudioManager mAudioManager;
     private boolean mHasVibrator;
     private boolean mUseFixedVolume;
     private boolean mIsTelevision;
-    private Context mContext;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mContext = getInstrumentation().getContext();
-        Utils.enableAppOps(mContext.getPackageName(), APPOPS_OP_STR, getInstrumentation());
+        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
         Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
         mHasVibrator = (vibrator != null) && vibrator.hasVibrator();
         mUseFixedVolume = mContext.getResources().getBoolean(
@@ -76,11 +73,6 @@
                         || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEVISION));
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        Utils.disableAppOps(mContext.getPackageName(), APPOPS_OP_STR, getInstrumentation());
-    }
-
     public void testMicrophoneMute() throws Exception {
         mAudioManager.setMicrophoneMute(true);
         assertTrue(mAudioManager.isMicrophoneMute());
diff --git a/tests/tests/media/src/android/media/cts/MidiSoloTest.java b/tests/tests/media/src/android/media/cts/MidiSoloTest.java
index 4c1a5e8..d198ee8 100644
--- a/tests/tests/media/src/android/media/cts/MidiSoloTest.java
+++ b/tests/tests/media/src/android/media/cts/MidiSoloTest.java
@@ -97,9 +97,7 @@
         MidiManager.DeviceCallback callback = new MidiManager.DeviceCallback();
 
         // These should not crash.
-        midiManager.unregisterDeviceCallback(null);
         midiManager.unregisterDeviceCallback(callback);
-        midiManager.registerDeviceCallback(null, null);
         midiManager.registerDeviceCallback(callback, null);
         midiManager.unregisterDeviceCallback(callback);
         midiManager.registerDeviceCallback(callback, new Handler(Looper.getMainLooper()));
@@ -107,9 +105,6 @@
         midiManager.unregisterDeviceCallback(callback);
         midiManager.unregisterDeviceCallback(callback);
         midiManager.unregisterDeviceCallback(callback);
-        midiManager.registerDeviceCallback(null, new Handler(Looper.getMainLooper()));
-        midiManager.unregisterDeviceCallback(callback);
-        midiManager.unregisterDeviceCallback(null);
     }
 
     public void testMidiReceiver() throws Exception {
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index e6b656f..592e308 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -95,7 +95,7 @@
      * brackets are optional):
      * <p/>
      * Mozilla/5.0 (Linux;[ U;] Android <version>;[ <language>-<country>;]
-     * [<devicemodel>;] Build/<buildID>[; wv]) AppleWebKit/<major>.<minor> (KHTML, like Gecko)
+     * [<devicemodel>;] Build/<buildID>; wv) AppleWebKit/<major>.<minor> (KHTML, like Gecko)
      * Version/<major>.<minor> Chrome/<major>.<minor>.<branch>.<build>[ Mobile]
      * Safari/<major>.<minor>
      */
@@ -107,7 +107,7 @@
         Log.i(LOG_TAG, String.format("Checking user agent string %s", actualUserAgentString));
         final String patternString =
                 "Mozilla/5\\.0 \\(Linux;( U;)? Android ([^;]+);( (\\w+)-(\\w+);)?" +
-                "\\s?(.*)\\sBuild/(.+?)(; wv)?\\) AppleWebKit/(\\d+)\\.(\\d+) " +
+                "\\s?(.*)\\sBuild/(.+); wv\\) AppleWebKit/(\\d+)\\.(\\d+) " +
                 "\\(KHTML, like Gecko\\) " +
                 "Version/\\d+\\.\\d+ Chrome/\\d+\\.\\d+\\.\\d+\\.\\d+( Mobile)? " +
                 "Safari/(\\d+)\\.(\\d+)";
@@ -119,12 +119,11 @@
         //  5   - language
         //  6 - device model (optional)
         //  7 - build ID
-        //  8 - WebView identifier "; wv" (optional)
-        //  9 - AppleWebKit major version number
-        // 10 - AppleWebKit minor version number
-        // 11 - " Mobile" string (optional)
-        // 12 - Safari major version number
-        // 13 - Safari minor version number
+        //  8 - AppleWebKit major version number
+        //  9 - AppleWebKit minor version number
+        // 10 - " Mobile" string (optional)
+        // 11 - Safari major version number
+        // 12 - Safari minor version number
         Log.i(LOG_TAG, String.format("Trying to match pattern %s", patternString));
         final Pattern userAgentExpr = Pattern.compile(patternString);
         Matcher patternMatcher = userAgentExpr.matcher(actualUserAgentString);
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
index 01f148ae..d74cce5 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
@@ -289,9 +289,8 @@
         @Override
         public void testFailed(TestIdentifier test, String trace) {
             super.testFailed(test, trace);
-            // sleep a small amount of time to ensure test failure stack trace makes it into logcat
-            // capture
-            RunUtil.getDefault().sleep(10);
+            // sleep 2s to ensure test failure stack trace makes it into logcat capture
+            RunUtil.getDefault().sleep(2 * 1000);
             InputStreamSource logSource = mDevice.getLogcat(mNumLogcatBytes);
             super.testLog(String.format("logcat-%s_%s", test.getClassName(), test.getTestName()),
                     LogDataType.TEXT, logSource);
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index f276f1d..12c3ddd 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -308,9 +308,6 @@
         instrTest.setRunName(mAppPackageName);
         instrTest.setPackageName(mAppNameSpace);
         instrTest.setRunnerName(mRunner);
-        instrTest.setTestPackageName(mTestPackageName);
-        instrTest.setClassName(mClassName);
-        instrTest.setMethodName(mMethodName);
         instrTest.setAbi(mAbi);
         instrTest.setTestsToRun(mTests, false
             /* force batch mode off to always run using testFile */);