Merge "Fix tests to handle sensors not supported. b/17578209" into lmp-dev
diff --git a/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
index 24f4803..bed4c05 100644
--- a/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
+++ b/hostsidetests/sample/src/android/sample/cts/SampleHostResultTest.java
@@ -24,11 +24,11 @@
 import com.android.cts.util.ResultUnit;
 import com.android.cts.util.ReportLog;
 import com.android.cts.util.Stat;
-import com.android.ddmlib.Log;
 import com.android.ddmlib.IDevice;
 import com.android.tradefed.build.IBuildInfo;
 import com.android.tradefed.device.ITestDevice;
 import com.android.tradefed.testtype.DeviceTestCase;
+import com.android.tradefed.testtype.IAbi;
 import com.android.tradefed.testtype.IAbiReceiver;
 import com.android.tradefed.testtype.IBuildReceiver;
 import com.android.tradefed.util.CommandResult;
@@ -68,13 +68,14 @@
      */
     private ITestDevice mDevice;
 
-    private String mAbiName;
-    private String mAbiBitness;
+    /**
+     * A reference to the ABI under test.
+     */
+    private IAbi mAbi;
 
     @Override
-    public void setAbi(String name, String bitness) {
-        mAbiName = name;
-        mAbiBitness = bitness;
+    public void setAbi(IAbi abi) {
+        mAbi = abi;
     }
 
     @Override
@@ -132,7 +133,7 @@
         // Compute the stats.
         Stat.StatResult stat = Stat.getStat(result);
         // Get the report for this test and add the results to record.
-        HostReportLog report = new HostReportLog(mDevice.getSerialNumber(), mAbiName,
+        HostReportLog report = new HostReportLog(mDevice.getSerialNumber(), mAbi.getName(),
                 ReportLog.getClassMethodNames());
         report.printArray("Times", result, ResultType.LOWER_BETTER, ResultUnit.MS);
         report.printValue("Min", stat.mMin, ResultType.LOWER_BETTER, ResultUnit.MS);
diff --git a/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java b/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java
index a261c1e..3cc4aa9 100644
--- a/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java
+++ b/hostsidetests/sample/src/android/sample/cts/SampleHostTest.java
@@ -67,7 +67,7 @@
     /**
      * The ABI to use.
      */
-    private String mAbi;
+    private IAbi mAbi;
 
     /**
      * A reference to the build.
@@ -133,6 +133,7 @@
                 testString = line.split(":")[1].trim();
             }
         }
+        in.close();
         // Assert the logged string matches the test string.
         assertEquals("Incorrect test string", TEST_STRING, testString);
     }
diff --git a/libs/commonutil/src/com/android/cts/util/CtsException.java b/libs/commonutil/src/com/android/cts/util/CtsException.java
deleted file mode 100644
index 7e79590..0000000
--- a/libs/commonutil/src/com/android/cts/util/CtsException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2012 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.cts.util;
-
-/**
- * Exception throw by CTS test to pass the result to host
- * This should not be thrown by test app unless the result is complete.
- */
-@SuppressWarnings("serial")
-public class CtsException extends Exception {
-    public CtsException(String message) {
-        super(message);
-    }
-}
diff --git a/libs/deviceutil/src/android/cts/util/DeviceReportLog.java b/libs/deviceutil/src/android/cts/util/DeviceReportLog.java
index a3ceecf..88565a7 100644
--- a/libs/deviceutil/src/android/cts/util/DeviceReportLog.java
+++ b/libs/deviceutil/src/android/cts/util/DeviceReportLog.java
@@ -24,7 +24,7 @@
 
 public class DeviceReportLog extends ReportLog {
     private static final String TAG = "DeviceCtsReport";
-    private static final String CTS_RESULT = "CTS_RESULT";
+    private static final String CTS_RESULT = "CTS_TEST_RESULT";
     private static final int INST_STATUS_IN_PROGRESS = 2;
     private static final int BASE_DEPTH = 4;
 
diff --git a/tests/assets/otacerts.zip b/tests/assets/otacerts.zip
deleted file mode 100644
index 937a128..0000000
--- a/tests/assets/otacerts.zip
+++ /dev/null
Binary files differ
diff --git a/tests/assets/otasigned.zip b/tests/assets/otasigned.zip
deleted file mode 100644
index a6bc53e..0000000
--- a/tests/assets/otasigned.zip
+++ /dev/null
Binary files differ
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
index bdc0cd5..cb0877d 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
@@ -4532,7 +4532,7 @@
                 AccessibilityNodeInfo.ACTION_PASTE));
 
         // Verify the content.
-        assertEquals(editText.getText().toString(), textContent + " " + textContent);
+        assertEquals(editText.getText().toString(), textContent + textContent);
 
         // Select all text.
         arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 0);
