Merge "Fix MediaStore_Video_MediaTest Again" into honeycomb
diff --git a/tests/SignatureTest/Android.mk b/tests/SignatureTest/Android.mk
index 18c7cea..4166002 100644
--- a/tests/SignatureTest/Android.mk
+++ b/tests/SignatureTest/Android.mk
@@ -20,7 +20,7 @@
 # and when built explicitly put it in the data partition
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
diff --git a/tests/SignatureTest/AndroidManifest.xml b/tests/SignatureTest/AndroidManifest.xml
index 696dc57..762dfae 100644
--- a/tests/SignatureTest/AndroidManifest.xml
+++ b/tests/SignatureTest/AndroidManifest.xml
@@ -30,10 +30,16 @@
             </intent-filter>
         </activity>
 
+        <uses-library android:name="android.test.runner" />
     </application>
 
     <instrumentation android:name=".InstrumentationRunner"
                      android:targetPackage="android.tests.sigtest"
                      android:label="API Signature Test"/>
 
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+        android:targetPackage="android.tests.sigtest"
+        android:label="Simple API Signature Test">
+    </instrumentation>
+
 </manifest>
diff --git a/tests/SignatureTest/src/android/tests/sigtest/SimpleSignatureTest.java b/tests/SignatureTest/src/android/tests/sigtest/SimpleSignatureTest.java
new file mode 100644
index 0000000..c206c9a
--- /dev/null
+++ b/tests/SignatureTest/src/android/tests/sigtest/SimpleSignatureTest.java
@@ -0,0 +1,324 @@
+/*
+ * Copyright (C) 2011 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.tests.sigtest;
+
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+import android.tests.sigtest.JDiffClassDescription.JDiffConstructor;
+import android.tests.sigtest.JDiffClassDescription.JDiffField;
+import android.tests.sigtest.JDiffClassDescription.JDiffMethod;
+import android.tests.sigtest.SignatureTestActivity.FAILURE_TYPE;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * A simpler version of {@link SignatureTest} that performs the signature check via a JUnit test.
+ * <p/>
+ * Eventually the existing  {@link SignatureTest} and {@link SignatureActivity} will be deleted
+ * once the move to a tradefederation based CTS harness is complete.
+ */
+public class SimpleSignatureTest extends AndroidTestCase {
+
+    private static final String TAG_ROOT = "api";
+    private static final String TAG_PACKAGE = "package";
+    private static final String TAG_CLASS = "class";
+    private static final String TAG_INTERFACE = "interface";
+    private static final String TAG_IMPLEMENTS = "implements";
+    private static final String TAG_CONSTRUCTOR = "constructor";
+    private static final String TAG_METHOD = "method";
+    private static final String TAG_PARAM = "parameter";
+    private static final String TAG_EXCEPTION = "exception";
+    private static final String TAG_FIELD = "field";
+
+    private static final String MODIFIER_ABSTRACT = "abstract";
+    private static final String MODIFIER_FINAL = "final";
+    private static final String MODIFIER_NATIVE = "native";
+    private static final String MODIFIER_PRIVATE = "private";
+    private static final String MODIFIER_PROTECTED = "protected";
+    private static final String MODIFIER_PUBLIC = "public";
+    private static final String MODIFIER_STATIC = "static";
+    private static final String MODIFIER_SYNCHRONIZED = "synchronized";
+    private static final String MODIFIER_TRANSIENT = "transient";
+    private static final String MODIFIER_VOLATILE = "volatile";
+    private static final String MODIFIER_VISIBILITY = "visibility";
+
+    private static final String ATTRIBUTE_NAME = "name";
+    private static final String ATTRIBUTE_EXTENDS = "extends";
+    private static final String ATTRIBUTE_TYPE = "type";
+    private static final String ATTRIBUTE_RETURN = "return";
+
+    private static ArrayList<String> mDebugArray = new ArrayList<String>();
+
+    private HashSet<String> mKeyTagSet;
+    private TestResultObserver mResultObserver;
+
+    private class TestResultObserver implements ResultObserver {
+        boolean mDidFail = false;
+        StringBuilder mErrorString = new StringBuilder();
+
+        public void notifyFailure(FAILURE_TYPE type, String name, String errorMessage) {
+            mDidFail = true;
+            mErrorString.append("\n");
+            mErrorString.append(type.toString().toLowerCase());
+            mErrorString.append(":\t");
+            mErrorString.append(name);
+        }
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mKeyTagSet = new HashSet<String>();
+        mKeyTagSet.addAll(Arrays.asList(new String[] {
+                TAG_PACKAGE, TAG_CLASS, TAG_INTERFACE, TAG_IMPLEMENTS, TAG_CONSTRUCTOR,
+                TAG_METHOD, TAG_PARAM, TAG_EXCEPTION, TAG_FIELD }));
+        mResultObserver = new TestResultObserver();
+    }
+
+    /**
+     * Tests that the device's API matches the expected set defined in xml.
+     * <p/>
+     * Will check the entire API, and then report the complete list of failures
+     */
+    public void testSignature() {
+        Resources r = getContext().getResources();
+        Class rClass = R.xml.class;
+        Field[] fs = rClass.getFields();
+        for (Field f : fs) {
+            try {
+                start(r.getXml(f.getInt(rClass)));
+            } catch (Exception e) {
+                mResultObserver.notifyFailure(FAILURE_TYPE.CAUGHT_EXCEPTION, e.getMessage(),
+                        e.getMessage());
+            }
+        }
+        if (mResultObserver.mDidFail) {
+            fail(mResultObserver.mErrorString.toString());
+        }
+    }
+
+    private  void beginDocument(XmlPullParser parser, String firstElementName)
+            throws XmlPullParserException, IOException {
+        int type;
+        while ((type=parser.next()) != XmlPullParser.START_TAG
+                   && type != XmlPullParser.END_DOCUMENT) { }
+
+        if (type != XmlPullParser.START_TAG) {
+            throw new XmlPullParserException("No start tag found");
+        }
+
+        if (!parser.getName().equals(firstElementName)) {
+            throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
+                    ", expected " + firstElementName);
+        }
+    }
+
+    /**
+     * Signature test entry point.
+     */
+    private void start(XmlPullParser parser) throws XmlPullParserException, IOException {
+        JDiffClassDescription currentClass = null;
+        String currentPackage = "";
+        JDiffMethod currentMethod = null;
+
+        beginDocument(parser, TAG_ROOT);
+        int type;
+        while (true) {
+            type = XmlPullParser.START_DOCUMENT;
+            while ((type=parser.next()) != XmlPullParser.START_TAG
+                       && type != XmlPullParser.END_DOCUMENT
+                       && type != XmlPullParser.END_TAG) {
+
+            }
+
+            if (type == XmlPullParser.END_TAG) {
+                if (TAG_CLASS.equals(parser.getName())
+                        || TAG_INTERFACE.equals(parser.getName())) {
+                    currentClass.checkSignatureCompliance();
+                } else if (TAG_PACKAGE.equals(parser.getName())) {
+                    currentPackage = "";
+                }
+                continue;
+            }
+
+            if (type == XmlPullParser.END_DOCUMENT) {
+                break;
+            }
+
+            String tagname = parser.getName();
+            if (!mKeyTagSet.contains(tagname)) {
+                continue;
+            }
+
+            if (type == XmlPullParser.START_TAG && tagname.equals(TAG_PACKAGE)) {
+                currentPackage = parser.getAttributeValue(null, ATTRIBUTE_NAME);
+            } else if (tagname.equals(TAG_CLASS)) {
+                currentClass = loadClassInfo(parser, false, currentPackage);
+            } else if (tagname.equals(TAG_INTERFACE)) {
+                currentClass = loadClassInfo(parser, true, currentPackage);
+            } else if (tagname.equals(TAG_IMPLEMENTS)) {
+                currentClass.addImplInterface(parser.getAttributeValue(null, ATTRIBUTE_NAME));
+            } else if (tagname.equals(TAG_CONSTRUCTOR)) {
+                JDiffConstructor constructor = loadConstructorInfo(parser, currentClass);
+                currentClass.addConstructor(constructor);
+                currentMethod = constructor;
+            } else if (tagname.equals(TAG_METHOD)) {
+                currentMethod = loadMethodInfo(currentClass.getClassName(), parser);
+                currentClass.addMethod(currentMethod);
+            } else if (tagname.equals(TAG_PARAM)) {
+                currentMethod.addParam(parser.getAttributeValue(null, ATTRIBUTE_TYPE));
+            } else if (tagname.equals(TAG_EXCEPTION)) {
+                currentMethod.addException(parser.getAttributeValue(null, ATTRIBUTE_TYPE));
+            } else if (tagname.equals(TAG_FIELD)) {
+                JDiffField field = loadFieldInfo(currentClass.getClassName(), parser);
+                currentClass.addField(field);
+            } else {
+                throw new RuntimeException(
+                        "unknow tag exception:" + tagname);
+            }
+        }
+    }
+
+    /**
+     * Load field information from xml to memory.
+     *
+     * @param className of the class being examined which will be shown in error messages
+     * @param parser The XmlPullParser which carries the xml information.
+     * @return the new field
+     */
+    private JDiffField loadFieldInfo(String className, XmlPullParser parser) {
+        String fieldName = parser.getAttributeValue(null, ATTRIBUTE_NAME);
+        String fieldType = parser.getAttributeValue(null, ATTRIBUTE_TYPE);
+        int modifier = jdiffModifierToReflectionFormat(className, parser);
+        return new JDiffField(fieldName, fieldType, modifier);
+    }
+
+    /**
+     * Load method information from xml to memory.
+     *
+     * @param className of the class being examined which will be shown in error messages
+     * @param parser The XmlPullParser which carries the xml information.
+     * @return the newly loaded method.
+     */
+    private JDiffMethod loadMethodInfo(String className, XmlPullParser parser) {
+        String methodName = parser.getAttributeValue(null, ATTRIBUTE_NAME);
+        String returnType = parser.getAttributeValue(null, ATTRIBUTE_RETURN);
+        int modifier = jdiffModifierToReflectionFormat(className, parser);
+        return new JDiffMethod(methodName, modifier, returnType);
+    }
+
+    /**
+     * Load constructor information from xml to memory.
+     *
+     * @param parser The XmlPullParser which carries the xml information.
+     * @param currentClass the current class being loaded.
+     * @return the new constructor
+     */
+    private JDiffConstructor loadConstructorInfo(XmlPullParser parser,
+                                                 JDiffClassDescription currentClass) {
+        String name = currentClass.getClassName();
+        int modifier = jdiffModifierToReflectionFormat(name, parser);
+        return new JDiffConstructor(name, modifier);
+    }
+
+    /**
+     * Load class or interface information to memory.
+     *
+     * @param parser The XmlPullParser which carries the xml information.
+     * @param isInterface true if the current class is an interface, otherwise is false.
+     * @param pkg the name of the java package this class can be found in.
+     * @return the new class description.
+     */
+    private JDiffClassDescription loadClassInfo(XmlPullParser parser,
+                                                boolean isInterface,
+                                                String pkg) {
+        String className = parser.getAttributeValue(null, ATTRIBUTE_NAME);
+        JDiffClassDescription currentClass = new JDiffClassDescription(pkg,
+                                                                       className,
+                                                                       mResultObserver);
+        currentClass.setModifier(jdiffModifierToReflectionFormat(className, parser));
+        currentClass.setType(isInterface ? JDiffClassDescription.JDiffType.INTERFACE :
+                             JDiffClassDescription.JDiffType.CLASS);
+        currentClass.setExtendsClass(parser.getAttributeValue(null, ATTRIBUTE_EXTENDS));
+        return currentClass;
+    }
+
+    /**
+     * Convert string modifier to int modifier.
+     *
+     * @param name of the class/method/field being examined which will be shown in error messages
+     * @param key modifier name
+     * @param value modifier value
+     * @return converted modifier value
+     */
+    private static int modifierDescriptionToReflectedType(String name, String key, String value) {
+        if (key.equals(MODIFIER_ABSTRACT)) {
+            return value.equals("true") ? Modifier.ABSTRACT : 0;
+        } else if (key.equals(MODIFIER_FINAL)) {
+            return value.equals("true") ? Modifier.FINAL : 0;
+        } else if (key.equals(MODIFIER_NATIVE)) {
+            return value.equals("true") ? Modifier.NATIVE : 0;
+        } else if (key.equals(MODIFIER_STATIC)) {
+            return value.equals("true") ? Modifier.STATIC : 0;
+        } else if (key.equals(MODIFIER_SYNCHRONIZED)) {
+            return value.equals("true") ? Modifier.SYNCHRONIZED : 0;
+        } else if (key.equals(MODIFIER_TRANSIENT)) {
+            return value.equals("true") ? Modifier.TRANSIENT : 0;
+        } else if (key.equals(MODIFIER_VOLATILE)) {
+            return value.equals("true") ? Modifier.VOLATILE : 0;
+        } else if (key.equals(MODIFIER_VISIBILITY)) {
+            if (value.equals(MODIFIER_PRIVATE)) {
+                throw new RuntimeException("Private visibility found in API spec: " + name);
+            } else if (value.equals(MODIFIER_PROTECTED)) {
+                return Modifier.PROTECTED;
+            } else if (value.equals(MODIFIER_PUBLIC)) {
+                return Modifier.PUBLIC;
+            } else if ("".equals(value)) {
+                // If the visibility is "", it means it has no modifier.
+                // which is package private. We should return 0 for this modifier.
+                return 0;
+            } else {
+                throw new RuntimeException("Unknown modifier found in API spec: " + value);
+            }
+        }
+        return 0;
+    }
+
+    /**
+     * Transfer string modifier to int one.
+     *
+     * @param name of the class/method/field being examined which will be shown in error messages
+     * @param parser XML resource parser
+     * @return converted modifier
+     */
+    private static int jdiffModifierToReflectionFormat(String name, XmlPullParser parser){
+        int modifier = 0;
+        for (int i = 0;i < parser.getAttributeCount();i++) {
+            modifier |= modifierDescriptionToReflectedType(name, parser.getAttributeName(i),
+                    parser.getAttributeValue(i));
+        }
+        return modifier;
+    }
+}
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerTest.java b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
index 46e3287..b4b8da4 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
@@ -561,44 +561,27 @@
                 assertEquals(k - 1, mAudioManager.getStreamVolume(streams[i]));
             }
 
