Merge "GLSurfaceView: Log egl failures"
diff --git a/api/current.xml b/api/current.xml
index 4af2a43..868f6fc 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -193673,6 +193673,17 @@
  visibility="public"
 >
 </method>
+<method name="getPluginState"
+ return="android.webkit.WebSettings.PluginState"
+ abstract="false"
+ native="false"
+ synchronized="true"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="getPluginsEnabled"
  return="boolean"
  abstract="false"
@@ -193680,7 +193691,7 @@
  synchronized="true"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </method>
@@ -194206,7 +194217,7 @@
 <parameter name="flag" type="boolean">
 </parameter>
 </method>
-<method name="setPluginsEnabled"
+<method name="setPluginState"
  return="void"
  abstract="false"
  native="false"
@@ -194216,6 +194227,19 @@
  deprecated="not deprecated"
  visibility="public"
 >
+<parameter name="state" type="android.webkit.WebSettings.PluginState">
+</parameter>
+</method>
+<method name="setPluginsEnabled"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="true"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
 <parameter name="flag" type="boolean">
 </parameter>
 </method>
@@ -194525,6 +194549,39 @@
 >
 </method>
 </class>
+<class name="WebSettings.PluginState"
+ extends="java.lang.Enum"
+ abstract="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="valueOf"
+ return="android.webkit.WebSettings.PluginState"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="name" type="java.lang.String">
+</parameter>
+</method>
+<method name="values"
+ return="android.webkit.WebSettings.PluginState[]"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+</class>
 <class name="WebSettings.RenderPriority"
  extends="java.lang.Enum"
  abstract="false"
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index fa6abec..a556a32 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -278,6 +278,10 @@
 
         int mClientCount = 0;
 
+        Application getApplication() {
+            return mApplication;
+        }
+
         public PackageInfo(ActivityThread activityThread, ApplicationInfo aInfo,
                 ActivityThread mainThread, ClassLoader baseLoader,
                 boolean securityViolation, boolean includeCode) {
@@ -648,7 +652,7 @@
             }
             mActivityThread.mAllApplications.add(app);
             mApplication = app;
-            
+
             if (instrumentation != null) {
                 try {
                     instrumentation.callApplicationOnCreate(app);
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index f296f43..4c2b36f 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -260,7 +260,8 @@
     
     @Override
     public Context getApplicationContext() {
-        return mMainThread.getApplication();
+        return (mPackageInfo != null) ?
+                mPackageInfo.getApplication() : mMainThread.getApplication();
     }
     
     @Override
diff --git a/core/java/android/database/sqlite/SQLiteCursor.java b/core/java/android/database/sqlite/SQLiteCursor.java
index 3f0fcb1..6e5b3e1 100644
--- a/core/java/android/database/sqlite/SQLiteCursor.java
+++ b/core/java/android/database/sqlite/SQLiteCursor.java
@@ -579,10 +579,12 @@
         try {
             // if the cursor hasn't been closed yet, close it first
             if (mWindow != null) {
-                close();
+                int len = mQuery.mSql.length();
                 Log.e(TAG, "Finalizing a Cursor that has not been deactivated or closed. " +
                         "database = " + mDatabase.getPath() + ", table = " + mEditTable +
-                        ", query = " + mQuery.mSql, mStackTrace);
+                        ", query = " + mQuery.mSql.substring(0, (len > 100) ? 100 : len),
+                        mStackTrace);
+                close();
                 SQLiteDebug.notifyActiveCursorFinalized();
             } else {
                 if (Config.LOGV) {
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 183fce3..255e317 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -28,6 +28,7 @@
  */
 public class Surface implements Parcelable {
     private static final String LOG_TAG = "Surface";
+    private static final boolean DEBUG_RELEASE = false;
     
     /* flags used in constructor (keep in sync with ISurfaceComposer.h) */
 
@@ -155,6 +156,9 @@
     // non compatibility mode.
     private Matrix mCompatibleMatrix;
 
+    @SuppressWarnings("unused")
+    private Exception mCreationStack;
+
     /**
      * Exception thrown when a surface couldn't be created or resized
      */
@@ -181,6 +185,9 @@
     public Surface(SurfaceSession s,
             int pid, int display, int w, int h, int format, int flags)
         throws OutOfResourcesException {
+        if (DEBUG_RELEASE) {
+            mCreationStack = new Exception();
+        }
         mCanvas = new CompatibleCanvas();
         init(s,pid,null,display,w,h,format,flags);
     }
@@ -192,6 +199,9 @@
     public Surface(SurfaceSession s,
             int pid, String name, int display, int w, int h, int format, int flags)
         throws OutOfResourcesException {
+        if (DEBUG_RELEASE) {
+            mCreationStack = new Exception();
+        }
         mCanvas = new CompatibleCanvas();
         init(s,pid,name,display,w,h,format,flags);
     }
@@ -202,6 +212,9 @@
      * {@hide}
      */
     public Surface() {
+        if (DEBUG_RELEASE) {
+            mCreationStack = new Exception();
+        }
         mCanvas = new CompatibleCanvas();
     }
 
@@ -407,6 +420,15 @@
     /* no user serviceable parts here ... */
     @Override
     protected void finalize() throws Throwable {
+        if (mSurface != 0 || mSurfaceControl != 0) {
+            if (DEBUG_RELEASE) {
+                Log.w(LOG_TAG, "Surface.finalize() has work. You should have called release() (" 
+                        + mSurface + ", " + mSurfaceControl + ")", mCreationStack);
+            } else {
+                Log.w(LOG_TAG, "Surface.finalize() has work. You should have called release() (" 
+                        + mSurface + ", " + mSurfaceControl + ")");
+            }
+        }
         release();
     }
     
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index c44854a..7f7d207 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -422,7 +422,7 @@
                 if (visibleChanged && (!visible || mNewSurfaceNeeded)) {
                     reportSurfaceDestroyed();
                 }
-                
+
                 mNewSurfaceNeeded = false;
                 
                 mSurfaceLock.lock();
@@ -470,6 +470,8 @@
                                 c.surfaceChanged(mSurfaceHolder, mFormat, mWidth, mHeight);
                             }
                         }
+                    } else {
+                        mSurface.release();
                     }
                 } finally {
                     mIsCreating = false;
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 9df8ac3..74943f3 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -1500,8 +1500,10 @@
                         focus.getFocusedRect(mTempRect);
                         if (DEBUG_INPUT_RESIZE) Log.v(TAG, "Focus " + focus
                                 + ": focusRect=" + mTempRect.toShortString());
-                        ((ViewGroup) mView).offsetDescendantRectToMyCoords(
-                                focus, mTempRect);
+                        if (mView instanceof ViewGroup) {
+                            ((ViewGroup) mView).offsetDescendantRectToMyCoords(
+                                    focus, mTempRect);
+                        }
                         if (DEBUG_INPUT_RESIZE) Log.v(TAG,
                                 "Focus in window: focusRect="
                                 + mTempRect.toShortString()
@@ -2491,8 +2493,12 @@
                                 // of previous focused into the coord system of
                                 // newly focused view
                                 focused.getFocusedRect(mTempRect);
-                                ((ViewGroup) mView).offsetDescendantRectToMyCoords(focused, mTempRect);
-                                ((ViewGroup) mView).offsetRectIntoDescendantCoords(v, mTempRect);
+                                if (mView instanceof ViewGroup) {
+                                    ((ViewGroup) mView).offsetDescendantRectToMyCoords(
+                                            focused, mTempRect);
+                                    ((ViewGroup) mView).offsetRectIntoDescendantCoords(
+                                            v, mTempRect);
+                                }
                                 focusPassed = v.requestFocus(direction, mTempRect);
                             }
 
diff --git a/core/java/android/webkit/ViewManager.java b/core/java/android/webkit/ViewManager.java
index fc5c425..23cf6b8 100644
--- a/core/java/android/webkit/ViewManager.java
+++ b/core/java/android/webkit/ViewManager.java
@@ -28,6 +28,7 @@
     private final ArrayList<ChildView> mChildren = new ArrayList<ChildView>();
     private boolean mHidden;
     private boolean mReadyToDraw;
+    private boolean mZoomInProgress = false;
 
     // Threshold at which a surface is prevented from further increasing in size
     private final int MAX_SURFACE_THRESHOLD;
@@ -39,11 +40,6 @@
         int height;
         View mView; // generic view to show
 
-        /* set to true if the view is a surface and it has exceeded the pixel
-           threshold specified in MAX_SURFACE_THRESHOLD.
-         */
-        boolean isFixedSize = false;
-
         ChildView() {
         }
 
@@ -66,19 +62,17 @@
                     // already attached, just set the new LayoutParams,
                     // otherwise attach the view and add it to the list of
                     // children.
-                    AbsoluteLayout.LayoutParams lp = computeLayout(ChildView.this);
+                    requestLayout(ChildView.this);
 
-                    if (mView.getParent() != null) {
-                        mView.setLayoutParams(lp);
-                    } else {
-                        attachViewOnUIThread(lp);
+                    if (mView.getParent() == null) {
+                        attachViewOnUIThread();
                     }
                 }
             });
         }
 