diff --git a/tests/tests/animation/src/android/animation/cts/AnimatorTest.java b/tests/tests/animation/src/android/animation/cts/AnimatorTest.java
index 5f07afb..fac9ff9 100644
--- a/tests/tests/animation/src/android/animation/cts/AnimatorTest.java
+++ b/tests/tests/animation/src/android/animation/cts/AnimatorTest.java
@@ -19,6 +19,7 @@
 import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
 import android.view.animation.AccelerateInterpolator;
 
 import java.util.List;
@@ -55,7 +56,8 @@
         assertEquals(startDelay, mAnimator.getStartDelay());
     }
 
-    public void testStart() {
+    @UiThreadTest
+    public void testStart() throws Exception {
         mAnimator.start();
         assertTrue(mAnimator.isRunning());
         assertTrue(mAnimator.isStarted());
@@ -135,10 +137,20 @@
         assertFalse(listener.mEnd);
         assertTrue(listener.mRepeat >= 0);
 
-        mAnimator.cancel();
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                mAnimator.cancel();
+            }
+        });
+        getInstrumentation().waitForIdleSync();
         assertTrue(listener.mCancel);
 
-        mAnimator.end();
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                mAnimator.end();
+            }
+        });
+        getInstrumentation().waitForIdleSync();
         assertTrue(listener.mEnd);
     }
 
diff --git a/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java b/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
index f8f1f43..f0db168 100644
--- a/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
+++ b/tests/tests/animation/src/android/animation/cts/ObjectAnimatorTest.java
@@ -88,13 +88,18 @@
         int startColor = mActivity.view.RED;
         int endColor = mActivity.view.BLUE;
 
-        ObjectAnimator colorAnimator = ObjectAnimator.ofInt(object, property,
+        final ObjectAnimator colorAnimator = ObjectAnimator.ofInt(object, property,
                 startColor, endColor);
         colorAnimator.setDuration(1000);
         colorAnimator.setEvaluator(new ArgbEvaluator());
         colorAnimator.setRepeatCount(1);
         colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
-        colorAnimator.start();
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                colorAnimator.start();
+            }
+        });
+        getInstrumentation().waitForIdleSync();
         startAnimation(mObjectAnimator, colorAnimator);
         Thread.sleep(100);
         Integer i = (Integer) colorAnimator.getAnimatedValue();
@@ -110,12 +115,17 @@
         int endColor = mActivity.view.BLUE;
         Object[] values = {new Integer(startColor), new Integer(endColor)};
         ArgbEvaluator evaluator = new ArgbEvaluator();
-        ObjectAnimator colorAnimator = ObjectAnimator.ofObject(object, property,
+        final ObjectAnimator colorAnimator = ObjectAnimator.ofObject(object, property,
                 evaluator, values);
         colorAnimator.setDuration(1000);
         colorAnimator.setRepeatCount(1);
         colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
-        colorAnimator.start();
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                colorAnimator.start();
+            }
+        });
+        getInstrumentation().waitForIdleSync();
         startAnimation(mObjectAnimator, colorAnimator);
         Thread.sleep(100);
         Integer i = (Integer) colorAnimator.getAnimatedValue();