+            // test ringer modes changes
             mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
             assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
             mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
             assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
-            if (streams[i] == AudioManager.STREAM_RING) {
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
-                assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
-                // adjusting the volume to zero should result in either silent or vibrate mode
-                assertTrue(mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE ||
-                        mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
-                mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
-                assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
-                assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
-            } else {
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
-                assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
-                // lowering the volume should NOT have changed the ringer mode
-                assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
-                // API quirk: volume must be decremented from 1 to get ringer mode change
-                mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
-                // lowering the volume should have changed the ringer mode
-                assertTrue(mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE ||
-                        mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
-                // adjusting the volume to zero should result in either silent or vibrate mode
-                assertTrue(mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE ||
-                        mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
-                // There are two possible ways the device may work. It may have a silent/vibrate
-                // mode or it may have distinct silent and vibrate modes.
-                assertTrue(mAudioManager.getRingerMode() == RINGER_MODE_NORMAL ||
-                        mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE);
-                // Increase the volume one more time to get out of the vibrate mode which may
-                // be separate from silent mode.
-                mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
-                assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
-            }
+
+            // decreasing the volume from 1 to 0 shouldn't change ringer modes
+            adjustStreamVolumeAndRingerMode(streams[i], ADJUST_LOWER);
+            assertEquals("Stream: " + i, 0, mAudioManager.getStreamVolume(streams[i]));
+            assertEquals("Stream: " + i, RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
+
+            // decreasing the volume from 0 should change ringer modes
+            adjustStreamVolumeAndRingerMode(streams[i], ADJUST_LOWER);
+            assertEquals("Stream: " + i, 0, mAudioManager.getStreamVolume(streams[i]));
+            assertTrue("Stream: " + i, mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
+                    || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
+
+            // increasing the volume from 0 should change back to normal
+            adjustStreamVolumeAndRingerMode(streams[i], ADJUST_RAISE);
+            assertEquals("Stream: " + i, 0, mAudioManager.getStreamVolume(streams[i]));
+            assertTrue("Stream: " + i, mAudioManager.getRingerMode() == RINGER_MODE_NORMAL);
 
             // volume raise
             mAudioManager.setStreamVolume(streams[i], 0, FLAG_SHOW_UI);
@@ -653,6 +636,17 @@
         assertFalse(mAudioManager.isMusicActive());
     }
 
+    /**
+     * Imitate how pressing the volume key adjusts the volume either up or down and releasing the
+     * key causes an ADJUST_SAME direction afterwards.
+     */
+    private void adjustStreamVolumeAndRingerMode(int streamType, int direction) {
+        mAudioManager.adjustStreamVolume(streamType, direction,
+                FLAG_SHOW_UI | FLAG_ALLOW_RINGER_MODES);
+        mAudioManager.adjustStreamVolume(streamType, ADJUST_SAME,
+                FLAG_SHOW_UI | FLAG_ALLOW_RINGER_MODES);
+    }
+
     public void setResult(int resultCode) {
         mSync.notifyResult();
         mResultCode = resultCode;
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
index 25c75e2..4811a93 100644
--- a/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsManagerTest.java
@@ -129,7 +129,9 @@
     })
     public void testSendMessages() throws InterruptedException {
         PackageManager packageManager = getContext().getPackageManager();
-        boolean hasTelephony = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
+        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
 
         mSendIntent = new Intent(SMS_SEND_ACTION);
         mDeliveryIntent = new Intent(SMS_DELIVERY_ACTION);
@@ -148,7 +150,7 @@
         sendTextMessage(mDestAddr, mDestAddr, mSentIntent, mDeliveredIntent);
         assertTrue(mSendReceiver.waitForCalls(1, TIME_OUT));
         if (mDeliveryReportSupported) {
-            assertEquals(hasTelephony, mDeliveryReceiver.waitForCalls(1, TIME_OUT));
+            assertTrue(mDeliveryReceiver.waitForCalls(1, TIME_OUT));
         }
 
         if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
@@ -164,7 +166,7 @@
         sendDataMessage(mDestAddr, port, data, mSentIntent, mDeliveredIntent);
         assertTrue(mSendReceiver.waitForCalls(1, TIME_OUT));
         if (mDeliveryReportSupported) {
-            assertEquals(hasTelephony, mDeliveryReceiver.waitForCalls(1, TIME_OUT));
+            assertTrue(mDeliveryReceiver.waitForCalls(1, TIME_OUT));
         }
 
         // send multi parts text sms
@@ -180,7 +182,7 @@
         sendMultiPartTextMessage(mDestAddr, parts, sentIntents, deliveryIntents);
         assertTrue(mSendReceiver.waitForCalls(numParts, TIME_OUT));
         if (mDeliveryReportSupported) {
-            assertEquals(hasTelephony, mDeliveryReceiver.waitForCalls(numParts, TIME_OUT));
+            assertTrue(mDeliveryReceiver.waitForCalls(numParts, TIME_OUT));
         }
     }
 
diff --git a/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java b/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java
index 515f8b5..8c6ad01 100644
--- a/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/SmsMessageTest.java
@@ -22,6 +22,7 @@
 import dalvik.annotation.TestTargets;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.telephony.SmsMessage;
 import android.telephony.TelephonyManager;
 import android.test.AndroidTestCase;
@@ -30,6 +31,7 @@
 public class SmsMessageTest extends AndroidTestCase{
 
     private TelephonyManager mTelephonyManager;
+    private PackageManager mPackageManager;
 
     private static final String DISPLAY_MESSAGE_BODY = "test subject /test body";
     private static final String DMB = "{ testBody[^~\\] }";
@@ -69,7 +71,7 @@
         super.setUp();
         mTelephonyManager =
             (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
-        assertNotNull(mTelephonyManager);
+        mPackageManager = getContext().getPackageManager();
     }
 
     @SuppressWarnings("deprecation")
@@ -171,10 +173,12 @@
         )
     })
     public void testCreateFromPdu() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
+                || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)) {
             // TODO: temp workaround, need to adjust test to use CDMA pdus
             return;
         }
