auto import from //depot/cupcake/@135843
diff --git a/tests/SmokeTest/Android.mk b/tests/SmokeTest/Android.mk
new file mode 100644
index 0000000..0adfd4c
--- /dev/null
+++ b/tests/SmokeTest/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# This builds "SmokeTestApp"
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_PACKAGE_NAME := SmokeTestApp
+
+include $(BUILD_PACKAGE)
+
+# This builds "SmokeTest"
+include $(call all-makefiles-under,$(LOCAL_PATH))
\ No newline at end of file
diff --git a/tests/SmokeTest/AndroidManifest.xml b/tests/SmokeTest/AndroidManifest.xml
new file mode 100644
index 0000000..f141bdc
--- /dev/null
+++ b/tests/SmokeTest/AndroidManifest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.smoketest">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+        <activity android:name=".SmokeTestActivity" 
+                  android:label="Smoke Tests">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.TEST" />
+            </intent-filter>
+        </activity>
+
+    </application>
+    
+</manifest>
diff --git a/tests/SmokeTest/README b/tests/SmokeTest/README
new file mode 100644
index 0000000..40218cf
--- /dev/null
+++ b/tests/SmokeTest/README
@@ -0,0 +1,8 @@
+The tests in this folder are a very controlled set of tests that will be run by
+the build system on every single build.  They are intended to run very quickly.
+Please use caution when adding tests here.
+
+If you wish to run these tests, issue the command:
+
+adb shell am instrument \
+  -w com.android.smoketest/.tests.SmokeTestInstrumentationTestRunner
diff --git a/tests/SmokeTest/src/com/android/smoketest/SmokeTestActivity.java b/tests/SmokeTest/src/com/android/smoketest/SmokeTestActivity.java
new file mode 100644
index 0000000..6bc5fd2
--- /dev/null
+++ b/tests/SmokeTest/src/com/android/smoketest/SmokeTestActivity.java
@@ -0,0 +1,41 @@
+/*
+ * 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 com.android.smoketest;
+
+import android.app.LauncherActivity;
+import android.content.Intent;
+
+/**
+ * Initial launcher for UI access to smoke tests.  This does not actually launch the tests,
+ * it simply provides manual access to the various UI activities that are used by the tests.
+ * 
+ * To run all of the tests in this suite:
+ * adb shell am instrument \
+ *   -w com.android.smoketest/.tests.SmokeTestInstrumentationTestRunner
+ */
+public class SmokeTestActivity extends LauncherActivity {
+
+    @Override
+    protected Intent getTargetIntent() {
+        // TODO: partition into categories by label like the sample code app
+        Intent targetIntent = new Intent(Intent.ACTION_MAIN, null);
+        // TODO: Do we add a new top-level intent?  Or just leave it hardcoded like this?
+        targetIntent.addCategory("android.intent.category.SMOKETEST_INSTRUMENTATION_TEST");
+        targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        return targetIntent;
+    }
+}
diff --git a/tests/SmokeTest/tests/Android.mk b/tests/SmokeTest/tests/Android.mk
new file mode 100644
index 0000000..86bf23d
--- /dev/null
+++ b/tests/SmokeTest/tests/Android.mk
@@ -0,0 +1,21 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+# Include all test java files.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+# Notice that we don't have to include the src files of SmokeTestApp because, by
+# running the tests using an instrumentation targeting SmokeTestApp, we
+# automatically get all of its classes loaded into our environment.
+
+LOCAL_PACKAGE_NAME := SmokeTest
+
+LOCAL_INSTRUMENTATION_FOR := SmokeTestApp
+
+include $(BUILD_PACKAGE)
+
diff --git a/tests/SmokeTest/tests/AndroidManifest.xml b/tests/SmokeTest/tests/AndroidManifest.xml
new file mode 100644
index 0000000..517eb1e
--- /dev/null
+++ b/tests/SmokeTest/tests/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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 name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.smoketest.tests">
+
+    <!-- We add an application tag here just so that we can indicate that
+         this package needs to link against the android.test library,
+         which is needed when building test cases. -->    
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <!--
+    This declares that this app uses the instrumentation test runner targeting
+    the package of com.android.smoketest.  To run the tests use the command:
+    "adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner"
+    -->
+    <instrumentation android:name="android.test.InstrumentationTestRunner"
+                     android:targetPackage="com.android.smoketest"
+                     android:label="System Smoke Tests"/>
+
+</manifest>
diff --git a/tests/SmokeTest/tests/src/com/android/smoketest/ProcessErrorsTest.java b/tests/SmokeTest/tests/src/com/android/smoketest/ProcessErrorsTest.java
new file mode 100644
index 0000000..85b91f1
--- /dev/null
+++ b/tests/SmokeTest/tests/src/com/android/smoketest/ProcessErrorsTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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 com.android.smoketest;
+
+import com.android.internal.os.RuntimeInit;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.server.data.CrashData;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This smoke test is designed to quickly sniff for any error conditions
+ * encountered after initial startup.
+ */
+public class ProcessErrorsTest extends AndroidTestCase {
+    
+    private final String TAG = "ProcessErrorsTest";
+    
+    protected ActivityManager mActivityManager;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mActivityManager = (ActivityManager) 
+                getContext().getSystemService(Context.ACTIVITY_SERVICE);
+    }
+
+    public void testSetUpConditions() throws Exception {
+        assertNotNull(mActivityManager);
+    }
+
+    public void testNoProcessErrors() throws Exception {
+        List<ActivityManager.ProcessErrorStateInfo> errList;        
+        errList = mActivityManager.getProcessesInErrorState();
+        
+        // note: this contains information about each process that is currently in an error
+        // condition.  if the list is empty (null) then "we're good".  
+        
+        // if the list is non-empty, then it's useful to report the contents of the list
+        // we'll put a copy in the log, and we'll report it back to the framework via the assert.
+        final String reportMsg = reportListContents(errList);
+        if (reportMsg != null) {
+            Log.w(TAG, reportMsg);
+        }
+        
+        // report a non-empty list back to the test framework
+        assertNull(reportMsg, errList);
+    }
+    
+    /**
+     * This helper function will dump the actual error reports.
+     * 
+     * @param errList The error report containing one or more error records.
+     * @return Returns a string containing all of the errors.
+     */
+    private String reportListContents(List<ActivityManager.ProcessErrorStateInfo> errList) {
+        if (errList == null) return null;
+
+        StringBuilder builder = new StringBuilder();
+
+        Iterator<ActivityManager.ProcessErrorStateInfo> iter = errList.iterator();
+        while (iter.hasNext()) {
+            ActivityManager.ProcessErrorStateInfo entry = iter.next();
+
+            String condition;
+            switch (entry.condition) {
+            case ActivityManager.ProcessErrorStateInfo.CRASHED:
+                condition = "CRASHED";
+                break;
+            case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING:
+                condition = "ANR";
+                break;
+            default:
+                condition = "<unknown>";
+            break;
+            }
+
+            String stackTrace = null;
+            try {
+                if (entry.crashData != null) {
+                    CrashData cd = RuntimeInit.unmarshallException(entry.crashData);
+                    stackTrace = cd.toString();
+                }
+            } catch (RuntimeException e) { }
+            if (stackTrace == null) {
+                stackTrace = "<no stack trace>";
+            }
+
+            final String entryReport = "Process error " + condition + " " + entry.shortMsg +
+                                        " detected in " + entry.processName + " " + entry.tag + 
+                                        ". \n" + stackTrace;
+
+            builder.append(entryReport).append("  ");
+        }
+        return builder.toString();
+    }
+    
+}