Merge "Fix SipSessionGroup from throwing ConcurrentModificationException" into gingerbread
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 7154aee..7242803 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -5267,7 +5267,14 @@
                 b.append(' ');
             }
             first = false;
-            b.append("dat=").append(mData);
+            b.append("dat=");
+            if (mData.getScheme().equalsIgnoreCase("tel")) {
+                b.append("tel:xxx-xxx-xxxx");
+            } else if (mData.getScheme().equalsIgnoreCase("smsto")) {
+                b.append("smsto:xxx-xxx-xxxx");
+            } else {
+                b.append(mData);
+            }
         }
         if (mType != null) {
             if (!first) {
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index f9a1637..e1a9dbb 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -411,7 +411,7 @@
     }
 
     public void setSyncAutomatically(Account account, String providerName, boolean sync) {
-        Log.d(TAG, "setSyncAutomatically: " + account + ", provider " + providerName
+        Log.d(TAG, "setSyncAutomatically: " + /*account +*/ ", provider " + providerName
                 + " -> " + sync);
         synchronized (mAuthorities) {
             AuthorityInfo authority = getOrCreateAuthorityLocked(account, providerName, -1, false);
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index c185007..de5b7b9 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -38,7 +38,10 @@
  * network access on the application's main thread, where UI
  * operations are received and animations take place.  Keeping disk
  * and network operations off the main thread makes for much smoother,
- * more responsive applications.
+ * more responsive applications.  By keeping your application's main thread
+ * responsive, you also prevent
+ * <a href="{@docRoot}guide/practices/design/responsiveness.html">ANR dialogs</a>
+ * from being shown to users.
  *
  * <p class="note">Note that even though an Android device's disk is
  * often on flash memory, many devices run a filesystem on top of that
diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java
index bf9e854..6d8bd9b 100644
--- a/core/java/android/provider/Telephony.java
+++ b/core/java/android/provider/Telephony.java
@@ -1205,9 +1205,8 @@
             }
 
             Uri uri = uriBuilder.build();
-            if (DEBUG) {
-                Log.v(TAG, "getOrCreateThreadId uri: " + uri);
-            }
+            //if (DEBUG) Log.v(TAG, "getOrCreateThreadId uri: " + uri);
+
             Cursor cursor = SqliteWrapper.query(context, context.getContentResolver(),
                     uri, ID_PROJECTION, null, null, null);
             if (DEBUG) {
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index a52a221..5cbfe74 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -71,7 +71,6 @@
     private final BluetoothService mBluetoothService;
     private final BluetoothAdapter mAdapter;
     private int   mTargetA2dpState;
-    private boolean mAdjustedPriority = false;
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
@@ -326,7 +325,10 @@
 
         String path = mBluetoothService.getObjectPathFromAddress(device.getAddress());
 
-        // State is DISCONNECTED
+        // State is DISCONNECTED and we are connecting.
+        if (getSinkPriority(device) < BluetoothA2dp.PRIORITY_AUTO_CONNECT) {
+            setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT);
+        }
         handleSinkStateChange(device, state, BluetoothA2dp.STATE_CONNECTING);
 
         if (!connectSinkNative(path)) {
@@ -491,14 +493,10 @@
             mTargetA2dpState = -1;
 
             if (getSinkPriority(device) > BluetoothA2dp.PRIORITY_OFF &&
-                    state == BluetoothA2dp.STATE_CONNECTING ||
                     state == BluetoothA2dp.STATE_CONNECTED) {
                 // We have connected or attempting to connect.
                 // Bump priority
                 setSinkPriority(device, BluetoothA2dp.PRIORITY_AUTO_CONNECT);
-            }
-
-            if (state == BluetoothA2dp.STATE_CONNECTED) {
                 // We will only have 1 device with AUTO_CONNECT priority
                 // To be backward compatible set everyone else to have PRIORITY_ON
                 adjustOtherSinkPriorities(device);
@@ -515,14 +513,11 @@
     }
 
     private void adjustOtherSinkPriorities(BluetoothDevice connectedDevice) {
-        if (!mAdjustedPriority) {
-            for (BluetoothDevice device : mAdapter.getBondedDevices()) {
-                if (getSinkPriority(device) >= BluetoothA2dp.PRIORITY_AUTO_CONNECT &&
-                    !device.equals(connectedDevice)) {
-                    setSinkPriority(device, BluetoothA2dp.PRIORITY_ON);
-                }
+        for (BluetoothDevice device : mAdapter.getBondedDevices()) {
+            if (getSinkPriority(device) >= BluetoothA2dp.PRIORITY_AUTO_CONNECT &&
+                !device.equals(connectedDevice)) {
+                setSinkPriority(device, BluetoothA2dp.PRIORITY_ON);
             }
-            mAdjustedPriority = true;
         }
     }
 
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 19abec1..e82ed9f 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -519,6 +519,7 @@
             return false;
         case MotionEvent.ACTION_UP:
         case MotionEvent.ACTION_CANCEL:
+            super.onTouchEvent(event);
             if (mHasPerformedLongClick) {
                 mGotTouchDown = false;
                 return false;
@@ -684,9 +685,6 @@
         // webkit's drawing.
         setWillNotDraw(!inPassword);
         setBackgroundDrawable(inPassword ? mBackground : null);
-        // For non-password fields, avoid the invals from TextView's blinking
-        // cursor
-        setCursorVisible(inPassword);
     }
 
     /**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 6df5445..84aca60 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -5039,6 +5039,8 @@
                     if (!mAllowPanAndScale) {
                         return true;
                     }
+                    mPrivateHandler.removeMessages(SWITCH_TO_SHORTPRESS);
+                    mPrivateHandler.removeMessages(SWITCH_TO_LONGPRESS);
                 }
                 x = mScaleDetector.getFocusX();
                 y = mScaleDetector.getFocusY();
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 5be52c4..6dcf4e6 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -92,6 +92,7 @@
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewDebug;
+import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.view.ViewParent;
 import android.view.ViewRoot;
@@ -6852,8 +6853,17 @@
     }
 
     private void prepareCursorControllers() {
+        boolean windowSupportsHandles = false;
+
+        ViewGroup.LayoutParams params = getRootView().getLayoutParams();
+        if (params instanceof WindowManager.LayoutParams) {
+            WindowManager.LayoutParams windowParams = (WindowManager.LayoutParams) params;
+            windowSupportsHandles = windowParams.type < WindowManager.LayoutParams.FIRST_SUB_WINDOW
+                    || windowParams.type > WindowManager.LayoutParams.LAST_SUB_WINDOW;
+        }
+
         // TODO Add an extra android:cursorController flag to disable the controller?
-        if (mCursorVisible && mLayout != null) {
+        if (windowSupportsHandles && mCursorVisible && mLayout != null) {
             if (mInsertionPointCursorController == null) {
                 mInsertionPointCursorController = new InsertionPointCursorController();
             }
@@ -6861,7 +6871,7 @@
             mInsertionPointCursorController = null;
         }
 
-        if (textCanBeSelected() && mLayout != null) {
+        if (windowSupportsHandles && textCanBeSelected() && mLayout != null) {
             if (mSelectionModifierCursorController == null) {
                 mSelectionModifierCursorController = new SelectionModifierCursorController();
             }
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index a33851c..e799527 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -63,6 +63,9 @@
         <item>@drawable/scrollbar_handle_horizontal</item>
         <item>@drawable/scrollbar_handle_vertical</item>
         <item>@drawable/spinner_dropdown_background</item>
+        <item>@drawable/text_select_handle_left</item>
+        <item>@drawable/text_select_handle_middle</item>
+        <item>@drawable/text_select_handle_right</item>
         <item>@drawable/title_bar</item>
         <item>@drawable/title_bar_shadow</item>
         <!-- Visual lock screen -->
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 849c564..99fc5c2 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -149,9 +149,15 @@
          Software implementation will be used if config_hardware_auto_brightness_available is not set -->
     <bool name="config_automatic_brightness_available">false</bool>
 
+    <!-- Don't name config resources like this.  It should look like config_annoyDianne -->
+    <bool name="config_annoy_dianne">true</bool>
+
     <!-- If this is true, the screen will come on when you unplug usb/power/whatever. -->
     <bool name="config_unplugTurnsOnScreen">false</bool>
     
+    <!-- If this is true, the screen will fade off. -->
+    <bool name="config_animateScreenLights">true</bool>
+    
     <!-- XXXXXX END OF RESOURCES USING WRONG NAMING CONVENTION -->
 
     <!-- The number of degrees to rotate the display when the keyboard is open. -->
diff --git a/docs/html/guide/developing/testing/index.jd b/docs/html/guide/developing/testing/index.jd
index ea61cc3..2164705 100644
--- a/docs/html/guide/developing/testing/index.jd
+++ b/docs/html/guide/developing/testing/index.jd
@@ -1,6 +1,5 @@
 page.title=Testing Overview
 @jd:body
-
 <p>
     Android includes powerful tools for setting up and running test applications.
     Whether you are working in Eclipse with ADT or working from the command line, these tools
@@ -9,7 +8,7 @@
 </p>
 <p>
     If you aren't yet familiar with the Android testing framework, please read the topic
-    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing and Instrumentation</a>
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>
     before you get started.
     For a step-by-step introduction to Android testing, try the <a
     href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello, Testing</a>
diff --git a/docs/html/guide/developing/testing/testing_eclipse.jd b/docs/html/guide/developing/testing/testing_eclipse.jd
index da1c0f0..ba7eaba 100644
--- a/docs/html/guide/developing/testing/testing_eclipse.jd
+++ b/docs/html/guide/developing/testing/testing_eclipse.jd
@@ -1,28 +1,23 @@
 page.title=Testing In Eclipse, with ADT
 @jd:body
-
 <div id="qv-wrapper">
-  <div id="qv">
-  <h2>In this document</h2>
-  <ol>
-    <li><a href="#CreateTestProjectEclipse">Creating a Test Project</a></li>
-    <li><a href="#CreateTestAppEclipse">Creating a Test Application</a></li>
-    <li><a href="#RunTestEclipse">Running Tests</a></li>
-  </ol>
-  </div>
+    <div id="qv">
+        <h2>In this document</h2>
+            <ol>
+                <li><a href="#CreateTestProjectEclipse">Creating a Test Project</a></li>
+                <li><a href="#CreateTestAppEclipse">Creating a Test Package</a></li>
+                <li><a href="#RunTestEclipse">Running Tests</a></li>
+            </ol>
+    </div>
 </div>
 <p>
-  This topic explains how create and run tests of Android applications in Eclipse with ADT.
-
-  with the basic processes for creating and running applications with ADT, as described in
-  <a href="{@docRoot}guide/developing/eclipse-adt.html">Developing In Eclipse, with ADT</a>.
-
-  Before you read this topic, you should read about how to create a Android application with the
-  basic processes for creating and running applications with ADT, as described in
-  <a href="{@docRoot}guide/developing/eclipse-adt.html">Developing In Eclipse, with ADT</a>.
-  You may also want to read
-  <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing and Instrumentation</a>,
-  which provides an overview of the Android testing framework.
+    This topic explains how create and run tests of Android applications in Eclipse with ADT.
+    Before you read this topic, you should read about how to create a Android application with the
+    basic processes for creating and running applications with ADT, as described in
+    <a href="{@docRoot}guide/developing/eclipse-adt.html">Developing In Eclipse, with ADT</a>.
+    You may also want to read
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
+    which provides an overview of the Android testing framework.
 </p>
 <p>
     ADT provides several features that help you set up and manage your testing environment
@@ -32,20 +27,20 @@
         <li>
             It lets you quickly create a test project and link it to the application under test.
             When it creates the test project, it automatically inserts the necessary
-            <code>&lt;instrumentation&gt;</code> element in the test application's manifest file.
+            <code>&lt;instrumentation&gt;</code> element in the test package's manifest file.
         </li>
         <li>
             It lets you quickly import the classes of the application under test, so that your
             tests can inspect them.
         </li>
         <li>
-            It lets you create run configurations for your test application and include in
+            It lets you create run configurations for your test package and include in
             them flags that are passed to the Android testing framework.
         </li>
         <li>
-            It lets you run your test application without leaving Eclipse. ADT builds both the
-            application under test and the test application automatically, installs them if
-            necessary to your device or emulator, runs the test application, and displays the
+            It lets you run your test package without leaving Eclipse. ADT builds both the
+            application under test and the test package automatically, installs them if
+            necessary to your device or emulator, runs the test package, and displays the
             results in a separate window in Eclipse.
         </li>
     </ul>
@@ -55,305 +50,452 @@
     <a href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other IDEs</a>.
 </p>
 <h2 id="CreateTestProjectEclipse">Creating a Test Project</h2>
-  <p>
+<p>
     To set up a test environment for your Android application, you must first create a separate
-    application project that holds the test code. The new project follows the directory structure
+    project that holds the test code. The new project follows the directory structure
     used for any Android application. It includes the same types of content and files, such as
-    source code, resources, a manifest file, and so forth. The test application you
+    source code, resources, a manifest file, and so forth. The test package you
     create is connected to the application under test by an
     <a href="{@docRoot}guide/topics/manifest/instrumentation-element.html">
     <code>&lt;instrumentation&gt;</code></a> element in its manifest file.
-  </p>
-  <p>
-    The <strong>New Android Test Project</strong> dialog makes it easy for you to generate a
-    new test project that has the proper structure, including the
-    <code>&lt;instrumentation&gt;</code> element in the manifest file. You can use the New Android
-    Test Project dialog to generate the test project at any time. The dialog appears just after you
-    create a new Android main application project, but you can also run it to create a test project
-    for a project that you created previously.
-  </p>
+</p>
 <p>
-  To create a test project in Eclipse with ADT:
+    The <em>New Android Test Project</em> dialog makes it easy for you to generate a
+    new test project that has the proper structure, including the
+    <code>&lt;instrumentation&gt;</code> element in the manifest file. You can use the New
+    Android Test Project dialog to generate the test project at any time. The dialog appears
+    just after you create a new Android main application project, but you can also run it to
+    create a test project for a project that you created previously.
+</p>
+<p>
+    To create a test project in Eclipse with ADT:
 </p>
 <ol>
-  <li>
-    In Eclipse, select <strong>File &gt; New &gt; Other</strong>. This
-    opens the Select a Wizard dialog.
-  </li>
-  <li>
-    In the dialog, in the Wizards drop-down list,
-    find the entry for Android, then click the toggle to the left. Select
-    Android Test Project, then at the bottom
-    of the dialog click Next. The New Android Test Project wizard appears.
-  </li>
-  <li>
-    Enter a project name. You may use any name, but you may want to
-    associate the name with the project name for your Application. One
-    way to do this is to take the Application's project name, append the
-    string "Test" to it, and then use this as the test case project name.
-  </li>
-  <li>
-    In the Test Target panel, set
-    An Existing Android Project, click
-    Browse, then select your Android application from
-    the list. You now see that the wizard has completed the Test
-    Target Package, Application Name, and
-    Package Name fields for you (the latter two are in
-    the Properties panel).
-  </li>
-  <li>
-    In the Build Target panel, select the Android SDK
-    platform that you will use to test your application. Make this the same as the
-    build target of the application under test.
-  </li>
-  <li>
-    Click Finish to complete the wizard. If
-    Finish is disabled, look
-    for error messages at the top of the wizard dialog, and then fix
-    any problems.
-  </li>
+    <li>
+        In Eclipse, select <strong>File &gt; New &gt; Other</strong>. This opens the <em>Select a
+        Wizard</em> dialog.
+    </li>
+    <li>
+        In the dialog, in the <em>Wizards</em> drop-down list, find the entry for Android, then
+        click the toggle to the left. Select <strong>Android Test Project</strong>, then at the
+        bottom of the dialog click <strong>Next</strong>. The <em>New Android Test Project</em>
+        wizard appears.
+    </li>
+    <li>
+        Next to <em>Test Project Name</em>, enter a name for the project. You may use any name,
+        but you may want to associate the name with the project name for the application under test.
+        One way to do this is to take the application's project name, append the string "Test" to
+        it, and then use this as the test package project name.
+        <p>
+            The name becomes part of the suggested project path, but you can change this in the
+            next step.
+        </p>
+    </li>
+    <li>
+        In the <em>Content</em> panel, examine the suggested path to the project.
+        If <em>Use default location</em> is set, then the wizard will suggest a path that is
+        a concatenation of the workspace path and the project name you entered. For example,
+        if your workspace path is <code>/usr/local/workspace</code> and your project name is
+        <code>MyTestApp</code>, then the wizard will suggest
+        <code>/usr/local/workspace/MyTestApp</code>. To enter your own
+        choice for a path, unselect <em>Use default location</em>, then enter or browse to the
+        path where you want your project.
+        <p>
+            To learn more about choosing the location of test projects, please read
+            <a href="{@docRoot}guide/topics/testing/testing_android.html#TestProjectPaths">
+            Testing Fundamentals</a>.
+        </p>
+    </li>
+    <li>
+        In the Test Target panel, set An Existing Android Project, click Browse, then select your
+        Android application from the list. You now see that the wizard has completed the Test
+        Target Package, Application Name, and Package Name fields for you (the latter two are in
+        the Properties panel).
+    </li>
+    <li>
+        In the Build Target panel, select the Android SDK platform that the application under test
+        uses.
+    </li>
+    <li>
+        Click Finish to complete the wizard. If Finish is disabled, look for error messages at the
+        top of the wizard dialog, and then fix any problems.
+    </li>
+</ol>
+<h2 id="CreateTestAppEclipse">Creating a Test Package</h2>
+<p>
+    Once you have created a test project, you populate it with a test package. This package does not
+    require an Activity, although you can define one if you wish. Although your test package can
+    combine Activity classes, test case classes, or ordinary classes, your main test case
+    should extend one of the Android test case classes or JUnit classes, because these provide the
+    best testing features.
+</p>
+<p>
+    Test packages do not need to have an Android GUI. When you run the package in
+    Eclipse with ADT, its results appear in the JUnit view. Running tests and seeing the results is
+    described in more detail in the section <a href="#RunTestEclipse">Running Tests</a>.
+</p>
+
+<p>
+    To create a test package, start with one of Android's test case classes defined in
+    {@link android.test android.test}. These extend the JUnit
+    {@link junit.framework.TestCase TestCase} class. The Android test classes for Activity objects
+    also provide instrumentation for testing an Activity. To learn more about test case
+    classes, please read the topic <a href="{@docRoot}guide/topics/testing/testing_android.html">
+    Testing Fundamentals</a>.
+</p>
+<p>
+    Before you create your test package, you choose the Java package identifier you want to use
+    for your test case classes and the Android package name you want to use. To learn more
+    about this, please read
+    <a href="{@docRoot}guide/topics/testing/testing_android.html#PackageNames">
+    Testing Fundamentals</a>.
+</p>
+<p>
+    To add a test case class to your project:
+</p>
+<ol>
+    <li>
+        In the <em>Project Explorer</em> tab, open your test project, then open the <em>src</em>
+        folder.
+    </li>
+    <li>
+        Find the Java package identifier set by the projection creation wizard. If you haven't
+        added classes yet, this node won't have any children, and its icon will not be filled in.
+        If you want to change the identifier value, right-click the identifier and select
+        <strong>Refactor</strong> &gt; <strong>Rename</strong>, then enter the new name.
+    </li>
+    <li>
+        When you are ready, right-click the Java package identifier again and select
+        <strong>New</strong> &gt; <strong>Class</strong>. This displays the <em>New Java Class</em>
+        dialog, with the <em>Source folder</em> and <em>Package</em> values already set.
+    </li>
+    <li>
+        In the <em>Name</em> field, enter a name for the test case class. One way to choose a
+        class name is to append the string "Test" to the class of the component you are testing.
+        For example, if you are testing the class MyAppActivity, your test case class
+        name would be MyAppActivityTest. Leave the modifiers set to <em>public</em>.
+    </li>
+    <li>
+        In the <em>Superclass</em> field, enter the name of the Android test case class you
+        are extending. You can also browse the available classes.
+    </li>
+    <li>
+        In <em>Which method stubs would you like to create?</em>, unset all the options, then
+        click <strong>Finish</strong>. You will set up the constructor manually.
+    </li>
+    <li>
+        Your new class appears in a new Java editor pane.
+    </li>
 </ol>
 <p>
-
-</p>
-<h2 id="CreateTestAppEclipse">Creating a Test Application</h2>
-<p>
-  Once you have created a test project, you populate it with a test
-  Android application. This application does not require an {@link android.app.Activity Activity},
-  although you can define one if you wish. Although your test application can
-  combine Activities, Android test class extensions, JUnit extensions, or
-  ordinary classes, you should extend one of the Android test classes or JUnit classes,
-  because these provide the best testing features.
+    You now have to ensure that the constructor is set up correctly. Create a constructor for your
+    class that has no arguments; this is required by JUnit. As the first statement in this
+    constructor, add a call to the base class' constructor. Each base test case class has its
+    own constructor signature. Refer to the class documentation in the documentation for
+    {@link android.test} for more information.
 </p>
 <p>
-  Test applications do not have an Android GUI. Instead, when you run the application in
-  Eclipse with ADT, its results appear in the JUnit view. If you run
-  your tests with {@link android.test.InstrumentationTestRunner InstrumentationTestRunner} (or a related test runner),
-  then it will run all the methods in each class. You can modify this behavior
-  by using the {@link junit.framework.TestSuite TestSuite} class.
-</p>
-
-<p>
-  To create a test application, start with one of Android's test classes in the Java package {@link android.test android.test}.
-  These extend the JUnit {@link junit.framework.TestCase TestCase} class. With a few exceptions, the Android test classes
-  also provide instrumentation for testing.
-</p>
-<p>
-  For test classes that extend {@link junit.framework.TestCase TestCase}, you probably want to override
-  the <code>setUp()</code> and <code>tearDown()</code> methods:
+    To control your test environment, you will want to override the <code>setUp()</code> and
+    <code>tearDown()</code> methods:
 </p>
 <ul>
-  <li>
-    <code>setUp()</code>: This method is invoked before any of the test methods in the class.
-      Use it to set up the environment for the test. You can use <code>setUp()</code>
-      to instantiate a new <code>Intent</code> object with the action <code>ACTION_MAIN</code>. You can
-      then use this intent to start the Activity under test.
-      <p class="note"><strong>Note:</strong> If you override this method, call
-        <code>super.setUp()</code> as the first statement in your code.
-      </p>
-  </li>
-  <li>
-    <code>tearDown()</code>: This method is invoked after all the test methods in the class. Use
-    it to do garbage collection and re-setting before moving on to the next set of tests.
-    <p class="note"><strong>Note:</strong> If you override this method, you must call
-    <code>super.tearDown()</code> as the <em>last</em> statement in your code.</p>
-  </li>
+    <li>
+        <code>setUp()</code>: This method is invoked before any of the test methods in the class.
+        Use it to set up the environment for the test (the test fixture. You can use
+        <code>setUp()</code> to instantiate a new Intent with the action <code>ACTION_MAIN</code>.
+        You can then use this intent to start the Activity under test.
+    </li>
+    <li>
+        <code>tearDown()</code>: This method is invoked after all the test methods in the class. Use
+        it to do garbage collection and to reset the test fixture.
+    </li>
 </ul>
 <p>
-  Another useful convention is to add the method <code>testPreConditions()</code> to your test
-  class. Use this method to test that the application under test is initialized correctly. If this
-  test fails, you know that that the initial conditions were in error. When this happens, further test
-  results are suspect, regardless of whether or not the tests succeeded.
+    Another useful convention is to add the method <code>testPreconditions()</code> to your test
+    class. Use this method to test that the application under test is initialized correctly. If this
+    test fails, you know that that the initial conditions were in error. When this happens, further
+    test results are suspect, regardless of whether or not the tests succeeded.
 </p>
 <p>
-  The Resources tab contains an <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
-  tutorial with more information about creating test classes and methods.
+    The Resources tab contains an
+    <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
+    tutorial with more information about creating test classes and methods.
 </p>
 <h2 id="RunTestEclipse">Running Tests</h2>
+    <div class="sidebox-wrapper">
+        <div class="sidebox">
+            <h2>Running tests from the command line</h2>
+                <p>
+                    If you've created your tests in Eclipse, you can still run your tests and test
+                    suites by using command-line tools included with the Android SDK. You may want
+                    to do this, for example, if you have a large number of tests to run, if you
+                    have a large test case, or if you want a fine level of control over which
+                    tests are run at a particular time.
+                </p>
+                <p>
+                    To run tests created in Eclipse with ADT with command-line tools, you must first
+                    install additional files into the test project using the <code>android</code>
+                    tool's "create test-project" option. To see how to do this, read
+                   <a href="{@docRoot}guide/developing/testing/testing_otheride.html#CreateProject">
+                    Testing in Other IDEs</a>.
+                </p>
+        </div>
+    </div>
+<p>
+    When you run a test package in Eclipse with ADT, the output appears in the Eclipse JUnit view.
+    You can run the entire test package or one test case class. To do run tests, Eclipse runs the
+    <code>adb</code> command for running a test package, and displays the output, so there is no
+    difference between running tests inside Eclipse and running them from the command line.
+</p>
+<p>
+    As with any other package, to run a test package in Eclipse with ADT you must either attach a
+    device to your computer or use the Android emulator. If you use the emulator, you must have an
+    Android Virtual Device (AVD) that uses the same target as the test package.
+</p>
+<p>
+    To run a test in Eclipse, you have two choices:</p>
+<ul>
+    <li>
+        Run a test just as you run an application, by selecting
+        <strong>Run As... &gt; Android JUnit Test</strong> from the project's context menu or
+        from the main menu's <strong>Run</strong> item.
+    </li>
+    <li>
+        Create an Eclipse run configuration for your test project. This is useful if you want
+        multiple test suites, each consisting of selected tests from the project. To run
+        a test suite, you run the test configuration.
+        <p>
+            Creating and running test configurations is described in the next section.
+        </p>
+    </li>
+</ul>
+<p>
+    To create and run a test suite using a run configuration:
+</p>
+<ol>
+    <li>
+        In the Package Explorer, select the test project, then from the main menu, select
+        <strong>Run &gt; Run Configurations...</strong>. The Run Configurations dialog appears.
+    </li>
+    <li>
+        In the left-hand pane, find the Android JUnit Test entry. In the right-hand pane, click the
+        Test tab. The Name: text box shows the name of your project. The Test class: dropdown box
+        shows one of the test classes in your project.
+    </li>
+    <li>
+        To run one test class, click  Run a single test, then enter your project name in the
+        Project: text box and the class name in the Test class: text box.
+        <p>
+            To run all the test classes, click Run all tests in the selected project or package,
+            then enter the project or package name in the text box.
+        </p>
+    </li>
+    <li>
+        Now click the Target tab.
+        <ul>
+            <li>
+                Optional: If you are using the emulator, click Automatic, then in the Android
+                Virtual Device (AVD) selection table, select an existing AVD.
+            </li>
+            <li>
+                In the Emulator Launch Parameters pane, set the Android emulator flags you want to
+                use. These are documented in the topic
+                <a href="{@docRoot}guide/developing/tools/emulator.html#startup-options">
+                Android Emulator</a>.
+            </li>
+        </ul>
+    </li>
+    <li>
+        Click the Common tab. In the Save As pane, click Local to save this run configuration
+        locally, or click Shared to save it to another project.
+    </li>
+    <li>
+        Optional: Add the configuration to the Run toolbar and the <strong>Favorites</strong>
+        menu: in the Display in Favorites pane click the checkbox next to Run.
+    </li>
+    <li>
+        Optional: To add this configuration to the <strong>Debug</strong> menu and toolbar, click
+        the checkbox next to Debug.
+    </li>
+    <li>
+        To save your settings, click Close.<br/>
+        <p class="note"><strong>Note:</strong>
+            Although you can run the test immediately by clicking Run, you should save the test
+            first and then run it by selecting it from the Eclipse standard toolbar.
+        </p>
+    </li>
+    <li>
+        On the Eclipse standard toolbar, click the down arrow next to the green Run arrow. This
+        displays a menu of saved Run and Debug configurations.
+    </li>
+    <li>
+        Select the test run configuration you just created. The test starts.
+    </li>
+</ol>
+<p>
+    The progress of your test appears in the Console view as a series of messages. Each message is
+    preceded by a timestamp and the <code>.apk</code> filename to which it applies. For example,
+    this message appears when you run a test to the emulator, and the emulator is not yet started:
+</p>
 <div class="sidebox-wrapper">
     <div class="sidebox">
-        <h2>Running tests from the command line</h2>
-            <p>
-                If you've created your tests in Eclipse, you can still run your tests and test
-                suites by using command-line tools included with the Android SDK. You may want to
-                do this, for example, if you have a large number of tests to run, if you have a
-                large test case, or if you want a fine level of control over which tests are run at
-                a particular time.
-            </p>
-            <p>
-                To run tests created in Eclipse with ADT with command-line tools, you must first
-                install additional files into the test project using the <code>android</code> tool's
-                "create test-project" option. To see how to do this, read the section
-                <a href="{@docRoot}guide/developing/testing/testing_otheride.html#CreateProject">
-                Creating a test project</a> in the topic
-                <a href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other
-                IDEs</a>.
-            </p>
+        <h2>Message Examples</h2>
+        <p>
+            The examples shown in this section come from the
+            <a href="{@docRoot}resources/samples/SpinnerTest/index.html">SpinnerTest</a>
+            sample test package, which tests the
+            <a href="{@docRoot}resources/samples/Spinner/index.html">Spinner</a>
+            sample application. This test package is also featured in the
+            <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
+            tutorial.
+        </p>
     </div>
 </div>
+<pre>
+    [<em>yyyy-mm-dd hh:mm:ss</em> - <em>testfile</em>] Waiting for HOME ('android.process.acore') to be launched...
+</pre>
 <p>
-  When you run a test application in Eclipse with ADT, the output appears in
-  an Eclipse view panel. You can run the entire test application, one class, or one
-  method of a class. To do this, Eclipse runs the <code>adb</code> command for running a test application, and
-  displays the output, so there is no difference between running tests inside Eclipse and running them from the command line.
+    In the following description of these messages, <code><em>devicename</em></code> is the name of
+    the device or emulator you are using to run the test, and <code><em>port</em></code> is the
+    port number for the device. The name and port number are in the format used by the
+    <code><a href="{@docRoot}guide/developing/tools/adb.html#devicestatus">adb devices</a></code>
+    command. Also, <code><em>testfile</em></code> is the <code>.apk</code> filename of the test
+    package you are running, and <em>appfile</em> is the filename of the application under test.
 </p>
-<p>
-    As with any other application, to run a test application in Eclipse with ADT you must either attach a device to your
-    computer or use the Android emulator. If you use the emulator, you must have an Android Virtual Device (AVD) that uses
-    the same target
-</p>
-<p>
-  To run a test in Eclipse, you have two choices:</p>
-<ol>
-  <li>
-  Run a test just as you run an application, by selecting
-  <strong>Run As... &gt; Android JUnit Test</strong> from the project's context menu or
-  from the main menu's <strong>Run</strong> item.
-  </li>
-  <li>
-  Create an Eclipse run configuration for your test project. This is useful if you want multiple test suites, each consisting of selected tests from the project. To run
-  a test suite, you run the test configuration.
-  <p>
-    Creating and running test configurations is described in the next section.
-  </p>
-  </li>
-</ol>
-<p>To create and run a test suite using a run configuration:</p>
-<ol>
-  <li>
-    In the Package Explorer, select the test
-    project, then from the main menu, select
-    <strong>Run &gt; Run Configurations...</strong>. The
-    Run Configurations dialog appears.
-  </li>
-  <li>
-    In the left-hand pane, find the
-    Android JUnit Test entry.
-    In the right-hand pane, click the Test tab.
-    The Name: text box
-    shows the name of your project. The
-    Test class: dropdown box shows one your project's classes
-    test classes in your project.
-  </li>
-  <li>
-    To run one test class, click  Run a single test, then enter your project
-    name in the Project: text box and the class name in the
-    Test class: text box.
-    <p>
-        To run all the test classes,
-        click Run all tests in the selected project or package,
-        then enter the project or package name in the text box.
-    </p>
- </li>
-  <li>
-    Now click the Target tab.
-    <ul>
-        <li>
-            Optional: If you are using the emulator, click
-            Automatic, then in the Android Virtual Device (AVD)
-            selection table, select an existing AVD.
-        </li>
-        <li>
-            In the Emulator Launch Parameters pane, set the
-            Android emulator flags you want to use. These are documented in the topic
-            <a href="{@docRoot}guide/developing/tools/emulator.html#startup-options">Emulator Startup Options</a>.
-        </li>
-    </ul>
-  <li>
-    Click the Common tab. In the
-    Save As pane, click Local to save
-    this run configuration locally, or click Shared to
-    save it to another project.
-  </li>
-  <li>
-    Optional: Add the configuration to the Run toolbar and the <strong>Favorites</strong>
-    menu: in the Display in Favorites pane
-    click the checkbox next to Run.
-  </li>
-  <li>
-    Optional: To add this configuration to the <strong>Debug</strong> menu and toolbar, click
-    the checkbox next to Debug.
-  </li>
-  <li>
-    To save your settings, click Close.<br/>
-    <p class="note"><strong>Note:</strong> Although you can run the test immediately by
-    clicking Run, you should save the test first and then
-    run it by selecting it from the Eclipse standard toolbar.</p>
-  </li>
-  <li>
-    On the Eclipse standard toolbar, click the down arrow next to the
-    green Run arrow. This displays a menu of saved Run and Debug
-    configurations.
-  </li>
-  <li>
-    Select the test run configuration you just created.
-  </li>
-  <li>
-    The progress of your test appears in the Console view.
-    You should see the following messages, among others:
-    <ul>
-      <li>
-        <code>Performing Android.test.InstrumentationTestRunner JUnit launch</code><br>
-        The class name that proceeds "JUnit" depends on the Android instrumentation
-        class you have chosen.
-      </li>
-      <li>
-        If you are using an emulator and you have not yet started it, then you will see
+<ul>
+    <li>
+        If you are using an emulator and you have not yet started it, then Eclipse
+        first starts the emulator. When this is complete, you see
         the message:
         <p>
-          <code>Automatic Target Mode: launching new emulator with compatible
-          AVD <em>avdname</em></code><br>(where <em>avdname</em> is the name of
-          the AVD you are using.)
+            <code>HOME is up on device '<em>devicename</em>-<em>port</em>'</code>
         </p>
-      </li>
-      <li>
-        If you have not already installed your test application, then you will see
+    </li>
+    <li>
+        If you have not already installed your test package, then you see
         the message:
         <p>
-          <code>Uploading <em>testclass</em>.apk onto device '<em>device-id</em>'</code><br>
-          where <em>testclass</em> is the name of your unit test class and <em>device-id</em>
-          is the name and port for your test device or emulator, followed by the message <code>Installing <em>testclass</em>.apk</code>
+            <code>Uploading <em>testfile</em> onto device '<em>devicename</em>-<em>port</em>'
+            </code>
         </p>
-      </li>
-      <li>
-       <code>Launching instrumentation Android.test.InstrumentationTestRunner on device <em>device-id</em></code>.<br>
-       This indicates that Android's Instrumentation system is now testing your code. Again, the
-       instrumentation class name depends on the Android instrumentation class you have chosen.
-      </li>
-      <li>
-       <code>Test run complete</code>.<br> When you see this, your unit tests have finished.
-      </li>
-    </ul>
-</ol>
+        <p>
+            then the message <code>Installing <em>testfile</em></code>.
+        </p>
+        <p>
+            and finally the message <code>Success!</code>
+        </p>
+    </li>
+</ul>
 <p>
-        The test results appear in the JUnit view. This is divided into an upper summary pane,
-        and a lower stack trace pane.
+    The following lines are an example of this message sequence:
+</p>
+<code>
+[2010-07-01 12:44:40 - MyTest] HOME is up on device 'emulator-5554'<br>
+[2010-07-01 12:44:40 - MyTest] Uploading MyTest.apk onto device 'emulator-5554'<br>
+[2010-07-01 12:44:40 - MyTest] Installing MyTest.apk...<br>
+[2010-07-01 12:44:49 - MyTest] Success!<br>
+</code>
+<br>
+<ul>
+    <li>
+        Next, if you have not yet installed the application under test to the device or
+        emulator, you see the message
+        <p>
+        <code>Project dependency found, installing: <em>appfile</em></code>
+        </p>
+        <p>
+            then the message <code>Uploading <em>appfile</em></code> onto device
+            '<em>devicename</em>-<em>port</em>'
+        </p>
+        <p>
+            then the message <code>Installing <em>appfile</em></code>
+        </p>
+        <p>
+            and finally the message <code>Success!</code>
+        </p>
+    </li>
+</ul>
+<p>
+    The following lines are an example of this message sequence:
+</p>
+<code>
+[2010-07-01 12:44:49 - MyTest] Project dependency found, installing: MyApp<br>
+[2010-07-01 12:44:49 - MyApp] Uploading MyApp.apk onto device 'emulator-5554'<br>
+[2010-07-01 12:44:49 - MyApp] Installing MyApp.apk...<br>
+[2010-07-01 12:44:54 - MyApp] Success!<br>
+</code>
+<br>
+<ul>
+    <li>
+        Next, you see the message
+        <code>Launching instrumentation <em>instrumentation_class</em> on device
+        <em>devicename</em>-<em>port</em></code>
+        <p>
+            <code>instrumentation_class</code> is the fully-qualified class name of the
+            instrumentation test runner you have specified (usually
+            {@link android.test.InstrumentationTestRunner}.
+        </p>
+    </li>
+    <li>
+        Next, as {@link android.test.InstrumentationTestRunner} builds a list of tests to run,
+        you see the message
+        <p>
+            <code>Collecting test information</code>
+        </p>
+        <p>
+            followed by
+        </p>
+        <p>
+            <code>Sending test information to Eclipse</code>
+        </p>
+    </li>
+    <li>
+        Finally, you see the message <code>Running tests</code>, which indicates that your tests
+        are running. At this point, you should start seeing the test results in the JUnit view.
+        When the tests are finished, you see the console message <code>Test run complete</code>.
+        This indicates that your tests are finished.
+    </li>
+</ul>
+<p>
+    The following lines are an example of this message sequence:
+</p>
+<code>
+[2010-01-01 12:45:02 - MyTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554<br>
+[2010-01-01 12:45:02 - MyTest] Collecting test information<br>
+[2010-01-01 12:45:02 - MyTest] Sending test information to Eclipse<br>
+[2010-01-01 12:45:02 - MyTest] Running tests...<br>
+[2010-01-01 12:45:22 - MyTest] Test run complete<br>
+</code>
+<br>
+<p>
+    The test results appear in the JUnit view. This is divided into an upper summary pane,
+    and a lower stack trace pane.
 </p>
 <p>
-        The upper pane contains test information. In the pane's header, you see the following
-        information:
+    The upper pane contains test information. In the pane's header, you see the following
+    information:
 </p>
-    <ul>
-        <li>
-           Total time elapsed for the test application (labeled Finished after <em>x</em> seconds).
-        </li>
-        <li>
-           Number of runs (Runs:) - the number of tests in the entire test class.
-        </li>
-        <li>
-           Number of errors (Errors:) - the number of program errors and exceptions encountered
-           during the test run.
-        </li>
-        <li>
-           Number of failures (Failures:) - the number of test failures encountered during the test
-           run. This is the number of assertion failures. A test can fail even if the program does
-           not encounter an error.
-        </li>
-        <li>
-           A progress bar. The progress bar extends from left to right as the tests run. If all the
-           tests succeed, the bar remains green. If a test fails, the bar turns from green to red.
-        </li>
-    </ul>
+<ul>
+    <li>
+        Total time elapsed for the test package (labeled Finished after <em>x</em> seconds).
+    </li>
+    <li>
+        Number of runs (Runs:) - the number of tests in the entire test class.
+    </li>
+    <li>
+        Number of errors (Errors:) - the number of program errors and exceptions encountered
+        during the test run.
+    </li>
+    <li>
+        Number of failures (Failures:) - the number of test failures encountered during the test
+        run. This is the number of assertion failures. A test can fail even if the program does
+        not encounter an error.
+    </li>
+    <li>
+        A progress bar. The progress bar extends from left to right as the tests run. If all the
+        tests succeed, the bar remains green. If a test fails, the bar turns from green to red.
+    </li>
+</ul>
 <p>
     The body of the upper pane contains the details of the test run. For each test case class
     that was run, you see a line with the class name. To look at the results for the individual
@@ -363,8 +505,30 @@
     pane and moves the focus to the first line of the test method.
 </p>
 <p>
+    The results of a successful test are shown in
+    <a href="#TestResults">Figure 1. Messages for a successful test</a>:
+</p>
+<a href="{@docRoot}images/testing/eclipse_test_results.png">
+    <img src="{@docRoot}images/testing/eclipse_test_results.png"
+         alt="Messages for a successful test" height="327px" id="TestResults"/>
+</a>
+<p class="img-caption">
+    <strong>Figure 1.</strong> Messages for a successful test
+</p>
+<p>
     The lower pane is for stack traces. If you highlight a failed test in the upper pane, the
     lower pane contains a stack trace for the test. If a line corresponds to a point in your
     test code, you can double-click it to display the code in an editor view pane, with the
     line highlighted. For a successful test, the lower pane is empty.
 </p>
+<p>
+    The results of a failed test are shown in
+    <a href="#FailedTestResults">Figure 2. Messages for a test failure</a>
+</p>
+<a href="{@docRoot}images/testing/eclipse_test_run_failure.png">
+    <img src="{@docRoot}images/testing/eclipse_test_run_failure.png"
+         alt="Messages for a test failure" height="372px" id="TestRun"/>
+</a>
+<p class="img-caption">
+    <strong>Figure 2.</strong> Messages for a test failure
+</p>
diff --git a/docs/html/guide/developing/testing/testing_otheride.jd b/docs/html/guide/developing/testing/testing_otheride.jd
index 2bdf4d0..523a8e5 100644
--- a/docs/html/guide/developing/testing/testing_otheride.jd
+++ b/docs/html/guide/developing/testing/testing_otheride.jd
@@ -2,122 +2,128 @@
 @jd:body
 
 <div id="qv-wrapper">
-  <div id="qv">
-  <h2>In this document</h2>
-  <ol>
-    <li>
-        <a href="#CreateTestProjectCommand">Working with Test Projects</a>
-        <ol>
-            <li>
-                <a href="#CreateTestProject">Creating a test project</a>
-            </li>
-            <li>
-                <a href="#UpdateTestProject">Updating a test project</a>
-            </li>
-        </ol>
-    </li>
-    <li>
-        <a href="#CreateTestApp">Creating a Test Application</a>
-    </li>
-    <li>
-        <a href="#RunTestsCommand">Running Tests</a>
-        <ol>
-            <li>
-                <a href="#RunTestsAnt">Quick build and run with Ant</a>
-            </li>
-            <li>
-                <a href="#RunTestsDevice">Running tests on a device or emulator</a>
-            </li>
-        </ol>
-    </li>
-    <li>
-        <a href="#AMSyntax">Using the Instrument Command</a>
-        <ol>
-            <li>
-                <a href="#AMOptionsSyntax">Instrument options</a>
-            </li>
-            <li>
-                <a href="#RunTestExamples">Instrument examples</a>
-            </li>
-        </ol>
-    </li>
-
-  </ol>
-  <h2>See Also</h2>
-  <ol>
-    <li>
-        <a
-        href="{@docRoot}guide/topics/testing/testing_android.html">Testing and Instrumentation</a>
-    </li>
-    <li>
-        <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
-    </li>
-    <li>
-        <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
-    </li>
-  </ol>
-  </div>
+    <div id="qv">
+        <h2>In this document</h2>
+            <ol>
+                <li>
+                    <a href="#CreateTestProjectCommand">Working with Test Projects</a>
+                    <ol>
+                        <li>
+                            <a href="#CreateTestProject">Creating a test project</a>
+                        </li>
+                        <li>
+                            <a href="#UpdateTestProject">Updating a test project</a>
+                        </li>
+                    </ol>
+                </li>
+                <li>
+                    <a href="#CreateTestApp">Creating a Test Package</a>
+                </li>
+                <li>
+                    <a href="#RunTestsCommand">Running Tests</a>
+                    <ol>
+                        <li>
+                            <a href="#RunTestsAnt">Quick build and run with Ant</a>
+                        </li>
+                        <li>
+                            <a href="#RunTestsDevice">Running tests on a device or emulator</a>
+                        </li>
+                    </ol>
+                </li>
+                <li>
+                    <a href="#AMSyntax">Using the Instrument Command</a>
+                    <ol>
+                        <li>
+                            <a href="#AMOptionsSyntax">Instrument options</a>
+                        </li>
+                        <li>
+                            <a href="#RunTestExamples">Instrument examples</a>
+                        </li>
+                    </ol>
+                </li>
+            </ol>
+        <h2>See Also</h2>
+            <ol>
+                <li>
+                    <a href="{@docRoot}guide/topics/testing/testing_android.html">
+                        Testing Fundamentals</a>
+                </li>
+                <li>
+                    <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
+                </li>
+            </ol>
+    </div>
 </div>
 <p>
-  This document describes how to create and run tests directly from the command line.
-  You can use the techniques described here if you are developing in an IDE other than Eclipse
-  or if you prefer to work from the command line. This document assumes that you already know how
-  to create a Android application in your programming environment. Before you start this
-  document, you should read the document <a
-  href="{@docRoot}guide/topics/testing/testing_android.html">Testing and Instrumentation</a>,
-  which provides an overview of Android testing.
+    This document describes how to create and run tests directly from the command line.
+    You can use the techniques described here if you are developing in an IDE other than Eclipse
+    or if you prefer to work from the command line. This document assumes that you already know how
+    to create a Android application in your programming environment. Before you start this
+    document, you should read the topic
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
+    which provides an overview of Android testing.
 </p>
 <p>
-  If you are developing in Eclipse with ADT, you can set up and run your tests
-directly in Eclipse. For more information, please read <a
-  href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing&nbsp;in&nbsp;Eclipse,&nbsp;with&nbsp;ADT</a>.
+    If you are developing in Eclipse with ADT, you can set up and run your tests
+    directly in Eclipse. For more information, please read
+    <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+    Testing in Eclipse, with ADT</a>.
 </p>
 <h2 id="CreateTestProjectCommand">Working with Test Projects</h2>
 <p>
-  You use the <code>android</code> tool to create test projects.
-  You also use <code>android</code> to convert existing test code into an Android test project,
-  or to add the <code>run-tests</code> Ant target to an existing Android test project.
-  These operations are described in more detail in the section <a
-  href="#UpdateTestProject">Updating a test project</a>.
-  The <code>run-tests</code> target is described in <a
-  href="#RunTestsAnt">Quick build and run with Ant</a>.
+    You use the <code>android</code> tool to create test projects.
+    You also use <code>android</code> to convert existing test code into an Android test project,
+    or to add the <code>run-tests</code> Ant target to an existing Android test project.
+    These operations are described in more detail in the section <a href="#UpdateTestProject">
+    Updating a test project</a>. The <code>run-tests</code> target is described in
+    <a href="#RunTestsAnt">Quick build and run with Ant</a>.
 </p>
 <h3 id="CreateTestProject">Creating a test project</h3>
 <p>
-  To create a test project with the <code>android</code> tool, enter:
-<pre>android create test-project -m &lt;main_path&gt; -n &lt;project_name&gt; -p &lt;test_path&gt;</pre>
+    To create a test project with the <code>android</code> tool, enter:
+</p>
+<pre>
+android create test-project -m &lt;main_path&gt; -n &lt;project_name&gt; -p &lt;test_path&gt;
+</pre>
 <p>
-  You must supply all the flags. The following table explains them in detail:
+    You must supply all the flags. The following table explains them in detail:
 </p>
 <table>
-  <tr>
-    <th>Flag</th>
-    <th>Value</th>
-    <th>Description</th>
-  <tr>
-    <td><code>-m, --main</code></td>
-    <td>
-        Path to the project of the application under test, relative to the test application
-        directory.
-    </td>
-    <td>
-        For example, if the application under test is in <code>source/HelloAndroid</code>, and you
-        want to create the test project in <code>source/HelloAndroidTest</code>, then the value of
-        <code>--main</code> should be <code>../HelloAndroid</code>.
+    <tr>
+        <th>Flag</th>
+        <th>Value</th>
+        <th>Description</th>
+    </tr>
+    <tr>
+        <td><code>-m, --main</code></td>
+        <td>
+            Path to the project of the application under test, relative to the test package
+            directory.
         </td>
-  <tr>
-    <td><code>-n, --name</code></td>
-    <td>Name that you want to give the test project.</td>
-    <td>&nbsp;</td>
-  </tr>
-  <tr>
-    <td><code>-p, --path</code></td>
-    <td>Directory in which you want to create the new test project.</td>
-    <td>
-      The <code>android</code> tool creates the test project files and directory structure in this
-      directory. If the directory does not exist, <code>android</code> creates it.
-    </td>
-  </tr>
+        <td>
+            For example, if the application under test is in <code>source/HelloAndroid</code>, and
+            you want to create the test project in <code>source/HelloAndroidTest</code>, then the
+            value of <code>--main</code> should be <code>../HelloAndroid</code>.
+        <p>
+            To learn more about choosing the location of test projects, please read
+            <a href="{@docRoot}guide/topics/testing/testing_android.html#TestProjects">
+            Testing Fundamentals</a>.
+        </p>
+        </td>
+    </tr>
+    <tr>
+        <td><code>-n, --name</code></td>
+        <td>Name that you want to give the test project.</td>
+        <td>&nbsp;</td>
+    </tr>
+    <tr>
+        <td><code>-p, --path</code></td>
+        <td>Directory in which you want to create the new test project.</td>
+        <td>
+            The <code>android</code> tool creates the test project files and directory structure
+            in this directory. If the directory does not exist, <code>android</code> creates it.
+        </td>
+    </tr>
 </table>
 <p>
     If the operation is successful, <code>android</code> lists to STDOUT the names of the files
@@ -135,11 +141,10 @@
     are testing and control it with instrumentation.
 </p>
 <p>
-    For example, suppose you create the <a
-    href="{@docRoot}resources/tutorials/hello-world.html">Hello, World</a> tutorial application
-    in the directory <code>~/source/HelloAndroid</code>. In the tutorial, this application uses the
-    package name <code>com.example.helloandroid</code> and the activity name
-    <code>HelloAndroid</code>. You can to create the test for this in
+    For example, suppose you create the <a href="{@docRoot}resources/tutorials/hello-world.html">
+    Hello, World</a> tutorial application in the directory <code>~/source/HelloAndroid</code>.
+    In the tutorial, this application uses the package name <code>com.example.helloandroid</code>
+    and the activity name <code>HelloAndroid</code>. You can to create the test for this in
     <code>~/source/HelloAndroidTest</code>. To do so, you enter:
 </p>
 <pre>
@@ -196,7 +201,7 @@
 <p class="note">
     <strong>Note:</strong> If you change the Android package name of the application under test,
     you must <em>manually</em> change the value of the <code>&lt;android:targetPackage&gt;</code>
-    attribute within the <code>AndroidManifest.xml</code> file of the test application.
+    attribute within the <code>AndroidManifest.xml</code> file of the test package.
     Running <code>android update test-project</code> does not do this.
 </p>
 <p>
@@ -205,38 +210,38 @@
 <pre>android update-test-project -m &lt;main_path&gt; -p &lt;test_path&gt;</pre>
 
 <table>
-<tr>
-  <th>Flag</th>
-  <th>Value</th>
-  <th>Description</th>
-</tr>
-<tr>
-  <td><code>-m, --main</code></td>
-  <td>The path to the project of the application under test, relative to the test project</td>
-  <td>
-    For example, if the application under test is in <code>source/HelloAndroid</code>, and
-    the test project is in <code>source/HelloAndroidTest</code>, then the value for
-    <code>--main</code> is <code>../HelloAndroid</code>.
-  </td>
-</tr>
-<tr>
-  <td><code>-p, --path</code></td>
-  <td>The of the test project.</td>
-  <td>
-    For example, if the test project is in <code>source/HelloAndroidTest</code>, then the
-    value for <code>--path</code> is <code>HelloAndroidTest</code>.
-  </td>
-</tr>
+    <tr>
+        <th>Flag</th>
+        <th>Value</th>
+        <th>Description</th>
+    </tr>
+    <tr>
+        <td><code>-m, --main</code></td>
+        <td>The path to the project of the application under test, relative to the test project</td>
+        <td>
+            For example, if the application under test is in <code>source/HelloAndroid</code>, and
+            the test project is in <code>source/HelloAndroidTest</code>, then the value for
+            <code>--main</code> is <code>../HelloAndroid</code>.
+        </td>
+    </tr>
+    <tr>
+        <td><code>-p, --path</code></td>
+        <td>The of the test project.</td>
+        <td>
+            For example, if the test project is in <code>source/HelloAndroidTest</code>, then the
+            value for <code>--path</code> is <code>HelloAndroidTest</code>.
+        </td>
+    </tr>
 </table>
 <p>
     If the operation is successful, <code>android</code> lists to STDOUT the names of the files
     and directories it has created.
 </p>
-<h2 id="CreateTestApp">Creating a Test Application</h2>
+<h2 id="CreateTestApp">Creating a Test Package</h2>
 <p>
-    Once you have created a test project, you populate it with a test application.
+    Once you have created a test project, you populate it with a test package.
     The application does not require an {@link android.app.Activity Activity},
-    although you can define one if you wish. Although your test application can
+    although you can define one if you wish. Although your test package can
     combine Activities, Android test class extensions, JUnit extensions, or
     ordinary classes, you should extend one of the Android test classes or JUnit classes,
     because these provide the best testing features.
@@ -248,7 +253,7 @@
 </p>
 
 <p>
-    To create a test application, start with one of Android's test classes in the Java package
+    To create a test package, start with one of Android's test classes in the Java package
     {@link android.test android.test}. These extend the JUnit
     {@link junit.framework.TestCase TestCase} class. With a few exceptions, the Android test
     classes also provide instrumentation for testing.
@@ -282,24 +287,17 @@
     test results are suspect, regardless of whether or not the tests succeeded.
 </p>
 <p>
-    To learn more about creating test applications, see the topic <a
-    href="{@docRoot}guide/topics/testing/testing_android.html">Testing and Instrumentation</a>,
+    To learn more about creating test packages, see the topic <a
+    href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
     which provides an overview of Android testing. If you prefer to follow a tutorial,
     try the <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
     tutorial, which leads you through the creation of tests for an actual Android application.
 </p>
 <h2 id="RunTestsCommand">Running Tests</h2>
 <p>
-    If you are not developing in Eclipse with ADT, you need to run tests from the command line.
-    You can do this either with Ant or with the {@link android.app.ActivityManager ActivityManager}
-    command line interface.
-</p>
-<p>
-    You can also run tests from the command line even if you are using Eclipse with ADT to develop
-    them. To do this, you need to create the proper files and directory structure in the test
-    project, using the <code>android</code> tool with the option <code>create test-project</code>.
-    This is described in the section <a
-    href="#CreateTestProjectCommand">Working with Test Projects</a>.
+    You run tests from the command line, either with Ant or with an
+    <a href="{@docRoot}http://developer.android.com/guide/developing/tools/adb.html">
+    Android Debug Bridge (adb)</a> shell.
 </p>
 <h3 id="RunTestsAnt">Quick build and run with Ant</h3>
 <p>
@@ -316,57 +314,63 @@
     You can update an existing test project to use this feature. To do this, use the
     <code>android</code> tool with the <code>update test-project</code> option. This is described
     in the section <a href="#UpdateTestProject">Updating a test project</a>.
+</p>
 <h3 id="RunTestsDevice">Running tests on a device or emulator</h3>
 <p>
-    When you run tests from the command line with the ActivityManager (<code>am</code>)
-    command-line tool, you get more options for choosing the tests to run than with any other
-    method. You can select individual test methods, filter tests according to their annotation, or
-    specify testing options. Since the test run is controlled entirely from a command line, you can
-    customize your testing with shell scripts in various ways.
+    When you run tests from the command line with
+    <a href="{@docRoot}http://developer.android.com/guide/developing/tools/adb.html">
+    Android Debug Bridge (adb)</a>, you get more options for choosing the tests
+    to run than with any other method. You can select individual test methods, filter tests
+    according to their annotation, or specify testing options. Since the test run is controlled
+    entirely from a command line, you can customize your testing with shell scripts in various ways.
 </p>
 <p>
-    You run the <code>am</code> tool on an Android device or emulator using the
-    <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge</a>
-    (<code>adb</code>) shell. When you do this, you use the ActivityManager
-    <code>instrument</code> option to run your test application using an Android test runner
-    (usually {@link android.test.InstrumentationTestRunner}). You set <code>am</code>
-    options with command-line flags.
+    To run a test from the command line, you run <code>adb shell</code> to start a command-line
+    shell on your device or emulator, and then in the shell run the <code>am instrument</code>
+    command. You control <code>am</code> and your tests with command-line flags.
 </p>
 <p>
-    To run a test with <code>am</code>:
+    As a shortcut, you can start an <code>adb</code> shell, call <code>am instrument</code>, and
+    specify command-line flags all on one input line. The shell opens on the device or emulator,
+    runs your tests, produces output, and then returns to the command line on your computer.
+</p>
+<p>
+    To run a test with <code>am instrument</code>:
 </p>
 <ol>
-  <li>
-    If necessary, re-build your main application and test application.
-  </li>
-  <li>
-    Install your test application and main application Android package files
-    (<code>.apk</code> files) to your current Android device or emulator</li>
-  <li>
-    At the command line, enter:
+    <li>
+        If necessary, rebuild your main application and test package.
+    </li>
+    <li>
+        Install your test package and main application Android package files
+        (<code>.apk</code> files) to your current Android device or emulator</li>
+    <li>
+        At the command line, enter:
 <pre>
 $ adb shell am instrument -w &lt;test_package_name&gt;/&lt;runner_class&gt;
 </pre>
-<p>
-    where <code>&lt;test_package_name&gt;</code> is the Android package name of your test
-    application, and <code>&lt;runner_class&gt;</code> is the name of the Android test runner
-    class you are using. The Android package name is the value of the <code>package</code>
-    attribute of the <code>manifest</code> element in the manifest file
-    (<code>AndroidManifest.xml</code>) of your test application. The Android test runner
-    class is usually <code>InstrumentationTestRunner</code>.
-</p>
-<p>Your test results appear in <code>STDOUT</code>.</p>
-  </li>
+        <p>
+            where <code>&lt;test_package_name&gt;</code> is the Android package name of your test
+            application, and <code>&lt;runner_class&gt;</code> is the name of the Android test
+            runner class you are using. The Android package name is the value of the
+            <code>package</code> attribute of the <code>manifest</code> element in the manifest file
+            (<code>AndroidManifest.xml</code>) of your test package. The Android test runner
+            class is usually {@link android.test.InstrumentationTestRunner}.
+        </p>
+        <p>
+            Your test results appear in <code>STDOUT</code>.
+        </p>
+    </li>
 </ol>
 <p>
-    This operation starts an <code>adb</code> shell, then runs <code>am instrument</code> in it
+    This operation starts an <code>adb</code> shell, then runs <code>am instrument</code>
     with the specified parameters. This particular form of the command will run all of the tests
-    in your test application. You can control this behavior with flags that you pass to
+    in your test package. You can control this behavior with flags that you pass to
     <code>am instrument</code>. These flags are described in the next section.
 </p>
-<h2 id="AMSyntax">Using the Instrument Command</h2>
+<h2 id="AMSyntax">Using the am instrument Command</h2>
 <p>
-  The general syntax of the <code>am instrument</code> command is:
+    The general syntax of the <code>am instrument</code> command is:
 </p>
 <pre>
     am instrument [flags] &lt;test_package&gt;/&lt;runner_class&gt;
@@ -391,11 +395,11 @@
             <code>&lt;test_package&gt;</code>
         </td>
         <td>
-            The Android package name of the test application.
+            The Android package name of the test package.
         </td>
         <td>
             The value of the <code>package</code> attribute of the <code>manifest</code>
-            element in the test application's manifest file.
+            element in the test package's manifest file.
         </td>
     </tr>
     <tr>
@@ -411,7 +415,7 @@
     </tr>
 </table>
 <p>
-The flags for <code>am instrument</code> are described in the following table:
+    The flags for <code>am instrument</code> are described in the following table:
 </p>
 <table>
     <tr>
@@ -461,20 +465,21 @@
              &lt;test_options&gt;
         </td>
         <td>
-            Provides testing options , in the form of key-value pairs. The
+            Provides testing options as key-value pairs. The
             <code>am instrument</code> tool passes these to the specified instrumentation class
             via its <code>onCreate()</code> method. You can specify multiple occurrences of
-            <code>-e &lt;test_options</code>. The keys and values are described in the next table.
+            <code>-e &lt;test_options&gt;</code>. The keys and values are described in the
+            section <a href="#AMOptionsSyntax">am instrument options</a>.
             <p>
-                The only instrumentation class that understands these key-value pairs is
-                <code>InstrumentationTestRunner</code> (or a subclass). Using them with
+                The only instrumentation class that uses these key-value pairs is
+                {@link android.test.InstrumentationTestRunner} (or a subclass). Using them with
                 any other class has no effect.
             </p>
         </td>
     </tr>
 </table>
 
-<h3 id="AMOptionsSyntax">Instrument options</h3>
+<h3 id="AMOptionsSyntax">am instrument options</h3>
 <p>
     The <code>am instrument</code> tool passes testing options to
     <code>InstrumentationTestRunner</code> or a subclass in the form of key-value pairs,
@@ -484,123 +489,127 @@
     -e &lt;key&gt; &lt;value&gt;
 </pre>
 <p>
-    Where applicable, a &lt;key&gt; may have multiple values separated by a comma (,).
+    Some keys accept multiple values. You specify multiple values in a comma-separated list.
     For example, this invocation of <code>InstrumentationTestRunner</code> provides multiple
     values for the <code>package</code> key:
+</p>
 <pre>
-$ adb shell am instrument -w -e package com.android.test.package1,com.android.test.package2 com.android.test/android.test.InstrumentationTestRunner
+$ adb shell am instrument -w -e package com.android.test.package1,com.android.test.package2 \
+&gt; com.android.test/android.test.InstrumentationTestRunner
 </pre>
 <p>
     The following table describes the key-value pairs and their result. Please review the
     <strong>Usage Notes</strong> following the table.
 </p>
 <table>
-<tr>
-    <th>Key</th>
-    <th>Value</th>
-    <th>Description</th>
-</tr>
-<tr>
-    <td>
-        <code>package</code>
-    </td>
-    <td>
-        &lt;Java_package_name&gt;
-    </td>
-    <td>
-        The fully-qualified <em>Java</em> package name for one of the packages in the test
-        application. Any test case class that uses this package name is executed. Notice that this
-        is not an <em>Android</em> package name; a test application has a single Android package
-        name but may have several Java packages within it.
-    </td>
-</tr>
-<tr>
-    <td rowspan="2"><code>class</code></td>
-    <td>&lt;class_name&gt;</td>
-    <td>
-        The fully-qualified Java class name for one of the test case classes. Only this test case
-        class is executed.
-    </td>
-</tr>
-<tr>
-    <td>&lt;class_name&gt;<strong>#</strong>method name</td>
-    <td>
-        A fully-qualified test case class name, and one of its methods. Only this method is
-        executed. Note the hash mark (#) between the class name and the method name.
-    </td>
-</tr>
-<tr>
-    <td><code>func</code></td>
-    <td><code>true</code></td>
-    <td>
-        Runs all test classes that extend {@link android.test.InstrumentationTestCase}.
-    </td>
-</tr>
-<tr>
-    <td><code>unit</code></td>
-    <td><code>true</code></td>
-    <td>
-        Runs all test classes that do <em>not</em> extend either
-        {@link android.test.InstrumentationTestCase} or {@link android.test.PerformanceTestCase}.
-    </td>
-</tr>
-<tr>
-    <td><code>size</code></td>
-    <td>[<code>small</code> | <code>medium</code> | <code>large</code>]
-    </td>
-    <td>
-        Runs a test method annotated by size. The  annotations are <code>@SmallTest</code>,
-        <code>@MediumTest</code>, and <code>@LargeTest</code>.
-    </td>
-</tr>
-<tr>
-    <td><code>perf</code></td>
-    <td><code>true</code></td>
-    <td>
-        Runs all test classes that implement {@link android.test.PerformanceTestCase}.
-        When you use this option, also specify the <code>-r</code> flag for
-        <code>am instrument</code>, so that the output is kept in raw format and not
-        re-formatted as test results.
-    </td>
-</tr>
-<tr>
-    <td><code>debug</code></td>
-    <td><code>true</code></td>
-    <td>
-        Runs tests in debug mode.
-    </td>
-</tr>
-<tr>
-    <td><code>log</code></td>
-    <td><code>true</code></td>
-    <td>
-        Loads and logs all specified tests, but does not run them. The test
-        information appears in <code>STDOUT</code>. Use this to verify combinations of other filters
-        and test specifications.
-    </td>
-</tr>
-<tr>
-    <td><code>emma</code></td>
-    <td><code>true</code></td>
-    <td>
-        Runs an EMMA code coverage analysis and writes the output to <code>/data//coverage.ec</code>
-        on the device. To override the file location, use the <code>coverageFile</code> key that
-        is described in the following entry.
-        <p class="note">
-            <strong>Note:</strong> This option requires an EMMA-instrumented build of the test
-            application, which you can generate with the <code>coverage</code> target.
-        </p>
-    </td>
-</tr>
-<tr>
-    <td><code>coverageFile</code></td>
-    <td><code>&lt;filename&gt;</code></td>
-    <td>
-        Overrides the default location of the EMMA coverage file on the device. Specify this
-        value as a path and filename in UNIX format. The default filename is described in the
-        entry for the <code>emma</code> key.
-    </td>
-</tr>
+    <tr>
+        <th>Key</th>
+        <th>Value</th>
+        <th>Description</th>
+    </tr>
+    <tr>
+        <td>
+            <code>package</code>
+        </td>
+        <td>
+            &lt;Java_package_name&gt;
+        </td>
+        <td>
+            The fully-qualified <em>Java</em> package name for one of the packages in the test
+            application. Any test case class that uses this package name is executed. Notice that
+            this is not an <em>Android</em> package name; a test package has a single
+            Android package name but may have several Java packages within it.
+        </td>
+    </tr>
+    <tr>
+        <td rowspan="2"><code>class</code></td>
+        <td>&lt;class_name&gt;</td>
+        <td>
+            The fully-qualified Java class name for one of the test case classes. Only this test
+            case class is executed.
+        </td>
+    </tr>
+    <tr>
+        <td>&lt;class_name&gt;<strong>#</strong>method name</td>
+        <td>
+            A fully-qualified test case class name, and one of its methods. Only this method is
+            executed. Note the hash mark (#) between the class name and the method name.
+        </td>
+    </tr>
+    <tr>
+        <td><code>func</code></td>
+        <td><code>true</code></td>
+        <td>
+            Runs all test classes that extend {@link android.test.InstrumentationTestCase}.
+        </td>
+    </tr>
+    <tr>
+        <td><code>unit</code></td>
+        <td><code>true</code></td>
+        <td>
+            Runs all test classes that do <em>not</em> extend either
+            {@link android.test.InstrumentationTestCase} or
+            {@link android.test.PerformanceTestCase}.
+        </td>
+    </tr>
+    <tr>
+        <td><code>size</code></td>
+        <td>
+            [<code>small</code> | <code>medium</code> | <code>large</code>]
+        </td>
+        <td>
+            Runs a test method annotated by size. The  annotations are <code>@SmallTest</code>,
+            <code>@MediumTest</code>, and <code>@LargeTest</code>.
+        </td>
+    </tr>
+    <tr>
+        <td><code>perf</code></td>
+        <td><code>true</code></td>
+        <td>
+            Runs all test classes that implement {@link android.test.PerformanceTestCase}.
+            When you use this option, also specify the <code>-r</code> flag for
+            <code>am instrument</code>, so that the output is kept in raw format and not
+            re-formatted as test results.
+        </td>
+    </tr>
+    <tr>
+        <td><code>debug</code></td>
+        <td><code>true</code></td>
+        <td>
+            Runs tests in debug mode.
+        </td>
+    </tr>
+    <tr>
+        <td><code>log</code></td>
+        <td><code>true</code></td>
+        <td>
+            Loads and logs all specified tests, but does not run them. The test
+            information appears in <code>STDOUT</code>. Use this to verify combinations of other
+            filters and test specifications.
+        </td>
+    </tr>
+    <tr>
+        <td><code>emma</code></td>
+        <td><code>true</code></td>
+        <td>
+            Runs an EMMA code coverage analysis and writes the output to
+            <code>/data//coverage.ec</code> on the device. To override the file location, use the
+            <code>coverageFile</code> key that is described in the following entry.
+            <p class="note">
+                <strong>Note:</strong> This option requires an EMMA-instrumented build of the test
+                application, which you can generate with the <code>coverage</code> target.
+            </p>
+        </td>
+    </tr>
+    <tr>
+        <td><code>coverageFile</code></td>
+        <td><code>&lt;filename&gt;</code></td>
+        <td>
+            Overrides the default location of the EMMA coverage file on the device. Specify this
+            value as a path and filename in UNIX format. The default filename is described in the
+            entry for the <code>emma</code> key.
+        </td>
+    </tr>
 </table>
 <strong><code>-e</code> Flag Usage Notes</strong>
 <ul>
@@ -618,13 +627,13 @@
         The <code>func</code> key and <code>unit</code> key are mutually exclusive.
     </li>
 </ul>
-<h3 id="RunTestExamples">Instrument examples</h3>
+<h3 id="RunTestExamples">Usage examples</h3>
 <p>
-Here are some examples of using <code>am instrument</code> to run tests. They are based on
-the following structure:</p>
+The following sections provide examples of using <code>am instrument</code> to run tests.
+They are based on the following structure:</p>
 <ul>
     <li>
-        The test application has the Android package name <code>com.android.demo.app.tests</code>
+        The test package has the Android package name <code>com.android.demo.app.tests</code>
     </li>
     <li>
         There are three test classes:
@@ -647,35 +656,35 @@
         The test runner is {@link android.test.InstrumentationTestRunner}.
     </li>
 </ul>
-<h4>Running the Entire Test Application</h4>
+<h4>Running the entire test package</h4>
 <p>
-    To run all of the test classes in the test application, enter:
+    To run all of the test classes in the test package, enter:
 </p>
 <pre>
 $ adb shell am instrument -w com.android.demo.app.tests/android.test.InstrumentationTestRunner
 </pre>
-<h4>Running All Tests in a Test Case Class</h4>
+<h4>Running all tests in a test case class</h4>
 <p>
     To run all of the tests in the class <code>UnitTests</code>, enter:
 </p>
 <pre>
 $ adb shell am instrument -w  \
--e class com.android.demo.app.tests.UnitTests \
-com.android.demo.app.tests/android.test.InstrumentationTestRunner
+&gt; -e class com.android.demo.app.tests.UnitTests \
+&gt; com.android.demo.app.tests/android.test.InstrumentationTestRunner
 </pre>
 <p>
   <code>am instrument</code> gets the value of the <code>-e</code> flag, detects the
   <code>class</code> keyword, and runs all the methods in the <code>UnitTests</code> class.
 </p>
-<h4>Selecting a Subset of Tests</h4>
+<h4>Selecting a subset of tests</h4>
 <p>
-  To run all of the tests in <code>UnitTests</code>, and the <code>testCamera</code> method in
-  <code>FunctionTests</code>, enter:
+    To run all of the tests in <code>UnitTests</code>, and the <code>testCamera</code> method in
+    <code>FunctionTests</code>, enter:
 </p>
 <pre>
 $ adb shell am instrument -w \
--e class com.android.demo.app.tests.UnitTests,com.android.demo.app.tests.FunctionTests#testCamera \
-com.android.demo.app.tests/android.test.InstrumentationTestRunner
+&gt; -e class com.android.demo.app.tests.UnitTests,com.android.demo.app.tests.FunctionTests#testCamera \
+&gt; com.android.demo.app.tests/android.test.InstrumentationTestRunner
 </pre>
 <p>
     You can find more examples of the command in the documentation for
diff --git a/docs/html/guide/guide_toc.cs b/docs/html/guide/guide_toc.cs
index cdf5feb..2b803424 100644
--- a/docs/html/guide/guide_toc.cs
+++ b/docs/html/guide/guide_toc.cs
@@ -254,12 +254,34 @@
             <li><a href="<?cs var:toroot?>guide/topics/search/searchable-config.html">Searchable Configuration</a></li>
           </ul>
       </li>
-      <li><a href="<?cs var:toroot?>guide/topics/testing/testing_android.html">
-            <span class="en">Testing and Instrumentation</span>
-          </a></li>
+      <li class="toggle-list">
+           <div>
+                <a href="<?cs var:toroot ?>guide/topics/testing/index.html">
+                   <span class="en">Testing</span>
+               </a> <span class="new">new!</span>
+           </div>
+           <ul>
+              <li><a href="<?cs var:toroot?>guide/topics/testing/testing_android.html">
+                <span class="en">Testing Fundamentals</span></a>
+              </li>
+              <li><a href="<?cs var:toroot?>guide/topics/testing/activity_testing.html">
+                <span class="en">Activity Testing</span></a>
+              </li>
+              <li><a href="<?cs var:toroot ?>guide/topics/testing/contentprovider_testing.html">
+                <span class="en">Content Provider Testing</span></a>
+              </li>
+              <li><a href="<?cs var:toroot ?>guide/topics/testing/service_testing.html">
+                <span class="en">Service Testing</span></a>
+              </li>
+              <li><a href="<?cs var:toroot ?>guide/topics/testing/what_to_test.html">
+                <span class="en">What To Test</span></a>
+              </li>
+           </ul>
+      </li>
      <li><a href="<?cs var:toroot?>guide/topics/admin/device-admin.html">
             <span class="en">Device Administration</span>
-         </a> <span class="new">new!</span><!-- 10/8/10 --></li>
+         </a> <span class="new">new!</span>
+    </li>
     </ul>
   </li>
 
diff --git a/docs/html/guide/practices/design/responsiveness.jd b/docs/html/guide/practices/design/responsiveness.jd
index b811d1b..a00e3aa 100644
--- a/docs/html/guide/practices/design/responsiveness.jd
+++ b/docs/html/guide/practices/design/responsiveness.jd
@@ -99,6 +99,10 @@
 event timeout. These same practices should be followed for any other threads
 that display UI, as they are also subject to the same timeouts.</p>
 
+<p>You can use {@link android.os.StrictMode} to help find potentially
+long running operations such as network or database operations that
+you might accidentally be doing your main thread.</p>
+
 <p>The specific constraint on IntentReceiver execution time emphasizes what
 they were meant to do: small, discrete amounts of work in the background such
 as saving a setting or registering a Notification. So as with other methods
diff --git a/docs/html/guide/topics/testing/activity_testing.jd b/docs/html/guide/topics/testing/activity_testing.jd
new file mode 100644
index 0000000..6392ad7
--- /dev/null
+++ b/docs/html/guide/topics/testing/activity_testing.jd
@@ -0,0 +1,392 @@
+page.title=Activity Testing
+@jd:body
+
+<div id="qv-wrapper">
+  <div id="qv">
+  <h2>In this document</h2>
+  <ol>
+    <li>
+      <a href="#ActivityTestAPI">The Activity Testing API</a>
+      <ol>
+        <li>
+            <a href="#ActivityInstrumentationTestCase2">ActivityInstrumentationTestCase2</a>
+        </li>
+        <li>
+            <a href="#ActivityUnitTestCase">ActivityUnitTestCase</a>
+        </li>
+        <li>
+            <a href="#SingleLaunchActivityTestCase">SingleLaunchActivityTestCase</a>
+        </li>
+        <li>
+            <a href="#MockObjectNotes">Mock objects and activity testing</a>
+        </li>
+        <li>
+            <a href="#AssertionNotes">Assertions for activity testing</a>
+        </li>
+      </ol>
+    </li>
+    <li>
+        <a href="#WhatToTest">What to Test</a>
+    </li>
+    <li>
+        <a href="#NextSteps">Next Steps</a>
+    </li>
+    <li>
+      <a href="#UITesting">Appendix: UI Testing Notes</a>
+      <ol>
+        <li>
+          <a href="#RunOnUIThread">Testing on the UI thread</a>
+        </li>
+        <li>
+          <a href="#NotouchMode">Turning off touch mode</a>
+        </li>
+        <li>
+          <a href="#UnlockDevice">Unlocking the Emulator or Device</a>
+        </li>
+        <li>
+          <a href="#UITestTroubleshooting">Troubleshooting UI tests</a>
+        </li>
+      </ol>
+    </li>
+    </ol>
+<h2>Key Classes</h2>
+    <ol>
+      <li>{@link android.test.InstrumentationTestRunner}</li>
+      <li>{@link android.test.ActivityInstrumentationTestCase2}</li>
+      <li>{@link android.test.ActivityUnitTestCase}</li>
+    </ol>
+<h2>Related Tutorials</h2>
+    <ol>
+      <li>
+        <a href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">
+        Hello, Testing</a>
+      </li>
+      <li>
+         <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
+      </li>
+    </ol>
+<h2>See Also</h2>
+      <ol>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+          Testing in Eclipse, with ADT</a>
+        </li>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+          Testing in Other IDEs</a>
+        </li>
+      </ol>
+  </div>
+</div>
+<p>
+    Activity testing is particularly dependent on the the Android instrumentation framework.
+    Unlike other components, activities have a complex lifecycle based on callback methods; these
+    can't be invoked directly except by instrumentation. Also, the only way to send events to the
+    user interface from a program is through instrumentation.
+</p>
+<p>
+    This document describes how to test activities using instrumentation and other test
+    facilities. The document assumes you have already read
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
+    the introduction to the Android testing and instrumentation framework.
+</p>
+<h2 id="ActivityTestAPI">The Activity Testing API</h2>
+<p>
+    The activity testing API base class is {@link android.test.InstrumentationTestCase},
+    which provides instrumentation to the test case subclasses you use for Activities.
+</p>
+<p>
+    For activity testing, this base class provides these functions:
+</p>
+<ul>
+    <li>
+        Lifecycle control: With instrumentation, you can start the activity under test, pause it,
+        and destroy it, using methods provided by the test case classes.
+    </li>
+    <li>
+        Dependency injection: Instrumentation allows you to create mock system objects such as
+        Contexts or Applications and use them to run the activity under test. This
+        helps you control the test environment and isolate it from production systems. You can
+        also set up customized Intents and start an activity with them.
+    </li>
+    <li>
+        User interface interaction: You use instrumentation to send keystrokes or touch events
+        directly to the UI of the activity under test.
+    </li>
+</ul>
+<p>
+    The activity testing classes also provide the JUnit framework by extending
+    {@link junit.framework.TestCase} and {@link junit.framework.Assert}.
+</p>
+<p>
+    The two main testing subclasses are {@link android.test.ActivityInstrumentationTestCase2} and
+    {@link android.test.ActivityUnitTestCase}. To test an Activity that is launched in a mode
+    other than <code>standard</code>, you use {@link android.test.SingleLaunchActivityTestCase}.
+</p>
+<h3 id="ActivityInstrumentationTestCase2">ActivityInstrumentationTestCase2</h3>
+<p>
+    The {@link android.test.ActivityInstrumentationTestCase2} test case class is designed to do
+    functional testing of one or more Activities in an application, using a normal system
+    infrastructure. It runs the Activities in a normal instance of the application under test,
+    using a standard system Context. It allows you to send mock Intents to the activity under
+    test, so you can use it to test an activity that responds to multiple types of intents, or
+    an activity that expects a certain type of data in the intent, or both. Notice, though, that it
+    does not allow mock Contexts or Applications, so you can not isolate the test from the rest of
+    a production system.
+</p>
+<h3 id="ActivityUnitTestCase">ActivityUnitTestCase</h3>
+<p>
+    The {@link android.test.ActivityUnitTestCase} test case class tests a single activity in
+    isolation. Before you start the activity, you can inject a mock Context or Application, or both.
+    You use it to run activity tests in isolation, and to do unit testing of methods
+    that do not interact with Android. You can not send mock Intents to the activity under test,
+    although you can call
+    {@link android.app.Activity#startActivity(Intent) Activity.startActivity(Intent)} and then
+    look at arguments that were received.
+</p>
+<h3 id="SingleLaunchActivityTestCase">SingleLaunchActivityTestCase</h3>
+<p>
+    The {@link android.test.SingleLaunchActivityTestCase} class is a convenience class for
+    testing a single activity in an environment that doesn't change from test to test.
+    It invokes {@link junit.framework.TestCase#setUp() setUp()} and
+    {@link junit.framework.TestCase#tearDown() tearDown()} only once, instead of once per
+    method call. It does not allow you to inject any mock objects.
+</p>
+<p>
+    This test case is useful for testing an activity that runs in a mode other than
+    <code>standard</code>. It ensures that the test fixture is not reset between tests. You
+    can then test that the activity handles multiple calls correctly.
+</p>
+<h3 id="MockObjectNotes">Mock objects and activity testing</h3>
+<p>
+    This section contains notes about the use of the mock objects defined in
+    {@link android.test.mock} with activity tests.
+</p>
+<p>
+    The mock object {@link android.test.mock.MockApplication} is only available for activity
+    testing if you use the {@link android.test.ActivityUnitTestCase} test case class.
+    By default, <code>ActivityUnitTestCase</code>, creates a hidden <code>MockApplication</code>
+    object that is used as the application under test. You can inject your own object using
+    {@link android.test.ActivityUnitTestCase#setApplication(Application) setApplication()}.
+</p>
+<h3 id="AssertionNotes">Assertions for activity testing</h3>
+<p>
+    {@link android.test.ViewAsserts} defines assertions for Views. You use it to verify the
+    alignment and position of View objects, and to look at the state of ViewGroup objects.
+</p>
+<h2 id="WhatToTest">What To Test</h2>
+<ul>
+    <li>
+        Input validation: Test that an activity responds correctly to input values in an
+        EditText View. Set up a keystroke sequence, send it to the activity, and then
+        use {@link android.view.View#findViewById(int)} to examine the state of the View. You can
+        verify that a valid keystroke sequence enables an OK button, while an invalid one leaves the
+        button disabled. You can also verify that the Activity responds to invalid input by
+        setting error messages in the View.
+    </li>
+    <li>
+        Lifecycle events: Test that each of your application's activities handles lifecycle events
+        correctly. In general, lifecycle events are actions, either from the system or from the
+        user, that trigger a callback method such as <code>onCreate()</code> or
+        <code>onClick()</code>. For example, an activity should respond to pause or destroy events
+        by saving its state. Remember that even a change in screen orientation causes the current
+        activity to be destroyed, so you should test that accidental device movements don't
+        accidentally lose the application state.
+    </li>
+    <li>
+        Intents: Test that each activity correctly handles the intents listed in the intent
+        filter specified in its manifest. You can use
+        {@link android.test.ActivityInstrumentationTestCase2} to send mock Intents to the
+        activity under test.
+    </li>
+    <li>
+        Runtime configuration changes: Test that each activity responds correctly to the
+        possible changes in the device's configuration while your application is running. These
+        include a change to the device's orientation, a change to the current language, and so
+        forth. Handling these changes is described in detail in the topic
+        <a href="{@docRoot}guide/topics/resources/runtime-changes.html">Handling Runtime
+        Changes</a>.
+    </li>
+    <li>
+        Screen sizes and resolutions: Before you publish your application, make sure to test it on
+        all of the screen sizes and densities on which you want it to run. You can test the
+        application on multiple sizes and densities using AVDs, or you can test your application
+        directly on the devices that you are targeting. For more information, see the topic
+        <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple Screens</a>.
+    </li>
+</ul>
+<h2 id="NextSteps">Next Steps</h2>
+<p>
+    To learn how to set up and run tests in Eclipse, please refer to <a
+    href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in
+    Eclipse, with ADT</a>. If you're not working in Eclipse, refer to <a
+    href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other
+    IDEs</a>.
+</p>
+<p>
+    If you want a step-by-step introduction to testing activities, try one of the
+    testing tutorials:
+</p>
+<ul>
+    <li>
+        The <a
+        href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello,
+        Testing</a> tutorial introduces basic testing concepts and procedures in the
+        context of the Hello, World application.
+    </li>
+    <li>
+        The <a
+        href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity
+        Testing</a> tutorial is an excellent follow-up to the Hello, Testing tutorial.
+        It guides you through a more complex testing scenario that you develop against a
+        more realistic activity-oriented application.
+    </li>
+</ul>
+<h2 id="UITesting">Appendix: UI Testing Notes</h2>
+<p>
+    The following sections have tips for testing the UI of your Android application, specifically
+    to help you handle actions that run in the UI thread, touch screen and keyboard events, and home
+    screen unlock during testing.
+</p>
+<h3 id="RunOnUIThread">Testing on the UI thread</h3>
+<p>
+    An application's activities run on the application's <strong>UI thread</strong>. Once the
+    UI is instantiated, for example in the activity's <code>onCreate()</code> method, then all
+    interactions with the UI must run in the UI thread. When you run the application normally, it
+    has access to the thread and does not have to do anything special.
+</p>
+<p>
+    This changes when you run tests against the application. With instrumentation-based classes,
+    you can invoke methods against the UI of the application under test. The other test classes
+    don't allow this. To run an entire test method on the UI thread, you can annotate the thread
+    with <code>@UIThreadTest</code>. Notice that this will run <em>all</em> of the method statements
+    on the UI thread.  Methods that do not interact with the UI are not allowed; for example, you
+    can't invoke <code>Instrumentation.waitForIdleSync()</code>.
+</p>
+<p>
+    To run a subset of a test method on the UI thread, create an anonymous class of type
+    <code>Runnable</code>, put the statements you want in the <code>run()</code> method, and
+    instantiate a new instance of the class as a parameter to the method
+    <code><em>appActivity</em>.runOnUiThread()</code>, where <code><em>appActivity</em></code> is
+    the instance of the application you are testing.
+</p>
+<p>
+    For example, this code instantiates an activity to test, requests focus (a UI action) for the
+    Spinner displayed by the activity, and then sends a key to it. Notice that the calls to
+    <code>waitForIdleSync</code> and <code>sendKeys</code> aren't allowed to run on the UI thread:
+</p>
+<pre>
+  private MyActivity mActivity; // MyActivity is the class name of the app under test
+  private Spinner mSpinner;
+
+  ...
+
+  protected void setUp() throws Exception {
+      super.setUp();
+      mInstrumentation = getInstrumentation();
+
+      mActivity = getActivity(); // get a references to the app under test
+
+      /*
+       * Get a reference to the main widget of the app under test, a Spinner
+       */
+      mSpinner = (Spinner) mActivity.findViewById(com.android.demo.myactivity.R.id.Spinner01);
+
+  ...
+
+  public void aTest() {
+      /*
+       * request focus for the Spinner, so that the test can send key events to it
+       * This request must be run on the UI thread. To do this, use the runOnUiThread method
+       * and pass it a Runnable that contains a call to requestFocus on the Spinner.
+       */
+      mActivity.runOnUiThread(new Runnable() {
+          public void run() {
+              mSpinner.requestFocus();
+          }
+      });
+
+      mInstrumentation.waitForIdleSync();
+
+      this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
+</pre>
+
+<h3 id="NotouchMode">Turning off touch mode</h3>
+<p>
+    To control the emulator or a device with key events you send from your tests, you must turn off
+    touch mode. If you do not do this, the key events are ignored.
+</p>
+<p>
+    To turn off touch mode, you invoke
+    <code>ActivityInstrumentationTestCase2.setActivityTouchMode(false)</code>
+    <em>before</em> you call <code>getActivity()</code> to start the activity. You must invoke the
+    method in a test method that is <em>not</em> running on the UI thread. For this reason, you
+    can't invoke the touch mode method from a test method that is annotated with
+    <code>@UIThread</code>. Instead, invoke the touch mode method from <code>setUp()</code>.
+</p>
+<h3 id="UnlockDevice">Unlocking the emulator or device</h3>
+<p>
+    You may find that UI tests don't work if the emulator's or device's home screen is disabled with
+    the keyguard pattern. This is because the application under test can't receive key events sent
+    by <code>sendKeys()</code>. The best way to avoid this is to start your emulator or device
+    first and then disable the keyguard for the home screen.
+</p>
+<p>
+    You can also explicitly disable the keyguard. To do this,
+    you need to add a permission in the manifest file (<code>AndroidManifest.xml</code>) and
+    then disable the keyguard in your application under test. Note, though, that you either have to
+    remove this before you publish your application, or you have to disable it with code in
+    the published application.
+</p>
+<p>
+    To add the the permission, add the element
+    <code>&lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt;</code>
+    as a child of the <code>&lt;manifest&gt;</code> element. To disable the KeyGuard, add the
+    following code to the <code>onCreate()</code> method of activities you intend to test:
+</p>
+<pre>
+  mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
+  mLock = mKeyGuardManager.newKeyguardLock("<em>activity_classname</em>");
+  mLock.disableKeyguard();
+</pre>
+<p>where <code><em>activity_classname</em></code> is the class name of the activity.</p>
+<h3 id="UITestTroubleshooting">Troubleshooting UI tests</h3>
+<p>
+    This section lists some of the common test failures you may encounter in UI testing, and their
+    causes:
+</p>
+<dl>
+    <dt><code>WrongThreadException</code></dt>
+    <dd>
+      <p><strong>Problem:</strong></p>
+      For a failed test, the Failure Trace contains the following error message:
+      <code>
+        android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created
+        a view hierarchy can touch its views.
+      </code>
+      <p><strong>Probable Cause:</strong></p>
+        This error is common if you tried to send UI events to the UI thread from outside the UI
+        thread. This commonly happens if you send UI events from the test application, but you don't
+        use the <code>@UIThread</code> annotation or the <code>runOnUiThread()</code> method. The
+        test method tried to interact with the UI outside the UI thread.
+      <p><strong>Suggested Resolution:</strong></p>
+        Run the interaction on the UI thread. Use a test class that provides instrumentation. See
+        the previous section <a href="#RunOnUIThread">Testing on the UI Thread</a>
+        for more details.
+    </dd>
+    <dt><code>java.lang.RuntimeException</code></dt>
+    <dd>
+      <p><strong>Problem:</strong></p>
+        For a failed test, the Failure Trace contains the following error message:
+      <code>
+        java.lang.RuntimeException: This method can not be called from the main application thread
+      </code>
+      <p><strong>Probable Cause:</strong></p>
+        This error is common if your test method is annotated with <code>@UiThreadTest</code> but
+        then tries to do something outside the UI thread or tries to invoke
+        <code>runOnUiThread()</code>.
+      <p><strong>Suggested Resolution:</strong></p>
+        Remove the <code>@UiThreadTest</code> annotation, remove the <code>runOnUiThread()</code>
+        call, or re-factor your tests.
+    </dd>
+</dl>
diff --git a/docs/html/guide/topics/testing/contentprovider_testing.jd b/docs/html/guide/topics/testing/contentprovider_testing.jd
new file mode 100644
index 0000000..893b5c9
--- /dev/null
+++ b/docs/html/guide/topics/testing/contentprovider_testing.jd
@@ -0,0 +1,224 @@
+page.title=Content Provider Testing
+@jd:body
+
+<div id="qv-wrapper">
+  <div id="qv">
+  <h2>In this document</h2>
+  <ol>
+    <li>
+        <a href="#DesignAndTest">Content Provider Design and Testing</a>
+    </li>
+    <li>
+      <a href="#ContentProviderTestAPI">The Content Provider Testing API</a>
+      <ol>
+        <li>
+          <a href="#ProviderTestCase2">ProviderTestCase2 </a>
+        </li>
+        <li>
+          <a href="#MockObjects">Mock object classes</a>
+        </li>
+      </ol>
+    </li>
+    <li>
+        <a href="#WhatToTest">What To Test</a>
+    </li>
+    <li>
+        <a href="#NextSteps">Next Steps</a>
+    </li>
+  </ol>
+  <h2>Key Classes</h2>
+    <ol>
+      <li>{@link android.test.InstrumentationTestRunner}</li>
+      <li>{@link android.test.ProviderTestCase2}</li>
+      <li>{@link android.test.IsolatedContext}</li>
+      <li>{@link android.test.mock.MockContentResolver}</li>
+    </ol>
+  <h2>See Also</h2>
+      <ol>
+        <li>
+          <a
+          href="{@docRoot}guide/topics/testing/topics/testing_android.html">
+          Testing Fundamentals</a>
+        </li>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+          Testing in Eclipse, with ADT</a>
+        </li>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+          Testing in Other IDEs</a>
+        </li>
+      </ol>
+  </div>
+</div>
+<p>
+    Content providers, which store and retrieve data and make it accessible across applications,
+    are a key part of the Android API. As an application developer you're allowed to provide your
+    own public providers for use by other applications. If you do, then you should test them
+    using the API you publish.
+</p>
+<p>
+    This document describes how to test public content providers, although the information is
+    also applicable to providers that you keep private to your own application. If you aren't
+    familiar with content  providers or the Android testing framework, please read
+    <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>,
+    the guide to developing content providers, and
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
+    the introduction to the Android testing and instrumentation framework.
+</p>
+<h2 id="DesignAndTest">Content Provider Design and Testing</h2>
+<p>
+    In Android, content providers are viewed externally as data APIs that provide
+    tables of data, with their internals hidden from view. A content provider may have many
+    public constants, but it usually has few if any public methods and no public variables.
+    This suggests that you should write your tests based only on the provider's public members.
+    A content provider that is designed like this is offering a contract between itself and its
+    users.
+</p>
+<p>
+    The base test case class for content providers,
+    {@link android.test.ProviderTestCase2}, allows you to test your content provider in an
+    isolated environment. Android mock objects such as {@link android.test.IsolatedContext} and
+    {@link android.test.mock.MockContentResolver} also help provide an isolated test environment.
+</p>
+<p>
+    As with other Android tests, provider test packages are run under the control of the test
+    runner {@link android.test.InstrumentationTestRunner}. The section
+    <a href="{@docRoot}guide/topics/testing/testing_android.html#InstrumentationTestRunner">
+    Running Tests With InstrumentationTestRunner</a> describes the test runner in
+    more detail. The topic <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+    Testing in Eclipse, with ADT</a> shows you how to run a test package in Eclipse, and the
+    topic <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+    Testing in Other IDEs</a>
+    shows you how to run a test package from the command line.
+</p>
+<h2 id="ContentProviderTestAPI">Content Provider Testing API</h2>
+<p>
+    The main focus of the provider testing API is to provide an isolated testing environment. This
+    ensures that tests always run against data dependencies set explicitly in the test case. It
+    also prevents tests from modifying actual user data. For example, you want to avoid writing
+    a test that fails because there was data left over from a previous test, and you want to
+    avoid adding or deleting contact information in a actual provider.
+</p>
+<p>
+    The test case class and mock object classes for provider testing set up this isolated testing
+    environment for you.
+</p>
+<h3 id="ProviderTestCase2">ProviderTestCase2</h3>
+<p>
+    You test a provider with a subclass of {@link android.test.ProviderTestCase2}. This base class
+    extends {@link android.test.AndroidTestCase}, so it provides the JUnit testing framework as well
+    as Android-specific methods for testing application permissions. The most important
+    feature of this class is its initialization, which creates the isolated test environment.
+</p>
+<p>
+    The initialization is done in the constructor for {@link android.test.ProviderTestCase2}, which
+    subclasses call in their own constructors. The {@link android.test.ProviderTestCase2}
+    constructor creates an {@link android.test.IsolatedContext} object that allows file and
+    database operations but stubs out other interactions with the Android system.
+    The file and database operations themselves take place in a directory that is local to the
+    device or emulator and has a special prefix.
+</p>
+<p>
+    The constructor then creates a {@link android.test.mock.MockContentResolver} to use as the
+    resolver for the test. The {@link android.test.mock.MockContentResolver} class is described in
+    detail in the section
+    <a href="{@docRoot}guide/topics/testing/test_android#MockObjectClasses">Mock object classes</a>.
+</p>
+<p>
+    Lastly, the constructor creates an instance of the provider under test. This is a normal
+    {@link android.content.ContentProvider} object, but it takes all of its environment information
+    from the {@link android.test.IsolatedContext}, so it is restricted to
+    working in the isolated test environment. All of the tests done in the test case class run
+    against this isolated object.
+</p>
+<h3 id="MockObjects">Mock object classes</h3>
+<p>
+    {@link android.test.ProviderTestCase2} uses {@link android.test.IsolatedContext} and
+    {@link android.test.mock.MockContentResolver}, which are standard mock object classes. To
+    learn more about them, please read
+    <a href="{@docRoot}guide/topics/testing/test_android#MockObjectClasses">
+    Testing Fundamentals</a>.
+</p>
+<h2 id="WhatToTest">What To Test</h2>
+<p>
+    The topic <a href="{@docRoot}guide/topics/testing/what_to_test.html">What To Test</a>
+    lists general considerations for testing Android components.
+    Here are some specific guidelines for testing content providers.
+</p>
+<ul>
+    <li>
+        Test with resolver methods: Even though you can instantiate a provider object in
+        {@link android.test.ProviderTestCase2}, you should always test with a resolver object
+        using the appropriate URI. This ensures that you are testing the provider using the same
+        interaction that a regular application would use.
+    </li>
+    <li>
+        Test a public provider as a contract: If you intent your provider to be public and
+        available to other applications, you should test it as a contract. This includes
+        the following ideas:
+        <ul>
+            <li>
+                Test with constants that your provider publicly exposes. For
+                example, look for constants that refer to column names in one of the provider's
+                data tables. These should always be constants publicly defined by the provider.
+            </li>
+            <li>
+                Test all the URIs offered by your provider. Your provider may offer several URIs,
+                each one referring to a different aspect of the data. The
+                <a href="{@docRoot}resources/samples/NotePad/index.html">Note Pad</a> sample,
+                for example, features a provider that offers one URI for retrieving a list of notes,
+                another for retrieving an individual note by it's database ID, and a third for
+                displaying notes in a live folder. The sample test package for Note Pad,
+                <a href="{@docRoot}resources/samples/NotePadTest/index.html"> Note Pad Test</a>, has
+                unit tests for two of these URIs.
+            </li>
+            <li>
+                Test invalid URIs: Your unit tests should deliberately call the provider with an
+                invalid URI, and look for errors. Good provider design is to throw an
+                IllegalArgumentException for invalid URIs.
+
+            </li>
+        </ul>
+    </li>
+    <li>
+        Test the standard provider interactions: Most providers offer six access methods:
+        query, insert, delete, update, getType, and onCreate(). Your tests should verify that all
+        of these methods work. These are described in more detail in the topic
+        <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>.
+    </li>
+    <li>
+        Test business logic: Don't forget to test the business logic that your provider should
+        enforce. Business logic includes handling of invalid values, financial or arithmetic
+        calculations, elimination or combining of duplicates, and so forth. A content provider
+        does not have to have business logic, because it may be implemented by activities that
+        modify the data. If the provider does implement business logic, you should test it.
+    </li>
+</ul>
+<h2 id="NextSteps">Next Steps</h2>
+<p>
+    To learn how to set up and run tests in Eclipse, please refer to <a
+    href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in
+    Eclipse, with ADT</a>. If you're not working in Eclipse, refer to <a
+    href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other
+    IDEs</a>.
+</p>
+<p>
+    If you want a step-by-step introduction to testing activities, try one of the
+    testing tutorials:
+</p>
+<ul>
+    <li>
+        The <a
+        href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello,
+        Testing</a> tutorial introduces basic testing concepts and procedures in the
+        context of the Hello, World application.
+    </li>
+    <li>
+        The <a
+        href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity
+        Testing</a> tutorial is an excellent follow-up to the Hello, Testing tutorial.
+        It guides you through a more complex testing scenario that you develop against a
+        more realistic activity-oriented application.
+    </li>
+</ul>
diff --git a/docs/html/guide/topics/testing/index.jd b/docs/html/guide/topics/testing/index.jd
new file mode 100644
index 0000000..92ed5a7
--- /dev/null
+++ b/docs/html/guide/topics/testing/index.jd
@@ -0,0 +1,80 @@
+page.title=Testing
+@jd:body
+<p>
+    The Android development environment includes an integrated testing framework that helps you
+    test all aspects of your application.
+</p>
+<h4>Fundamentals</h4>
+<p>
+    To start learning how to use the framework to create tests for your applications, please
+    read the topic <a href="{@docRoot}guide/topics/testing/testing_android.html">
+    Testing Fundamentals</a>.
+</p>
+<h4>Concepts</h4>
+<ul>
+    <li>
+        Testing Tools describes the Eclipse with ADT and command-line tools you use to test
+        Android applications.
+    </li>
+    <li>
+        What to Test is an overview of the types of testing you should do. It focuses on testing
+        system-wide aspects of Android that can affect every component in your application.
+    </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/activity_testing.html">
+        Activity Testing</a> focuses on testing activities. It describes how instrumentation allows
+        you to control activities outside the normal application lifecycle. It also lists
+        activity-specific features you should test, and it provides tips for testing Android
+        user interfaces.
+    </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/contentprovider_testing.html">
+        Content Provider Testing</a> focuses on testing content providers. It describes the
+        mock system objects you can use, provides tips for designing providers so that they
+        can be tested, and lists provider-specific features you should test.
+    </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/service_testing.html">
+        Service Testing</a> focuses on testing services. It also lists service-specific features
+        you should test.
+    </li>
+</ul>
+<h4>Procedures</h4>
+<ul>
+    <li>
+        The topic <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+        Testing in Eclipse, with ADT</a> describes how to create and run tests in Eclipse with ADT.
+    </li>
+    <li>
+        The topic <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+        Testing in other IDEs</a> describes how to create and run tests with command-line tools.
+    </li>
+</ul>
+<h4>Tutorials</h4>
+<ul>
+    <li>
+        The <a href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">
+        Hello, Testing</a> tutorial introduces basic testing concepts and procedures.
+    </li>
+    <li>
+        For a more advanced tutorial, try
+        <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>,
+        which guides you through a more complex testing scenario.
+    </li>
+</ul>
+<h4>Samples</h4>
+<ul>
+    <li>
+        <a href="{@docRoot}resources/samples/NotePadTest.html">Note Pad Provider
+        Test</a> is a test package for the
+        <a href="{@docRoot}resources/samples/NotePad.html">Note Pad</a> sample
+        application. It provides a simple example of unit testing
+        a {@link android.content.ContentProvider}.
+    </li>
+    <li>
+        The <a href="{@docRoot}resources/samples/AlarmServiceTest.html">Alarm Service Test</a>
+        is a test package for the <a href="{@docRoot}resources/samples/Alarm.html">Alarm</a>
+        sample application. It provides a simple example of unit
+        testing a {@link android.app.Service}.
+    </li>
+</ul>
diff --git a/docs/html/guide/topics/testing/service_testing.jd b/docs/html/guide/topics/testing/service_testing.jd
new file mode 100644
index 0000000..3979f3c
--- /dev/null
+++ b/docs/html/guide/topics/testing/service_testing.jd
@@ -0,0 +1,178 @@
+page.title=Service Testing
+@jd:body
+
+<div id="qv-wrapper">
+  <div id="qv">
+  <h2>In this document</h2>
+  <ol>
+    <li>
+        <a href="#DesignAndTest">Service Design and Testing</a>
+    </li>
+    <li>
+        <a href="#ServiceTestCase">ServiceTestCase</a>
+    </li>
+    <li>
+        <a href="#MockObjects">Mock object classes</a>
+    </li>
+    <li>
+        <a href="#TestAreas">What to Test</a>
+    </li>
+  </ol>
+  <h2>Key Classes</h2>
+    <ol>
+      <li>{@link android.test.InstrumentationTestRunner}</li>
+      <li>{@link android.test.ServiceTestCase}</li>
+      <li>{@link android.test.mock.MockApplication}</li>
+      <li>{@link android.test.RenamingDelegatingContext}</li>
+    </ol>
+  <h2>Related Tutorials</h2>
+    <ol>
+        <li>
+            <a href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">
+            Hello, Testing</a>
+        </li>
+        <li>
+            <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
+        </li>
+    </ol>
+  <h2>See Also</h2>
+      <ol>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+          Testing in Eclipse, with ADT</a>
+        </li>
+        <li>
+          <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+          Testing in Other IDEs</a>
+        </li>
+      </ol>
+  </div>
+</div>
+<p>
+    Android provides a testing framework for Service objects that can run them in
+    isolation and provides mock objects. The test case class for Service objects is
+    {@link android.test.ServiceTestCase}. Since the Service class assumes that it is separate
+    from its clients, you can test a Service object without using instrumentation.
+</p>
+<p>
+    This document describes techniques for testing Service objects. If you aren't familiar with the
+    Service class, please read <a href="{@docRoot}guide/topics/fundamentals.html">
+    Application Fundamentals</a>. If you aren't familiar with Android testing, please read
+    <a href="{@docRoot}guide/topics/testing/testing_android.html">Testing Fundamentals</a>,
+    the introduction to the Android testing and instrumentation framework.
+</p>
+<h2 id="DesignAndTest">Service Design and Testing</h2>
+<p>
+    When you design a Service, you should consider how your tests can examine the various states
+    of the Service lifecycle. If the lifecycle methods that start up your Service, such as
+    {@link android.app.Service#onCreate() onCreate()} or
+    {@link android.app.Service#onStartCommand(Intent, int, int) onStartCommand()} do not normally
+    set a global variable to indicate that they were successful, you may want to provide such a
+    variable for testing purposes.
+</p>
+<p>
+    Most other testing is facilitated by the methods in the {@link android.test.ServiceTestCase}
+    test case class. For example, the {@link android.test.ServiceTestCase#getService()} method
+    returns a handle to the Service under test, which you can test to confirm that the Service is
+    running even at the end of your tests.
+</p>
+<h2 id="ServiceTestCase">ServiceTestCase</h2>
+<p>
+    {@link android.test.ServiceTestCase} extends the JUnit {@link junit.framework.TestCase} class
+    with with methods for testing application permissions and for controlling the application and
+    Service under test. It also provides mock application and Context objects that isolate your
+    test from the rest of the system.
+</p>
+<p>
+    {@link android.test.ServiceTestCase} defers initialization of the test environment until you
+    call {@link android.test.ServiceTestCase#startService(Intent) ServiceTestCase.startService()} or
+    {@link android.test.ServiceTestCase#bindService(Intent) ServiceTestCase.bindService()}. This
+    allows you to set up your test environment, particularly your mock objects, before the Service
+    is started.
+</p>
+<p>
+    Notice that the parameters to <code>ServiceTestCase.bindService()</code>are different from
+    those for <code>Service.bindService()</code>. For the <code>ServiceTestCase</code> version,
+    you only provide an Intent. Instead of returning a boolean,
+    <code>ServiceTestCase.bindService()</code> returns an object that subclasses
+    {@link android.os.IBinder}.
+</p>
+<p>
+    The {@link android.test.ServiceTestCase#setUp()} method for {@link android.test.ServiceTestCase}
+    is called before each test. It sets up the test fixture by making a copy of the current system
+    Context before any test methods touch it. You can retrieve this Context by calling
+    {@link android.test.ServiceTestCase#getSystemContext()}. If you override this method, you must
+    call <code>super.setUp()</code> as the first statement in the override.
+</p>
+<p>
+    The methods {@link android.test.ServiceTestCase#setApplication(Application) setApplication()}
+    and {@link android.test.AndroidTestCase#setContext(Context)} setContext()} allow you to set
+    a mock Context or mock Application (or both) for the Service, before you start it. These mock
+    objects are described in <a href="#MockObjects">Mock object classes</a>.
+</p>
+<p>
+    By default, {@link android.test.ServiceTestCase} runs the test method
+    {@link android.test.AndroidTestCase#testAndroidTestCaseSetupProperly()}, which asserts that
+    the base test case class successfully set up a Context before running.
+</p>
+<h2 id="MockObjects">Mock object classes</h2>
+<p>
+    <code>ServiceTestCase</code> assumes that you will use a mock Context or mock Application
+    (or both) for the test environment. These objects isolate the test environment from the
+    rest of the system. If you don't provide your own instances of these objects before you
+    start the Service, then {@link android.test.ServiceTestCase} will create its own internal
+    instances and inject them into the Service. You can override this behavior by creating and
+    injecting your own instances before starting the Service
+</p>
+<p>
+    To inject a mock Application object into the Service under test, first create a subclass of
+    {@link android.test.mock.MockApplication}. <code>MockApplication</code> is a subclass of
+    {@link android.app.Application} in which all the methods throw an Exception, so to use it
+    effectively you subclass it and override the methods you need. You then inject it into the
+    Service with the
+    {@link android.test.ServiceTestCase#setApplication(Application) setApplication()} method.
+    This mock object allows you to control the application values that the Service sees, and
+    isolates it from the real system. In addition, any hidden dependencies your Service has on
+    its application reveal themselves as exceptions when you run the test.
+</p>
+<p>
+    You inject a mock Context into the Service under test with the
+    {@link android.test.AndroidTestCase#setContext(Context) setContext()} method. The mock
+    Context classes you can use are described in more detail in
+    <a href="{@docRoot}guide/topics/testing/testing_android.html#MockObjectClasses">
+    Testing Fundamentals</a>.
+</p>
+<h2 id="TestAreas">What to Test</h2>
+<p>
+    The topic <a href="{@docRoot}guide/topics/testing/what_to_test.html">What To Test</a>
+    lists general considerations for testing Android components.
+    Here are some specific guidelines for testing a Service:
+</p>
+<ul>
+    <li>
+        Ensure that the {@link android.app.Service#onCreate()} is called in response to
+        {@link android.content.Context#startService(Intent) Context.startService()} or
+    {@link android.content.Context#bindService(Intent,ServiceConnection,int) Context.bindService()}.
+        Similarly, you should ensure that {@link android.app.Service#onDestroy()} is called in
+        response to {@link android.content.Context#stopService(Intent) Context.stopService()},
+        {@link android.content.Context#unbindService(ServiceConnection) Context.unbindService()},
+        {@link android.app.Service#stopSelf()}, or
+        {@link android.app.Service#stopSelfResult(int) stopSelfResult()}.
+    </li>
+    <li>
+        Test that your Service correctly handles multiple calls from
+        <code>Context.startService()</code>. Only the first call triggers
+        <code>Service.onCreate()</code>, but all calls trigger a call to
+        <code>Service.onStartCommand()</code>.
+        <p>
+            In addition, remember that <code>startService()</code> calls don't
+            nest, so a single call to <code>Context.stopService()</code> or
+            <code>Service.stopSelf()</code> (but not <code>stopSelf(int)</code>)
+            will stop the Service. You should test that your Service stops at the correct point.
+        </p>
+    </li>
+    <li>
+        Test any business logic that your Service implements. Business logic includes checking for
+        invalid values, financial and arithmetic calculations, and so forth.
+    </li>
+</ul>
diff --git a/docs/html/guide/topics/testing/testing_android.jd b/docs/html/guide/topics/testing/testing_android.jd
index 935aaf9..1d5f911 100755
--- a/docs/html/guide/topics/testing/testing_android.jd
+++ b/docs/html/guide/topics/testing/testing_android.jd
@@ -1,4 +1,4 @@
-page.title=Testing and Instrumentation
+page.title=Testing Fundamentals
 @jd:body
 
 <div id="qv-wrapper">
@@ -6,65 +6,62 @@
   <h2>In this document</h2>
   <ol>
     <li>
-        <a href="#Overview">Overview</a>
+        <a href="#TestStructure">Test Structure</a>
+    </li>
+    <li>
+        <a href="#TestProjects">Test Projects</a>
     </li>
     <li>
       <a href="#TestAPI">The Testing API</a>
       <ol>
         <li>
-          <a href="#Extensions">JUnit test case classes</a>
+          <a href="#JUnit">JUnit</a>
         </li>
         <li>
-          <a href="#Instrumentation">Instrumentation test case classes</a>
+          <a href="#Instrumentation">Instrumentation</a>
         </li>
         <li>
-          <a href="#Assert">Assert classes</a>
+            <a href="#TestCaseClasses">Test case classes</a>
         </li>
         <li>
-          <a href="#MockObjects">Mock object classes</a>
+          <a href="#AssertionClasses">Assertion classes</a>
         </li>
-            <li>
-                <a href="#InstrumentationTestRunner">Instrumentation Test Runner</a>
-            </li>
+        <li>
+          <a href="#MockObjectClasses">Mock object classes</a>
+        </li>
       </ol>
     </li>
     <li>
-     <a href="#TestEnviroment">Working in the Test Environment</a>
+        <a href="#InstrumentationTestRunner">Running Tests</a>
     </li>
     <li>
-        <a href="#TestAreas">What to Test</a>
+        <a href="#TestResults">Seeing Test Results</a>
     </li>
     <li>
-      <a href="#UITesting">Appendix: UI Testing Notes</a>
-      <ol>
-        <li>
-          <a href="#RunOnUIThread">Testing on the UI thread</a>
-        </li>
-        <li>
-          <a href="#NotouchMode">Turning off touch mode</a>
-        </li>
-        <li>
-          <a href="#UnlockDevice">Unlocking the Emulator or Device</a>
-        </li>
-        <li>
-          <a href="#UITestTroubleshooting">Troubleshooting UI tests</a>
-        </li>
-      </ol>
+        <a href="#Monkeys">Monkey and MonkeyRunner</a>
+    </li>
+    <li>
+       <a href="#PackageNames">Working With Package Names</a>
+    </li>
+    <li>
+        <a href="#WhatToTest">What To Test</a>
+    </li>
+    <li>
+        <a href="#NextSteps">Next Steps</a>
     </li>
   </ol>
   <h2>Key classes</h2>
     <ol>
       <li>{@link android.test.InstrumentationTestRunner}</li>
-      <li>{@link android.test.ActivityInstrumentationTestCase2}</li>
-      <li>{@link android.test.ActivityUnitTestCase}</li>
-      <li>{@link android.test.ApplicationTestCase}</li>
-      <li>{@link android.test.ProviderTestCase2}</li>
-      <li>{@link android.test.ServiceTestCase}</li>
+      <li>{@link android.test}</li>
+      <li>{@link android.test.mock}</li>
+      <li>{@link junit.framework}</li>
     </ol>
   <h2>Related tutorials</h2>
     <ol>
         <li>
-            <a href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello, Testing</a>
+            <a href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">
+            Hello, Testing</a>
         </li>
         <li>
             <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity Testing</a>
@@ -73,445 +70,590 @@
   <h2>See also</h2>
       <ol>
         <li>
-          <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in Eclipse, with ADT</a>
+          <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">
+          Testing in Eclipse, with ADT</a>
         </li>
         <li>
-          <a href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other IDEs</a>
+          <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+          Testing in Other IDEs</a>
         </li>
       </ol>
   </div>
 </div>
-
-<p>Android includes a powerful set of testing tools that extend the
-industry-standard JUnit test framework with features specific to the Android
-environment. Although you can test an Android application with JUnit, the
-Android tools allow you to write much more sophisticated tests for every aspect
-of your application, both at the unit and framework levels.</p>
-
-<p>Key features of the Android testing environment include:</p>
-
+<p>
+    The Android testing framework, an integral part of the development environment,
+    provides an architecture and powerful tools that help you test every aspect of your application
+    at every level from unit to framework.
+</p>
+<p>
+    The testing framework has these key features:
+</p>
 <ul>
-  <li>Android extensions to the JUnit framework that provide access to Android
-system objects.</li>
-  <li>An instrumentation framework that lets tests control and examine the
-application.</li>
-  <li>Mock versions of commonly-used Android system objects.</li>
-  <li>Tools for running single tests or test suites, with or without
-instrumentation.</li>
-  <li>Support for managing tests and test projects in the ADT Plugin for Eclipse
-and at the command line.</li>
+    <li>
+        Android test suites are based on JUnit. You can use plain JUnit to test a class that doesn't
+        call the Android API, or Android's JUnit extensions to test Android components. If you're
+        new to Android testing, you can start with general-purpose test case classes such as {@link
+        android.test.AndroidTestCase} and then go on to use more sophisticated classes.
+    </li>
+    <li>
+        The Android JUnit extensions provide component-specific test case classes. These classes
+        provide helper methods for creating mock objects and methods that help you control the
+        lifecycle of a component.
+    </li>
+    <li>
+        Test suites are contained in test packages that are similar to main application packages, so
+        you don't need to learn a new set of tools or techniques for designing and building tests.
+    </li>
+    <li>
+        The SDK tools for building and tests are available in Eclipse with ADT, and also in
+        command-line form for use with other IDES. These tools get information from the project of
+        the application under test and use this information to automatically create the build files,
+        manifest file, and directory structure for the test package.
+    </li>
+    <li>
+        The SDK also provides
+        <a href="{@docRoot}guide/topics/testing/monkeyrunner.html">MonkeyRunner</a>, an API for
+        testing devices with Jython scripts, and <a
+        href="{@docRoot}guide/developing/tools/monkey.html">Monkey</a>, a command-line tool for
+        stress-testing UIs by sending pseudo-random events to a device.
+    </li>
 </ul>
-
-<p>This document is an overview of the Android testing environment and the way
-you use it. The document assumes you have a basic knowledge of Android
-application programming and JUnit testing methodology.</p>
-
-<h2 id="Overview">Overview</h2>
-
-<p> At the heart of the Android testing environment is an instrumentation
-framework that your test application uses to precisely control the application
-under test. With instrumentation, you can set up mock system objects such as
-Contexts before the main application starts, control your application at various
-points of its lifecycle, send UI events to the application, and examine the
-application's state during its execution. The instrumentation framework
-accomplishes this by running both the main application and the test application
-in the same process. </p>
-
-<p>Your test application is linked to the application under test by means of an
-<a
-href="{@docRoot}guide/topics/manifest/instrumentation-element.html"><code>&lt;instrumentation&gt;</code></a>
-element in the test application's manifest file. The attributes of the element
-specify the package name of the application under test and also tell Android how
-to run the test application. Instrumentation is described in more detail in the
-section <a href="#InstrumentationTestRunner">Instrumentation Test
-Runner</a>.</p>
-
-<p>The following diagram summarizes the Android testing environment:</p>
-
-<img src="{@docRoot}images/testing/android_test_framework.png"/>
-
-<p>In Android, test applications are themselves Android applications, so you
-write them in much the same way as the application you are testing. The SDK
-tools help you create a main application project and its test project at the same
-time. You can run Android tests within Eclipse with ADT or from the command
-line. Eclipse with ADT provides an extensive set of tools for creating tests,
-running them, and viewing their results. You can also use the <code>adb</code>
-tool to run tests, or use a built-in Ant target.</p>
-
-<p>To learn how to set up and run tests in Eclipse, please refer to <a
-href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in
-Eclipse, with ADT</a>. If you're not working in Eclipse, refer to <a
-href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other
-IDEs</a>.</p>
-
-<p>If you want a step-by-step introduction to Android testing, try one of the
-testing tutorials:</p>
-
-<ul>
-  <li>The <a
-href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello,
-Testing</a> tutorial introduces basic testing concepts and procedures in the
-context of the Hello, World application.</li>
-  <li>The <a
-href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity
-Testing</a> tutorial is an excellent follow-up to the Hello, Testing tutorial.
-It guides you through a more complex testing scenario that you develop against a
-more realistic application.</li>
-</ul>
-
+<p>
+    This document describes the fundamentals of the Android testing framework, including the
+    structure of tests, the APIs that you use to develop tests, and the tools that you use to run
+    tests and view results. The document assumes you have a basic knowledge of Android application
+    programming and JUnit testing methodology.
+</p>
+<p>
+    The following diagram summarizes the testing framework:
+</p>
+<div style="width: 70%; margin-left:auto; margin-right:auto;">
+<a href="{@docRoot}images/testing/test_framework.png">
+    <img src="{@docRoot}images/testing/test_framework.png"
+        alt="The Android testing framework"/>
+</a>
+</div>
+<h2 id="TestStructure">Test Structure</h2>
+<p>
+    Android's build and test tools assume that test projects are organized into a standard
+    structure of tests, test case classes, test packages, and test projects.
+</p>
+<p>
+    Android testing is based on JUnit. In general, a JUnit test is a method whose
+    statements test a part of the application under test. You organize test methods into classes
+    called test cases (or test suites). Each test is an isolated test of an individual module in
+    the application under test. Each class is a container for related test methods, although it
+    often provides helper methods as well.
+</p>
+<p>
+    In JUnit, you build one or more test source files into a class file. Similarly, in Android you
+    use the SDK's build tools to build one or more test source files into class files in an
+    Android test package. In JUnit, you use a test runner to execute test classes. In Android, you
+    use test tools to load the test package and the application under test, and the tools then
+    execute an Android-specific test runner.
+</p>
+<h2 id="TestProjects">Test Projects</h2>
+<p>
+    Tests, like Android applications, are organized into projects.
+</p>
+<p>
+    A test project is a directory or Eclipse project in which you create the source code, manifest
+    file, and other files for a test package. The Android SDK contains tools for Eclipse with ADT
+    and for the command line that create and update test projects for you. The tools create the
+    directories you use for source code and resources and the manifest file for the test package.
+    The command-line tools also create the Ant build files you need.
+</p>
+<p>
+    You should always use Android tools to create a test project. Among other benefits,
+    the tools:
+</p>
+    <ul>
+        <li>
+            Automatically set up your test package to use
+            {@link android.test.InstrumentationTestRunner} as the test case runner. You must use
+            <code>InstrumentationTestRunner</code> (or a subclass) to run JUnit tests.
+        </li>
+        <li>
+            Create an appropriate name for the test package. If the application
+            under test has a package name of <code>com.mydomain.myapp</code>, then the
+            Android tools set the test package name to <code>com.mydomain.myapp.test</code>. This
+            helps you identify their relationship, while preventing conflicts within the system.
+        </li>
+        <li>
+            Automatically create the proper build files, manifest file, and directory
+            structure for the test project. This helps you to build the test package without
+            having to modify build files and sets up the linkage between your test package and
+            the application under test.
+            The
+        </li>
+    </ul>
+<p>
+    You can create a test project anywhere in your file system, but the best approach is to
+    add the test project so that its root directory <code>tests/</code> is at the same level
+    as the <code>src/</code> directory of the main application's project. This helps you find the
+    tests associated with an application. For example, if your application project's root directory
+    is <code>MyProject</code>, then you should use the following directory structure:
+</p>
+<pre class="classic no-pretty-print">
+  MyProject/
+      AndroidManifest.xml
+      res/
+          ... (resources for main application)
+      src/
+          ... (source code for main application) ...
+      tests/
+          AndroidManifest.xml
+          res/
+              ... (resources for tests)
+          src/
+              ... (source code for tests)
+</pre>
 <h2 id="TestAPI">The Testing API</h2>
 <p>
-    For writing tests and test applications in the Java programming language, Android provides a
-    testing API that is based in part on the JUnit test framework. Adding to that, Android includes
-    a powerful instrumentation framework that lets your tests access the state and runtime objects
-    of the application under tests.
+    The Android testing API is based on the JUnit API and extended with a instrumentation
+    framework and Android-specific testing classes.
 </p>
-<p>The sections below describe the major components of the testing API available in Android.</p>
-<h3 id="Extensions">JUnit test case classes</h3>
+<h3 id="JUnit">JUnit</h3>
 <p>
-  Some of the classes in the testing API extend the JUnit {@link junit.framework.TestCase TestCase} but do not use the instrumentation framework. These classes
-  contain methods for accessing system objects such as the Context of the application under test. With this Context, you can look at its resources, files, databases,
-  and so forth. The base class is {@link android.test.AndroidTestCase}, but you usually use a subclass associated with a particular component.
-<p>
-  The subclasses are:
-</p>
-  <ul>
-    <li>
-      {@link android.test.ApplicationTestCase} - A class for testing an entire application. It allows you to inject a mock Context into the application,
-      set up initial test parameters before the application starts, and examine the application after it finishes but before it is destroyed.
-    </li>
-    <li>
-      {@link android.test.ProviderTestCase2} - A class for isolated testing of a single {@link android.content.ContentProvider}. Since it is restricted to using a
-      {@link android.test.mock.MockContentResolver} for the provider, and it injects an {@link android.test.IsolatedContext}, your provider testing is isolated
-      from the rest of the OS.
-    </li>
-    <li>
-      {@link android.test.ServiceTestCase} - a class for isolated testing of a single {@link android.app.Service}. You can inject a mock Context or
-      mock Application (or both), or let Android provide you a full Context and a {@link android.test.mock.MockApplication}.
-    </li>
-  </ul>
-<h3 id="Instrumentation">Instrumentation test case classes</h3>
-<p>
-  The API for testing activities extends the JUnit {@link junit.framework.TestCase TestCase} class and also uses the instrumentation framework. With instrumentation,
-  Android can automate UI testing by sending events to the application under test, precisely control the start of an activity, and monitor the state of the
-  activity during its life cycle.
+    You can use the JUnit {@link junit.framework.TestCase TestCase} class to do unit testing on
+    a plain Java object. <code>TestCase</code> is also the base class for
+    {@link android.test.AndroidTestCase}, which you can use to test Android-dependent objects.
+    Besides providing the JUnit framework, AndroidTestCase offers Android-specific setup,
+    teardown, and helper methods.
 </p>
 <p>
-  The base class is {@link android.test.InstrumentationTestCase}. All of its subclasses have the ability to send a keystroke or touch event to the UI of the application
-  under test. The subclasses can also inject a mock Intent.
-  The subclasses are:
+    You use the JUnit {@link junit.framework.Assert} class to display test results.
+    The assert methods compare values you expect from a test to the actual results and
+    throw an exception if the comparison fails. Android also provides a class of assertions that
+    extend the possible types of comparisons, and another class of assertions for testing the UI.
+    These are described in more detail in the section <a href="#AssertionClasses">
+    Assertion classes</a>
 </p>
-  <ul>
-    <li>
-      {@link android.test.ActivityTestCase} - A base class for activity test classes.
-    </li>
-    <li>
-      {@link android.test.SingleLaunchActivityTestCase} - A convenience class for testing a single activity.
-      It invokes {@link junit.framework.TestCase#setUp() setUp()} and {@link junit.framework.TestCase#tearDown() tearDown()} only
-      once, instead of once per method call. Use it when all of your test methods run against the same activity.
-    </li>
-    <li>
-      {@link android.test.SyncBaseInstrumentation} - A class that tests synchronization of a content provider. It uses instrumentation to cancel and disable
-      existing synchronizations before starting the test synchronization.
-    </li>
-    <li>
-      {@link android.test.ActivityUnitTestCase} - This class does an isolated test of a single activity. With it, you can inject a mock context or application, or both.
-      It is intended for doing unit tests of an activity, and is the activity equivalent of the test classes described in <a href="#Extensions">JUnit test case classes</a>.
-      <p> Unlike the other instrumentation classes, this test class cannot inject a mock Intent.</p>
-    </li>
-    <li>
-      {@link android.test.ActivityInstrumentationTestCase2} - This class tests a single activity within the normal system environment.
-      You cannot inject a mock Context, but you can inject mock Intents. Also, you can run a test method on the UI thread (the main thread of the application under test),
-      which allows you to send key and touch events to the application UI.
-    </li>
-  </ul>
-<h3 id="Assert">Assert classes</h3>
 <p>
-  Android also extends the JUnit {@link junit.framework.Assert} class that is the basis of <code>assert()</code> calls in tests.
-  There are two extensions to this class, {@link android.test.MoreAsserts} and {@link android.test.ViewAsserts}:
+    To learn more about JUnit, you can read the documentation on the
+    <a href="http://www.junit.org">junit.org</a> home page.
+    Note that the Android testing API supports JUnit 3 code style, but not JUnit 4. Also, you must
+    use Android's instrumented test runner {@link android.test.InstrumentationTestRunner} to run
+    your test case classes. This test runner is described in the
+    section <a href="#InstrumentationTestRunner">Running Tests</a>.
+</p>
+<h3 id="Instrumentation">Instrumentation</h3>
+<p>
+    Android instrumentation is a set of control methods or "hooks" in the Android system. These hooks
+    control an Android component independently of its normal lifecycle. They also control how
+    Android loads applications.
+</p>
+<p>
+    Normally, an Android component runs in a lifecycle determined by the system. For example, an
+    Activity object's lifecycle starts when the Activity is activated by an Intent. The object's
+    <code>onCreate()</code> method is called, followed by <code>onResume()</code>. When the user
+    starts another application, the <code>onPause()</code> method is called. If the Activity
+    code calls the <code>finish()</code> method, the <code>onDestroy()</code> method is called.
+    The Android framework API does not provide a way for your code to invoke these callback
+    methods directly, but you can do so using instrumentation.
+</p>
+<p>
+    Also, the system runs all the components of an application into the same
+    process. You can allow some components, such as content providers, to run in a separate process,
+    but you can't force an application to run in the same process as another application that is
+    already running.
+</p>
+<p>
+    With Android instrumentation, though, you can invoke callback methods in your test code.
+    This allows you to run through the lifecycle of a component step by step, as if you were
+    debugging the component. The following test code snippet demonstrates how to use this to
+    test that an Activity saves and restores its state:
+</p>
+<a name="ActivitySnippet"></a>
+<pre>
+    // Start the main activity of the application under test
+    mActivity = getActivity();
+
+    // Get a handle to the Activity object's main UI widget, a Spinner
+    mSpinner = (Spinner)mActivity.findViewById(com.android.example.spinner.R.id.Spinner01);
+
+    // Set the Spinner to a known position
+    mActivity.setSpinnerPosition(TEST_STATE_DESTROY_POSITION);
+
+    // Stop the activity - The onDestroy() method should save the state of the Spinner
+    mActivity.finish();
+
+    // Re-start the Activity - the onResume() method should restore the state of the Spinner
+    mActivity = getActivity();
+
+    // Get the Spinner's current position
+    int currentPosition = mActivity.getSpinnerPosition();
+
+    // Assert that the current position is the same as the starting position
+    assertEquals(TEST_STATE_DESTROY_POSITION, currentPosition);
+</pre>
+<p>
+    The key method used here is
+    {@link android.test.ActivityInstrumentationTestCase2#getActivity()}, which is a
+    part of the instrumentation API. The Activity under test is not started until you call this
+    method. You can set up the test fixture in advance, and then call this method to start the
+    Activity.
+</p>
+<p>
+    Also, instrumentation can load both a test package and the application under test into the
+    same process. Since the application components and their tests are in the same process, the
+    tests can invoke methods in the components, and modify and examine fields in the components.
+</p>
+<h3 id="TestCaseClasses">Test case classes</h3>
+<p>
+    Android provides several test case classes that extend {@link junit.framework.TestCase} and
+    {@link junit.framework.Assert} with Android-specific setup, teardown, and helper methods.
+</p>
+<h4 id="AndroidTestCase">AndroidTestCase</h4>
+<p>
+    A useful general test case class, especially if you are
+    just starting out with Android testing, is {@link android.test.AndroidTestCase}. It extends
+    both {@link junit.framework.TestCase} and {@link junit.framework.Assert}. It provides the
+    JUnit-standard <code>setUp()</code> and <code>tearDown()</code> methods, as well as well as
+    all of JUnit's Assert methods. In addition, it provides methods for testing permissions, and a
+    method that guards against memory leaks by clearing out certain class references.
+</p>
+<h4 id="ComponentTestCase">Component-specific test cases</h4>
+<p>
+    A key feature of the Android testing framework is its component-specific test case classes.
+    These address specific component testing needs with methods for fixture setup and
+    teardown and component lifecycle control. They also provide methods for setting up mock objects.
+    These classes are described in the component-specific testing topics:
 </p>
 <ul>
-  <li>
-    The <code>MoreAsserts</code> class contains more powerful assertions such as {@link android.test.MoreAsserts#assertContainsRegex} that does regular expression matching.
-  </li>
-  <li>
-    The {@link android.test.ViewAsserts} class contains useful assertions about Android Views, such as {@link android.test.ViewAsserts#assertHasScreenCoordinates} that tests if a View has a particular X and Y
-    position on the visible screen. These asserts simplify testing of geometry and alignment in the UI.
-  </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/activity_testing.html">Activity Testing</a>
+    </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/contentprovider_testing.html">
+        Content Provider Testing</a>
+    </li>
+    <li>
+        <a href="{@docRoot}guide/topics/testing/service_testing.html">Service Testing</a>
+    </li>
 </ul>
-<h3 id="MockObjects">Mock object classes</h3>
-  <p>
-    Android has convenience classes for creating mock system objects such as applications, contexts, content resolvers, and resources. Android also provides
-    methods in some test classes for creating mock Intents. Use these mocks to facilitate dependency injection, since they are easier to use than creating their
-    real counterparts. These convenience classes are found in {@link android.test} and {@link android.test.mock}. They are:
-  </p>
+<p>
+    Android does not provide a separate test case class for BroadcastReceiver. Instead, test a
+    BroadcastReceiver by testing the component that sends it Intent objects, to verify that the
+    BroadcastReceiver responds correctly.
+</p>
+<h4 id="ApplicationTestCase">ApplicationTestCase</h4>
+<p>
+    You use the {@link android.test.ApplicationTestCase} test case class to test the setup and
+    teardown of {@link android.app.Application} objects. These objects maintain the global state of
+    information that applies to all the components in an application package. The test case can
+    be useful in verifying that the &lt;application&gt; element in the manifest file is correctly
+    set up. Note, however, that this test case does not allow you to control testing of the
+    components within your application package.
+</p>
+<h4 id="InstrumentationTestCase">InstrumentationTestCase</h4>
+<p>
+    If you want to use instrumentation methods in a test case class, you must use
+    {@link android.test.InstrumentationTestCase} or one of its subclasses. The
+    {@link android.app.Activity} test cases extend this base class with other functionality that
+    assists in Activity testing.
+</p>
+
+<h3 id="AssertionClasses">Assertion classes</h3>
+<p>
+    Because Android test case classes extend JUnit, you can use assertion methods to display the
+    results of tests. An assertion method compares an actual value returned by a test to an
+    expected value, and throws an AssertionException if the comparison test fails. Using assertions
+    is more convenient than doing logging, and provides better test performance.
+</p>
+<p>
+    Besides the JUnit {@link junit.framework.Assert} class methods, the testing API also provides
+    the {@link android.test.MoreAsserts} and {@link android.test.ViewAsserts} classes:
+</p>
+<ul>
+    <li>
+        {@link android.test.MoreAsserts} contains more powerful assertions such as
+        {@link android.test.MoreAsserts#assertContainsRegex}, which does regular expression
+        matching.
+    </li>
+    <li>
+        {@link android.test.ViewAsserts} contains useful assertions about Views. For example
+        it contains {@link android.test.ViewAsserts#assertHasScreenCoordinates} that tests if a View
+        has a particular X and Y position on the visible screen. These asserts simplify testing of
+        geometry and alignment in the UI.
+    </li>
+</ul>
+<h3 id="MockObjectClasses">Mock object classes</h3>
+<p>
+    To facilitate dependency injection in testing, Android provides classes that create mock system
+    objects such as {@link android.content.Context} objects,
+    {@link android.content.ContentProvider} objects, {@link android.content.ContentResolver}
+    objects, and {@link android.app.Service} objects. Some test cases also provide mock
+    {@link android.content.Intent} objects. You use these mocks both to isolate tests
+    from the rest of the system and to facilitate dependency injection for testing. These classes
+    are found in the Java packages {@link android.test} and {@link android.test.mock}.
+</p>
+<p>
+    Mock objects isolate tests from a running system by stubbing out or overriding
+    normal operations. For example, a {@link android.test.mock.MockContentResolver}
+    replaces the normal resolver framework with its own local framework, which is isolated
+    from the rest of the system. MockContentResolver also also stubs out the
+    {@link android.content.ContentResolver#notifyChange(Uri, ContentObserver, boolean)} method
+    so that observer objects outside the test environment are not accidentally triggered.
+</p>
+<p>
+    Mock object classes also facilitate dependency injection by providing a subclass of the
+    normal object that is non-functional except for overrides you define. For example, the
+    {@link android.test.mock.MockResources} object provides a subclass of
+    {@link android.content.res.Resources} in which all the methods throw Exceptions when called.
+    To use it, you override only those methods that must provide information.
+</p>
+<p>
+    These are the mock object classes available in Android:
+</p>
+<h4 id="SimpleMocks">Simple mock object classes</h4>
+<p>
+    {@link android.test.mock.MockApplication}, {@link android.test.mock.MockContext},
+    {@link android.test.mock.MockContentProvider}, {@link android.test.mock.MockCursor},
+    {@link android.test.mock.MockDialogInterface}, {@link android.test.mock.MockPackageManager}, and
+    {@link android.test.mock.MockResources} provide a simple and useful mock strategy. They are
+    stubbed-out versions of the corresponding system object class, and all of their methods throw an
+    {@link java.lang.UnsupportedOperationException} exception if called. To use them, you override
+    the methods you need in order to provide mock dependencies.
+</p>
+<p class="Note"><strong>Note:</strong>
+    {@link android.test.mock.MockContentProvider}
+    and {@link android.test.mock.MockCursor} are new as of API level 8.
+</p>
+<h4 id="ResolverMocks">Resolver mock objects</h4>
+<p>
+    {@link android.test.mock.MockContentResolver} provides isolated testing of content providers by
+    masking out the normal system resolver framework. Instead of looking in the system to find a
+    content provider given an authority string, MockContentResolver uses its own internal table. You
+    must explicitly add providers to this table using
+    {@link android.test.mock.MockContentResolver#addProvider(String,ContentProvider)}.
+</p>
+<p>
+    With this feature, you can associate a mock content provider with an authority. You can create
+    an instance of a real provider but use test data in it. You can even set the provider for an
+    authority to <code>null</code>. In effect, a MockContentResolver object isolates your test
+    from providers that contain real data. You can control the
+    function of the provider, and you can prevent your test from affecting real data.
+</p>
+<h3 id="ContextMocks">Contexts for testing</h3>
+<p>
+    Android provides two Context classes that are useful for testing:
+</p>
+<ul>
+    <li>
+        {@link android.test.IsolatedContext} provides an isolated {@link android.content.Context},
+        File, directory, and database operations that use this Context take place in a test area.
+        Though its functionality is limited, this Context has enough stub code to respond to
+        system calls.
+        <p>
+            This class allows you to test an application's data operations without affecting real
+            data that may be present on the device.
+        </p>
+    </li>
+    <li>
+        {@link android.test.RenamingDelegatingContext} provides a Context in which
+        most functions are handled by an existing {@link android.content.Context}, but
+        file and database operations are handled by a {@link android.test.IsolatedContext}.
+        The isolated part uses a test directory and creates special file and directory names.
+        You can control the naming yourself, or let the constructor determine it automatically.
+        <p>
+            This object provides a quick way to set up an isolated area for data operations,
+            while keeping normal functionality for all other Context operations.
+        </p>
+    </li>
+</ul>
+<h2 id="InstrumentationTestRunner">Running Tests</h2>
+<p>
+    Test cases are run by a test runner class that loads the test case class, set ups,
+    runs, and tears down each test. An Android test runner must also be instrumented, so that
+    the system utility for starting applications can control how the test package
+    loads test cases and the application under test. You tell the Android platform
+    which instrumented test runner to use by setting a value in the test package's manifest file.
+</p>
+<p>
+    {@link android.test.InstrumentationTestRunner} is the primary Android test runner class. It
+    extends the JUnit test runner framework and is also instrumented. It can run any of the test
+    case classes provided by Android and supports all possible types of testing.
+</p>
+<p>
+    You specify <code>InstrumentationTestRunner</code> or a subclass in your test package's
+    manifest file, in the <a href="{@docRoot}guide/topics/manifest/instrumentation-element.html">
+    instrumentation</a> element. Also, <code>InstrumentationTestRunner</code> code resides
+    in the shared library <code>android.test.runner</code>,  which is not normally linked to
+    Android code. To include it, you must specify it in a
+    <a href="{@docRoot}guide/topics/manifest/uses-library-element.html">uses-library</a> element.
+    You do not have to set up these elements yourself. Both Eclipse with ADT and the
+    <code>android</code> command-line tool construct them automatically and add them to your
+    test package's manifest file.
+</p>
+<p class="Note">
+    <strong>Note:</strong> If you use a test runner other than
+    <code>InstrumentationTestRunner</code>, you must change the &lt;instrumentation&gt;
+    element to point to the class you want to use.
+</p>
+<p>
+    To run {@link android.test.InstrumentationTestRunner}, you use internal system classes called by
+    Android tools. When you run a test in Eclipse with ADT, the classes are called automatically.
+    When you run a test from the command line, you run these classes with
+    <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug Bridge (adb)</a>.
+</p>
+<p>
+    The system classes load and start the test package, kill any processes that
+    are running an instance of the application under test, and then load a new instance of the
+    application under test. They then pass control to
+    {@link android.test.InstrumentationTestRunner}, which runs
+    each test case class in the test package. You can also control which test cases and
+    methods are run using settings in Eclipse with ADT, or using flags with the command-line tools.
+</p>
+<p>
+    Neither the system classes nor {@link android.test.InstrumentationTestRunner} run
+    the application under test. Instead, the test case does this directly. It either calls methods
+    in the application under test, or it calls its own methods that trigger lifecycle events in
+    the application under test. The application is under the complete control of the test case,
+    which allows it to set up the test environment (the test fixture) before running a test. This
+    is demonstrated in the previous <a href="#ActivitySnippet">code snippet</a> that tests an
+    Activity that displays a Spinner widget.
+</p>
+<p>
+    To learn more about running tests, please read the topics
+    <a href="{@docRoot}guide/developing/testing/testing_eclipse.html"">
+    Testing in Eclipse, with ADT</a> or
+    <a href="{@docRoot}guide/developing/testing/testing_otheride.html">
+    Testing in Other IDes</a>.
+</p>
+<h2 id="TestResults">Seeing Test Results</h2>
+<p>
+    The Android testing framework returns test results back to the tool that started the test.
+    If you run a test in Eclipse with ADT, the results are displayed in a new JUnit view pane. If
+    you run a test from the command line, the results are displayed in <code>STDOUT</code>. In
+    both cases, you see a test summary that displays the name of each test case and method that
+    was run. You also see all the assertion failures that occurred. These include pointers to the
+    line in the test code where the failure occurred. Assertion failures also list the expected
+    value and actual value.
+</p>
+<p>
+    The test results have a format that is specific to the IDE that you are using. The test
+    results format for Eclipse with ADT is described in
+    <a href="{@docRoot}guide/developing/testing/testing_eclipse.html#RunTestEclipse">
+    Testing in Eclipse, with ADT</a>. The test results format for tests run from the
+    command line is described in
+    <a href="{@docRoot}guide/developing/testing/testing_otheride.html#RunTestsCommand">
+    Testing in Other IDEs</a>.
+</p>
+<h2 id="Monkeys">Monkey and MonkeyRunner</h2>
+<p>
+    The SDK provides two tools for functional-level application testing:
+</p>
     <ul>
-      <li>
-        {@link android.test.IsolatedContext} - Mocks a Context so that the application using it runs in isolation.
-        At the same time, it has enough stub code to satisfy OS code that tries to communicate with contexts. This class is useful in unit testing.
-      </li>
-      <li>
-        {@link android.test.RenamingDelegatingContext} - Delegates most context functions to an existing, normal context while changing the default file and database
-        names in the context. Use this to test file and database operations with a normal system context, using test names.
-      </li>
-      <li>
-        {@link android.test.mock.MockApplication}, {@link android.test.mock.MockContentResolver}, {@link android.test.mock.MockContext},
-        {@link android.test.mock.MockDialogInterface}, {@link android.test.mock.MockPackageManager},
-        {@link android.test.mock.MockResources} - Classes that create mock Android system objects for use in testing. They expose only those methods that are
-        useful in managing the object. The default implementations of these methods simply throw an Exception. You are expected to extend the classes and
-        override any methods that are called by the application under test.
-      </li>
+        <li>
+            <a href="{@docRoot}guide/developing/tools/monkey.html">Monkey</a> is a command-line
+            tool that sends pseudo-random streams of keystrokes, touches, and gestures to a
+            device. You run it with the <a href="{@docRoot}guide/developing/tools/adb.html">
+            Android Debug Bridge</a> (adb) tool. You use it to stress-test your application and
+            report back errors that are encountered. You can repeat a stream of events by
+            running the tool each time with the same random number seed.
+        </li>
+        <li>
+            <a href="{@docRoot}guide/topics/testing/monkeyrunner.html">MonkeyRunner</a> is a
+            Jython API that you use in test programs written in Python. The API includes functions
+            for connecting to a device, installing and uninstalling packages, taking screenshots,
+            comparing two images, and running a test package against an application. Using the API
+            with Python, you can write a wide range of large, powerful, and complex tests.
+        </li>
     </ul>
-<h3 id="InstrumentationTestRunner">Instrumentation Test Runner</h3>
+<h2 id="PackageNames">Working With Package names</h2>
 <p>
-  Android provides a custom class for running tests with instrumentation called called
-  {@link android.test.InstrumentationTestRunner}. This class
-  controls of the application under test, runs the test application and the main application in the same process, and routes
-  test output to the appropriate place. Using instrumentation is key to the ability of <code>InstrumentationTestRunner</code> to control the entire test
-  environment at runtime. Notice that you use this test runner even if your test class does not itself use instrumentation.
+    In the test environment, you work with both Android application package names and
+    Java package identifiers. Both use the same naming format, but they represent substantially
+    different entities. You need to know the difference to set up your tests correctly.
 </p>
 <p>
-  When you run a test application, you first run a system utility called Activity Manager. Activity Manager uses the instrumentation framework to start and control the test runner, which in turn uses instrumentation to shut down any running instances
-  of the main application, starts the test application, and then starts the main application in the same process. This allows various aspects of the test application to work directly with the main application.
+    An Android package name is a unique system name for a <code>.apk</code> file, set by the
+    &quot;android:package&quot; attribute of the &lt;manifest&gt; element in the package's
+    manifest. The Android package name of your test package must be different from the
+    Android package name of the application under test. By default, Android tools create the
+    test package name by appending ".test" to the package name of the application under test.
 </p>
 <p>
-  If you are developing in Eclipse, the ADT plugin assists you in the setup of <code>InstrumentationTestRunner</code> or other test runners.
-  The plugin UI prompts you to specify the test runner class to use, as well as the package name of the application under test.
-  The plugin then adds an <code>&lt;instrumentation&gt;</code> element with appropriate attributes to the manifest file of the test application.
-  Eclipse with ADT automatically starts a test application under the control of Activity Manager using instrumentation,
-  and redirects the test output to the Eclipse window's JUnit view.
+    The test package also uses an Android package name to target the application package it
+    tests. This is set in the &quot;android:targetPackage&quot; attribute of the
+    &lt;instrumentation&gt; element in the test package's manifest.
 </p>
 <p>
-  If you prefer working from the command line, you can use Ant and the <code>android</code>
-  tool to help you set up your test projects. To run tests with instrumentation, you can access the
-  Activity Manager through the <a href="{@docRoot}guide/developing/tools/adb.html">Android Debug
-  Bridge</a> (<code>adb</code>) tool and the output is directed to <code>STDOUT</code>.
-</p>
-<h2 id="TestEnviroment">Working in the Test Environment</h2>
-<p>
-    The tests for an Android application are contained in a test application, which itself is an Android application. A test application resides in a separate Android project that has the
-    same files and directories as a regular Android application. The test project is linked to the project of the application it tests
-    (known as the application under test) by its manifest file.
+    A Java package identifier applies to a source file. This package name reflects the directory
+    path of the source file. It also affects the visibility of classes and members to each other.
 </p>
 <p>
-    Each test application contains one or more test case classes based on an Android class for a
-    particular type of component. The test case class contains methods that define tests on some part of the application under test. When you run the test application, Android
-    starts it, loads the application under test into the same process, and then invokes each method in the test case class.
+    Android tools that create test projects set up an Android test package name for you.
+    From your input, the tools set up the test package name and the target package name for the
+    application under test. For these tools to work, the application project must already exist.
 </p>
 <p>
-    The tools and procedures you use with testing depend on the development environment you are using. If you use Eclipse, then the ADT plug in for Eclipse provides tools that
-    allow you to develop and run tests entirely within Eclipse. This is documented in the topic <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in Eclipse, with ADT</a>.
-    If you use another development environment, then you use Android's command-line tools, as documented in the topic <a href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other IDEs</a>.
+    By default, these tools set the Java package identifier for the test class to be the same
+    as the Android package identifier. You may want to change this if you want to expose
+    members in the application under test by giving them package visibility. If you do this,
+    change only the Java package identifier, not the Android package names, and change only the
+    test case source files. Do not change the Java package name of the generated
+    <code>R.java</code> class in your test package, because it will then conflict with the
+    <code>R.java</code> class in the application under test. Do not change the Android package name
+    of your test package to be the same as the application it tests, because then their names
+    will no longer be unique in the system.
 </p>
-<h3 id="TestProjects">Working with test projects</h3>
+<h2 id="WhatToTest">What to Test</h2>
 <p>
-    To start testing an Android application, you create a test project for it using Android tools. The tools create the project directory and the files and subdirectories needed.
-    The tools also create a manifest file that links the application in the test project to the application under test. The procedure for creating a test project in Eclipse with
-    ADT is documented in <a href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in Eclipse, with ADT</a>. The procedure for creating a test project for use with development
-    tools other than Eclipse is documented in <a href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other IDEs</a>.
-</p>
-<h3 id="TestClasses">Working with test case classes</h3>
-<p>
-    A test application contains one or more test case classes that extend an Android test case class. You choose a test case class based on the type of Android component you are testing and the
-    tests you are doing. A test application can test different components, but each test case class is designed to test a single type of component.
-    The Android test case classes are described in the section <a href="#TestAPI">The Testing API</a>.
+    The topic <a href="{@docRoot}guide/topics/testing/what_to_test.html">What To Test</a>
+    describes the key functionality you should test in an Android application, and the key
+    situations that might affect that functionality.
 </p>
 <p>
-    Some Android components have more than one associated test case class. In this case, you choose among the available classes based on the type of tests you want to do. For activities,
-    for example, you have the choice of either {@link android.test.ActivityInstrumentationTestCase2} or {@link android.test.ActivityUnitTestCase}.
-<p>
-    <code>ActivityInstrumentationTestCase2</code> is designed to do functional testing, so it tests activities in a normal system infrastructure. You can inject mocked Intents, but not
-    mocked Contexts. In general, you can't mock dependencies for the activity under test.
+    Most unit testing is specific to the Android component you are testing.
+    The topics <a href="{@docRoot}guide/topics/testing/activity_testing.html">Activity Testing</a>,
+    <a href="{@docRoot}guide/topics/testing/contentprovider_testing.html">
+    Content Provider Testing</a>, and <a href="{@docRoot}guide/topics/testing/service_testing.html">
+    Service Testing</a> each have a section entitled "What To Test" that lists possible testing
+    areas.
 </p>
 <p>
-    In comparison, <code>ActivityUnitTestCase</code> is designed for unit testing, so it tests activities in an isolated system infrastructure. You can inject mocked or wrappered dependencies for
-    the activity under test, particularly mocked Contexts. On the other hand, when you use this test case class the activity under test runs in isolation and can't interact with other activities.
+    When possible, you should run these tests on an actual device. If this is not possible, you can
+    use the <a href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a> with
+    <a href="{@docRoot}guide/developing/tools/avd.html">Android Virtual Devices</a> configured for
+    the hardware, screens, and versions you want to test.
+</p>
+<h2 id="NextSteps">Next Steps</h2>
+<p>
+    To learn how to set up and run tests in Eclipse, please refer to <a
+    href="{@docRoot}guide/developing/testing/testing_eclipse.html">Testing in
+    Eclipse, with ADT</a>. If you're not working in Eclipse, refer to <a
+    href="{@docRoot}guide/developing/testing/testing_otheride.html">Testing in Other
+    IDEs</a>.
 </p>
 <p>
-    As a rule of thumb, if you wanted to test an activity's interaction with the rest of Android, you would use <code>ActivityInstrumentationTestCase2</code>. If you wanted to do regression testing
-    on an activity, you would use <code>ActivityUnitTestCase</code>.
+    If you want a step-by-step introduction to Android testing, try one of the
+    testing tutorials or sample test packages:
 </p>
-<h3 id="Tests">Working with test methods</h3>
-<p>
-    Each test case class provides methods that you use to set up the test environment and control the application under test. For example, all test case classes provide the JUnit {@link junit.framework.TestCase#setUp() setUp()}
-    method that you can override to set up fixtures. In addition, you add methods to the class to define individual tests. Each method you add is run once each time you run the test application. If you override the <code>setUp()</code>
-    method, it runs before each of your methods. Similarly, the JUnit {@link junit.framework.TestCase#tearDown() tearDown()} method is run once after each of your methods.
-</p>
-<p>
-    The test case classes give you substantial control over starting and stopping components. For this reason, you have to specifically tell Android to start a component before you run tests against it. For example, you use the
-    {@link android.test.ActivityInstrumentationTestCase2#getActivity()} method to start the activity under test. You can call this method once during the entire test case, or once for each test method. You can even destroy the
-    activity under test by calling its {@link android.app.Activity#finish()} method and then restart it with <code>getActivity()</code> within a single test method.
-</p>
-<h3 id="RunTests">Running tests and seeing the results</h3>
-<p>
-    To run your tests, you build your test project and then run the test application using the system utility Activity Manager with instrumentation. You provide to Activity Manager the name of the test runner (usually
-    {@link android.test.InstrumentationTestRunner}) you specified for your application; the name includes both your test application's package name and the test runner class name. Activity Manager loads and starts your
-    test application, kills any instances of the application under test, loads an instance of the application under test into the same process as the test application, and then passes control to the first test case
-    class in your test application. The test runner then takes control of the tests, running each of your test methods against the application under test until all the methods in all the classes have been run.
-</p>
-<p>
-    If you run a test within Eclipse with ADT, the output appears in a new JUnit view pane. If you run a test from the command line, the output goes to STDOUT.
-</p>
-<h2 id="TestAreas">What to Test</h2>
-<p>
-  In addition to the functional areas you would normally test, here are some areas
-  of Android application testing that you should consider:
-</p>
-  <ul>
+<ul>
     <li>
-      Activity lifecycle events: You should test that your activities handle lifecycle events correctly. For example
-      an activity should respond to pause or destroy events by saving its state. Remember that even a change in screen orientation
-      causes the current activity to be destroyed, so you should test that accidental device movements don't accidentally lose the
-      application state.
+        The <a
+        href="{@docRoot}resources/tutorials/testing/helloandroid_test.html">Hello,
+        Testing</a> tutorial introduces basic testing concepts and procedures in the
+        context of the Hello, World application.
     </li>
     <li>
-      Database operations: You should ensure that database operations correctly handle changes to the application's state.
-      To do this, use mock objects from the package {@link android.test.mock android.test.mock}.
+        The <a href="{@docRoot}resources/tutorials/testing/activity_test.html">Activity
+        Testing</a> tutorial is an excellent follow-up to the Hello, Testing tutorial.
+        It guides you through a more complex testing scenario that you develop against a
+        more realistic application.
     </li>
     <li>
-        Screen sizes and resolutions: Before you publish your application, make sure to test it on all of the
-        screen sizes and densities on which you want it to run. You can test the application on multiple sizes and densities using
-        AVDs, or you can test your application directly on the devices that you are targeting. For more information, see
-        the topic <a href="{@docRoot}guide/practices/screens_support.html">Supporting Multiple Screens</a>.
+        The sample test package
+        <a href="{@docRoot}resources/samples/NotePadTest">Note Pad Test</a> is an example of
+        testing a {@link android.content.ContentProvider}. It contains a set of unit tests for the
+        Note Pad sample application's {@link android.content.ContentProvider}.
     </li>
-  </ul>
-<p>
-  When possible, you should run these tests on an actual device. If this is not possible, you can
-  use the <a href="{@docRoot}guide/developing/tools/emulator.html">Android Emulator</a> with
-  <a href="{@docRoot}guide/developing/tools/avd.html">Android Virtual Devices</a> configured for
-  the hardware, screens, and versions you want to test.
-</p>
-<h2 id="UITesting">Appendix: UI Testing Notes</h2>
-<p>
-  The following sections have tips for testing the UI of your Android application, specifically
-  to help you handle actions that run in the UI thread, touch screen and keyboard events, and home
-  screen unlock during testing.
-</p>
-<h3 id="RunOnUIThread">Testing on the UI thread</h3>
-<p>
-  An application's activities run on the application's <strong>UI thread</strong>. Once the
-  UI is instantiated, for example in the activity's <code>onCreate()</code> method, then all
-  interactions with the UI must run in the UI thread. When you run the application normally, it
-  has access to the thread and does not have to do anything special.
-</p>
-<p>
-  This changes when you run tests against the application. With instrumentation-based classes,
-  you can invoke methods against the UI of the application under test. The other test classes don't allow this.
-  To run an entire test method on the UI thread, you can annotate the thread with <code>@UIThreadTest</code>.
-  Notice that this will run <em>all</em> of the method statements on the UI thread.  Methods that do not interact with the UI
-  are not allowed; for example, you can't invoke <code>Instrumentation.waitForIdleSync()</code>.
-</p>
-<p>
-  To run a subset of a test method on the UI thread, create an anonymous class of type
-  <code>Runnable</code>, put the statements you want in the <code>run()</code> method, and instantiate a new
-  instance of the class as a parameter to the method <code><em>appActivity</em>.runOnUiThread()</code>, where
-  <code><em>appActivity</em></code> is the instance of the app you are testing.
-</p>
-<p>
-  For example, this code instantiates an activity to test, requests focus (a UI action) for the Spinner displayed
-  by the activity, and then sends a key to it. Notice that the calls to <code>waitForIdleSync</code> and <code>sendKeys</code>
-  aren't allowed to run on the UI thread:</p>
-<pre>
-  private MyActivity mActivity; // MyActivity is the class name of the app under test
-  private Spinner mSpinner;
-
-  ...
-
-  protected void setUp() throws Exception {
-      super.setUp();
-      mInstrumentation = getInstrumentation();
-
-      mActivity = getActivity(); // get a references to the app under test
-
-      /*
-       * Get a reference to the main widget of the app under test, a Spinner
-       */
-      mSpinner = (Spinner) mActivity.findViewById(com.android.demo.myactivity.R.id.Spinner01);
-
-  ...
-
-  public void aTest() {
-      /*
-       * request focus for the Spinner, so that the test can send key events to it
-       * This request must be run on the UI thread. To do this, use the runOnUiThread method
-       * and pass it a Runnable that contains a call to requestFocus on the Spinner.
-       */
-      mActivity.runOnUiThread(new Runnable() {
-          public void run() {
-              mSpinner.requestFocus();
-          }
-      });
-
-      mInstrumentation.waitForIdleSync();
-
-      this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
-</pre>
-
-<h3 id="NotouchMode">Turning off touch mode</h3>
-<p>
-  To control the emulator or a device with key events you send from your tests, you must turn off
-  touch mode. If you do not do this, the key events are ignored.
-</p>
-<p>
-  To turn off touch mode, you invoke <code>ActivityInstrumentationTestCase2.setActivityTouchMode(false)</code>
-  <em>before</em> you call <code>getActivity()</code> to start the activity. You must invoke the method in a test method
-  that is <em>not</em> running on the UI thread. For this reason, you can't invoke the touch mode method
-  from a test method that is annotated with <code>@UIThread</code>. Instead, invoke the touch mode method from <code>setUp()</code>.
-</p>
-<h3 id="UnlockDevice">Unlocking the emulator or device</h3>
-<p>
-  You may find that UI tests don't work if the emulator's or device's home screen is disabled with the keyguard pattern.
-  This is because the application under test can't receive key events sent by <code>sendKeys()</code>. The best
-  way to avoid this is to start your emulator or device first and then disable the keyguard for the home screen.
-</p>
-<p>
-  You can also explicitly disable the keyguard. To do this,
-  you need to add a permission in the manifest file (<code>AndroidManifest.xml</code>) and
-  then disable the keyguard in your application under test. Note, though, that you either have to remove this before
-  you publish your application, or you have to disable it programmatically in the published app.
-</p>
-<p>
-  To add the the permission, add the element <code>&lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt;</code>
-  as a child of the <code>&lt;manifest&gt;</code> element. To disable the KeyGuard, add the following code
-  to the <code>onCreate()</code> method of activities you intend to test:
-</p>
-<pre>
-  mKeyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
-  mLock = mKeyGuardManager.newKeyguardLock("<em>activity_classname</em>");
-  mLock.disableKeyguard();
-</pre>
-<p>where <code><em>activity_classname</em></code> is the class name of the activity.</p>
-<h3 id="UITestTroubleshooting">Troubleshooting UI tests</h3>
-<p>
-  This section lists some of the common test failures you may encounter in UI testing, and their causes:
-</p>
-<dl>
-    <dt><code>WrongThreadException</code></dt>
-    <dd>
-      <p><strong>Problem:</strong></p>
-      For a failed test, the Failure Trace contains the following error message:
-      <code>
-        android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
-      </code>
-      <p><strong>Probable Cause:</strong></p>
-        This error is common if you tried to send UI events to the UI thread from outside the UI thread. This commonly happens if you send UI events
-        from the test application, but you don't use the <code>@UIThread</code> annotation or the <code>runOnUiThread()</code> method. The test method tried to interact with the UI outside the UI thread.
-      <p><strong>Suggested Resolution:</strong></p>
-        Run the interaction on the UI thread. Use a test class that provides instrumentation. See the previous section <a href="#RunOnUIThread">Testing on the UI Thread</a>
-        for more details.
-    </dd>
-    <dt><code>java.lang.RuntimeException</code></dt>
-    <dd>
-      <p><strong>Problem:</strong></p>
-      For a failed test, the Failure Trace contains the following error message:
-      <code>
-        java.lang.RuntimeException: This method can not be called from the main application thread
-      </code>
-      <p><strong>Probable Cause:</strong></p>
-        This error is common if your test method is annotated with <code>@UiThreadTest</code> but then tries to
-        do something outside the UI thread or tries to invoke <code>runOnUiThread()</code>.
-      <p><strong>Suggested Resolution:</strong></p>
-        Remove the <code>@UiThreadTest</code> annotation, remove the <code>runOnUiThread()</code> call, or re-factor your tests.
-    </dd>
-</dl>
+    <li>
+        The sample test package <a href="{@docRoot}resources/samples/AlarmServiceTest"}>
+        Alarm Service Test</a> is an example of testing a {@link android.app.Service}. It contains
+        a set of unit tests for the Alarm Service sample application's {@link android.app.Service}.
+    </li>
+</ul>
 
diff --git a/docs/html/guide/topics/testing/what_to_test.jd b/docs/html/guide/topics/testing/what_to_test.jd
new file mode 100644
index 0000000..e13538a
--- /dev/null
+++ b/docs/html/guide/topics/testing/what_to_test.jd
@@ -0,0 +1,84 @@
+page.title=What To Test
+@jd:body
+<p>
+    As you develop Android applications, knowing what to test is as important as knowing how to
+    test. This document lists some most common Android-related situations that you should consider
+    when you test, even at the unit test level. This is not an exhaustive list, and you consult the
+    documentation for the features that you use for more ideas. The
+    <a href="http://groups.google.com/group/android-developers">android-developers</a> Google Groups
+    site is another resource for information about testing.
+</p>
+<h2 id="Tests">Ideas for Testing</h2>
+<p>
+    The following sections are organized by behaviors or situations that you should test. Each
+    section contains a scenario that further illustrates the situation and the test or tests you
+    should do.
+</p>
+<h4>Change in orientation</h4>
+<p>
+    For devices that support multiple orientations, Android detects a change in orientation when
+    the user turns the device so that the display is "landscape" (long edge is horizontal) instead
+    of "portrait" (long edge is vertical).
+</p>
+<p>
+    When Android detects a change in orientation, its default behavior is to destroy and then
+    re-start the foreground Activity. You should consider testing the following:
+</p>
+<ul>
+    <li>
+        Is the screen re-drawn correctly? Any custom UI code you have should handle changes in the
+        orientation.
+    </li>
+    <li>
+        Does the application maintain its state? The Activity should not lose anything that the
+        user has already entered into the UI. The application should not "forget" its place in the
+        current transaction.
+    </li>
+</ul>
+<h4>Change in configuration</h4>
+<p>
+    A situation that is more general than a change in orientation is a change in the device's
+    configuration, such as a change in the availability of a keyboard or a change in system
+    language.
+</p>
+<p>
+    A change in configuration also triggers the default behavior of destroying and then restarting
+    the foreground Activity. Besides testing that the application maintains the UI and its
+    transaction state, you should also test that the application updates itself to respond
+    correctly to the new configuration.
+</p>
+<h4>Battery life</h4>
+<p>
+    Mobile devices primarily run on battery power. A device has finite "battery budget", and when it
+    is gone, the device is useless until it is recharged. You need to write your application to
+    minimize battery usage, you need to test its battery performance, and you need to test the
+    methods that manage battery usage.
+</p>
+<p>
+    Techniques for minimizing battery usage were presented at the 2010 Google I/O conference in the
+    presentation
+    <a href="http://code.google.com/events/io/2009/sessions/CodingLifeBatteryLife.html">
+    Coding for Life -- Battery Life, That Is</a>. This presentation describes the impact on battery
+    life of various operations, and the ways you can design your application to minimize these
+    impacts. When you code your application to reduce battery usage, you also write the
+    appropriate unit tests.
+</p>
+<h4>Dependence on external resources</h4>
+<p>
+    If your application depends on network access, SMS, Bluetooth, or GPS, then you should
+    test what happens when the resource or resources are not available.
+</p>
+<p>
+    For example, if your application uses the network,it can notify the user if access is
+    unavailable, or disable network-related features, or do both. For GPS, it can switch to
+    IP-based location awareness. It can also wait for WiFi access before doing large data transfers,
+    since WiFi transfers maximize battery usage compared to transfers over 3G or EDGE.
+</p>
+<p>
+    You can use the emulator to test network access and bandwidth. To learn more, please see
+    <a href="{@docRoot}guide/developing/tools/emulator.html#netspeed">Network Speed Emulation</a>.
+    To test GPS, you can use the emulator console and {@link android.location.LocationManager}. To
+    learn more about the emulator console, please see
+    <a href="{@docRoot}/guide/developing/tools/emulator.html#console">
+    Using the Emulator Console</a>.
+</p>
diff --git a/docs/html/images/testing/android_test_framework.png b/docs/html/images/testing/android_test_framework.png
index 6f80530..459975c 100755
--- a/docs/html/images/testing/android_test_framework.png
+++ b/docs/html/images/testing/android_test_framework.png
Binary files differ
diff --git a/docs/html/images/testing/eclipse_test_results.png b/docs/html/images/testing/eclipse_test_results.png
new file mode 100644
index 0000000..105e149
--- /dev/null
+++ b/docs/html/images/testing/eclipse_test_results.png
Binary files differ
diff --git a/docs/html/images/testing/eclipse_test_run_failure.png b/docs/html/images/testing/eclipse_test_run_failure.png
new file mode 100644
index 0000000..8111127
--- /dev/null
+++ b/docs/html/images/testing/eclipse_test_run_failure.png
Binary files differ
diff --git a/docs/html/images/testing/test_framework.png b/docs/html/images/testing/test_framework.png
new file mode 100644
index 0000000..fbc5fc2
--- /dev/null
+++ b/docs/html/images/testing/test_framework.png
Binary files differ
diff --git a/include/surfaceflinger/ISurfaceComposer.h b/include/surfaceflinger/ISurfaceComposer.h
index 6533600..1a1821c 100644
--- a/include/surfaceflinger/ISurfaceComposer.h
+++ b/include/surfaceflinger/ISurfaceComposer.h
@@ -118,6 +118,8 @@
             uint32_t* width, uint32_t* height, PixelFormat* format,
             uint32_t reqWidth, uint32_t reqHeight) = 0;
 
+    virtual status_t turnElectronBeamOff(int32_t mode) = 0;
+
     /* Signal surfaceflinger that there might be some work to do
      * This is an ASYNCHRONOUS call.
      */
@@ -142,7 +144,8 @@
         FREEZE_DISPLAY,
         UNFREEZE_DISPLAY,
         SIGNAL,
-        CAPTURE_SCREEN
+        CAPTURE_SCREEN,
+        TURN_ELECTRON_BEAM_OFF
     };
 
     virtual status_t    onTransact( uint32_t code,
diff --git a/libs/surfaceflinger_client/ISurfaceComposer.cpp b/libs/surfaceflinger_client/ISurfaceComposer.cpp
index d676f5e..d72561f 100644
--- a/libs/surfaceflinger_client/ISurfaceComposer.cpp
+++ b/libs/surfaceflinger_client/ISurfaceComposer.cpp
@@ -142,6 +142,15 @@
         return reply.readInt32();
     }
 
+    virtual status_t turnElectronBeamOff(int32_t mode)
+    {
+        Parcel data, reply;
+        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
+        data.writeInt32(mode);
+        remote()->transact(BnSurfaceComposer::TURN_ELECTRON_BEAM_OFF, data, &reply);
+        return reply.readInt32();
+    }
+
     virtual void signal() const
     {
         Parcel data, reply;
@@ -224,6 +233,12 @@
             reply->writeInt32(f);
             reply->writeInt32(res);
         } break;
+        case TURN_ELECTRON_BEAM_OFF: {
+            CHECK_INTERFACE(ISurfaceComposer, data, reply);
+            int32_t mode = data.readInt32();
+            status_t res = turnElectronBeamOff(mode);
+            reply->writeInt32(res);
+        }
         default:
             return BBinder::onTransact(code, data, reply, flags);
     }
diff --git a/libs/ui/InputDispatcher.cpp b/libs/ui/InputDispatcher.cpp
index 054042f..6ba19d7 100644
--- a/libs/ui/InputDispatcher.cpp
+++ b/libs/ui/InputDispatcher.cpp
@@ -432,10 +432,9 @@
     switch (dropReason) {
     case DROP_REASON_POLICY:
 #if DEBUG_INBOUND_EVENT_DETAILS
-        LOGD("Dropped event because policy requested that it not be delivered to the application.");
+        LOGD("Dropped event because policy consumed it.");
 #endif
-        reason = "inbound event was dropped because the policy requested that it not be "
-                "delivered to the application";
+        reason = "inbound event was dropped because the policy consumed it";
         break;
     case DROP_REASON_DISABLED:
         LOGI("Dropped event because input dispatch is disabled.");
@@ -625,15 +624,13 @@
         if (*dropReason == DROP_REASON_NOT_DROPPED) {
             *dropReason = DROP_REASON_POLICY;
         }
-        resetTargetsLocked();
-        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_SUCCEEDED);
-        return true;
     }
 
     // Clean up if dropping the event.
     if (*dropReason != DROP_REASON_NOT_DROPPED) {
         resetTargetsLocked();
-        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
+        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
+                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
         return true;
     }
 
@@ -713,7 +710,8 @@
     // Clean up if dropping the event.
     if (*dropReason != DROP_REASON_NOT_DROPPED) {
         resetTargetsLocked();
-        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
+        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
+                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
         return true;
     }
 
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index d9bceec..3cf4360 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1057,10 +1057,6 @@
     @Override
     public boolean interceptKeyBeforeDispatching(WindowState win, int action, int flags,
             int keyCode, int metaState, int repeatCount, int policyFlags) {
-        if ((policyFlags & WindowManagerPolicy.FLAG_TRUSTED) == 0) {
-            return false;
-        }
-
         final boolean keyguardOn = keyguardOn();
         final boolean down = (action == KeyEvent.ACTION_DOWN);
         final boolean canceled = ((flags & KeyEvent.FLAG_CANCELED) != 0);
@@ -1739,9 +1735,6 @@
     public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down,
             int policyFlags, boolean isScreenOn) {
         int result = ACTION_PASS_TO_USER;
-        if ((policyFlags & WindowManagerPolicy.FLAG_TRUSTED) == 0) {
-            return result;
-        }
 
         if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0) {
             performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
@@ -1749,7 +1742,14 @@
 
         final boolean isWakeKey = (policyFlags
                 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
-        
+
+        // If the key is injected, pretend that the screen is on and don't let the
+        // device go to sleep.  This feature is mainly used for testing purposes.
+        final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
+        if (isInjected) {
+            isScreenOn = true;
+        }
+
         // If screen is off then we treat the case where the keyguard is open but hidden
         // the same as if it were open and in front.
         // This will prevent any keys other than the power button from waking the screen
@@ -1848,7 +1848,7 @@
                         || (handled && hungUp && keyCode == KeyEvent.KEYCODE_POWER)) {
                     mShouldTurnOffOnKeyUp = false;
                 } else {
-                    // only try to turn off the screen if we didn't already hang up
+                    // Only try to turn off the screen if we didn't already hang up.
                     mShouldTurnOffOnKeyUp = true;
                     mHandler.postDelayed(mPowerLongPress,
                             ViewConfiguration.getGlobalActionKeyTimeout());
@@ -1871,12 +1871,14 @@
                     if (keyguardActive
                             || (sleeps && !gohome)
                             || (gohome && !goHome() && sleeps)) {
-                        // they must already be on the keyguad or home screen,
-                        // go to sleep instead
-                        Log.d(TAG, "I'm tired mEndcallBehavior=0x"
-                                + Integer.toHexString(mEndcallBehavior));
-                        result &= ~ACTION_POKE_USER_ACTIVITY;
-                        result |= ACTION_GO_TO_SLEEP;
+                        // They must already be on the keyguard or home screen,
+                        // go to sleep instead unless the event was injected.
+                        if (!isInjected) {
+                            Log.d(TAG, "I'm tired mEndcallBehavior=0x"
+                                    + Integer.toHexString(mEndcallBehavior));
+                            result &= ~ACTION_POKE_USER_ACTIVITY;
+                            result |= ACTION_GO_TO_SLEEP;
+                        }
                     }
                     result &= ~ACTION_PASS_TO_USER;
                 }
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index bc802a8..1df583a 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -7208,6 +7208,8 @@
                     pw.print("    pkgFlags=0x"); pw.print(Integer.toHexString(ps.pkgFlags));
                             pw.print(" installStatus="); pw.print(ps.installStatus);
                             pw.print(" enabled="); pw.println(ps.enabled);
+                    pw.print("    versionCode="); pw.print(ps.versionCode);
+                            pw.print(" versionName="); pw.println(ps.pkg.mVersionName);
                     if (ps.disabledComponents.size() > 0) {
                         pw.println("    disabledComponents:");
                         for (String s : ps.disabledComponents) {
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 88a4c90..f53ce2d 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -141,9 +141,7 @@
     // used for noChangeLights in setPowerState()
     private static final int LIGHTS_MASK        = SCREEN_BRIGHT_BIT | BUTTON_BRIGHT_BIT | KEYBOARD_BRIGHT_BIT;
 
-    static final boolean ANIMATE_SCREEN_LIGHTS = true;
-    static final boolean ANIMATE_BUTTON_LIGHTS = false;
-    static final boolean ANIMATE_KEYBOARD_LIGHTS = false;
+    boolean mAnimateScreenLights = true;
 
     static final int ANIM_STEPS = 60/4;
     // Slower animation for autobrightness changes
@@ -201,15 +199,12 @@
     private UnsynchronizedWakeLock mPreventScreenOnPartialLock;
     private UnsynchronizedWakeLock mProximityPartialLock;
     private HandlerThread mHandlerThread;
+    private HandlerThread mScreenOffThread;
+    private Handler mScreenOffHandler;
     private Handler mHandler;
     private final TimeoutTask mTimeoutTask = new TimeoutTask();
-    private final LightAnimator mLightAnimator = new LightAnimator();
     private final BrightnessState mScreenBrightness
             = new BrightnessState(SCREEN_BRIGHT_BIT);
-    private final BrightnessState mKeyboardBrightness
-            = new BrightnessState(KEYBOARD_BRIGHT_BIT);
-    private final BrightnessState mButtonBrightness
-            = new BrightnessState(BUTTON_BRIGHT_BIT);
     private boolean mStillNeedSleepNotification;
     private boolean mIsPowered = false;
     private IActivityManager mActivityService;
@@ -261,6 +256,7 @@
     
     private native void nativeInit();
     private native void nativeSetPowerState(boolean screenOn, boolean screenBright);
+    private native void nativeStartSurfaceFlingerAnimation();
 
     /*
     static PrintStream mLog;
@@ -485,6 +481,35 @@
         mKeyboardLight = lights.getLight(LightsService.LIGHT_ID_KEYBOARD);
         mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
 
+        nativeInit();
+        synchronized (mLocks) {
+            updateNativePowerStateLocked();
+        }
+
+        mInitComplete = false;
+        mScreenOffThread = new HandlerThread("PowerManagerService.mScreenOffThread") {
+            @Override
+            protected void onLooperPrepared() {
+                mScreenOffHandler = new Handler();
+                synchronized (mScreenOffThread) {
+                    mInitComplete = true;
+                    mScreenOffThread.notifyAll();
+                }
+            }
+        };
+        mScreenOffThread.start();
+
+        synchronized (mScreenOffThread) {
+            while (!mInitComplete) {
+                try {
+                    mScreenOffThread.wait();
+                } catch (InterruptedException e) {
+                    // Ignore
+                }
+            }
+        }
+        
+        mInitComplete = false;
         mHandlerThread = new HandlerThread("PowerManagerService") {
             @Override
             protected void onLooperPrepared() {
@@ -531,6 +556,9 @@
 
         Resources resources = mContext.getResources();
 
+        mAnimateScreenLights = resources.getBoolean(
+                com.android.internal.R.bool.config_animateScreenLights);
+
         mUnplugTurnsOnScreen = resources.getBoolean(
                 com.android.internal.R.bool.config_unplugTurnsOnScreen);
 
@@ -1093,8 +1121,6 @@
             pw.println("  mUseSoftwareAutoBrightness=" + mUseSoftwareAutoBrightness);
             pw.println("  mAutoBrightessEnabled=" + mAutoBrightessEnabled);
             mScreenBrightness.dump(pw, "  mScreenBrightness: ");
-            mKeyboardBrightness.dump(pw, "  mKeyboardBrightness: ");
-            mButtonBrightness.dump(pw, "  mButtonBrightness: ");
 
             int N = mLocks.size();
             pw.println();
@@ -1724,7 +1750,8 @@
         // I don't think we need to check the current state here because all of these
         // Power.setScreenState and sendNotificationLocked can both handle being
         // called multiple times in the same state. -joeo
-        EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, reason, mTotalTouchDownTime, mTouchCycles);
+        EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, reason, mTotalTouchDownTime,
+                mTouchCycles);
         mLastTouchDown = 0;
         int err = setScreenStateLocked(false);
         if (err == 0) {
@@ -1754,145 +1781,95 @@
         int onMask = 0;
 
         int preferredBrightness = getPreferredBrightness();
-        boolean startAnimation = false;
 
         if ((difference & KEYBOARD_BRIGHT_BIT) != 0) {
-            if (ANIMATE_KEYBOARD_LIGHTS) {
-                if ((newState & KEYBOARD_BRIGHT_BIT) == 0) {
-                    mKeyboardBrightness.setTargetLocked(Power.BRIGHTNESS_OFF,
-                            ANIM_STEPS, INITIAL_KEYBOARD_BRIGHTNESS,
-                            Power.BRIGHTNESS_ON);
-                } else {
-                    mKeyboardBrightness.setTargetLocked(Power.BRIGHTNESS_ON,
-                            ANIM_STEPS, INITIAL_KEYBOARD_BRIGHTNESS,
-                            Power.BRIGHTNESS_OFF);
-                }
-                startAnimation = true;
+            if ((newState & KEYBOARD_BRIGHT_BIT) == 0) {
+                offMask |= KEYBOARD_BRIGHT_BIT;
             } else {
-                if ((newState & KEYBOARD_BRIGHT_BIT) == 0) {
-                    offMask |= KEYBOARD_BRIGHT_BIT;
-                } else {
-                    onMask |= KEYBOARD_BRIGHT_BIT;
-                }
+                onMask |= KEYBOARD_BRIGHT_BIT;
             }
         }
 
         if ((difference & BUTTON_BRIGHT_BIT) != 0) {
-            if (ANIMATE_BUTTON_LIGHTS) {
-                if ((newState & BUTTON_BRIGHT_BIT) == 0) {
-                    mButtonBrightness.setTargetLocked(Power.BRIGHTNESS_OFF,
-                            ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS,
-                            Power.BRIGHTNESS_ON);
-                } else {
-                    mButtonBrightness.setTargetLocked(Power.BRIGHTNESS_ON,
-                            ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS,
-                            Power.BRIGHTNESS_OFF);
-                }
-                startAnimation = true;
+            if ((newState & BUTTON_BRIGHT_BIT) == 0) {
+                offMask |= BUTTON_BRIGHT_BIT;
             } else {
-                if ((newState & BUTTON_BRIGHT_BIT) == 0) {
-                    offMask |= BUTTON_BRIGHT_BIT;
-                } else {
-                    onMask |= BUTTON_BRIGHT_BIT;
-                }
+                onMask |= BUTTON_BRIGHT_BIT;
             }
         }
 
         if ((difference & (SCREEN_ON_BIT | SCREEN_BRIGHT_BIT)) != 0) {
-            if (ANIMATE_SCREEN_LIGHTS) {
-                int nominalCurrentValue = -1;
-                // If there was an actual difference in the light state, then
-                // figure out the "ideal" current value based on the previous
-                // state.  Otherwise, this is a change due to the brightness
-                // override, so we want to animate from whatever the current
-                // value is.
-                if ((realDifference & (SCREEN_ON_BIT | SCREEN_BRIGHT_BIT)) != 0) {
-                    switch (oldState & (SCREEN_BRIGHT_BIT|SCREEN_ON_BIT)) {
-                        case SCREEN_BRIGHT_BIT | SCREEN_ON_BIT:
-                            nominalCurrentValue = preferredBrightness;
-                            break;
-                        case SCREEN_ON_BIT:
-                            nominalCurrentValue = Power.BRIGHTNESS_DIM;
-                            break;
-                        case 0:
-                            nominalCurrentValue = Power.BRIGHTNESS_OFF;
-                            break;
-                        case SCREEN_BRIGHT_BIT:
-                        default:
-                            // not possible
-                            nominalCurrentValue = (int)mScreenBrightness.curValue;
-                            break;
-                    }
+            int nominalCurrentValue = -1;
+            // If there was an actual difference in the light state, then
+            // figure out the "ideal" current value based on the previous
+            // state.  Otherwise, this is a change due to the brightness
+            // override, so we want to animate from whatever the current
+            // value is.
+            if ((realDifference & (SCREEN_ON_BIT | SCREEN_BRIGHT_BIT)) != 0) {
+                switch (oldState & (SCREEN_BRIGHT_BIT|SCREEN_ON_BIT)) {
+                    case SCREEN_BRIGHT_BIT | SCREEN_ON_BIT:
+                        nominalCurrentValue = preferredBrightness;
+                        break;
+                    case SCREEN_ON_BIT:
+                        nominalCurrentValue = Power.BRIGHTNESS_DIM;
+                        break;
+                    case 0:
+                        nominalCurrentValue = Power.BRIGHTNESS_OFF;
+                        break;
+                    case SCREEN_BRIGHT_BIT:
+                    default:
+                        // not possible
+                        nominalCurrentValue = (int)mScreenBrightness.curValue;
+                        break;
                 }
-                int brightness = preferredBrightness;
-                int steps = ANIM_STEPS;
-                if ((newState & SCREEN_BRIGHT_BIT) == 0) {
-                    // dim or turn off backlight, depending on if the screen is on
-                    // the scale is because the brightness ramp isn't linear and this biases
-                    // it so the later parts take longer.
-                    final float scale = 1.5f;
-                    float ratio = (((float)Power.BRIGHTNESS_DIM)/preferredBrightness);
-                    if (ratio > 1.0f) ratio = 1.0f;
-                    if ((newState & SCREEN_ON_BIT) == 0) {
-                        if ((oldState & SCREEN_BRIGHT_BIT) != 0) {
-                            // was bright
-                            steps = ANIM_STEPS;
-                        } else {
-                            // was dim
-                            steps = (int)(ANIM_STEPS*ratio*scale);
-                        }
-                        brightness = Power.BRIGHTNESS_OFF;
+            }
+            int brightness = preferredBrightness;
+            int steps = ANIM_STEPS;
+            if ((newState & SCREEN_BRIGHT_BIT) == 0) {
+                // dim or turn off backlight, depending on if the screen is on
+                // the scale is because the brightness ramp isn't linear and this biases
+                // it so the later parts take longer.
+                final float scale = 1.5f;
+                float ratio = (((float)Power.BRIGHTNESS_DIM)/preferredBrightness);
+                if (ratio > 1.0f) ratio = 1.0f;
+                if ((newState & SCREEN_ON_BIT) == 0) {
+                    if ((oldState & SCREEN_BRIGHT_BIT) != 0) {
+                        // was bright
+                        steps = ANIM_STEPS;
                     } else {
-                        if ((oldState & SCREEN_ON_BIT) != 0) {
-                            // was bright
-                            steps = (int)(ANIM_STEPS*(1.0f-ratio)*scale);
-                        } else {
-                            // was dim
-                            steps = (int)(ANIM_STEPS*ratio);
-                        }
-                        if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
-                            // If the "stay on while plugged in" option is
-                            // turned on, then the screen will often not
-                            // automatically turn off while plugged in.  To
-                            // still have a sense of when it is inactive, we
-                            // will then count going dim as turning off.
-                            mScreenOffTime = SystemClock.elapsedRealtime();
-                        }
-                        brightness = Power.BRIGHTNESS_DIM;
+                        // was dim
+                        steps = (int)(ANIM_STEPS*ratio*scale);
                     }
-                }
-                long identity = Binder.clearCallingIdentity();
-                try {
-                    mBatteryStats.noteScreenBrightness(brightness);
-                } catch (RemoteException e) {
-                    // Nothing interesting to do.
-                } finally {
-                    Binder.restoreCallingIdentity(identity);
-                }
-                if (mScreenBrightness.setTargetLocked(brightness,
-                        steps, INITIAL_SCREEN_BRIGHTNESS, nominalCurrentValue)) {
-                    startAnimation = true;
-                }
-            } else {
-                if ((newState & SCREEN_BRIGHT_BIT) == 0) {
-                    // dim or turn off backlight, depending on if the screen is on
-                    if ((newState & SCREEN_ON_BIT) == 0) {
-                        offMask |= SCREEN_BRIGHT_BIT;
-                    } else {
-                        dimMask |= SCREEN_BRIGHT_BIT;
-                    }
+                    brightness = Power.BRIGHTNESS_OFF;
                 } else {
-                    onMask |= SCREEN_BRIGHT_BIT;
+                    if ((oldState & SCREEN_ON_BIT) != 0) {
+                        // was bright
+                        steps = (int)(ANIM_STEPS*(1.0f-ratio)*scale);
+                    } else {
+                        // was dim
+                        steps = (int)(ANIM_STEPS*ratio);
+                    }
+                    if (mStayOnConditions != 0 && mBatteryService.isPowered(mStayOnConditions)) {
+                        // If the "stay on while plugged in" option is
+                        // turned on, then the screen will often not
+                        // automatically turn off while plugged in.  To
+                        // still have a sense of when it is inactive, we
+                        // will then count going dim as turning off.
+                        mScreenOffTime = SystemClock.elapsedRealtime();
+                    }
+                    brightness = Power.BRIGHTNESS_DIM;
                 }
             }
-        }
-
-        if (startAnimation) {
-            if (mSpew) {
-                Slog.i(TAG, "Scheduling light animator!");
+            long identity = Binder.clearCallingIdentity();
+            try {
+                mBatteryStats.noteScreenBrightness(brightness);
+            } catch (RemoteException e) {
+                // Nothing interesting to do.
+            } finally {
+                Binder.restoreCallingIdentity(identity);
             }
-            mHandler.removeCallbacks(mLightAnimator);
-            mHandler.post(mLightAnimator);
+            mScreenBrightness.setTargetLocked(brightness, steps,
+                    INITIAL_SCREEN_BRIGHTNESS, nominalCurrentValue);
         }
 
         if (offMask != 0) {
@@ -1934,7 +1911,7 @@
         }
     }
 
-    class BrightnessState {
+    class BrightnessState implements Runnable {
         final int mask;
 
         boolean initialized;
@@ -1954,13 +1931,13 @@
                     + " delta=" + delta);
         }
 
-        boolean setTargetLocked(int target, int stepsToTarget, int initialValue,
+        void setTargetLocked(int target, int stepsToTarget, int initialValue,
                 int nominalCurrentValue) {
             if (!initialized) {
                 initialized = true;
                 curValue = (float)initialValue;
             } else if (targetValue == target) {
-                return false;
+                return;
             }
             targetValue = target;
             delta = (targetValue -
@@ -1974,7 +1951,12 @@
                         + noticeMe);
             }
             animating = true;
-            return true;
+
+            if (mSpew) {
+                Slog.i(TAG, "scheduling light animator");
+            }
+            mScreenOffHandler.removeCallbacks(this);
+            mScreenOffHandler.post(this);
         }
 
         boolean stepLocked() {
@@ -2000,32 +1982,50 @@
                     more = false;
                 }
             }
-            //Slog.i(TAG, "Animating brightess " + curIntValue + ": " + mask);
+            if (mSpew) Slog.d(TAG, "Animating curIntValue=" + curIntValue + ": " + mask);
             setLightBrightness(mask, curIntValue);
+            finishAnimation(more, curIntValue);
+            return more;
+        }
+
+        void jumpToTarget() {
+            if (mSpew) Slog.d(TAG, "jumpToTarget targetValue=" + targetValue + ": " + mask);
+            setLightBrightness(mask, targetValue);
+            final int tv = targetValue;
+            curValue = tv;
+            targetValue = -1;
+            finishAnimation(false, tv);
+        }
+
+        private void finishAnimation(boolean more, int curIntValue) {
             animating = more;
             if (!more) {
                 if (mask == SCREEN_BRIGHT_BIT && curIntValue == Power.BRIGHTNESS_OFF) {
                     screenOffFinishedAnimatingLocked(mScreenOffReason);
                 }
             }
-            return more;
         }
-    }
 
-    private class LightAnimator implements Runnable {
         public void run() {
-            synchronized (mLocks) {
-                long now = SystemClock.uptimeMillis();
-                boolean more = mScreenBrightness.stepLocked();
-                if (mKeyboardBrightness.stepLocked()) {
-                    more = true;
+            if (mAnimateScreenLights) {
+                synchronized (mLocks) {
+                    long now = SystemClock.uptimeMillis();
+                    boolean more = mScreenBrightness.stepLocked();
+                    if (more) {
+                        mScreenOffHandler.postAtTime(this, now+(1000/60));
+                    }
                 }
-                if (mButtonBrightness.stepLocked()) {
-                    more = true;
+            } else {
+                boolean animate;
+                boolean jump;
+                synchronized (mLocks) {
+                    jump = animating; // we haven't already run this animation
+                    animate = jump && targetValue == Power.BRIGHTNESS_OFF; // we're turning off
                 }
-                if (more) {
-                    mHandler.postAtTime(mLightAnimator, now+(1000/60));
+                if (animate) {
+                    nativeStartSurfaceFlingerAnimation();
                 }
+                mScreenBrightness.jumpToTarget();
             }
         }
     }
@@ -2343,49 +2343,15 @@
                     Slog.d(TAG, "keyboardValue " + keyboardValue);
                 }
 
-                boolean startAnimation = false;
                 if (mAutoBrightessEnabled && mScreenBrightnessOverride < 0) {
-                    if (ANIMATE_SCREEN_LIGHTS) {
-                        if (mScreenBrightness.setTargetLocked(lcdValue,
-                                AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_SCREEN_BRIGHTNESS,
-                                (int)mScreenBrightness.curValue)) {
-                            startAnimation = true;
-                        }
-                    } else {
-                        int brightnessMode = (mAutoBrightessEnabled
-                                            ? LightsService.BRIGHTNESS_MODE_SENSOR
-                                            : LightsService.BRIGHTNESS_MODE_USER);
-                        mLcdLight.setBrightness(lcdValue, brightnessMode);
-                    }
+                    mScreenBrightness.setTargetLocked(lcdValue, AUTOBRIGHTNESS_ANIM_STEPS,
+                            INITIAL_SCREEN_BRIGHTNESS, (int)mScreenBrightness.curValue);
                 }
                 if (mButtonBrightnessOverride < 0) {
-                    if (ANIMATE_BUTTON_LIGHTS) {
-                        if (mButtonBrightness.setTargetLocked(buttonValue,
-                                AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS,
-                                (int)mButtonBrightness.curValue)) {
-                            startAnimation = true;
-                        }
-                    } else {
-                         mButtonLight.setBrightness(buttonValue);
-                    }
+                    mButtonLight.setBrightness(buttonValue);
                 }
                 if (mButtonBrightnessOverride < 0 || !mKeyboardVisible) {
-                    if (ANIMATE_KEYBOARD_LIGHTS) {
-                        if (mKeyboardBrightness.setTargetLocked(keyboardValue,
-                                AUTOBRIGHTNESS_ANIM_STEPS, INITIAL_BUTTON_BRIGHTNESS,
-                                (int)mKeyboardBrightness.curValue)) {
-                            startAnimation = true;
-                        }
-                    } else {
-                        mKeyboardLight.setBrightness(keyboardValue);
-                    }
-                }
-                if (startAnimation) {
-                    if (mDebugLightSensor) {
-                        Slog.i(TAG, "lightSensorChangedLocked scheduling light animator");
-                    }
-                    mHandler.removeCallbacks(mLightAnimator);
-                    mHandler.post(mLightAnimator);
+                    mKeyboardLight.setBrightness(keyboardValue);
                 }
             }
         }
@@ -2753,6 +2719,7 @@
         }
     }
 
+    // for watchdog
     public void monitor() {
         synchronized (mLocks) { }
     }
@@ -2772,34 +2739,23 @@
     public void setBacklightBrightness(int brightness) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
         // Don't let applications turn the screen all the way off
-        brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
-        mLcdLight.setBrightness(brightness);
-        mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0);
-        mButtonLight.setBrightness(brightness);
-        long identity = Binder.clearCallingIdentity();
-        try {
-            mBatteryStats.noteScreenBrightness(brightness);
-        } catch (RemoteException e) {
-            Slog.w(TAG, "RemoteException calling noteScreenBrightness on BatteryStatsService", e);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
+        synchronized (mLocks) {
+            brightness = Math.max(brightness, Power.BRIGHTNESS_DIM);
+            mLcdLight.setBrightness(brightness);
+            mKeyboardLight.setBrightness(mKeyboardVisible ? brightness : 0);
+            mButtonLight.setBrightness(brightness);
+            long identity = Binder.clearCallingIdentity();
+            try {
+                mBatteryStats.noteScreenBrightness(brightness);
+            } catch (RemoteException e) {
+                Slog.w(TAG, "RemoteException calling noteScreenBrightness on BatteryStatsService", e);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
 
-        // update our animation state
-        if (ANIMATE_SCREEN_LIGHTS) {
-            mScreenBrightness.curValue = brightness;
-            mScreenBrightness.animating = false;
-            mScreenBrightness.targetValue = -1;
-        }
-        if (ANIMATE_KEYBOARD_LIGHTS) {
-            mKeyboardBrightness.curValue = brightness;
-            mKeyboardBrightness.animating = false;
-            mKeyboardBrightness.targetValue = -1;
-        }
-        if (ANIMATE_BUTTON_LIGHTS) {
-            mButtonBrightness.curValue = brightness;
-            mButtonBrightness.animating = false;
-            mButtonBrightness.targetValue = -1;
+            // update our animation state
+            mScreenBrightness.targetValue = brightness;
+            mScreenBrightness.jumpToTarget();
         }
     }
 
diff --git a/services/jni/Android.mk b/services/jni/Android.mk
index cdc0a6f..c90879d 100644
--- a/services/jni/Android.mk
+++ b/services/jni/Android.mk
@@ -23,7 +23,8 @@
 	libnativehelper \
     libsystem_server \
 	libutils \
-	libui
+	libui \
+    libsurfaceflinger_client
 
 ifeq ($(TARGET_SIMULATOR),true)
 ifeq ($(TARGET_OS),linux)
diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp
index a0b0aba..1bd1874 100644
--- a/services/jni/com_android_server_InputManager.cpp
+++ b/services/jni/com_android_server_InputManager.cpp
@@ -842,31 +842,35 @@
         flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
     }
 
-    const int32_t WM_ACTION_PASS_TO_USER = 1;
-    const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
-    const int32_t WM_ACTION_GO_TO_SLEEP = 4;
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - Ask the window manager what to do with normal events and trusted injected events.
+    // - For normal events wake and brighten the screen if currently off or dim.
+    if ((policyFlags & POLICY_FLAG_TRUSTED)) {
+        const int32_t WM_ACTION_PASS_TO_USER = 1;
+        const int32_t WM_ACTION_POKE_USER_ACTIVITY = 2;
+        const int32_t WM_ACTION_GO_TO_SLEEP = 4;
 
-    bool isScreenOn = this->isScreenOn();
-    bool isScreenBright = this->isScreenBright();
+        bool isScreenOn = this->isScreenOn();
+        bool isScreenBright = this->isScreenBright();
 
-    JNIEnv* env = jniEnv();
-    jint wmActions = env->CallIntMethod(mCallbacksObj,
-            gCallbacksClassInfo.interceptKeyBeforeQueueing,
-            when, keyCode, action == AKEY_EVENT_ACTION_DOWN, policyFlags, isScreenOn);
-    if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
-        wmActions = 0;
-    }
-
-    if (policyFlags & POLICY_FLAG_TRUSTED) {
-        if (! isScreenOn) {
-            // Key presses and releases wake the device.
-            policyFlags |= POLICY_FLAG_WOKE_HERE;
-            flags |= AKEY_EVENT_FLAG_WOKE_HERE;
+        JNIEnv* env = jniEnv();
+        jint wmActions = env->CallIntMethod(mCallbacksObj,
+                gCallbacksClassInfo.interceptKeyBeforeQueueing,
+                when, keyCode, action == AKEY_EVENT_ACTION_DOWN, policyFlags, isScreenOn);
+        if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
+            wmActions = 0;
         }
 
-        if (! isScreenBright) {
-            // Key presses and releases brighten the screen if dimmed.
-            policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+        if (!(flags & POLICY_FLAG_INJECTED)) {
+            if (!isScreenOn) {
+                policyFlags |= POLICY_FLAG_WOKE_HERE;
+                flags |= AKEY_EVENT_FLAG_WOKE_HERE;
+            }
+
+            if (!isScreenBright) {
+                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+            }
         }
 
         if (wmActions & WM_ACTION_GO_TO_SLEEP) {
@@ -876,9 +880,11 @@
         if (wmActions & WM_ACTION_POKE_USER_ACTIVITY) {
             android_server_PowerManagerService_userActivity(when, POWER_MANAGER_BUTTON_EVENT);
         }
-    }
 
-    if (wmActions & WM_ACTION_PASS_TO_USER) {
+        if (wmActions & WM_ACTION_PASS_TO_USER) {
+            policyFlags |= POLICY_FLAG_PASS_TO_USER;
+        }
+    } else {
         policyFlags |= POLICY_FLAG_PASS_TO_USER;
     }
 }
@@ -888,33 +894,47 @@
     LOGD("interceptGenericBeforeQueueing - when=%lld, policyFlags=0x%x", when, policyFlags);
 #endif
 
-    if (isScreenOn()) {
-        // Only dispatch events when the device is awake.
-        // Do not wake the device.
-        policyFlags |= POLICY_FLAG_PASS_TO_USER;
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - No special filtering for injected events required at this time.
+    // - Filter normal events based on screen state.
+    // - For normal events brighten (but do not wake) the screen if currently dim.
+    if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
+        if (isScreenOn()) {
+            policyFlags |= POLICY_FLAG_PASS_TO_USER;
 
-        if ((policyFlags & POLICY_FLAG_TRUSTED) && !isScreenBright()) {
-            // Brighten the screen if dimmed.
-            policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+            if (!isScreenBright()) {
+                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+            }
         }
+    } else {
+        policyFlags |= POLICY_FLAG_PASS_TO_USER;
     }
 }
 
 bool NativeInputManager::interceptKeyBeforeDispatching(const sp<InputChannel>& inputChannel,
         const KeyEvent* keyEvent, uint32_t policyFlags) {
-    JNIEnv* env = jniEnv();
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - Filter normal events and trusted injected events through the window manager policy to
+    //   handle the HOME key and the like.
+    if (policyFlags & POLICY_FLAG_TRUSTED) {
+        JNIEnv* env = jniEnv();
 
-    // Note: inputChannel may be null.
-    jobject inputChannelObj = getInputChannelObjLocal(env, inputChannel);
-    jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
-            gCallbacksClassInfo.interceptKeyBeforeDispatching,
-            inputChannelObj, keyEvent->getAction(), keyEvent->getFlags(),
-            keyEvent->getKeyCode(), keyEvent->getMetaState(),
-            keyEvent->getRepeatCount(), policyFlags);
-    bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
+        // Note: inputChannel may be null.
+        jobject inputChannelObj = getInputChannelObjLocal(env, inputChannel);
+        jboolean consumed = env->CallBooleanMethod(mCallbacksObj,
+                gCallbacksClassInfo.interceptKeyBeforeDispatching,
+                inputChannelObj, keyEvent->getAction(), keyEvent->getFlags(),
+                keyEvent->getKeyCode(), keyEvent->getMetaState(),
+                keyEvent->getRepeatCount(), policyFlags);
+        bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
 
-    env->DeleteLocalRef(inputChannelObj);
-    return consumed && ! error;
+        env->DeleteLocalRef(inputChannelObj);
+        return consumed && ! error;
+    } else {
+        return false;
+    }
 }
 
 void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
diff --git a/services/jni/com_android_server_PowerManagerService.cpp b/services/jni/com_android_server_PowerManagerService.cpp
index 146c177..2ec20bd 100644
--- a/services/jni/com_android_server_PowerManagerService.cpp
+++ b/services/jni/com_android_server_PowerManagerService.cpp
@@ -20,9 +20,14 @@
 
 #include "JNIHelp.h"
 #include "jni.h"
+
 #include <limits.h>
+
 #include <android_runtime/AndroidRuntime.h>
 #include <utils/Timers.h>
+#include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/SurfaceComposerClient.h>
+
 #include "com_android_server_PowerManagerService.h"
 
 namespace android {
@@ -119,6 +124,12 @@
     gScreenBright = screenBright;
 }
 
+static void android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation(JNIEnv* env,
+        jobject obj) {
+    sp<ISurfaceComposer> s(ComposerService::getComposerService());
+    s->turnElectronBeamOff(0);
+}
+
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gPowerManagerServiceMethods[] = {
@@ -127,6 +138,8 @@
             (void*) android_server_PowerManagerService_nativeInit },
     { "nativeSetPowerState", "(ZZ)V",
             (void*) android_server_PowerManagerService_nativeSetPowerState },
+    { "nativeStartSurfaceFlingerAnimation", "()V",
+            (void*) android_server_PowerManagerService_nativeStartSurfaceFlingerAnimation },
 };
 
 #define FIND_CLASS(var, className) \
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
index 1d09f84..fe9a5ab 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
@@ -359,7 +359,7 @@
 
 DisplayHardwareBase::DisplayHardwareBase(const sp<SurfaceFlinger>& flinger,
         uint32_t displayIndex) 
-    : mCanDraw(true)
+    : mCanDraw(true), mScreenAcquired(true)
 {
     mDisplayEventThread = new DisplayEventThread(flinger);
     if (mDisplayEventThread->initCheck() != NO_ERROR) {
@@ -374,18 +374,21 @@
     mDisplayEventThread->requestExitAndWait();
 }
 
+void DisplayHardwareBase::setCanDraw(bool canDraw)
+{
+    mCanDraw = canDraw;
+}
 
 bool DisplayHardwareBase::canDraw() const
 {
-    return mCanDraw;
+    return mCanDraw && mScreenAcquired;
 }
 
 void DisplayHardwareBase::releaseScreen() const
 {
     status_t err = mDisplayEventThread->releaseScreen();
     if (err >= 0) {
-        //LOGD("screen given-up");
-        mCanDraw = false;
+        mScreenAcquired = false;
     }
 }
 
@@ -393,9 +396,14 @@
 {
     status_t err = mDisplayEventThread->acquireScreen();
     if (err >= 0) {
-        //LOGD("screen returned");
         mCanDraw = true;
+        mScreenAcquired = true;
     }
 }
 
+bool DisplayHardwareBase::isScreenAcquired() const
+{
+    return mScreenAcquired;
+}
+
 }; // namespace android
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
index 8369bb8..fa6a0c4 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
@@ -40,7 +40,11 @@
     // console managment
     void releaseScreen() const;
     void acquireScreen() const;
+    bool isScreenAcquired() const;
+
     bool canDraw() const;
+    void setCanDraw(bool canDraw);
+
 
 private:
     class DisplayEventThreadBase : public Thread {
@@ -89,6 +93,7 @@
 
     sp<DisplayEventThreadBase>  mDisplayEventThread;
     mutable int                 mCanDraw;
+    mutable int                 mScreenAcquired;
 };
 
 }; // namespace android
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index e5e87c6..a919ddf 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -423,14 +423,14 @@
         hw.acquireScreen();
     }
 
-    if (mDeferReleaseConsole && hw.canDraw()) {
+    if (mDeferReleaseConsole && hw.isScreenAcquired()) {
         // We got the release signal before the acquire signal
         mDeferReleaseConsole = false;
         hw.releaseScreen();
     }
 
     if (what & eConsoleReleased) {
-        if (hw.canDraw()) {
+        if (hw.isScreenAcquired()) {
             hw.releaseScreen();
         } else {
             mDeferReleaseConsole = true;
@@ -1456,6 +1456,7 @@
         case FREEZE_DISPLAY:
         case UNFREEZE_DISPLAY:
         case BOOT_FINISHED:
+        case TURN_ELECTRON_BEAM_OFF:
         {
             // codes that require permission check
             IPCThreadState* ipc = IPCThreadState::self();
@@ -1544,6 +1545,231 @@
     return err;
 }
 
+
+// ---------------------------------------------------------------------------
+
+status_t SurfaceFlinger::turnElectronBeamOffImplLocked()
+{
+    status_t result = PERMISSION_DENIED;
+
+    if (!GLExtensions::getInstance().haveFramebufferObject())
+        return INVALID_OPERATION;
+
+    // get screen geometry
+    const int dpy = 0;
+    const DisplayHardware& hw(graphicPlane(dpy).displayHardware());
+    if (!hw.canDraw()) {
+        // we're already off
+        return NO_ERROR;
+    }
+
+    const uint32_t hw_w = hw.getWidth();
+    const uint32_t hw_h = hw.getHeight();
+    const Region screenBounds(hw.bounds());
+    GLfloat u = 1;
+    GLfloat v = 1;
+
+    // make sure to clear all GL error flags
+    while ( glGetError() != GL_NO_ERROR ) ;
+
+    // create a FBO
+    GLuint name, tname;
+    glGenTextures(1, &tname);
+    glBindTexture(GL_TEXTURE_2D, tname);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, hw_w, hw_h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
+    if (glGetError() != GL_NO_ERROR) {
+        GLint tw = (2 << (31 - clz(hw_w)));
+        GLint th = (2 << (31 - clz(hw_h)));
+        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
+        u = GLfloat(hw_w) / tw;
+        v = GLfloat(hw_h) / th;
+    }
+    glGenFramebuffersOES(1, &name);
+    glBindFramebufferOES(GL_FRAMEBUFFER_OES, name);
+    glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, tname, 0);
+
+    GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
+    if (status == GL_FRAMEBUFFER_COMPLETE_OES) {
+        // redraw the screen entirely...
+        glClearColor(0,0,0,1);
+        glClear(GL_COLOR_BUFFER_BIT);
+        const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
+        const size_t count = layers.size();
+        for (size_t i=0 ; i<count ; ++i) {
+            const sp<LayerBase>& layer(layers[i]);
+            layer->drawForSreenShot();
+        }
+        // back to main framebuffer
+        glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
+        glDisable(GL_SCISSOR_TEST);
+
+        GLfloat vtx[8];
+        const GLfloat texCoords[4][2] = { {0,v}, {0,0}, {u,0}, {u,v} };
+        glEnable(GL_TEXTURE_2D);
+        glBindTexture(GL_TEXTURE_2D, tname);
+        glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+        glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+        glVertexPointer(2, GL_FLOAT, 0, vtx);
+
+        class s_curve_interpolator {
+            const float nbFrames, s, v;
+        public:
+            s_curve_interpolator(int nbFrames, float s)
+                : nbFrames(1.0f / (nbFrames-1)), s(s),
+                  v(1.0f + expf(-s + 0.5f*s)) {
+            }
+            float operator()(int f) {
+                const float x = f * nbFrames;
+                return ((1.0f/(1.0f + expf(-x*s + 0.5f*s))) - 0.5f) * v + 0.5f;
+            }
+        };
+
+        class v_stretch {
+            const GLfloat hw_w, hw_h;
+        public:
+            v_stretch(uint32_t hw_w, uint32_t hw_h)
+                : hw_w(hw_w), hw_h(hw_h) {
+            }
+            void operator()(GLfloat* vtx, float v) {
+                const GLfloat w = hw_w + (hw_w * v);
+                const GLfloat h = hw_h - (hw_h * v);
+                const GLfloat x = (hw_w - w) * 0.5f;
+                const GLfloat y = (hw_h - h) * 0.5f;
+                vtx[0] = x;         vtx[1] = y;
+                vtx[2] = x;         vtx[3] = y + h;
+                vtx[4] = x + w;     vtx[5] = y + h;
+                vtx[6] = x + w;     vtx[7] = y;
+            }
+        };
+
+        class h_stretch {
+            const GLfloat hw_w, hw_h;
+        public:
+            h_stretch(uint32_t hw_w, uint32_t hw_h)
+                : hw_w(hw_w), hw_h(hw_h) {
+            }
+            void operator()(GLfloat* vtx, float v) {
+                const GLfloat w = hw_w - (hw_w * v);
+                const GLfloat h = 1.0f;
+                const GLfloat x = (hw_w - w) * 0.5f;
+                const GLfloat y = (hw_h - h) * 0.5f;
+                vtx[0] = x;         vtx[1] = y;
+                vtx[2] = x;         vtx[3] = y + h;
+                vtx[4] = x + w;     vtx[5] = y + h;
+                vtx[6] = x + w;     vtx[7] = y;
+            }
+        };
+
+        // the full animation is 24 frames
+        const int nbFrames = 12;
+
+        v_stretch vverts(hw_w, hw_h);
+        s_curve_interpolator itr(nbFrames, 7.5f);
+        s_curve_interpolator itg(nbFrames, 8.0f);
+        s_curve_interpolator itb(nbFrames, 8.5f);
+        glEnable(GL_BLEND);
+        glBlendFunc(GL_ONE, GL_ONE);
+        for (int i=0 ; i<nbFrames ; i++) {
+            float x, y, w, h;
+            const float vr = itr(i);
+            const float vg = itg(i);
+            const float vb = itb(i);
+
+            // clear screen
+            glColorMask(1,1,1,1);
+            glClear(GL_COLOR_BUFFER_BIT);
+            glEnable(GL_TEXTURE_2D);
+
+            // draw the red plane
+            vverts(vtx, vr);
+            glColorMask(1,0,0,1);
+            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+            // draw the green plane
+            vverts(vtx, vg);
+            glColorMask(0,1,0,1);
+            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+            // draw the blue plane
+            vverts(vtx, vb);
+            glColorMask(0,0,1,1);
+            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+            // draw the white highlight (we use the last vertices)
+            glDisable(GL_TEXTURE_2D);
+            glColorMask(1,1,1,1);
+            glColor4f(vg, vg, vg, 1);
+            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+            hw.flip(screenBounds);
+        }
+
+        h_stretch hverts(hw_w, hw_h);
+        glDisable(GL_BLEND);
+        glDisable(GL_TEXTURE_2D);
+        glColorMask(1,1,1,1);
+        for (int i=0 ; i<nbFrames ; i++) {
+            const float v = itg(i);
+            hverts(vtx, v);
+            glClear(GL_COLOR_BUFFER_BIT);
+            glColor4f(1-v, 1-v, 1-v, 1);
+            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+            hw.flip(screenBounds);
+        }
+
+        glColorMask(1,1,1,1);
+        glEnable(GL_SCISSOR_TEST);
+        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+        result = NO_ERROR;
+    } else {
+        // release FBO resources
+        glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
+        result = BAD_VALUE;
+    }
+
+    glDeleteFramebuffersOES(1, &name);
+    glDeleteTextures(1, &tname);
+
+    if (result == NO_ERROR) {
+        DisplayHardware& hw(graphicPlane(dpy).editDisplayHardware());
+        hw.setCanDraw(false);
+    }
+
+    return result;
+}
+
+status_t SurfaceFlinger::turnElectronBeamOff(int32_t mode)
+{
+    if (!GLExtensions::getInstance().haveFramebufferObject())
+        return INVALID_OPERATION;
+
+    class MessageTurnElectronBeamOff : public MessageBase {
+        SurfaceFlinger* flinger;
+        status_t result;
+    public:
+        MessageTurnElectronBeamOff(SurfaceFlinger* flinger)
+            : flinger(flinger), result(PERMISSION_DENIED) {
+        }
+        status_t getResult() const {
+            return result;
+        }
+        virtual bool handler() {
+            Mutex::Autolock _l(flinger->mStateLock);
+            result = flinger->turnElectronBeamOffImplLocked();
+            return true;
+        }
+    };
+
+    sp<MessageBase> msg = new MessageTurnElectronBeamOff(this);
+    status_t res = postMessageSync(msg);
+    if (res == NO_ERROR) {
+        res = static_cast<MessageTurnElectronBeamOff*>( msg.get() )->getResult();
+    }
+    return res;
+}
+
 // ---------------------------------------------------------------------------
 
 status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
@@ -2005,6 +2231,10 @@
     return *mHw;
 }
 
+DisplayHardware& GraphicPlane::editDisplayHardware() {
+    return *mHw;
+}
+
 const Transform& GraphicPlane::transform() const {
     return mGlobalTransform;
 }
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index f0a167b..f85a22b 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -141,6 +141,7 @@
         int                     getHeight() const;
 
         const DisplayHardware&  displayHardware() const;
+        DisplayHardware&        editDisplayHardware();
         const Transform&        transform() const;
         EGLDisplay              getEGLDisplay() const;
         
@@ -200,6 +201,7 @@
                                                       PixelFormat* format,
                                                       uint32_t reqWidth,
                                                       uint32_t reqHeight);
+    virtual status_t                    turnElectronBeamOff(int32_t mode);
 
             void                        screenReleased(DisplayID dpy);
             void                        screenAcquired(DisplayID dpy);
@@ -325,6 +327,8 @@
                     uint32_t* width, uint32_t* height, PixelFormat* format,
                     uint32_t reqWidth = 0, uint32_t reqHeight = 0);
 
+            status_t turnElectronBeamOffImplLocked();
+
             friend class FreezeLock;
             sp<FreezeLock> getFreezeLock() const;
             inline void incFreezeCount() {
diff --git a/telephony/java/com/android/internal/telephony/CallManager.java b/telephony/java/com/android/internal/telephony/CallManager.java
index b09df82..3f0ec0a 100644
--- a/telephony/java/com/android/internal/telephony/CallManager.java
+++ b/telephony/java/com/android/internal/telephony/CallManager.java
@@ -56,7 +56,7 @@
 
     private static final String LOG_TAG ="CallManager";
     private static final boolean DBG = true;
-    private static final boolean VDBG = true;
+    private static final boolean VDBG = false;
 
     private static final int EVENT_DISCONNECT = 100;
     private static final int EVENT_PRECISE_CALL_STATE_CHANGED = 101;
@@ -292,7 +292,7 @@
 
         if (basePhone != null && !mPhones.contains(basePhone)) {
 
-            if (VDBG) {
+            if (DBG) {
                 Log.d(LOG_TAG, "registerPhone(" +
                         phone.getPhoneName() + " " + phone + ")");
             }
@@ -319,7 +319,7 @@
 
         if (basePhone != null && mPhones.contains(basePhone)) {
 
-            if (VDBG) {
+            if (DBG) {
                 Log.d(LOG_TAG, "unregisterPhone(" +
                         phone.getPhoneName() + " " + phone + ")");
             }
@@ -487,7 +487,7 @@
             boolean hasBgCall = ! (activePhone.getBackgroundCall().isIdle());
             boolean sameChannel = (activePhone == ringingPhone);
 
-            if (DBG) {
+            if (VDBG) {
                 Log.d(LOG_TAG, "hasBgCall: "+ hasBgCall + "sameChannel:" + sameChannel);
             }
 
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java
index 360d35e..1e9b930 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfo.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfo.java
@@ -383,8 +383,8 @@
      */
     public String toString() {
         return new StringBuilder(384)
-                .append("\nname: " + name)
-                .append("\nphoneNumber: " + phoneNumber)
+                .append("\nname: " + /*name*/ "nnnnnn")
+                .append("\nphoneNumber: " + /*phoneNumber*/ "xxxxxxx")
                 .append("\ncnapName: " + cnapName)
                 .append("\nnumberPresentation: " + numberPresentation)
                 .append("\nnamePresentation: " + namePresentation)
@@ -395,8 +395,8 @@
                 .append("\nphotoResource: " + photoResource)
                 .append("\nperson_id: " + person_id)
                 .append("\nneedUpdate: " + needUpdate)
-                .append("\ncontactRefUri: " + contactRefUri)
-                .append("\ncontactRingtoneUri: " + contactRefUri)
+                .append("\ncontactRefUri: " + /*contactRefUri*/ "xxxxxxx")
+                .append("\ncontactRingtoneUri: " + /*contactRefUri*/ "xxxxxxx")
                 .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail)
                 .append("\ncachedPhoto: " + cachedPhoto)
                 .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent)
diff --git a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
index 25ca559..3419567 100644
--- a/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
+++ b/telephony/java/com/android/internal/telephony/CallerInfoAsyncQuery.java
@@ -135,7 +135,7 @@
                 } else {
 
                     if (DBG) log("Processing event: " + cw.event + " token (arg1): " + msg.arg1 +
-                            " command: " + msg.what + " query URI: " + args.uri);
+                        " command: " + msg.what + " query URI: " + sanitizeUriToString(args.uri));
 
                     switch (cw.event) {
                         case EVENT_NEW_QUERY:
@@ -297,7 +297,7 @@
             OnQueryCompleteListener listener, Object cookie) {
         if (DBG) {
             log("##### CallerInfoAsyncQuery startQuery()... #####");
-            log("- number: " + number);
+            log("- number: " + /*number*/ "xxxxxxx");
             log("- cookie: " + cookie);
         }
 
@@ -309,7 +309,7 @@
 
         if (PhoneNumberUtils.isUriNumber(number)) {
             // "number" is really a SIP address.
-            if (DBG) log("  - Treating number as a SIP address: " + number);
+            if (DBG) log("  - Treating number as a SIP address: " + /*number*/ "xxxxxxx");
 
             // We look up SIP addresses directly in the Data table:
             contactRef = Data.CONTENT_URI;
@@ -341,7 +341,7 @@
         }
 
         if (DBG) {
-            log("==> contactRef: " + contactRef);
+            log("==> contactRef: " + sanitizeUriToString(contactRef));
             log("==> selection: " + selection);
             if (selectionArgs != null) {
                 for (int i = 0; i < selectionArgs.length; i++) {
@@ -383,8 +383,8 @@
      */
     public void addQueryListener(int token, OnQueryCompleteListener listener, Object cookie) {
 
-        if (DBG) log("adding listener to query: " + mHandler.mQueryUri + " handler: " +
-                mHandler.toString());
+        if (DBG) log("adding listener to query: " + sanitizeUriToString(mHandler.mQueryUri) +
+                " handler: " + mHandler.toString());
 
         //create cookieWrapper, add query request to end of queue.
         CookieWrapper cw = new CookieWrapper();
@@ -418,6 +418,20 @@
         mHandler = null;
     }
 
+    private static String sanitizeUriToString(Uri uri) {
+        if (uri != null) {
+            String uriString = uri.toString();
+            int indexOfLastSlash = uriString.lastIndexOf('/');
+            if (indexOfLastSlash > 0) {
+                return uriString.substring(0, indexOfLastSlash) + "/xxxxxxx";
+            } else {
+                return uriString;
+            }
+        } else {
+            return "";
+        }
+    }
+
     /**
      * static logging method
      */
diff --git a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
index d711a80..b14896a 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
@@ -238,7 +238,7 @@
         msisdn = number;
         msisdnTag = alphaTag;
 
-        if(DBG) log("Set MSISDN: " + msisdnTag +" " + msisdn);
+        if(DBG) log("Set MSISDN: " + msisdnTag + " " + /*msisdn*/ "xxxxxxx");
 
 
         AdnRecord adn = new AdnRecord(msisdnTag, msisdn);
@@ -496,7 +496,7 @@
                     imsi = null;
                 }
 
-                Log.d(LOG_TAG, "IMSI: " + imsi.substring(0, 6) + "xxxxxxxxx");
+                Log.d(LOG_TAG, "IMSI: " + imsi.substring(0, 6) + "xxxxxxx");
 
                 if (mncLength == UNKNOWN) {
                     // the SIM has told us all it knows, but it didn't know the mnc length.
@@ -619,7 +619,7 @@
                 msisdn = adn.getNumber();
                 msisdnTag = adn.getAlphaTag();
 
-                Log.d(LOG_TAG, "MSISDN: " + msisdn);
+                Log.d(LOG_TAG, "MSISDN: " + /*msisdn*/ "xxxxxxx");
             break;
 
             case EVENT_SET_MSISDN_DONE:
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 281077c..06f6696 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -1285,15 +1285,13 @@
                         if (macaddr != null) {
                             mWifiInfo.setMacAddress(macaddr);
                         }
-                        if (mRunState == RUN_STATE_STARTING) {
-                            mRunState = RUN_STATE_RUNNING;
-                            if (!mIsScanOnly) {
-                                reconnectCommand();
-                            } else {
-                                // In some situations, supplicant needs to be kickstarted to
-                                // start the background scanning
-                                scan(true);
-                            }
+                        mRunState = RUN_STATE_RUNNING;
+                        if (!mIsScanOnly) {
+                            reconnectCommand();
+                        } else {
+                            // In some situations, supplicant needs to be kickstarted to
+                            // start the background scanning
+                            scan(true);
                         }
                     }
                     break;
@@ -1613,12 +1611,10 @@
     }
 
     public synchronized boolean restart() {
-        if (mRunState == RUN_STATE_STOPPED) {
+        if (isDriverStopped()) {
             mRunState = RUN_STATE_STARTING;
             resetConnections(true);
             return startDriver();
-        } else if (mRunState == RUN_STATE_STOPPING) {
-            mRunState = RUN_STATE_STARTING;
         }
         return true;
     }