+
         String pdu = "07916164260220F0040B914151245584F600006060605130308A04D4F29C0E";
         SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
         assertEquals(SCA1, sms.getServiceCenterAddress());
@@ -254,7 +258,8 @@
         )
     })
     public void testCPHSVoiceMail() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
+                || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)) {
             // TODO: temp workaround, need to adjust test to use CDMA pdus
             return;
         }
@@ -302,7 +307,8 @@
         )
     })
     public void testGetUserData() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
+                || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)) {
             // TODO: temp workaround, need to adjust test to use CDMA pdus
             return;
         }
@@ -331,6 +337,10 @@
         )
     })
     public void testGetSubmitPdu() throws Exception {
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            return;
+        }
+
         String scAddress = null, destinationAddress = null;
         String message = null;
         boolean statusReportRequested = false;
@@ -403,10 +413,12 @@
         )
     })
     public void testEmailGateway() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+        if (!mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)
+                || mPackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)) {
             // TODO: temp workaround, need to adjust test to use CDMA pdus
             return;
         }
+
         String pdu = "07914151551512f204038105f300007011103164638a28e6f71b50c687db" +
                          "7076d9357eb7412f7a794e07cdeb6275794c07bde8e5391d247e93f3";
 
diff --git a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
index 4cfddb1..603c725 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
@@ -296,7 +296,6 @@
                 break;
 
             case TelephonyManager.PHONE_TYPE_NONE:
-                assertNull(deviceId);
                 assertSerialNumber();
                 assertMacAddressReported();
                 break;
diff --git a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessageTest.java b/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessageTest.java
deleted file mode 100644
index 8b26880..0000000
--- a/tests/tests/telephony/src/android/telephony/gsm/cts/SmsMessageTest.java
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * Copyright (C) 2008 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.gsm.cts;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import android.content.Context;
-import android.telephony.TelephonyManager;
-import android.telephony.gsm.SmsMessage;
-import android.test.AndroidTestCase;
-
-@SuppressWarnings("deprecation")
-@TestTargetClass(SmsMessage.class)
-public class SmsMessageTest extends AndroidTestCase{
-
-    private TelephonyManager mTelephonyManager;
-
-    private static final String DISPLAY_MESSAGE_BODY = "test subject /test body";
-    private static final String DMB = "{ testBody[^~\\] }";
-    private static final String EMAIL_ADD = "foo@example.com";
-    private static final String EMAIL_FROM = "foo@example.com";
-    private static final String MB = DMB;
-    private static final String MESSAGE_BODY1 = "Test";
-    private static final String MESSAGE_BODY2 = "(Subject)Test";
-    private static final String MESSAGE_BODY3 = "\u2122\u00a9\u00aehello";
-    private static final String MESSAGE_BODY4 = " ";
-    private static final String MESSAGE_BODY5 = " ";
-    private static final String OA = "foo@example.com";
-    private static final String OA1 = "+14154255486";
-    private static final String OA2 = "+15122977683";
-    private static final String OA3 = "_@";
-    private static final String OA4 = "\u0394@";
-    // pseudo subject will always be empty
-    private static final String PSEUDO_SUBJECT = "";
-    private static final String SCA1 = "+16466220020";
-    private static final String SCA2 = "+12063130012";
-    private static final String SCA3 = "+14155551212";
-    private static final String SCA4 = "+14155551212";
-    private static final int NOT_CREATE_FROM_SIM = -1;
-    private static final int PROTOCOL_IDENTIFIER = 0;
-    private static final int SMS_NUMBER1 = 1;
-    private static final int SMS_NUMBER2 = 1;
-    private static final int SMS_NUMBER3 = 1;
-    private static final int STATUS = 0;
-    private static final int STATUS_ON_SIM_DEF = -1;
-    private static final int TPLAYER_LENGTH_FOR_PDU = 23;
-    private static final long TIMESTAMP_MILLIS = 1149631383000l;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mTelephonyManager =
-            (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
-        assertNotNull(mTelephonyManager);
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "createFromPdu",
-            args = {byte[].class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getServiceCenterAddress",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getOriginatingAddress",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getTPLayerLengthForPDU",
-            args = {String.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getMessageBody",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "calculateLength",
-            args = {CharSequence.class, boolean.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "calculateLength",
-            args = {String.class, boolean.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getPdu",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isEmail",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isCphsMwiMessage",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isMwiDontStore",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isReplyPathPresent",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isStatusReportMessage",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getProtocolIdentifier",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getIndexOnSim",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getMessageClass",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getStatus",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getStatusOnSim",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getTimestampMillis",
-            args = {}
-        )
-    })
-    public void testCreateFromPdu() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
-            // TODO: temp workaround, need to adjust test to use CDMA pdus
-            return;
-        }
-
-        String pdu = "07916164260220F0040B914151245584F600006060605130308A04D4F29C0E";
-        SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertEquals(SCA1, sms.getServiceCenterAddress());
-        assertEquals(OA1, sms.getOriginatingAddress());
-        assertEquals(MESSAGE_BODY1, sms.getMessageBody());
-        assertEquals(TPLAYER_LENGTH_FOR_PDU, SmsMessage.getTPLayerLengthForPDU(pdu));
-        int[] result = SmsMessage.calculateLength(sms.getMessageBody(), true);
-        assertEquals(SMS_NUMBER1, result[0]);
-        assertEquals(sms.getMessageBody().length(), result[1]);
-        assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
-        assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
-        assertEquals(pdu, toHexString(sms.getPdu()));
-
-        assertEquals(NOT_CREATE_FROM_SIM, sms.getIndexOnSim());
-        assertEquals(PROTOCOL_IDENTIFIER, sms.getProtocolIdentifier());
-        assertFalse(sms.isEmail());
-        assertFalse(sms.isReplyPathPresent());
-        assertFalse(sms.isStatusReportMessage());
-        assertFalse(sms.isCphsMwiMessage());
-        assertEquals(SmsMessage.MessageClass.UNKNOWN, sms.getMessageClass());
-        assertEquals(STATUS, sms.getStatus());
-        assertEquals(STATUS_ON_SIM_DEF, sms.getStatusOnSim());
-        assertEquals(TIMESTAMP_MILLIS, sms.getTimestampMillis());
-
-        // Test create from null Pdu
-        sms = SmsMessage.createFromPdu(null);
-        assertNotNull(sms);
-
-        //Test create from long Pdu
-        pdu = "07912160130310F2040B915121927786F300036060924180008A0DA"
-            + "8695DAC2E8FE9296A794E07";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertEquals(SCA2, sms.getServiceCenterAddress());
-        assertEquals(OA2, sms.getOriginatingAddress());
-        assertEquals(MESSAGE_BODY2, sms.getMessageBody());
-        CharSequence msgBody = (CharSequence) sms.getMessageBody();
-        result = SmsMessage.calculateLength(msgBody, false);
-        assertEquals(SMS_NUMBER2, result[0]);
-        assertEquals(sms.getMessageBody().length(), result[1]);
-        assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
-        assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
-
-        // Test createFromPdu Ucs to Sms
-        pdu = "07912160130300F4040B914151245584"
-            + "F600087010807121352B10212200A900AE00680065006C006C006F";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertEquals(MESSAGE_BODY3, sms.getMessageBody());
-        result = SmsMessage.calculateLength(sms.getMessageBody(), true);
-        assertEquals(SMS_NUMBER3, result[0]);
-        assertEquals(sms.getMessageBody().length(), result[1]);
-        assertEquals(SmsMessage.MAX_USER_DATA_SEPTETS - sms.getMessageBody().length(), result[2]);
-        assertEquals(SmsMessage.ENCODING_7BIT, result[3]);
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isReplace",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isMWISetMessage",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isMWIClearMessage",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isMwiDontStore",
-            args = {}
-        )
-    })
-    public void testCPHSVoiceMail() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
-            // TODO: temp workaround, need to adjust test to use CDMA pdus
-            return;
-        }
-
-        // "set MWI flag"
-        String pdu = "07912160130310F20404D0110041006060627171118A0120";
-        SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertTrue(sms.isReplace());
-        assertEquals(OA3, sms.getOriginatingAddress());
-        assertEquals(MESSAGE_BODY4, sms.getMessageBody());
-        assertTrue(sms.isMWISetMessage());
-
-        // "clear mwi flag"
-        pdu = "07912160130310F20404D0100041006021924193352B0120";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertTrue(sms.isMWIClearMessage());
-
-        // "clear MWI flag"
-        pdu = "07912160130310F20404D0100041006060627161058A0120";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertTrue(sms.isReplace());
-        assertEquals(OA4, sms.getOriginatingAddress());
-        assertEquals(MESSAGE_BODY5, sms.getMessageBody());
-        assertTrue(sms.isMWIClearMessage());
-
-        // "set MWI flag"
-        pdu = "07912180958750F84401800500C87020026195702B06040102000200";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertTrue(sms.isMWISetMessage());
-        assertTrue(sms.isMwiDontStore());
-
-        // "clear mwi flag"
-        pdu = "07912180958750F84401800500C07020027160112B06040102000000";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-
-        assertTrue(sms.isMWIClearMessage());
-        assertTrue(sms.isMwiDontStore());
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getUserData",
-            args = {}
-        )
-    })
-    public void testGetUserData() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
-            // TODO: temp workaround, need to adjust test to use CDMA pdus
-            return;
-        }
-
-        String pdu = "07914140279510F6440A8111110301003BF56080207130138A8C0B05040B8423F"
-            + "000032A02010106276170706C69636174696F6E2F766E642E7761702E6D6D732D"
-            + "6D65737361676500AF848D0185B4848C8298524E453955304A6D7135514141426"
-            + "66C414141414D7741414236514141414141008D908918802B3135313232393737"
-            + "3638332F545950453D504C4D4E008A808E022B918805810306977F83687474703"
-            + "A2F2F36";
-        SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        byte[] userData = sms.getUserData();
-        assertNotNull(userData);
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getSubmitPdu",
-            args = {String.class, String.class, String.class, boolean.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getSubmitPdu",
-            args = {String.class, String.class, short.class, byte[].class, boolean.class}
-        )
-    })
-    public void testGetSubmitPdu() throws Exception {
-        String scAddress = null, destinationAddress = null;
-        String message = null;
-        boolean statusReportRequested = false;
-
-        try {
-            // null message, null destination
-            SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException expected) {
-            // expected
-        }
-
-        message = "This is a test message";
-        try {
-            // non-null message
-            SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException expected) {
-            // expected
-        }
-
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
-            // TODO: temp workaround, OCTET encoding for EMS not properly supported
-            return;
-        }
-
-        scAddress = "1650253000";
-        destinationAddress = "18004664411";
-        message = "This is a test message";
-        statusReportRequested = false;
-        SmsMessage.SubmitPdu smsPdu =
-            SmsMessage.getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested);
-        assertNotNull(smsPdu);
-
-        smsPdu = SmsMessage.getSubmitPdu(scAddress, destinationAddress, (short)80,
-                message.getBytes(), statusReportRequested);
-        assertNotNull(smsPdu);
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getEmailBody",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getEmailFrom",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getDisplayMessageBody",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getPseudoSubject",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getDisplayOriginatingAddress",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "isEmail",
-            args = {}
-        )
-    })
-    public void testEmailGateway() throws Exception {
-        if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
-            // TODO: temp workaround, need to adjust test to use CDMA pdus
-            return;
-        }
-        String pdu = "07914151551512f204038105f300007011103164638a28e6f71b50c687db" +
-                         "7076d9357eb7412f7a794e07cdeb6275794c07bde8e5391d247e93f3";
-
-        SmsMessage sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertEquals(SCA4, sms.getServiceCenterAddress());
-        assertTrue(sms.isEmail());
-        assertEquals(EMAIL_ADD, sms.getEmailFrom());
-        assertEquals(EMAIL_ADD, sms.getDisplayOriginatingAddress());
-        assertEquals(PSEUDO_SUBJECT, sms.getPseudoSubject());
-
-        assertEquals(DISPLAY_MESSAGE_BODY, sms.getDisplayMessageBody());
-        assertEquals(DISPLAY_MESSAGE_BODY, sms.getEmailBody());
-
-        pdu = "07914151551512f204038105f400007011103105458a29e6f71b50c687db" +
-                        "7076d9357eb741af0d0a442fcfe9c23739bfe16d289bdee6b5f1813629";
-        sms = SmsMessage.createFromPdu(hexStringToByteArray(pdu));
-        assertEquals(SCA3, sms.getServiceCenterAddress());
-        assertTrue(sms.isEmail());
-        assertEquals(OA, sms.getDisplayOriginatingAddress());
-        assertEquals(EMAIL_FROM, sms.getEmailFrom());
-        assertEquals(DMB, sms.getDisplayMessageBody());
-        assertEquals(MB, sms.getEmailBody());
-    }
-
-    private final static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
-            'A', 'B', 'C', 'D', 'E', 'F' };
-
-    public static String toHexString(byte[] array) {
-        int length = array.length;
-        char[] buf = new char[length * 2];
-
-        int bufIndex = 0;
-        for (int i = 0 ; i < length; i++)
-        {
-            byte b = array[i];
-            buf[bufIndex++] = HEX_DIGITS[(b >>> 4) & 0x0F];
-            buf[bufIndex++] = HEX_DIGITS[b & 0x0F];
-        }
-
-        return new String(buf);
-    }
-
-    private static int toByte(char c) {
-        if (c >= '0' && c <= '9') return (c - '0');
-        if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
-        if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
-
-        throw new RuntimeException ("Invalid hex char '" + c + "'");
-    }
-
-    private static byte[] hexStringToByteArray(String hexString) {
-        int length = hexString.length();
-        byte[] buffer = new byte[length / 2];
-
-        for (int i = 0 ; i < length ; i += 2) {
-            buffer[i / 2] =
-                (byte)((toByte(hexString.charAt(i)) << 4) | toByte(hexString.charAt(i+1)));
-        }
-
-        return buffer;
-    }
-}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/InstrumentationAppTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/InstrumentationAppTest.java
new file mode 100644
index 0000000..41f9b79
--- /dev/null
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/InstrumentationAppTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 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.tradefed.testtype;
+
+import com.android.ddmlib.Log;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.result.ITestInvocationListener;
+import com.android.tradefed.testtype.InstrumentationTest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * A {@link InstrumentationTest] that will install other dependent apks before test execution,
+ * and uninstall apps on execution completion.
+ */
+public class InstrumentationAppTest extends InstrumentationTest {
+
+    private static final String LOG_TAG = "InstrumentationAppTest";
+
+    // TODO: consider moving this class to tradefed proper
+
+    private Collection<File> mInstallFiles = new ArrayList<File>();
+    private Collection<String> mInstallPackages = new ArrayList<String>();
+
+    /**
+     * Add a dependent apk to install.
+     *
+     * @param apkFile the apk file
+     * @param packageName the apk's Android package name
+     */
+    public void addInstallApp(File apkFile, String packageName) {
+        mInstallFiles.add(apkFile);
+        mInstallPackages.add(packageName);
+    }
+
+    @Override
+    public void run(final List<ITestInvocationListener> listeners)
+            throws DeviceNotAvailableException {
+        if (getDevice() == null) {
+            throw new IllegalStateException("missing device");
+        }
+        try {
+            for (File apkFile : mInstallFiles) {
+                Log.d(LOG_TAG, String.format("Installing %s on %s", apkFile.getName(),
+                        getDevice().getSerialNumber()));
+                getDevice().installPackage(apkFile, true);
+            }
+            super.run(listeners);
+        } finally {
+            for (String packageName : mInstallPackages) {
+                Log.d(LOG_TAG, String.format("Uninstalling %s on %s", packageName,
+                        getDevice().getSerialNumber()));
+                getDevice().uninstallPackage(packageName);
+            }
+        }
+    }
+}
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 79723c1..3b89926 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
@@ -33,6 +33,8 @@
 class TestPackageDef implements ITestPackageDef {
 
     private static final String LOG_TAG = "TestPackageDef";
+    private static final String SIGNATURE_TEST_METHOD = "testSignature";
+    private static final String SIGNATURE_TEST_CLASS = "android.tests.sigtest.SimpleSignatureTest";
 
     private String mUri = null;
     private String mAppNameSpace = null;
@@ -42,6 +44,8 @@
     private String mJarPath = null;
     private boolean mIsSignatureTest = false;
     private boolean mIsReferenceAppTest = false;
+    private String mPackageToTest = null;
+    private String mApkToTestName = null;
 
     // use a LinkedHashSet for predictable iteration insertion-order, and fast lookups
     private Collection<TestIdentifier> mTests = new LinkedHashSet<TestIdentifier>();
@@ -116,6 +120,14 @@
         return mIsReferenceAppTest;
     }
 