-        private void attachViewOnUIThread(AbsoluteLayout.LayoutParams lp) {
-            mWebView.addView(mView, lp);
+        private void attachViewOnUIThread() {
+            mWebView.addView(mView);
             mChildren.add(this);
             if (!mReadyToDraw) {
                 mView.setVisibility(View.GONE);
@@ -146,35 +140,87 @@
     /**
      * This should only be called from the UI thread.
      */
-    private AbsoluteLayout.LayoutParams computeLayout(ChildView v) {
+    private void requestLayout(ChildView v) {
 
-        // if the surface has exceed a predefined threshold then fix the size
-        // of the surface.
-        if (!v.isFixedSize && (v.width * v.height) > MAX_SURFACE_THRESHOLD
-                && v.mView instanceof SurfaceView) {
-            ((SurfaceView)v.mView).getHolder().setFixedSize(v.width, v.height);
-            v.isFixedSize = true;
-        }
+        int width = ctvD(v.width);
+        int height = ctvD(v.height);
+        int x = ctvX(v.x);
+        int y = ctvY(v.y);
 
         AbsoluteLayout.LayoutParams lp;
         ViewGroup.LayoutParams layoutParams = v.mView.getLayoutParams();
 
         if (layoutParams instanceof AbsoluteLayout.LayoutParams) {
             lp = (AbsoluteLayout.LayoutParams) layoutParams;
-            lp.width = ctvD(v.width);
-            lp.height = ctvD(v.height);
-            lp.x = ctvX(v.x);
-            lp.y = ctvY(v.y);
+            lp.width = width;
+            lp.height = height;
+            lp.x = x;
+            lp.y = y;
         } else {
-            lp = new AbsoluteLayout.LayoutParams(ctvD(v.width), ctvD(v.height),
-                    ctvX(v.x), ctvY(v.y));
+            lp = new AbsoluteLayout.LayoutParams(width, height, x, y);
         }
-        return lp;
+
+        // apply the layout to the view
+        v.mView.setLayoutParams(lp);
+
+        if(v.mView instanceof SurfaceView) {
+
+            final SurfaceView sView = (SurfaceView) v.mView;
+            boolean exceedThreshold = (width * height) > MAX_SURFACE_THRESHOLD;
+
+            /* If the surface has exceeded a predefined threshold or the webview
+             * is currently zoom then fix the size of the surface.
+             *
+             * NOTE: plugins (e.g. Flash) must not explicitly fix the size of
+             * their surface. The logic below will result in unexpected behavior
+             * for the plugin if they attempt to fix the size of the surface.
+             */
+            if (!sView.isFixedSize() && (exceedThreshold || mZoomInProgress)) {
+                sView.getHolder().setFixedSize(width, height);
+            }
+            else if (sView.isFixedSize() && !exceedThreshold && !mZoomInProgress) {
+                /* The changing of visibility is a hack to get around a bug in
+                 * the framework that causes the surface to revert to the size
+                 * it was prior to being fixed before it redraws using the
+                 * values currently in its layout.
+                 *
+                 * The surface is destroyed when it is set to invisible and then
+                 * recreated at the new dimensions when it is made visible. The
+                 * same destroy/create step occurs without the change in
+                 * visibility, but then exhibits the behavior described in the
+                 * previous paragraph.
+                 */
+                if (sView.getVisibility() == View.VISIBLE) {
+                    sView.setVisibility(View.INVISIBLE);
+                    sView.getHolder().setSizeFromLayout();
+                    sView.setVisibility(View.VISIBLE);
+                } else {
+                    sView.getHolder().setSizeFromLayout();
+                }
+            }
+            else if (sView.isFixedSize() && exceedThreshold) {
+                sView.requestLayout();
+            }
+        }
+    }
+
+    void startZoom() {
+        mZoomInProgress = true;
+        for (ChildView v : mChildren) {
+            requestLayout(v);
+        }
+    }
+
+    void endZoom() {
+        mZoomInProgress = false;
+        for (ChildView v : mChildren) {
+            requestLayout(v);
+        }
     }
 
     void scaleAll() {
         for (ChildView v : mChildren) {
-            v.mView.setLayoutParams(computeLayout(v));
+            requestLayout(v);
         }
     }
 
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index d1da5ea..1b801d4 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -120,6 +120,21 @@
         LOW
     }
 
+    /**
+     * The plugin state effects how plugins are treated on a page. ON means
+     * that any object will be loaded even if a plugin does not exist to handle
+     * the content. ON_DEMAND means that if there is a plugin installed that
+     * can handle the content, a placeholder is shown until the user clicks on
+     * the placeholder. Once clicked, the plugin will be enabled on the page.
+     * OFF means that all plugins will be turned off and any fallback content
+     * will be used.
+     */
+    public enum PluginState {
+        ON,
+        ON_DEMAND,
+        OFF
+    }
+
     // WebView associated with this WebSettings.
     private WebView mWebView;
     // BrowserFrame used to access the native frame pointer.
@@ -157,7 +172,7 @@
     private boolean         mBlockNetworkImage = false;
     private boolean         mBlockNetworkLoads;
     private boolean         mJavaScriptEnabled = false;
-    private boolean         mPluginsEnabled = false;
+    private PluginState     mPluginState = PluginState.OFF;
     private boolean         mJavaScriptCanOpenWindowsAutomatically = false;
     private boolean         mUseDoubleTree = false;
     private boolean         mUseWideViewport = false;
@@ -1011,10 +1026,23 @@
     /**
      * Tell the WebView to enable plugins.
      * @param flag True if the WebView should load plugins.
+     * @deprecated This method has been deprecated in favor of
+     *             {@link #setPluginState}
      */
     public synchronized void setPluginsEnabled(boolean flag) {
-        if (mPluginsEnabled != flag) {
-            mPluginsEnabled = flag;
+        setPluginState(PluginState.ON);
+    }
+
+    /**
+     * Tell the WebView to enable, disable, or have plugins on demand. On
+     * demand mode means that if a plugin exists that can handle the embedded
+     * content, a placeholder icon will be shown instead of the plugin. When
+     * the placeholder is clicked, the plugin will be enabled.
+     * @param state One of the PluginState values.
+     */
+    public synchronized void setPluginState(PluginState state) {
+        if (mPluginState != state) {
+            mPluginState = state;
             postSync();
         }
     }
@@ -1176,9 +1204,18 @@
     /**
      * Return true if plugins are enabled.
      * @return True if plugins are enabled.
+     * @deprecated This method has been replaced by {@link #getPluginState}
      */
     public synchronized boolean getPluginsEnabled() {
-        return mPluginsEnabled;
+        return mPluginState == PluginState.ON;
+    }
+
+    /**
+     * Return the current plugin state.
+     * @return A value corresponding to the enum PluginState.
+     */
+    public synchronized PluginState getPluginState() {
+        return mPluginState;
     }
 
     /**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 784f886..714ae70 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -1668,7 +1668,7 @@
         }
         nativeClearCursor(); // start next trackball movement from page edge
         if (bottom) {
-            return pinScrollTo(mScrollX, computeVerticalScrollRange(), true, 0);
+            return pinScrollTo(mScrollX, computeRealVerticalScrollRange(), true, 0);
         }
         // Page down.
         int h = getHeight();
@@ -1907,7 +1907,7 @@
     private int pinLocY(int y) {
         if (mInOverScrollMode) return y;
         return pinLoc(y, getViewHeightWithTitle(),
-                      computeVerticalScrollRange() + getTitleHeight());
+                      computeRealVerticalScrollRange() + getTitleHeight());
     }
 
     /**
@@ -2258,8 +2258,7 @@
         return false;
     }
 
-    @Override
-    protected int computeHorizontalScrollRange() {
+    private int computeRealHorizontalScrollRange() {
         if (mDrawHistory) {
             return mHistoryWidth;
         } else {
@@ -2269,7 +2268,27 @@
     }
 
     @Override
-    protected int computeVerticalScrollRange() {
+    protected int computeHorizontalScrollRange() {
+        int range = computeRealHorizontalScrollRange();
+
+        // Adjust reported range if overscrolled to compress the scroll bars
+        final int scrollX = mScrollX;
+        final int overscrollRight = computeMaxScrollX();
+        if (scrollX < 0) {
+            range -= scrollX;
+        } else if (scrollX > overscrollRight) {
+            range += scrollX - overscrollRight;
+        }
+
+        return range;
+    }
+
+    @Override
+    protected int computeHorizontalScrollOffset() {
+        return Math.max(mScrollX, 0);
+    }
+
+    private int computeRealVerticalScrollRange() {
         if (mDrawHistory) {
             return mHistoryHeight;
         } else {
@@ -2279,6 +2298,22 @@
     }
 
     @Override
+    protected int computeVerticalScrollRange() {
+        int range = computeRealVerticalScrollRange();
+
+        // Adjust reported range if overscrolled to compress the scroll bars
+        final int scrollY = mScrollY;
+        final int overscrollBottom = computeMaxScrollY();
+        if (scrollY < 0) {
+            range -= scrollY;
+        } else if (scrollY > overscrollBottom) {
+            range += scrollY - overscrollBottom;
+        }
+
+        return range;
+    }
+
+    @Override
     protected int computeVerticalScrollOffset() {
         return Math.max(mScrollY - getTitleHeight(), 0);
     }
@@ -3134,14 +3169,14 @@
             canvas.save();
             canvas.translate(mScrollX, mScrollY);
             canvas.clipRect(-mScrollX, top - mScrollY,
-                    computeHorizontalScrollRange() - mScrollX, top
-                            + computeVerticalScrollRange() - mScrollY,
+                    computeRealHorizontalScrollRange() - mScrollX, top
+                            + computeRealVerticalScrollRange() - mScrollY,
                     Region.Op.DIFFERENCE);
             canvas.drawPaint(mOverScrollBackground);
             canvas.restore();
             // next clip the region for the content
-            canvas.clipRect(0, top, computeHorizontalScrollRange(), top
-                    + computeVerticalScrollRange());
+            canvas.clipRect(0, top, computeRealHorizontalScrollRange(), top
+                    + computeRealVerticalScrollRange());
         }
         if (mTitleBar != null) {
             canvas.translate(0, (int) mTitleBar.getHeight());
@@ -4272,7 +4307,7 @@
         public DragTrackerHandler(float x, float y, DragTracker proxy) {
             mProxy = proxy;
 
-            int docBottom = computeVerticalScrollRange() + getTitleHeight();
+            int docBottom = computeRealVerticalScrollRange() + getTitleHeight();
             int viewTop = getScrollY();
             int viewBottom = viewTop + getHeight();
 
@@ -4460,6 +4495,9 @@
             if (inEditingMode() && nativeFocusCandidateIsPassword()) {
                 mWebTextView.setInPassword(false);
             }
+
+            mViewManager.startZoom();
+
             return true;
         }
 
@@ -4493,6 +4531,8 @@
             mConfirmMove = true;
             startTouch(detector.getFocusX(), detector.getFocusY(),
                     mLastTouchTime);
+
+            mViewManager.endZoom();
         }
 
         public boolean onScale(ScaleGestureDetector detector) {
@@ -5359,11 +5399,11 @@
     }
 
     private int computeMaxScrollX() {
-        return Math.max(computeHorizontalScrollRange() - getViewWidth(), 0);
+        return Math.max(computeRealHorizontalScrollRange() - getViewWidth(), 0);
     }
 
     private int computeMaxScrollY() {
-        return Math.max(computeVerticalScrollRange() + getTitleHeight()
+        return Math.max(computeRealVerticalScrollRange() + getTitleHeight()
                 - getViewHeightWithTitle(), 0);
     }
 
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index eb2da71..e15a520 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -92,6 +92,13 @@
 
     private static final int HINT_VIEW_ID = 0x17;
 
+    /**
+     * This value controls the length of time that the user
+     * must leave a pointer down without scrolling to expand
+     * the autocomplete dropdown list to cover the IME.
+     */
+    private static final int EXPAND_LIST_TIMEOUT = 250;
+
     private CharSequence mHintText;
     private int mHintResource;
 
@@ -132,6 +139,7 @@
 
     private ListSelectorHider mHideSelector;
     private Runnable mShowDropDownRunnable;
+    private Runnable mResizePopupRunnable = new ResizePopupRunnable();
 
     private PassThroughClickListener mPassThroughClickListener;
     private PopupDataSetObserver mObserver;
@@ -1297,6 +1305,7 @@
                 public void onNothingSelected(AdapterView<?> parent) {
                 }
             });
+            mDropDownList.setOnScrollListener(new PopupScrollListener());
 
             if (mItemSelectedListener != null) {
                 mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
@@ -1437,17 +1446,41 @@
         }
     }
 
+    private class ResizePopupRunnable implements Runnable {
+        public void run() {
+            mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
+            showDropDown();
+        }
+    }
+
     private class PopupTouchInterceptor implements OnTouchListener {
         public boolean onTouch(View v, MotionEvent event) {
-            if (event.getAction() == MotionEvent.ACTION_DOWN &&
+            final int action = event.getAction();
+            if (action == MotionEvent.ACTION_DOWN &&
                     mPopup != null && mPopup.isShowing()) {
-                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
-                showDropDown();
+                postDelayed(mResizePopupRunnable, EXPAND_LIST_TIMEOUT);
+            } else if (action == MotionEvent.ACTION_UP) {
+                removeCallbacks(mResizePopupRunnable);
             }
             return false;
         }
     }
     
+    private class PopupScrollListener implements ListView.OnScrollListener {
+        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
+                int totalItemCount) {
+
+        }
+
+        public void onScrollStateChanged(AbsListView view, int scrollState) {
+            if (scrollState == SCROLL_STATE_TOUCH_SCROLL &&
+                    !isInputMethodNotNeeded() && mPopup.getContentView() != null) {
+                removeCallbacks(mResizePopupRunnable);
+                mResizePopupRunnable.run();
+            }
+        }
+    }
+
     private class DropDownItemClickListener implements AdapterView.OnItemClickListener {
         public void onItemClick(AdapterView parent, View v, int position, long id) {
             performCompletion(v, position, id);
diff --git a/core/java/android/widget/DateTimeView.java b/core/java/android/widget/DateTimeView.java
index 3dab9f2..6b845b0 100644
--- a/core/java/android/widget/DateTimeView.java
+++ b/core/java/android/widget/DateTimeView.java
@@ -206,7 +206,12 @@
         if (format == null || "".equals(format)) {
             return DateFormat.getDateInstance(DateFormat.SHORT);
         } else {
-            return new SimpleDateFormat(format);
+            try {
+                return new SimpleDateFormat(format);
+            } catch (IllegalArgumentException e) {
+                // If we tried to use a bad format string, fall back to a default.
+                return DateFormat.getDateInstance(DateFormat.SHORT);
+            }
         }
     }
 
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index 239c5f4..f009432 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -573,6 +573,7 @@
         } else {
             super.scrollTo(scrollX, scrollY);
         }
+        awakenScrollBars();
     }
     
     private int getOverscrollMax() {
@@ -1297,7 +1298,6 @@
                 mScrollViewMovedFocus = false;
             }
     