@@ -132,12 +142,17 @@
         int values[] = {startColor, endColor};
         ArgbEvaluator evaluator = new ArgbEvaluator();
         PropertyValuesHolder propertyValuesHolder = PropertyValuesHolder.ofInt(propertyName, values);
-        ObjectAnimator colorAnimator = ObjectAnimator.ofPropertyValuesHolder(object,
+        final ObjectAnimator colorAnimator = ObjectAnimator.ofPropertyValuesHolder(object,
             propertyValuesHolder);
         colorAnimator.setDuration(1000);
         colorAnimator.setRepeatCount(1);
         colorAnimator.setRepeatMode(ValueAnimator.REVERSE);
-        colorAnimator.start();
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                colorAnimator.start();
+            }
+        });
+        getInstrumentation().waitForIdleSync();
         startAnimation(mObjectAnimator, colorAnimator);
         Thread.sleep(100);
         Integer i = (Integer) colorAnimator.getAnimatedValue();
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
index 3d55c85..e06698a 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
@@ -351,10 +351,14 @@
      * Test tone map modes and controls.
      */
     public void testToneMapControl() throws Exception {
-        for (int i = 0; i < mCameraIds.length; i++) {
+        for (String id : mCameraIds) {
             try {
-                openDevice(mCameraIds[i]);
-
+                openDevice(id);
+                if (!mStaticInfo.isManualToneMapSupported()) {
+                    Log.i(TAG, "Camera " + id +
+                            " doesn't support tone mapping controls, skipping test");
+                    continue;
+                }
                 toneMapTestByCamera();
             } finally {
                 closeDevice();
@@ -369,7 +373,11 @@
         for (String id : mCameraIds) {
             try {
                 openDevice(id);
-
+                if (!mStaticInfo.isManualColorCorrectionSupported()) {
+                    Log.i(TAG, "Camera " + id +
+                            " doesn't support color correction controls, skipping test");
+                    continue;
+                }
                 colorCorrectionTestByCamera();
             } finally {
                 closeDevice();
@@ -381,9 +389,9 @@
         for (String id : mCameraIds) {
             try {
                 openDevice(id);
-                if (!mStaticInfo.getCharacteristics().getKeys().
-                        contains(CameraCharacteristics.EDGE_AVAILABLE_EDGE_MODES)) {
-                    Log.i(TAG, "Camera " + id + " doesn't support EDGE_MODE controls.");
+                if (!mStaticInfo.isEdgeModeControlSupported()) {
+                    Log.i(TAG, "Camera " + id +
+                            " doesn't support EDGE_MODE controls, skipping test");
                     continue;
                 }
 
@@ -402,7 +410,14 @@
             try {
                 openDevice(id);
                 if (!mStaticInfo.hasFocuser()) {
-                    Log.i(TAG, "Camera " + id + " has no focuser");
+                    Log.i(TAG, "Camera " + id + " has no focuser, skipping test");
+                    continue;
+                }
+
+                if (!mStaticInfo.isCapabilitySupported(
+                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) {
+                    Log.i(TAG, "Camera " + id +
+                            " does not support MANUAL_SENSOR, skipping test");
                     continue;
                 }
 
@@ -417,9 +432,9 @@
         for (String id : mCameraIds) {
             try {
                 openDevice(id);
-                if (!mStaticInfo.getCharacteristics().getKeys().contains(
-                        CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES)) {
-                    Log.i(TAG, "Camera " + id + " doesn't support noise reduction mode");
+                if (!mStaticInfo.isNoiseReductionModeControlSupported()) {
+                    Log.i(TAG, "Camera " + id +
+                            " doesn't support noise reduction mode, skipping test");
                     continue;
                 }
 
@@ -2041,9 +2056,11 @@
             fpsRange = fpsRanges[i];
             Size previewSz = getMaxPreviewSizeForFpsRange(fpsRange);
             // If unable to find a preview size, then log the failure, and skip this run.
-            if (!mCollector.expectTrue(String.format(
-                    "Unable to find a preview size supporting given fps range %s",
-                    fpsRange), previewSz != null)) {
+            if (previewSz == null && mStaticInfo.isCapabilitySupported(
+                    CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) {
+                mCollector.addMessage(String.format(
+                        "Unable to find a preview size supporting given fps range %s",
+                        fpsRange));
                 continue;
             }
 
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureResultTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureResultTest.java
index 744f4ca..aa2ba60 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureResultTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureResultTest.java
@@ -515,6 +515,11 @@
             waiverKeys.add(CaptureResult.SENSOR_FRAME_DURATION);
             waiverKeys.add(CaptureResult.SENSOR_SENSITIVITY);
             waiverKeys.add(CaptureResult.BLACK_LEVEL_LOCK);
+            waiverKeys.add(CaptureResult.LENS_FOCUS_RANGE);
+            waiverKeys.add(CaptureResult.LENS_FOCUS_DISTANCE);
+            waiverKeys.add(CaptureResult.LENS_STATE);
+            waiverKeys.add(CaptureResult.LENS_APERTURE);
+            waiverKeys.add(CaptureResult.LENS_FILTER_DENSITY);
         }
 
         if (mStaticInfo.isHardwareLevelLimited()) {
@@ -529,11 +534,6 @@
         waiverKeys.add(CaptureResult.CONTROL_AWB_STATE);
         waiverKeys.add(CaptureResult.FLASH_STATE);
         waiverKeys.add(CaptureResult.LENS_OPTICAL_STABILIZATION_MODE);
-        waiverKeys.add(CaptureResult.LENS_FOCUS_RANGE);
-        waiverKeys.add(CaptureResult.LENS_FOCUS_DISTANCE);
-        waiverKeys.add(CaptureResult.LENS_STATE);
-        waiverKeys.add(CaptureResult.LENS_APERTURE);
-        waiverKeys.add(CaptureResult.LENS_FILTER_DENSITY);
         waiverKeys.add(CaptureResult.SENSOR_ROLLING_SHUTTER_SKEW);
         waiverKeys.add(CaptureResult.STATISTICS_LENS_SHADING_MAP_MODE);
         waiverKeys.add(CaptureResult.STATISTICS_SCENE_FLICKER);
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/testcases/Camera2SurfaceViewTestCase.java b/tests/tests/hardware/src/android/hardware/camera2/cts/testcases/Camera2SurfaceViewTestCase.java
index 31fe8e3..bcc4061 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/testcases/Camera2SurfaceViewTestCase.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/testcases/Camera2SurfaceViewTestCase.java
@@ -34,6 +34,7 @@
 import android.hardware.camera2.CameraAccessException;
 import android.hardware.camera2.CameraCaptureSession;
 import android.hardware.camera2.CameraCaptureSession.CaptureCallback;
+import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraDevice;
 import android.hardware.camera2.CameraManager;
 import android.hardware.camera2.CameraMetadata;
@@ -679,8 +680,12 @@
             Long minDuration = mMinPreviewFrameDurationMap.get(size);
             if (minDuration == null ||
                     minDuration == 0) {
-                throw new IllegalArgumentException(
-                        "No min frame duration available for the selected format.");
+                if (mStaticInfo.isCapabilitySupported(
+                        CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) {
+                    throw new IllegalArgumentException(
+                            "No min frame duration available for the size " + size);
+                }
+                continue;
             }
             if (minDuration <= frameDurationRange[0]) {
                 return size;
diff --git a/tests/tests/os/AndroidManifest.xml b/tests/tests/os/AndroidManifest.xml
index 0599c89..f225903 100644
--- a/tests/tests/os/AndroidManifest.xml
+++ b/tests/tests/os/AndroidManifest.xml
@@ -43,16 +43,16 @@
     <uses-permission android:name="android.permission.CALL_PHONE" />
     <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
     <uses-permission android:name="android.permission.DEVICE_POWER" />
-    <uses-permission android:name="android.app.cts.permission.TEST_GRANTED" />
+    <uses-permission android:name="android.os.cts.permission.TEST_GRANTED" />
 
     <application>
-        <activity android:name="android.app.os.LaunchpadActivity"
+        <activity android:name="android.os.cts.LaunchpadActivity"
                   android:configChanges="keyboardHidden|orientation|screenSize"
                   android:multiprocess="true">
         </activity>
 
-        <activity android:name="android.app.os.AliasActivityStub">
-            <meta-data android:name="android.app.alias"
+        <activity android:name="android.os.cts.AliasActivityStub">
+            <meta-data android:name="android.os.alias"
                 android:resource="@xml/alias" />
         </activity>
 
diff --git a/tests/assets/alter-footer.zip b/tests/tests/os/assets/alter-footer.zip
similarity index 100%
rename from tests/assets/alter-footer.zip
rename to tests/tests/os/assets/alter-footer.zip
Binary files differ
diff --git a/tests/assets/alter-metadata.zip b/tests/tests/os/assets/alter-metadata.zip
similarity index 100%
rename from tests/assets/alter-metadata.zip
rename to tests/tests/os/assets/alter-metadata.zip
Binary files differ
diff --git a/tests/assets/fake-eocd.zip b/tests/tests/os/assets/fake-eocd.zip
similarity index 100%
rename from tests/assets/fake-eocd.zip
rename to tests/tests/os/assets/fake-eocd.zip
Binary files differ
diff --git a/tests/assets/jarsigned.zip b/tests/tests/os/assets/jarsigned.zip
similarity index 100%
rename from tests/assets/jarsigned.zip
rename to tests/tests/os/assets/jarsigned.zip
Binary files differ
diff --git a/tests/assets/random.zip b/tests/tests/os/assets/random.zip
similarity index 100%
rename from tests/assets/random.zip
rename to tests/tests/os/assets/random.zip
Binary files differ
diff --git a/tests/assets/unsigned.zip b/tests/tests/os/assets/unsigned.zip
similarity index 100%
rename from tests/assets/unsigned.zip
rename to tests/tests/os/assets/unsigned.zip
Binary files differ
diff --git a/tests/tests/os/res/xml/alias.xml b/tests/tests/os/res/xml/alias.xml
index f88f3dc..1166669 100644
--- a/tests/tests/os/res/xml/alias.xml
+++ b/tests/tests/os/res/xml/alias.xml
@@ -19,8 +19,8 @@
 
 <alias xmlns:android="http://schemas.android.com/apk/res/android">
     <intent android:action="android.intent.action.MAIN"
-        android:targetPackage="com.android.cts.stub"
-        android:targetClass="android.app.cts.ChildActivity"
+        android:targetPackage="com.android.cts.os"
+        android:targetClass="android.os.cts.ChildActivity"
         android:data="http://www.google.com/">
     </intent>
 </alias>
diff --git a/tests/tests/os/src/android/os/cts/LaunchpadActivity.java b/tests/tests/os/src/android/os/cts/LaunchpadActivity.java
index e812908..3919ece 100644
--- a/tests/tests/os/src/android/os/cts/LaunchpadActivity.java
+++ b/tests/tests/os/src/android/os/cts/LaunchpadActivity.java
@@ -79,36 +79,36 @@
     }
 
     // Also used as the Binder interface descriptor string in these tests
-    public static final String LAUNCH = "android.app.cts.activity.LAUNCH";
+    public static final String LAUNCH = "android.os.cts.activity.LAUNCH";
 
-    public static final String FORWARD_RESULT = "android.app.cts.activity.FORWARD_RESULT";
-    public static final String RETURNED_RESULT = "android.app.cts.activity.RETURNED_RESULT";
+    public static final String FORWARD_RESULT = "android.os.cts.activity.FORWARD_RESULT";
+    public static final String RETURNED_RESULT = "android.os.cts.activity.RETURNED_RESULT";
 
-    public static final String BAD_PARCELABLE = "android.app.cts.activity.BAD_PARCELABLE";
+    public static final String BAD_PARCELABLE = "android.os.cts.activity.BAD_PARCELABLE";
 
     public static final int LAUNCHED_RESULT = 1;
     public static final int FORWARDED_RESULT = 2;
 
-    public static final String LIFECYCLE_BASIC = "android.app.cts.activity.LIFECYCLE_BASIC";
-    public static final String LIFECYCLE_SCREEN = "android.app.cts.activity.LIFECYCLE_SCREEN";
-    public static final String LIFECYCLE_DIALOG = "android.app.cts.activity.LIFECYCLE_DIALOG";
+    public static final String LIFECYCLE_BASIC = "android.os.cts.activity.LIFECYCLE_BASIC";
+    public static final String LIFECYCLE_SCREEN = "android.os.cts.activity.LIFECYCLE_SCREEN";
+    public static final String LIFECYCLE_DIALOG = "android.os.cts.activity.LIFECYCLE_DIALOG";
 
-    public static final String BROADCAST_REGISTERED = "android.app.cts.activity.BROADCAST_REGISTERED";
-    public static final String BROADCAST_LOCAL = "android.app.cts.activity.BROADCAST_LOCAL";
-    public static final String BROADCAST_REMOTE = "android.app.cts.activity.BROADCAST_REMOTE";
-    public static final String BROADCAST_ALL = "android.app.cts.activity.BROADCAST_ALL";
-    public static final String BROADCAST_REPEAT = "android.app.cts.activity.BROADCAST_REPEAT";
-    public static final String BROADCAST_MULTI = "android.app.cts.activity.BROADCAST_MULTI";
-    public static final String BROADCAST_ABORT = "android.app.cts.activity.BROADCAST_ABORT";
+    public static final String BROADCAST_REGISTERED = "android.os.cts.activity.BROADCAST_REGISTERED";
+    public static final String BROADCAST_LOCAL = "android.os.cts.activity.BROADCAST_LOCAL";
+    public static final String BROADCAST_REMOTE = "android.os.cts.activity.BROADCAST_REMOTE";
+    public static final String BROADCAST_ALL = "android.os.cts.activity.BROADCAST_ALL";
+    public static final String BROADCAST_REPEAT = "android.os.cts.activity.BROADCAST_REPEAT";
+    public static final String BROADCAST_MULTI = "android.os.cts.activity.BROADCAST_MULTI";
+    public static final String BROADCAST_ABORT = "android.os.cts.activity.BROADCAST_ABORT";
 
     public static final String EXPANDLIST_SELECT = "EXPANDLIST_SELECT";
     public static final String EXPANDLIST_VIEW = "EXPANDLIST_VIEW";
     public static final String EXPANDLIST_CALLBACK = "EXPANDLIST_CALLBACK";
 
-    public static final String BROADCAST_STICKY1 = "android.app.cts.activity.BROADCAST_STICKY1";
-    public static final String BROADCAST_STICKY2 = "android.app.cts.activity.BROADCAST_STICKY2";
+    public static final String BROADCAST_STICKY1 = "android.os.cts.activity.BROADCAST_STICKY1";
+    public static final String BROADCAST_STICKY2 = "android.os.cts.activity.BROADCAST_STICKY2";
 
-    public static final String ALIAS_ACTIVITY = "android.app.cts.activity.ALIAS_ACTIVITY";
+    public static final String ALIAS_ACTIVITY = "android.os.cts.activity.ALIAS_ACTIVITY";
 
     public static final String RECEIVER_REG = "receiver-reg";
     public static final String RECEIVER_LOCAL = "receiver-local";
diff --git a/tests/tests/telephony/Android.mk b/tests/tests/telephony/Android.mk
index 676138d..e15d0d5 100644
--- a/tests/tests/telephony/Android.mk
+++ b/tests/tests/telephony/Android.mk
@@ -30,8 +30,6 @@
 
 LOCAL_PACKAGE_NAME := CtsTelephonyTestCases
 
-LOCAL_INSTRUMENTATION_FOR := CtsTestStubs
-
 # uncomment when b/13250611 is fixed
 #LOCAL_SDK_VERSION := current
 LOCAL_JAVA_LIBRARIES += android.test.runner
diff --git a/tests/tests/telephony/AndroidManifest.xml b/tests/tests/telephony/AndroidManifest.xml
index 36d1e5e..cd3864e 100644
--- a/tests/tests/telephony/AndroidManifest.xml
+++ b/tests/tests/telephony/AndroidManifest.xml
@@ -18,12 +18,20 @@
     package="com.android.cts.telephony">
 
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+    <uses-permission android:name="android.permission.READ_CONTACTS" />
+    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.SEND_SMS" />
+    <uses-permission android:name="android.permission.RECEIVE_SMS" />
+
     <application>
         <uses-library android:name="android.test.runner" />
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
-                     android:targetPackage="com.android.cts.stub"
+                     android:targetPackage="com.android.cts.telephony"
                      android:label="CTS tests of android.telephony">
         <meta-data android:name="listener"
             android:value="com.android.cts.runner.CtsTestRunListener" />
diff --git a/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java b/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
index 61b97b2..e58d26f 100644
--- a/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/CellLocationTest.java
@@ -18,7 +18,6 @@
 
 import android.content.Context;
 import android.os.Looper;
-import android.os.cts.TestThread;
 import android.telephony.CellLocation;
 import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;
diff --git a/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java b/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
index bfc4c85..b084245 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneStateListenerTest.java
@@ -17,7 +17,6 @@
 
 import android.content.Context;
 import android.os.Looper;
-import android.os.cts.TestThread;
 import android.telephony.CellLocation;
 import android.telephony.PhoneStateListener;
 import android.telephony.ServiceState;
diff --git a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
index 9986e67..803baec 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
@@ -24,7 +24,6 @@
 import android.net.wifi.WifiManager;
 import android.os.Build;
 import android.os.Looper;
-import android.os.cts.TestThread;
 import android.telephony.CellLocation;
 import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;
diff --git a/tests/tests/telephony/src/android/telephony/cts/TestThread.java b/tests/tests/telephony/src/android/telephony/cts/TestThread.java
new file mode 100644
index 0000000..9bf40de
--- /dev/null
+++ b/tests/tests/telephony/src/android/telephony/cts/TestThread.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 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.telephony.cts;
+
+/**
+ * Thread class for executing a Runnable containing assertions in a separate thread.
+ * Uncaught exceptions in the Runnable are rethrown in the context of the the thread
+ * calling the <code>runTest()</code> method.
+ */
+public final class TestThread extends Thread {
+    private Throwable mThrowable;
+    private Runnable mTarget;
+
+    public TestThread(Runnable target) {
+        mTarget = target;
+    }
+
+    @Override
+    public final void run() {
+        try {
+            mTarget.run();
+        } catch (Throwable t) {
+            mThrowable = t;
+        }
+    }
+
+    /**
+     * Run the target Runnable object and wait until the test finish or throw
+     * out Exception if test fail.
+     *
+     * @param runTime
+     * @throws Throwable
+     */
+    public void runTest(long runTime) throws Throwable {
+        start();
+        joinAndCheck(runTime);
+    }
+
+    /**
+     * Get the Throwable object which is thrown when test running
+     * @return  The Throwable object
+     */
+    public Throwable getThrowable() {
+        return mThrowable;
+    }
+
+    /**
+     * Set the Throwable object which is thrown when test running
+     * @param t The Throwable object
+     */
+    public void setThrowable(Throwable t) {
+        mThrowable = t;
+    }
+
+    /**
+     * Wait for the test thread to complete and throw the stored exception if there is one.
+     *
+     * @param runTime The time to wait for the test thread to complete.
+     * @throws Throwable
+     */
+    public void joinAndCheck(long runTime) throws Throwable {
+        this.join(runTime);
+        if (this.isAlive()) {
+            this.interrupt();
+            this.join(runTime);
+            throw new Exception("Thread did not finish within allotted time.");
+        }
+        checkException();
+    }
+
+    /**
+     * Check whether there is an exception when running Runnable object.
+     * @throws Throwable
+     */
+    public void checkException() throws Throwable {
+        if (mThrowable != null) {
+            throw mThrowable;
+        }
+    }
+}