+    void setPackageToTest(String packageName) {
+        mPackageToTest = packageName;
+    }
+
+    void setApkToTest(String apkName) {
+        mApkToTestName = apkName;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -129,22 +141,17 @@
             hostTest.setTests(filterTests(mTests, className, methodName));
             return hostTest;
         } else if (mIsSignatureTest) {
-            // TODO: implement this
-            Log.w(LOG_TAG, String.format("Skipping currently unsupported signature test %s",
-                    mName));
-            return null;
-        } else if (mIsReferenceAppTest) {
-            // TODO: implement this
-            Log.w(LOG_TAG, String.format("Skipping currently unsupported reference app test %s",
-                    mName));
-            return null;
-        } else {
-            Log.d(LOG_TAG, String.format("Creating instrumentation test for %s", mName));
+            // TODO: hardcode the runner/class/method for now, since current package xml
+            // points to specialized instrumentation. Eventually this special case for signatureTest
+            // can be removed, and it can be treated just like a normal InstrumentationTest
+            Log.d(LOG_TAG, String.format("Creating signature test %s", mName));
             InstrumentationTest instrTest = new InstrumentationTest();
             instrTest.setPackageName(mAppNameSpace);
-            instrTest.setRunnerName(mRunner);
-            instrTest.setClassName(className);
-            instrTest.setMethodName(methodName);
+            instrTest.setRunnerName("android.test.InstrumentationTestRunner");
+            instrTest.setClassName(SIGNATURE_TEST_CLASS);
+            instrTest.setMethodName(SIGNATURE_TEST_METHOD);
+            // add signature test to list of known tests
+            addTest(new TestIdentifier(SIGNATURE_TEST_CLASS, SIGNATURE_TEST_METHOD));
             // mName means 'apk file name' for instrumentation tests
             File apkFile = new File(testCaseDir, String.format("%s.apk", mName));
             if (!apkFile.exists()) {
@@ -154,10 +161,51 @@
             }
             instrTest.setInstallFile(apkFile);
             return instrTest;
+        } else if (mIsReferenceAppTest) {
+            // a reference app test is just a InstrumentationTest with one extra apk to install
+            InstrumentationAppTest instrTest = new InstrumentationAppTest();
+            File apkFile = new File(testCaseDir, String.format("%s.apk", mApkToTestName));
+            if (!apkFile.exists()) {
+                Log.w(LOG_TAG, String.format("Could not find apk file %s",
+                        apkFile.getAbsolutePath()));
+                return null;
+            }
+            instrTest.addInstallApp(apkFile, mPackageToTest);
+            return setInstrumentationTest(testCaseDir, className, methodName, instrTest);
+        } else {
+            Log.d(LOG_TAG, String.format("Creating instrumentation test for %s", mName));
+            InstrumentationTest instrTest = new InstrumentationTest();
+            return setInstrumentationTest(testCaseDir, className, methodName, instrTest);
         }
     }
 
     /**
+     * Populates given {@link InstrumentationTest} with data from the package xml
+     *
+     * @param testCaseDir
+     * @param className
+     * @param methodName
+     * @param instrTest
+     * @return the populated {@link InstrumentationTest} or <code>null</code>
+     */
+    private InstrumentationTest setInstrumentationTest(File testCaseDir, String className,
+            String methodName, InstrumentationTest instrTest) {
+        instrTest.setPackageName(mAppNameSpace);
+        instrTest.setRunnerName(mRunner);
+        instrTest.setClassName(className);
+        instrTest.setMethodName(methodName);
+        // mName means 'apk file name' for instrumentation tests
+        File apkFile = new File(testCaseDir, String.format("%s.apk", mName));
+        if (!apkFile.exists()) {
+            Log.w(LOG_TAG, String.format("Could not find apk file %s",
+                    apkFile.getAbsolutePath()));
+            return null;
+        }
+        instrTest.setInstallFile(apkFile);
+        return instrTest;
+    }
+
+    /**
      * Filter the tests to run based on class and method name
      *
      * @param tests the full set of tests in package
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
index 9bf6968..d12fb9d 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
@@ -70,6 +70,8 @@
                 final String jarPath = attributes.getValue("jarPath");
                 final String signatureCheck = attributes.getValue("signatureCheck");
                 final String referenceApp = attributes.getValue("referenceAppTest");
+                final String apkToTest = attributes.getValue("apkToTestName");
+                final String packageToTest = attributes.getValue("packageToTest");
 
                 mPackageDef = new TestPackageDef();
                 mPackageDef.setUri(entryUriValue);
@@ -80,6 +82,8 @@
                 mPackageDef.setJarPath(jarPath);
                 mPackageDef.setIsSignatureCheck(parseBoolean(signatureCheck));
                 mPackageDef.setIsReferenceApp(parseBoolean(referenceApp));
+                mPackageDef.setApkToTest(apkToTest);
+                mPackageDef.setPackageToTest(packageToTest);
 
                 // reset the class name
                 mClassNameStack = new Stack<String>();