-            awakenScrollBars(mScroller.getDuration());
             invalidate();
         }
     }
diff --git a/core/java/android/widget/SimpleAdapter.java b/core/java/android/widget/SimpleAdapter.java
index 479965a..4b17a92 100644
--- a/core/java/android/widget/SimpleAdapter.java
+++ b/core/java/android/widget/SimpleAdapter.java
@@ -172,6 +172,10 @@
                     if (v instanceof Checkable) {
                         if (data instanceof Boolean) {
                             ((Checkable) v).setChecked((Boolean) data);
+                        } else if (v instanceof TextView) {
+                            // Note: keep the instanceof TextView check at the bottom of these
+                            // ifs since a lot of views are TextViews (e.g. CheckBoxes).
+                            setViewText((TextView) v, text);
                         } else {
                             throw new IllegalStateException(v.getClass().getName() +
                                     " should be bound to a Boolean, not a " +
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 060ca50..ed26cbe 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -35,6 +35,11 @@
 
 namespace android {
 
+enum {
+    // should match Parcelable.java
+    PARCELABLE_WRITE_RETURN_VALUE = 0x0001
+};
+
 // ----------------------------------------------------------------------------
 
 static const char* const OutOfResourcesException =
@@ -612,6 +617,9 @@
 
     const sp<SurfaceControl>& control(getSurfaceControl(env, clazz));
     SurfaceControl::writeSurfaceToParcel(control, parcel);
+    if (flags & PARCELABLE_WRITE_RETURN_VALUE) {
+        setSurfaceControl(env, clazz, 0);
+    }
 }
 
 // ----------------------------------------------------------------------------
diff --git a/core/res/assets/webkit/togglePlugin.png b/core/res/assets/webkit/togglePlugin.png
new file mode 100644
index 0000000..008333c
--- /dev/null
+++ b/core/res/assets/webkit/togglePlugin.png
Binary files differ
diff --git a/core/res/assets/webkit/togglePluginBg.png b/core/res/assets/webkit/togglePluginBg.png
new file mode 100644
index 0000000..2c65acb
--- /dev/null
+++ b/core/res/assets/webkit/togglePluginBg.png
Binary files differ
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/ConnectivityManagerTest/Android.mk
similarity index 94%
rename from tests/ConnectivityManagerTest/Android.mk
rename to core/tests/ConnectivityManagerTest/Android.mk
index bd773d0..a1546fa 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/ConnectivityManagerTest/Android.mk
@@ -1,4 +1,4 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010, The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
diff --git a/tests/ConnectivityManagerTest/AndroidManifest.xml b/core/tests/ConnectivityManagerTest/AndroidManifest.xml
similarity index 100%
rename from tests/ConnectivityManagerTest/AndroidManifest.xml
rename to core/tests/ConnectivityManagerTest/AndroidManifest.xml
diff --git a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
similarity index 94%
rename from tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
rename to core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
index 1dffa02..badcc1b 100644
--- a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.android.connectivitymanagertest;
 
 import android.app.Activity;
diff --git a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
similarity index 62%
rename from tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
rename to core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
index 3affa65..592be92 100644
--- a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.android.connectivitymanagertest;
 
 import android.os.Bundle;
@@ -13,7 +29,7 @@
  *
  * To run the connectivity manager tests:
  *
- * adb shell am instrument \
+ * adb shell am instrument -e ssid <ssid> \
  *     -w com.android.connectivitymanagertest/.ConnectivityManagerTestRunner
  */
 
@@ -39,5 +55,5 @@
         }
     }
 
-    public String TEST_SSID = "GoogleGuest";
+    public String TEST_SSID = null;
 }
diff --git a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
similarity index 91%
rename from tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
rename to core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
index 925120e..2e5a0f8 100644
--- a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/NetworkState.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package com.android.connectivitymanagertest;
 
 import android.net.NetworkInfo.State;
diff --git a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
similarity index 88%
rename from tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
rename to core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
index ab81bb8..ad564ae 100644
--- a/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
 package com.android.connectivitymanagertest.functional;
 
 import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
@@ -86,7 +104,7 @@
             Log.v(LOG_TAG, "the state for WIFI is changed");
             Log.v(LOG_TAG, "reason: " +
                     cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
-            assertTrue(false);
+            assertTrue("state validation fail", false);
         }
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
             Log.v(LOG_TAG, "the state for MOBILE is changed");
@@ -101,6 +119,7 @@
     // Test case 2: test connection to a given AP
     @LargeTest
     public void testConnectToWifi() {
+        assertNotNull("SSID is null", TEST_ACCESS_POINT);
         //Prepare for connectivity verification
         NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE, networkInfo.getState(),
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
index 9c9d777..ca0094e 100644
--- a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
+++ b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
@@ -16,6 +16,7 @@
 
 package android.content.pm;
 
+import com.android.ddmlib.IDevice;
 import com.android.ddmlib.IShellOutputReceiver;
 import com.android.ddmlib.Log;
 import com.android.ddmlib.MultiLineReceiver;
@@ -35,17 +36,56 @@
  */
 public class PackageManagerHostTests extends DeviceTestCase {
 
+    private static final String LOG_TAG = "PackageManagerHostTests";
+
+    // TODO: get this value from Android Environment instead of hardcoding
+    private static final String APP_PRIVATE_PATH = "/data/app-private/";
+    private static final String DEVICE_APP_PATH = "/data/app/";
+    private static final String SDCARD_APP_PATH = "/mnt/secure/asec/";
+
+    private static final int MAX_WAIT_FOR_DEVICE_TIME = 120 * 1000;
+    private static final int WAIT_FOR_DEVICE_POLL_TIME = 10 * 1000;
+
+    // Various test files and their corresponding package names...
+
     // testPushAppPrivate constants
     // these constants must match values defined in test-apps/SimpleTestApp
     private static final String SIMPLE_APK = "SimpleTestApp.apk";
     private static final String SIMPLE_PKG = "com.android.framework.simpletestapp";
-    // TODO: get this value from Android Environment instead of hardcoding
-    private static final String APP_PRIVATE_PATH = "/data/app-private/";
 
-    private static final String LOG_TAG = "PackageManagerHostTests";
-
-    private static final int MAX_WAIT_FOR_DEVICE_TIME = 120 * 1000;
-    private static final int WAIT_FOR_DEVICE_POLL_TIME = 10 * 1000;
+    // Apk with install location set to auto
+    private static final String AUTO_LOC_APK = "AutoLocTestApp.apk";
+    private static final String AUTO_LOC_PKG = "com.android.framework.autoloctestapp";
+    // Apk with install location set to internalOnly
+    private static final String INTERNAL_LOC_APK = "InternalLocTestApp.apk";
+    private static final String INTERNAL_LOC_PKG = "com.android.framework.internalloctestapp";
+    // Apk with install location set to preferExternal
+    private static final String EXTERNAL_LOC_APK = "ExternalLocTestApp.apk";
+    private static final String EXTERNAL_LOC_PKG = "com.android.framework.externalloctestapp";
+    // Apk with no install location set
+    private static final String NO_LOC_APK = "NoLocTestApp.apk";
+    private static final String NO_LOC_PKG = "com.android.framework.noloctestapp";
+    // Apk with 2 different versions - v1 is set to external, v2 has no location setting
+    private static final String UPDATE_EXTERNAL_LOC_V1_EXT_APK
+            = "UpdateExternalLocTestApp_v1_ext.apk";
+    private static final String UPDATE_EXTERNAL_LOC_V2_NONE_APK
+            = "UpdateExternalLocTestApp_v2_none.apk";
+    private static final String UPDATE_EXTERNAL_LOC_PKG
+            = "com.android.framework.updateexternalloctestapp";
+    // Apk with 2 different versions - v1 is set to external, v2 is set to internalOnly
+    private static final String UPDATE_EXT_TO_INT_LOC_V1_EXT_APK
+            = "UpdateExtToIntLocTestApp_v1_ext.apk";
+    private static final String UPDATE_EXT_TO_INT_LOC_V2_INT_APK
+            = "UpdateExtToIntLocTestApp_v2_int.apk";
+    private static final String UPDATE_EXT_TO_INT_LOC_PKG
+            = "com.android.framework.updateexttointloctestapp";
+    // Apks with the same package name, but install location set to
+    // one of: Internal, External, Auto, or None
+    private static final String VERSATILE_LOC_PKG = "com.android.framework.versatiletestapp";
+    private static final String VERSATILE_LOC_INTERNAL_APK = "VersatileTestApp_Internal.apk";
+    private static final String VERSATILE_LOC_EXTERNAL_APK = "VersatileTestApp_External.apk";
+    private static final String VERSATILE_LOC_AUTO_APK = "VersatileTestApp_Auto.apk";
+    private static final String VERSATILE_LOC_NONE_APK = "VersatileTestApp_None.apk";
 
     @Override
     protected void setUp() throws Exception {
@@ -94,6 +134,18 @@
     }
 
     /**
+     * Helper method to install a file to device
+     * @param localFilePath the absolute file system path to file on local host to install
+     * @param reinstall set to <code>true</code> if re-install of app should be performed
+     * @throws IOException
+     */
+    private void installFile(final String localFilePath, final boolean replace)
+            throws IOException {
+        String result = getDevice().installPackage(localFilePath, replace);
+        assertEquals(null, result);
+    }
+
+    /**
      * Helper method to determine if file on device exists.
      *
      * @param destPath the absolute path of file on device to check
@@ -107,6 +159,21 @@
     }
 
     /**
+     * Helper method to determine if file exists on the device containing a given string.
+     *
+     * @param destPath the
+     * @return <code>true</code> if file exists containing given string,
+     *         <code>false</code> otherwise.
+     * @throws IOException if adb shell command failed
+     */
+    private boolean doesRemoteFileExistContainingString(String destPath, String searchString)
+            throws IOException {
+        String lsResult = executeShellCommand(String.format("ls %s",
+                destPath));
+        return lsResult.contains(searchString);
+    }
+
+    /**
      * Helper method to determine if package on device exists.
      *
      * @param packageName the Android manifest package to check.
@@ -120,6 +187,28 @@
     }
 
     /**
+     * Helper method to determine if app was installed on device.
+     *
+     * @param packageName package name to check for
+     * @return <code>true</code> if file exists, <code>false</code> otherwise.
+     * @throws IOException if adb shell command failed
+     */
+    private boolean doesAppExistOnDevice(String packageName) throws IOException {
+        return doesRemoteFileExistContainingString(DEVICE_APP_PATH, packageName);
+    }
+
+    /**
+     * Helper method to determine if app was installed on SD card.
+     *
+     * @param packageName package name to check for
+     * @return <code>true</code> if file exists, <code>false</code> otherwise.
+     * @throws IOException if adb shell command failed
+     */
+    private boolean doesAppExistOnSDCard(String packageName) throws IOException {
+        return doesRemoteFileExistContainingString(SDCARD_APP_PATH, packageName);
+    }
+
+    /**
      * Waits for device's package manager to respond.
      *
      * @throws InterruptedException
@@ -213,4 +302,218 @@
             // ignore
         }
     }
+
+    /**
+     * Helper method for installing an app to wherever is specified in its manifest, and
+     * then verifying the app was installed onto SD Card.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    void installAppAndVerifyExistsOnSDCard(String apkName, String pkgName, boolean overwrite)
+            throws IOException, InterruptedException {
+        // Start with a clean slate if we're not overwriting
+        if (!overwrite) {
+            // cleanup test app just in case it already exists
+            getDevice().uninstallPackage(pkgName);
+            // grep for package to make sure its not installed
+            assertFalse(doesPackageExist(pkgName));
+        }
+
+        installFile(getTestAppFilePath(apkName), overwrite);
+        assertTrue(doesAppExistOnSDCard(pkgName));
+        assertFalse(doesAppExistOnDevice(pkgName));
+        waitForDevice();
+
+        // grep for package to make sure it is installed
+        assertTrue(doesPackageExist(pkgName));
+    }
+
+    /**
+     * Helper method for installing an app to wherever is specified in its manifest, and
+     * then verifying the app was installed onto device.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    void installAppAndVerifyExistsOnDevice(String apkName, String pkgName, boolean overwrite)
+            throws IOException, InterruptedException {
+        // Start with a clean slate if we're not overwriting
+        if (!overwrite) {
+            // cleanup test app just in case it already exists
+            getDevice().uninstallPackage(pkgName);
+            // grep for package to make sure its not installed
+            assertFalse(doesPackageExist(pkgName));
+        }
+
+        installFile(getTestAppFilePath(apkName), overwrite);
+        assertFalse(doesAppExistOnSDCard(pkgName));
+        assertTrue(doesAppExistOnDevice(pkgName));
+        waitForDevice();
+
+        // grep for package to make sure it is installed
+        assertTrue(doesPackageExist(pkgName));
+    }
+
+    /**
+     * Helper method for uninstalling an app.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    void uninstallApp(String pkgName) throws IOException, InterruptedException {
+        getDevice().uninstallPackage(pkgName);
+        // make sure its not installed anymore
+        assertFalse(doesPackageExist(pkgName));
+    }
+
+    /**
+     * Regression test to verify that an app with its manifest set to installLocation=auto
+     * will install the app to the device.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    public void testInstallAppAutoLoc() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test an app with installLocation=auto gets installed on device");
+
+        try {
+            installAppAndVerifyExistsOnDevice(AUTO_LOC_APK, AUTO_LOC_PKG, false);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(AUTO_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that an app with its manifest set to installLocation=internalOnly
+     * will install the app to the device.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    public void testInstallAppInternalLoc() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test an app with installLocation=internalOnly gets installed on device");
+
+        try {
+            installAppAndVerifyExistsOnDevice(INTERNAL_LOC_APK, INTERNAL_LOC_PKG, false);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(INTERNAL_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that an app with its manifest set to installLocation=preferExternal
+     * will install the app to the SD card.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    public void testInstallAppExternalLoc() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test an app with installLocation=preferExternal gets installed on SD Card");
+
+        try {
+            installAppAndVerifyExistsOnSDCard(EXTERNAL_LOC_APK, EXTERNAL_LOC_PKG, false);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(EXTERNAL_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that we can install an app onto the device,
+     * uninstall it, and reinstall it onto the SD card.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    // TODO: This currently relies on the app's manifest to switch from device to
+    // SD card install locations. We might want to make Device's installPackage()
+    // accept a installLocation flag so we can install a package to the
+    // destination of our choosing.
+    public void testReinstallInternalToExternal() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test installing an app first to the device, then to the SD Card");
+
+        try {
+            installAppAndVerifyExistsOnDevice(VERSATILE_LOC_INTERNAL_APK, VERSATILE_LOC_PKG, false);
+            uninstallApp(VERSATILE_LOC_PKG);
+            installAppAndVerifyExistsOnSDCard(VERSATILE_LOC_EXTERNAL_APK, VERSATILE_LOC_PKG, false);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(VERSATILE_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that we can install an app onto the SD Card,
+     * uninstall it, and reinstall it onto the device.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    // TODO: This currently relies on the app's manifest to switch from device to
+    // SD card install locations. We might want to make Device's installPackage()
+    // accept a installLocation flag so we can install a package to the
+    // destination of our choosing.
+    public void testReinstallExternalToInternal() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test installing an app first to the SD Care, then to the device");
+
+        try {
+            // install the app externally
+            installAppAndVerifyExistsOnSDCard(VERSATILE_LOC_EXTERNAL_APK, VERSATILE_LOC_PKG, false);
+            uninstallApp(VERSATILE_LOC_PKG);
+            // then replace the app with one marked for internalOnly
+            installAppAndVerifyExistsOnDevice(VERSATILE_LOC_INTERNAL_APK, VERSATILE_LOC_PKG, true);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(VERSATILE_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that updating an app on the SD card will install
+     * the update onto the SD card as well when location is not explicitly set in the
+     * updated apps' manifest file.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    public void testUpdateToSDCard() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
+
+        try {
+            // install the app externally
+            installAppAndVerifyExistsOnSDCard(UPDATE_EXTERNAL_LOC_V1_EXT_APK,
+                    UPDATE_EXTERNAL_LOC_PKG, false);
+            // now replace the app with one where the location is blank (app should stay external)
+            installAppAndVerifyExistsOnSDCard(UPDATE_EXTERNAL_LOC_V2_NONE_APK,
+                    UPDATE_EXTERNAL_LOC_PKG, true);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(UPDATE_EXTERNAL_LOC_PKG);
+        }
+    }
+
+    /**
+     * Regression test to verify that updating an app on the SD card will install
+     * the update onto the SD card as well when location is not explicitly set in the
+     * updated apps' manifest file.
+     * <p/>
+     * Assumes adb is running as root in device under test.
+     */
+    public void testUpdateSDCardToDevice() throws IOException, InterruptedException {
+        Log.i(LOG_TAG, "Test updating an app on the SD card to the Device through manifest change");
+
+        try {
+            // install the app externally
+            installAppAndVerifyExistsOnSDCard(UPDATE_EXT_TO_INT_LOC_V1_EXT_APK,
+                    UPDATE_EXT_TO_INT_LOC_PKG, false);
+            // now replace the app with an update marked for internalOnly...
+            installAppAndVerifyExistsOnDevice(UPDATE_EXT_TO_INT_LOC_V2_INT_APK,
+                    UPDATE_EXT_TO_INT_LOC_PKG, true);
+        }
+        // cleanup test app
+        finally {
+            uninstallApp(UPDATE_EXT_TO_INT_LOC_PKG);
+        }
+    }
+
 }
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/AutoLocTestApp/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/AutoLocTestApp/Android.mk
index bd773d0..b3cab48 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/AutoLocTestApp/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := AutoLocTestApp
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/AutoLocTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/AutoLocTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..d8c806a
--- /dev/null
+++ b/core/tests/hosttests/test-apps/AutoLocTestApp/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.autoloctestapp"
+       android:installLocation="auto">
+
+    <application android:label="AutoLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/AutoLocTestApp/src/com/android/framework/autoloctestapp/AutoLocTestAppActivity.java b/core/tests/hosttests/test-apps/AutoLocTestApp/src/com/android/framework/autoloctestapp/AutoLocTestAppActivity.java
new file mode 100644
index 0000000..fba5691
--- /dev/null
+++ b/core/tests/hosttests/test-apps/AutoLocTestApp/src/com/android/framework/autoloctestapp/AutoLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.autoloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class AutoLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/Android.mk
index bd773d0..9a05fa6 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := ExternalLocPermFLTestApp
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..f45c627
--- /dev/null
+++ b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.externallocpermsfltestapp"
+       android:installLocation="preferExternal">
+
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+
+    <application android:label="ExternalLocPermsFLTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/src/com/android/framework/externallocpermsfltestapp/ExternalLocPermsFLTestAppActivity.java b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/src/com/android/framework/externallocpermsfltestapp/ExternalLocPermsFLTestAppActivity.java
new file mode 100644
index 0000000..48fd744
--- /dev/null
+++ b/core/tests/hosttests/test-apps/ExternalLocPermsFLTestApp/src/com/android/framework/externallocpermsfltestapp/ExternalLocPermsFLTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.externallocpermsfltestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class ExternalLocPermsFLTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/ExternalLocTestApp/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/ExternalLocTestApp/Android.mk
index bd773d0..5aec78a 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/ExternalLocTestApp/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := ExternalLocTestApp
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/ExternalLocTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/ExternalLocTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..a0c7b02
--- /dev/null
+++ b/core/tests/hosttests/test-apps/ExternalLocTestApp/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.externalloctestapp"
+       android:installLocation="preferExternal">
+
+    <application android:label="ExternalLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/ExternalLocTestApp/src/com/android/framework/externalloctestapp/ExternalLocTestAppActivity.java b/core/tests/hosttests/test-apps/ExternalLocTestApp/src/com/android/framework/externalloctestapp/ExternalLocTestAppActivity.java
new file mode 100644
index 0000000..0a61628
--- /dev/null
+++ b/core/tests/hosttests/test-apps/ExternalLocTestApp/src/com/android/framework/externalloctestapp/ExternalLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.externalloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class ExternalLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/InternalLocTestApp/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/InternalLocTestApp/Android.mk
index bd773d0..5b58e72 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/InternalLocTestApp/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := InternalLocTestApp
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/InternalLocTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/InternalLocTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..fae3ae0
--- /dev/null
+++ b/core/tests/hosttests/test-apps/InternalLocTestApp/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.internalloctestapp"
+       android:installLocation="internalOnly">
+
+    <application android:label="InternalLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/InternalLocTestApp/src/com/android/framework/internalloctestapp/InternalLocTestAppActivity.java b/core/tests/hosttests/test-apps/InternalLocTestApp/src/com/android/framework/internalloctestapp/InternalLocTestAppActivity.java
new file mode 100644
index 0000000..6934641
--- /dev/null
+++ b/core/tests/hosttests/test-apps/InternalLocTestApp/src/com/android/framework/internalloctestapp/InternalLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.internalloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class InternalLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/NoLocTestApp/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/NoLocTestApp/Android.mk
index bd773d0..11916b0 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/NoLocTestApp/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := NoLocTestApp
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/NoLocTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/NoLocTestApp/AndroidManifest.xml
new file mode 100644
index 0000000..bfdad37
--- /dev/null
+++ b/core/tests/hosttests/test-apps/NoLocTestApp/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.noloctestapp">
+
+    <application android:label="NoLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/NoLocTestApp/src/com/android/framework/noloctestapp/NoLocTestAppActivity.java b/core/tests/hosttests/test-apps/NoLocTestApp/src/com/android/framework/noloctestapp/NoLocTestAppActivity.java
new file mode 100644
index 0000000..72c8d2b
--- /dev/null
+++ b/core/tests/hosttests/test-apps/NoLocTestApp/src/com/android/framework/noloctestapp/NoLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.noloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class NoLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/Android.mk
index bd773d0..f2baefe 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := UpdateExtToIntLocTestApp_v1_ext
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/AndroidManifest.xml b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/AndroidManifest.xml
new file mode 100644
index 0000000..b572e86
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.updateexttointloctestapp"
+       android:installLocation="preferExternal"
+       android:versionCode="1"
+       android:versionName="1.0">
+
+    <application android:label="UpdateExtToIntLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java
new file mode 100644
index 0000000..5c51fb7
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v1_ext/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.updateexttointloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class UpdateExtToIntLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/Android.mk
index bd773d0..492c326 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := UpdateExtToIntLocTestApp_v2_int
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/AndroidManifest.xml b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/AndroidManifest.xml
new file mode 100644
index 0000000..c9437ae
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.updateexttointloctestapp"
+       android:installLocation="internalOnly"
+       android:versionCode="2"
+       android:versionName="2.0">
+
+    <application android:label="UpdateExtToIntLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java
new file mode 100644
index 0000000..5c51fb7
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExtToIntLocTestApp_v2_int/src/com/android/framework/updateexttointloctestapp/UpdateExtToIntLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.updateexttointloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class UpdateExtToIntLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/Android.mk
index bd773d0..45867f7 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := UpdateExternalLocTestApp_v1_ext
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/AndroidManifest.xml b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/AndroidManifest.xml
new file mode 100644
index 0000000..ec622ce
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/AndroidManifest.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.updateexternalloctestapp"
+       android:installLocation="preferExternal"
+       android:versionCode="1"
+       android:versionName="1.0">
+
+    <application android:label="UpdateExternalLocTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java
new file mode 100644
index 0000000..02ecb75
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v1_ext/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.updateexternalloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class UpdateExternalLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/Android.mk
index bd773d0..780a9d7 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := UpdateExternalLocTestApp_v2_none
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/AndroidManifest.xml b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/AndroidManifest.xml
new file mode 100644
index 0000000..50fb104
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.updateexternalloctestapp"
+       android:versionCode="2"
+       android:versionName="2.0">
+
+    <application android:label="UpdateExternalLocTestApp"/>
+</manifest>
diff --git a/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java
new file mode 100644
index 0000000..02ecb75
--- /dev/null
+++ b/core/tests/hosttests/test-apps/UpdateExternalLocTestApp_v2_none/src/com/android/framework/updateexternalloctestapp/UpdateExternalLocTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.updateexternalloctestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class UpdateExternalLocTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/VersatileTestApp_Auto/Android.mk
index bd773d0..fc42bc4a 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := VersatileTestApp_Auto
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_Auto/AndroidManifest.xml b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/AndroidManifest.xml
new file mode 100644
index 0000000..f249250
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.versatiletestapp"
+       android:installLocation="auto">
+
+    <application android:label="VersatileTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_Auto/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
new file mode 100644
index 0000000..c201c7a
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Auto/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.versatiletestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class VersatileTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/VersatileTestApp_External/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/VersatileTestApp_External/Android.mk
index bd773d0..c72a92c 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_External/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := VersatileTestApp_External
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_External/AndroidManifest.xml b/core/tests/hosttests/test-apps/VersatileTestApp_External/AndroidManifest.xml
new file mode 100644
index 0000000..0d17ac2
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_External/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.versatiletestapp"
+       android:installLocation="preferExternal">
+
+    <application android:label="VersatileTestApp"/>
+
+</manifest>
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_External/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java b/core/tests/hosttests/test-apps/VersatileTestApp_External/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
new file mode 100644
index 0000000..c201c7a
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_External/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.versatiletestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class VersatileTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/VersatileTestApp_Internal/Android.mk
index bd773d0..e477825 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := VersatileTestApp_Internal
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_Internal/AndroidManifest.xml b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/AndroidManifest.xml
new file mode 100644
index 0000000..e8cae6e
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/AndroidManifest.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.versatiletestapp"
+       android:installLocation="internalOnly">
+
+    <application android:label="VersatileTestApp"/>
+</manifest>
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_Internal/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
new file mode 100644
index 0000000..c201c7a
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_Internal/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.versatiletestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class VersatileTestAppActivity extends Activity {
+
+}
diff --git a/tests/ConnectivityManagerTest/Android.mk b/core/tests/hosttests/test-apps/VersatileTestApp_None/Android.mk
similarity index 67%
copy from tests/ConnectivityManagerTest/Android.mk
copy to core/tests/hosttests/test-apps/VersatileTestApp_None/Android.mk
index bd773d0..1fc516c 100644
--- a/tests/ConnectivityManagerTest/Android.mk
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_None/Android.mk
@@ -1,10 +1,10 @@
-# Copyright 2010, The Android Open Source Project
+# Copyright (C) 2010 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#      http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,18 +13,15 @@
 # limitations under the License.
 
 LOCAL_PATH:= $(call my-dir)
+
 include $(CLEAR_VARS)
 
-# We only want this apk build for tests.
 LOCAL_MODULE_TAGS := tests
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-# Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_PACKAGE_NAME := ConnectivityManagerTest
+LOCAL_SDK_VERSION := current
 
-#LOCAL_INSTRUMENTATION_FOR := connectivitymanagertest
+LOCAL_PACKAGE_NAME := VersatileTestApp_None
 
 include $(BUILD_PACKAGE)
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_None/AndroidManifest.xml b/core/tests/hosttests/test-apps/VersatileTestApp_None/AndroidManifest.xml
new file mode 100644
index 0000000..1df40d4
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_None/AndroidManifest.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+       package="com.android.framework.versatiletestapp">
+
+    <application android:label="VersatileTestApp"/>
+</manifest>
diff --git a/core/tests/hosttests/test-apps/VersatileTestApp_None/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java b/core/tests/hosttests/test-apps/VersatileTestApp_None/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
new file mode 100644
index 0000000..c201c7a
--- /dev/null
+++ b/core/tests/hosttests/test-apps/VersatileTestApp_None/src/com/android/framework/versatiletestapp/VersatileTestAppActivity.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.framework.versatiletestapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Empty activity, not needed for this test
+ */
+public class VersatileTestAppActivity extends Activity {
+
+}
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 164df72..407fd57 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -1153,6 +1153,8 @@
             Mutex::Autolock autoLock(mLock);
             if (mFlags & PREPARE_CANCELLED) {
                 LOGI("prepare was cancelled before preparing the prefetcher");
+
+                prefetcher.clear();
                 abortPrepare(UNKNOWN_ERROR);
                 return;
             }
diff --git a/tests/AndroidTests/apks/install_decl_perm/res/values/strings.xml b/tests/AndroidTests/apks/install_decl_perm/res/values/strings.xml
index 5564300..3b8b3b1 100644
--- a/tests/AndroidTests/apks/install_decl_perm/res/values/strings.xml
+++ b/tests/AndroidTests/apks/install_decl_perm/res/values/strings.xml
@@ -2,4 +2,5 @@
 
 <!-- Just need this dummy file to have something to build. -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+  <string name="dummy">dummy</string>
 </resources>
diff --git a/tests/AndroidTests/apks/install_use_perm_good/res/values/strings.xml b/tests/AndroidTests/apks/install_use_perm_good/res/values/strings.xml
index 5564300..3b8b3b1 100644
--- a/tests/AndroidTests/apks/install_use_perm_good/res/values/strings.xml
+++ b/tests/AndroidTests/apks/install_use_perm_good/res/values/strings.xml
@@ -2,4 +2,5 @@
 
 <!-- Just need this dummy file to have something to build. -->
 <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+  <string name="dummy">dummy</string>
 </resources>