Merge "Replaced /sdcard with Environment.getExternalStorageDirectory()"
diff --git a/cmds/surfaceflinger/Android.mk b/cmds/surfaceflinger/Android.mk
index bfa58a1..1df32bb 100644
--- a/cmds/surfaceflinger/Android.mk
+++ b/cmds/surfaceflinger/Android.mk
@@ -10,7 +10,7 @@
 	libutils
 
 LOCAL_C_INCLUDES := \
-	$(LOCAL_PATH)/../../libs/surfaceflinger
+	$(LOCAL_PATH)/../../services/surfaceflinger
 
 LOCAL_MODULE:= surfaceflinger
 
diff --git a/cmds/system_server/library/Android.mk b/cmds/system_server/library/Android.mk
index 1813d3e..a880a91 100644
--- a/cmds/system_server/library/Android.mk
+++ b/cmds/system_server/library/Android.mk
@@ -7,9 +7,9 @@
 base = $(LOCAL_PATH)/../../..
 
 LOCAL_C_INCLUDES := \
-	$(base)/camera/libcameraservice \
-	$(base)/libs/audioflinger \
-	$(base)/libs/surfaceflinger \
+	$(base)/services/camera/libcameraservice \
+	$(base)/services/audioflinger \
+	$(base)/services/surfaceflinger \
 	$(base)/media/libmediaplayerservice \
 	$(JNI_H_INCLUDE)
 
diff --git a/core/java/android/app/ApplicationErrorReport.java b/core/java/android/app/ApplicationErrorReport.java
index f0cef98..ec39ac7 100644
--- a/core/java/android/app/ApplicationErrorReport.java
+++ b/core/java/android/app/ApplicationErrorReport.java
@@ -174,7 +174,7 @@
     /**
      * Return activity in receiverPackage that handles ACTION_APP_ERROR.
      *
-     * @param pm PackageManager isntance
+     * @param pm PackageManager instance
      * @param errorPackage package which caused the error
      * @param receiverPackage candidate package to receive the error
      * @return activity component within receiverPackage which handles
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 3387fc9..e671359 100755
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -1305,8 +1305,8 @@
                     keyboardHidden, mConfiguration.navigation, width, height,
                     mConfiguration.screenLayout, mConfiguration.uiMode, sSdkVersion);
 
-            drawableCacheClear(mDrawableCache, configChanges);
-            drawableCacheClear(mColorDrawableCache, configChanges);
+            clearDrawableCache(mDrawableCache, configChanges);
+            clearDrawableCache(mColorDrawableCache, configChanges);
 
             mColorStateListCache.clear();
 
@@ -1320,7 +1320,7 @@
         }
     }
 
-    private void drawableCacheClear(
+    private void clearDrawableCache(
             LongSparseArray<WeakReference<ConstantState>> cache,
             int configChanges) {
         int N = cache.size();
@@ -1781,7 +1781,7 @@
                     //Log.i(TAG, "Returning cached drawable @ #" +
                     //        Integer.toHexString(((Integer)key).intValue())
                     //        + " in " + this + ": " + entry);
-                    return entry.newDrawable();
+                    return entry.newDrawable(this);
                 }
                 else {  // our entry has been purged
                     drawableCache.delete(key);
diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java
index 39d4ac1..22c30a5 100644
--- a/core/java/android/net/Proxy.java
+++ b/core/java/android/net/Proxy.java
@@ -16,8 +16,6 @@
 
 package android.net;
 
-import org.apache.harmony.luni.platform.INetworkSystem;
-import org.apache.harmony.luni.platform.Platform;
 import org.apache.http.HttpHost;
 
 import android.content.ContentResolver;
@@ -44,8 +42,6 @@
     static final public String PROXY_CHANGE_ACTION =
         "android.intent.action.PROXY_CHANGE";
 
-    static final private INetworkSystem NETIMPL = Platform.getNetworkSystem();
-
     /**
      * Return the proxy host set by the user.
      * @param ctx A Context used to get the settings for the proxy host.
@@ -169,8 +165,7 @@
                 if (host.equalsIgnoreCase("localhost")) {
                     return true;
                 }
-                if (InetAddress.getByAddress(NETIMPL.ipStringToByteArray(host))
-                        .isLoopbackAddress()) {
+                if (InetAddress.getByName(host).isLoopbackAddress()) {
                     return true;
                 }
             }
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 2e14667..86f9a6b 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -94,7 +94,8 @@
     /**
      * Default trace file path and file
      */
-    private static final String DEFAULT_TRACE_PATH_PREFIX = "/sdcard/";
+    private static final String DEFAULT_TRACE_PATH_PREFIX =
+        Environment.getExternalStorageDirectory().getPath() + "/";
     private static final String DEFAULT_TRACE_BODY = "dmtrace";
     private static final String DEFAULT_TRACE_EXTENSION = ".trace";
     private static final String DEFAULT_TRACE_FILE_PATH =
@@ -127,7 +128,7 @@
         public int otherPrivateDirty;
         /** The shared dirty pages used by everything else. */
         public int otherSharedDirty;
-        
+
         public MemoryInfo() {
         }
 
@@ -137,21 +138,21 @@
         public int getTotalPss() {
             return dalvikPss + nativePss + otherPss;
         }
-        
+
         /**
          * Return total private dirty memory usage in kB.
          */
         public int getTotalPrivateDirty() {
             return dalvikPrivateDirty + nativePrivateDirty + otherPrivateDirty;
         }
-        
+
         /**
          * Return total shared dirty memory usage in kB.
          */
         public int getTotalSharedDirty() {
             return dalvikSharedDirty + nativeSharedDirty + otherSharedDirty;
         }
-        
+
         public int describeContents() {
             return 0;
         }
@@ -179,7 +180,7 @@
             otherPrivateDirty = source.readInt();
             otherSharedDirty = source.readInt();
         }
-        
+
         public static final Creator<MemoryInfo> CREATOR = new Creator<MemoryInfo>() {
             public MemoryInfo createFromParcel(Parcel source) {
                 return new MemoryInfo(source);
@@ -460,7 +461,7 @@
      * Like startMethodTracing(String, int, int), but taking an already-opened
      * FileDescriptor in which the trace is written.  The file name is also
      * supplied simply for logging.  Makes a dup of the file descriptor.
-     * 
+     *
      * Not exposed in the SDK unless we are really comfortable with supporting
      * this and find it would be useful.
      * @hide
@@ -1070,7 +1071,7 @@
      *    static {
      *        // Sets all the fields
      *        Debug.setFieldsOn(MyDebugVars.class);
-     * 
+     *
      *        // Sets only the fields annotated with @Debug.DebugProperty
      *        // Debug.setFieldsOn(MyDebugVars.class, true);
      *    }
diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java
index bf9e854..d271e93 100644
--- a/core/java/android/provider/Telephony.java
+++ b/core/java/android/provider/Telephony.java
@@ -25,6 +25,7 @@
 import android.database.Cursor;
 import android.database.sqlite.SqliteWrapper;
 import android.net.Uri;
+import android.os.Environment;
 import android.telephony.SmsMessage;
 import android.text.TextUtils;
 import android.util.Config;
@@ -1526,7 +1527,8 @@
              * which streams the captured image to the uri. Internally we write the media content
              * to this file. It's named '.temp.jpg' so Gallery won't pick it up.
              */
-            public static final String SCRAP_FILE_PATH = "/sdcard/mms/scrapSpace/.temp.jpg";
+            public static final String SCRAP_FILE_PATH =
+                Environment.getExternalStorageDirectory().getPath() + "/mms/scrapSpace/.temp.jpg";
         }
 
         public static final class Intents {
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 740c010..8e363d6 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -238,7 +238,7 @@
  *
  * <p>The screen density of a device is based on the screen resolution. A screen with low density
  * has fewer available pixels per inch, where a screen with high density
- * has more — sometimes significantly more — pixels per inch. The density of a
+ * has more - sometimes significantly more - pixels per inch. The density of a
  * screen is important because, other things being equal, a UI element (such as a button) whose
  * height and width are defined in terms of screen pixels will appear larger on the lower density
  * screen and smaller on the higher density screen.
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index aadb576..167e45d 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -844,7 +844,7 @@
     
     private final Map<String, KernelWakelockStats> readKernelWakelockStats() {
         
-        byte[] buffer = new byte[4096];
+        byte[] buffer = new byte[8192];
         int len;
         
         try {
@@ -891,9 +891,11 @@
                 for (endIndex=startIndex; 
                         endIndex < len && wlBuffer[endIndex] != '\n' && wlBuffer[endIndex] != '\0'; 
                         endIndex++);
-                // Don't go over the end of the buffer
-                if (endIndex < len) {
-                    endIndex++; // endIndex is an exclusive upper bound.
+                endIndex++; // endIndex is an exclusive upper bound.
+                // Don't go over the end of the buffer, Process.parseProcLine might
+                // write to wlBuffer[endIndex]
+                if (endIndex >= (len - 1) ) {
+                    return m;
                 }
 
                 String[] nameStringArray = mProcWakelocksName;
diff --git a/core/java/com/android/internal/os/SamplingProfilerIntegration.java b/core/java/com/android/internal/os/SamplingProfilerIntegration.java
index 5f5c7a4..127fb23 100644
--- a/core/java/com/android/internal/os/SamplingProfilerIntegration.java
+++ b/core/java/com/android/internal/os/SamplingProfilerIntegration.java
@@ -85,7 +85,8 @@
             pending = true;
             snapshotWriter.execute(new Runnable() {
                 public void run() {
-                    String dir = "/sdcard/snapshots";
+                    String dir =
+                        Environment.getExternalStorageDirectory().getPath() + "/snapshots";
                     if (!dirMade) {
                         new File(dir).mkdirs();
                         if (new File(dir).isDirectory()) {
diff --git a/core/tests/hosttests/Android.mk b/core/tests/hosttests/Android.mk
index 0001201..07d99cb 100644
--- a/core/tests/hosttests/Android.mk
+++ b/core/tests/hosttests/Android.mk
@@ -23,7 +23,7 @@
 
 LOCAL_MODULE := FrameworkCoreHostTests
 
-LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib junit
+LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib-prebuilt junit
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
index 91cbe2f..b225c37 100644
--- a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
+++ b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTestUtils.java
@@ -16,32 +16,32 @@
 
 package android.content.pm;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.AndroidDebugBridge;
 import com.android.ddmlib.IDevice;
 import com.android.ddmlib.IShellOutputReceiver;
+import com.android.ddmlib.InstallException;
 import com.android.ddmlib.Log;
 import com.android.ddmlib.MultiLineReceiver;
-import com.android.ddmlib.SyncService;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.SyncException;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.SyncService.ISyncProgressMonitor;
-import com.android.ddmlib.SyncService.SyncResult;
 import com.android.ddmlib.testrunner.ITestRunListener;
 import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
 import com.android.ddmlib.testrunner.TestIdentifier;
-import com.android.hosttest.DeviceTestCase;
-import com.android.hosttest.DeviceTestSuite;
 
 import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.StringReader;
 import java.lang.Runtime;
 import java.lang.Process;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import junit.framework.Assert;
-import com.android.hosttest.DeviceTestCase;
 
 /**
  * Set of tests that verify host side install cases
@@ -119,8 +119,14 @@
      * Helper method to run tests and return the listener that collected the results.
      * @param pkgName Android application package for tests
      * @return the {@link CollectingTestRunListener}
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    private CollectingTestRunListener doRunTests(String pkgName) throws IOException {
+    private CollectingTestRunListener doRunTests(String pkgName) throws IOException,
+    TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(
                 pkgName, mDevice);
         CollectingTestRunListener listener = new CollectingTestRunListener();
@@ -133,8 +139,14 @@
      *
      * @param pkgName Android application package for tests
      * @return true if every test passed, false otherwise.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean runDeviceTestsDidAllTestsPass(String pkgName) throws IOException {
+    public boolean runDeviceTestsDidAllTestsPass(String pkgName) throws IOException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         CollectingTestRunListener listener = doRunTests(pkgName);
         return listener.didAllTestsPass();
     }
@@ -142,22 +154,26 @@
     /**
      * Helper method to push a file to device
      * @param apkAppPrivatePath
-     * @throws IOException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
      */
     public void pushFile(final String localFilePath, final String destFilePath)
-            throws IOException {
-        SyncResult result = mDevice.getSyncService().pushFile(
-                localFilePath, destFilePath, new NullSyncProgressMonitor());
-        assertEquals(SyncService.RESULT_OK, result.getCode());
+            throws IOException, SyncException, TimeoutException, AdbCommandRejectedException {
+        mDevice.getSyncService().pushFile(localFilePath,
+                destFilePath, new NullSyncProgressMonitor());
     }
 
     /**
      * Helper method to install a file
      * @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
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed
      */
-    public void installFile(final String localFilePath, final boolean replace) throws IOException {
+    public void installFile(final String localFilePath, final boolean replace) throws IOException,
+            InstallException {
         String result = mDevice.installPackage(localFilePath, replace);
         assertEquals(null, result);
     }
@@ -167,10 +183,11 @@
      * @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
      * @return the string output of the failed install attempt
-     * @throws IOException
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed
      */
     public String installFileFail(final String localFilePath, final boolean replace)
-            throws IOException {
+            throws IOException, InstallException {
         String result = mDevice.installPackage(localFilePath, replace);
         assertNotNull(result);
         return result;
@@ -180,10 +197,17 @@
      * Helper method to install a file to device as forward locked
      * @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
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
     public String installFileForwardLocked(final String localFilePath, final boolean replace)
-            throws IOException {
+            throws IOException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, InstallException {
         String remoteFilePath = mDevice.syncPackageToDevice(localFilePath);
         InstallReceiver receiver = new InstallReceiver();
         String cmd = String.format(replace ? "pm install -r -l \"%1$s\"" :
@@ -198,9 +222,14 @@
      *
      * @param destPath the absolute path of file on device to check
      * @return <code>true</code> if file exists, <code>false</code> otherwise.
-     * @throws IOException if adb shell command failed
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean doesRemoteFileExist(String destPath) throws IOException {
+    public boolean doesRemoteFileExist(String destPath) throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         String lsGrep = executeShellCommand(String.format("ls %s", destPath));
         return !lsGrep.contains("No such file or directory");
     }
@@ -211,10 +240,15 @@
      * @param destPath the absolute path of the file
      * @return <code>true</code> if file exists containing given string,
      *         <code>false</code> otherwise.
-     * @throws IOException if adb shell command failed
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
     public boolean doesRemoteFileExistContainingString(String destPath, String searchString)
-            throws IOException {
+            throws IOException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         String lsResult = executeShellCommand(String.format("ls %s", destPath));
         return lsResult.contains(searchString);
     }
@@ -224,9 +258,14 @@
      *
      * @param packageName the Android manifest package to check.
      * @return <code>true</code> if package exists, <code>false</code> otherwise
-     * @throws IOException if adb shell command failed
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean doesPackageExist(String packageName) throws IOException {
+    public boolean doesPackageExist(String packageName) throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         String pkgGrep = executeShellCommand(String.format("pm path %s", packageName));
         return pkgGrep.contains("package:");
     }
@@ -236,9 +275,14 @@
      *
      * @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
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean doesAppExistOnDevice(String packageName) throws IOException {
+    public boolean doesAppExistOnDevice(String packageName) throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         return doesRemoteFileExistContainingString(DEVICE_APP_PATH, packageName);
     }
 
@@ -247,9 +291,14 @@
      *
      * @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
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean doesAppExistOnSDCard(String packageName) throws IOException {
+    public boolean doesAppExistOnSDCard(String packageName) throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         return doesRemoteFileExistContainingString(SDCARD_APP_PATH, packageName);
     }
 
@@ -258,9 +307,14 @@
      *
      * @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
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public boolean doesAppExistAsForwardLocked(String packageName) throws IOException {
+    public boolean doesAppExistAsForwardLocked(String packageName) throws IOException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         return doesRemoteFileExistContainingString(APP_PRIVATE_PATH, packageName);
     }
 
@@ -268,9 +322,14 @@
      * Waits for device's package manager to respond.
      *
      * @throws InterruptedException
-     * @throws IOException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public void waitForPackageManager() throws InterruptedException, IOException {
+    public void waitForPackageManager() throws InterruptedException, IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "waiting for device");
         int currentWaitTime = 0;
         // poll the package manager until it returns something for android
@@ -336,9 +395,14 @@
      *
      * @param packageName The name of the package to wait to load
      * @throws InterruptedException
-     * @throws IOException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public void waitForApp(String packageName) throws InterruptedException, IOException {
+    public void waitForApp(String packageName) throws InterruptedException, IOException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "waiting for app to launch");
         int currentWaitTime = 0;
         // poll the package manager until it returns something for the package we're looking for
@@ -355,9 +419,14 @@
     /**
      * Helper method which executes a adb shell command and returns output as a {@link String}
      * @return the output of the command
-     * @throws IOException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public String executeShellCommand(String command) throws IOException {
+    public String executeShellCommand(String command) throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, String.format("adb shell %s", command));
         CollectingOutputReceiver receiver = new CollectingOutputReceiver();
         mDevice.executeShellCommand(command, receiver);
@@ -369,9 +438,14 @@
     /**
      * Helper method ensures we are in root mode on the host side. It returns only after
      * PackageManager is actually up and running.
-     * @throws IOException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public void runAdbRoot() throws IOException, InterruptedException {
+    public void runAdbRoot() throws IOException, InterruptedException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "adb root");
         Runtime runtime = Runtime.getRuntime();
         Process process = runtime.exec("adb root"); // adb should be in the path
@@ -389,10 +463,15 @@
     /**
      * Helper method which reboots the device and returns once the device is online again
      * and package manager is up and running (note this function is synchronous to callers).
-     * @throws IOException
      * @throws InterruptedException
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public void rebootDevice() throws IOException, InterruptedException {
+    public void rebootDevice() throws IOException, InterruptedException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         String command = "reboot"; // no need for -s since mDevice is already tied to a device
         Log.i(LOG_TAG, command);
         CollectingOutputReceiver receiver = new CollectingOutputReceiver();
@@ -468,7 +547,7 @@
             mAllTestsPassed = false;
         }
 
-        public void testRunEnded(long elapsedTime) {
+        public void testRunEnded(long elapsedTime, Map<String, String> resultBundle) {
             // ignore
         }
 
@@ -545,17 +624,23 @@
     /**
      * 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.
      *
      * @param the path of the apk to install
      * @param the name of the package
      * @param <code>true</code> if the app should be overwritten, <code>false</code> otherwise
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
-     * <p/>
-     * Assumes adb is running as root in device under test.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void installAppAndVerifyExistsOnSDCard(String apkPath, String pkgName, boolean overwrite)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         // Start with a clean slate if we're not overwriting
         if (!overwrite) {
             // cleanup test app just in case it already exists
@@ -576,17 +661,23 @@
     /**
      * 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.
      *
      * @param the path of the apk to install
      * @param the name of the package
      * @param <code>true</code> if the app should be overwritten, <code>false</code> otherwise
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
-     * <p/>
-     * Assumes adb is running as root in device under test.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void installAppAndVerifyExistsOnDevice(String apkPath, String pkgName, boolean overwrite)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         // Start with a clean slate if we're not overwriting
         if (!overwrite) {
             // cleanup test app just in case it already exists
@@ -607,17 +698,24 @@
     /**
      * Helper method for installing an app as forward-locked, and
      * then verifying the app was installed in the proper forward-locked location.
+     * <p/>
+     * Assumes adb is running as root in device under test.
      *
      * @param the path of the apk to install
      * @param the name of the package
      * @param <code>true</code> if the app should be overwritten, <code>false</code> otherwise
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
-     * <p/>
-     * Assumes adb is running as root in device under test.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
      */
     public void installFwdLockedAppAndVerifyExists(String apkPath,
-            String pkgName, boolean overwrite) throws IOException, InterruptedException {
+            String pkgName, boolean overwrite) throws IOException, InterruptedException,
+            InstallException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         // Start with a clean slate if we're not overwriting
         if (!overwrite) {
             // cleanup test app just in case it already exists
@@ -638,14 +736,21 @@
 
     /**
      * Helper method for uninstalling an app.
-     *
-     * @param pkgName package name to uninstall
-     * @throws IOException if adb shell command failed
-     * @throws InterruptedException if the thread was interrupted
      * <p/>
      * Assumes adb is running as root in device under test.
+     *
+     * @param pkgName package name to uninstall
+     * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the uninstall failed.
      */
-    public void uninstallApp(String pkgName) throws IOException, InterruptedException {
+    public void uninstallApp(String pkgName) throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         mDevice.uninstallPackage(pkgName);
         // make sure its not installed anymore
         assertFalse(doesPackageExist(pkgName));
@@ -655,12 +760,18 @@
      * Helper method for clearing any installed non-system apps.
      * Useful ensuring no non-system apps are installed, and for cleaning up stale files that
      * may be lingering on the system for whatever reason.
-     *
-     * @throws IOException if adb shell command failed
      * <p/>
      * Assumes adb is running as root in device under test.
+     *
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the uninstall failed.
      */
-    public void wipeNonSystemApps() throws IOException {
+    public void wipeNonSystemApps() throws IOException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, InstallException {
       String allInstalledPackages = executeShellCommand("pm list packages -f");
       BufferedReader outputReader = new BufferedReader(new StringReader(allInstalledPackages));
 
@@ -685,8 +796,14 @@
      *
      * <p/>
      * Assumes adb is running as root in device under test.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public void setDevicePreferredInstallLocation(InstallLocPreference pref) throws IOException {
+    public void setDevicePreferredInstallLocation(InstallLocPreference pref) throws IOException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         String command = "pm setInstallLocation %d";
         int locValue = 0;
         switch (pref) {
@@ -708,8 +825,14 @@
      *
      * <p/>
      * Assumes adb is running as root in device under test.
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    public InstallLocPreference getDevicePreferredInstallLocation() throws IOException {
+    public InstallLocPreference getDevicePreferredInstallLocation() throws IOException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         String result = executeShellCommand("pm getInstallLocation");
         if (result.indexOf('0') != -1) {
             return InstallLocPreference.AUTO;
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
index 1b797d5..22a2be6 100644
--- a/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
+++ b/core/tests/hosttests/src/android/content/pm/PackageManagerHostTests.java
@@ -16,13 +16,12 @@
 
 package android.content.pm;
 
-import com.android.ddmlib.IDevice;
-import com.android.ddmlib.IShellOutputReceiver;
+import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.InstallException;
 import com.android.ddmlib.Log;
-import com.android.ddmlib.MultiLineReceiver;
-import com.android.ddmlib.SyncService;
-import com.android.ddmlib.SyncService.ISyncProgressMonitor;
-import com.android.ddmlib.SyncService.SyncResult;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.SyncException;
+import com.android.ddmlib.TimeoutException;
 import com.android.hosttest.DeviceTestCase;
 import com.android.hosttest.DeviceTestSuite;
 
@@ -156,10 +155,18 @@
      * the app, and otherwise cause the system to blow up.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
-    public void testPushAppPrivate() throws IOException, InterruptedException {
+    public void testPushAppPrivate() throws IOException, InterruptedException, InstallException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
+            SyncException {
         Log.i(LOG_TAG, "testing pushing an apk to /data/app-private");
         final String apkAppPrivatePath =  appPrivatePath + SIMPLE_APK;
 
@@ -187,12 +194,18 @@
      * @param apkName the file name of the test app apk
      * @param pkgName the package name of the test app apk
      * @param expectedLocation the file name of the test app apk
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     private void doStandardInstall(String apkName, String pkgName,
             PackageManagerHostTestUtils.InstallLocation expectedLocation)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
 
         if (expectedLocation == PackageManagerHostTestUtils.InstallLocation.DEVICE) {
             mPMHostUtils.installAppAndVerifyExistsOnDevice(
@@ -211,12 +224,18 @@
      * Assumes adb is running as root in device under test.
      * @param preference the device's preferred location of where to install apps
      * @param expectedLocation the expected location of where the apk was installed
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
             PackageManagerHostTestUtils.InstallLocation expectedLocation)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, InstallException {
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
                 PackageManagerHostTestUtils.InstallLocPreference.AUTO;
@@ -239,10 +258,16 @@
      * will install the app to the device when device's preference is auto.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppAutoLocPrefIsAuto() throws IOException, InterruptedException {
+    public void testInstallAppAutoLocPrefIsAuto() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=auto, prefer=auto gets installed on device");
         installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -253,10 +278,17 @@
      * will install the app to the device when device's preference is internal.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppAutoLocPrefIsInternal() throws IOException, InterruptedException {
+    public void testInstallAppAutoLocPrefIsInternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=auto, prefer=internal gets installed on device");
         installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -267,10 +299,17 @@
      * will install the app to the SD card when device's preference is external.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppAutoLocPrefIsExternal() throws IOException, InterruptedException {
+    public void testInstallAppAutoLocPrefIsExternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=auto, prefer=external gets installed on device");
         installAppAutoLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -283,12 +322,18 @@
      * Assumes adb is running as root in device under test.
      * @param preference the device's preferred location of where to install apps
      * @param expectedLocation the expected location of where the apk was installed
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the (un)install failed.
      */
     public void installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
             PackageManagerHostTestUtils.InstallLocation expectedLocation)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, InstallException {
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
             PackageManagerHostTestUtils.InstallLocPreference.AUTO;
@@ -311,10 +356,17 @@
      * will install the app to the device when device's preference is auto.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppInternalLocPrefIsAuto() throws IOException, InterruptedException {
+    public void testInstallAppInternalLocPrefIsAuto() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=internal, prefer=auto gets installed on device");
         installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -325,10 +377,17 @@
      * will install the app to the device when device's preference is internal.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppInternalLocPrefIsInternal() throws IOException, InterruptedException {
+    public void testInstallAppInternalLocPrefIsInternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=internal, prefer=internal is installed on device");
         installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -339,10 +398,17 @@
      * will install the app to the device when device's preference is external.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppInternalLocPrefIsExternal() throws IOException, InterruptedException {
+    public void testInstallAppInternalLocPrefIsExternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=internal, prefer=external is installed on device");
         installAppInternalLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.DEVICE);
@@ -355,12 +421,18 @@
      * Assumes adb is running as root in device under test.
      * @param preference the device's preferred location of where to install apps
      * @param expectedLocation the expected location of where the apk was installed
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference preference,
             PackageManagerHostTestUtils.InstallLocation expectedLocation)
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, InstallException {
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
             PackageManagerHostTestUtils.InstallLocPreference.AUTO;
@@ -384,10 +456,17 @@
      * will install the app to the device when device's preference is auto.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppExternalLocPrefIsAuto() throws IOException, InterruptedException {
+    public void testInstallAppExternalLocPrefIsAuto() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=external, pref=auto gets installed on SD Card");
         installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.AUTO,
                 PackageManagerHostTestUtils.InstallLocation.SDCARD);
@@ -398,10 +477,17 @@
      * will install the app to the device when device's preference is internal.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppExternalLocPrefIsInternal() throws IOException, InterruptedException {
+    public void testInstallAppExternalLocPrefIsInternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=external, pref=internal gets installed on SD Card");
         installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.INTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.SDCARD);
@@ -412,10 +498,17 @@
      * will install the app to the device when device's preference is external.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppExternalLocPrefIsExternal() throws IOException, InterruptedException {
+    public void testInstallAppExternalLocPrefIsExternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installLocation=external, pref=external gets installed on SD Card");
         installAppExternalLoc(PackageManagerHostTestUtils.InstallLocPreference.EXTERNAL,
                 PackageManagerHostTestUtils.InstallLocation.SDCARD);
@@ -427,10 +520,17 @@
      * system decide.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppNoLocPrefIsAuto() throws IOException, InterruptedException {
+    public void testInstallAppNoLocPrefIsAuto() throws IOException, InterruptedException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
+            InstallException {
         Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device");
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
@@ -456,10 +556,17 @@
      * external.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppNoLocPrefIsExternal() throws IOException, InterruptedException {
+    public void testInstallAppNoLocPrefIsExternal() throws IOException, InterruptedException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
+            InstallException {
         Log.i(LOG_TAG, "Test an app with no installLocation gets installed on SD card");
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
@@ -485,10 +592,17 @@
      * internal.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallAppNoLocPrefIsInternal() throws IOException, InterruptedException {
+    public void testInstallAppNoLocPrefIsInternal() throws IOException, InterruptedException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
+            InstallException {
         Log.i(LOG_TAG, "Test an app with no installLocation gets installed on device");
 
         PackageManagerHostTestUtils.InstallLocPreference savedPref =
@@ -513,10 +627,18 @@
      * forward-locked will get installed to the correct location.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallFwdLockedAppInternal() throws IOException, InterruptedException {
+    public void testInstallFwdLockedAppInternal() throws IOException, InterruptedException,
+            InstallException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
 
         try {
@@ -534,10 +656,18 @@
      * forward-locked will get installed to the correct location.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallFwdLockedAppExternal() throws IOException, InterruptedException {
+    public void testInstallFwdLockedAppExternal() throws IOException, InterruptedException,
+            InstallException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test an app with installLoc set to Internal gets installed to app-private");
 
         try {
@@ -555,10 +685,18 @@
      * forward-locked will get installed to the correct location.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallFwdLockedAppAuto() throws IOException, InterruptedException {
+    public void testInstallFwdLockedAppAuto() throws IOException, InterruptedException,
+            InstallException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test an app with installLoc set to Auto gets installed to app-private");
 
         try {
@@ -576,10 +714,18 @@
      * forward-locked installed will get installed to the correct location.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
-    public void testInstallFwdLockedAppNone() throws IOException, InterruptedException {
+    public void testInstallFwdLockedAppNone() throws IOException, InterruptedException,
+            InstallException, SyncException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test an app with no installLoc set gets installed to app-private");
 
         try {
@@ -597,14 +743,21 @@
      * uninstall it, and reinstall it onto the SD card.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     // 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 {
+    public void testReinstallInternalToExternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installing an app first to the device, then to the SD Card");
 
         try {
@@ -625,14 +778,21 @@
      * uninstall it, and reinstall it onto the device.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     // 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 {
+    public void testReinstallExternalToInternal() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installing an app first to the SD Care, then to the device");
 
         try {
@@ -655,10 +815,16 @@
      * the update onto the SD card as well when location is set to external for both versions
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testUpdateBothExternal() throws IOException, InterruptedException {
+    public void testUpdateBothExternal() throws IOException, InterruptedException, InstallException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
 
         try {
@@ -681,10 +847,16 @@
      * updated apps' manifest file.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testUpdateToSDCard() throws IOException, InterruptedException {
+    public void testUpdateToSDCard() throws IOException, InterruptedException, InstallException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
 
         try {
@@ -706,10 +878,17 @@
      * the update onto the device if the manifest has changed to installLocation=internalOnly
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
-    public void testUpdateSDCardToDevice() throws IOException, InterruptedException {
+    public void testUpdateSDCardToDevice() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating an app on the SD card to the Device through manifest change");
 
         try {
@@ -731,11 +910,18 @@
      * the update onto the device's forward-locked location
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndUpdateExternalLocForwardLockedApp()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, SyncException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating a forward-locked app marked preferExternal");
 
         try {
@@ -757,11 +943,18 @@
      * the update onto the device's forward-locked location
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndUpdateNoLocForwardLockedApp()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, SyncException,
+            TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating a forward-locked app with no installLocation pref set");
 
         try {
@@ -783,11 +976,18 @@
      * and then launched without crashing.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws SyncException if the sync failed for another reason.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchAllPermsAppOnSD()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with all perms set, installed on SD card");
 
         try {
@@ -808,11 +1008,17 @@
      * run without permissions errors.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchFLPermsAppOnSD()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
 
         try {
@@ -833,11 +1039,17 @@
      * run without permissions errors.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchBTPermsAppOnSD()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with bluetooth perms set, installed on SD card");
 
         try {
@@ -858,11 +1070,17 @@
      * SecurityException when launched if its other shared apps are not installed.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchSharedPermsAppOnSD_NoPerms()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
 
         try {
@@ -888,11 +1106,17 @@
      * shared apps are installed.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchSharedPermsAppOnSD_GrantedPerms()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with no explicit perms set, installed on SD card");
 
         try {
@@ -921,11 +1145,17 @@
      * run without permissions errors even after a reboot
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchFLPermsAppOnSD_Reboot()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app with location perms set, installed on SD card");
 
         try {
@@ -951,11 +1181,17 @@
      * shared apps are installed, even after a reboot.
      * <p/>
      * Assumes adb is running as root in device under test.
-     * @throws IOException if adb shell command failed
      * @throws InterruptedException if the thread was interrupted
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output anything for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
+     * @throws InstallException if the install failed.
      */
     public void testInstallAndLaunchSharedPermsAppOnSD_Reboot()
-            throws IOException, InterruptedException {
+            throws IOException, InterruptedException, InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test launching an app on SD, with no explicit perms set after reboot");
 
         try {
diff --git a/core/tests/hosttests/src/android/content/pm/PackageManagerStressHostTests.java b/core/tests/hosttests/src/android/content/pm/PackageManagerStressHostTests.java
index 715c55b..a2a5dd3 100644
--- a/core/tests/hosttests/src/android/content/pm/PackageManagerStressHostTests.java
+++ b/core/tests/hosttests/src/android/content/pm/PackageManagerStressHostTests.java
@@ -16,8 +16,11 @@
 
 package android.content.pm;
 
-import com.android.ddmlib.IDevice;
+import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.InstallException;
 import com.android.ddmlib.Log;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.TimeoutException;
 import com.android.hosttest.DeviceTestCase;
 import com.android.hosttest.DeviceTestSuite;
 
@@ -138,7 +141,9 @@
      * <p/>
      * Assumes adb is running as root in device under test.
      */
-    public void testUpdateAppManyTimesOnSD() throws IOException, InterruptedException {
+    public void testUpdateAppManyTimesOnSD() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating an app on SD numerous times");
 
         // cleanup test app just in case it already exists
@@ -173,7 +178,9 @@
      * <p/>
      * Assumes adb is running as root in device under test.
      */
-    public void testUninstallReinstallAppOnSDManyTimes() throws IOException, InterruptedException {
+    public void testUninstallReinstallAppOnSDManyTimes() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test updating an app on the SD card stays on the SD card");
 
         // cleanup test app just in case it was already exists
@@ -207,7 +214,9 @@
      * <p/>
      * Assumes adb is running as root in device under test.
      */
-    public void testInstallManyLargeAppsOnSD() throws IOException, InterruptedException {
+    public void testInstallManyLargeAppsOnSD() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installing 20 large apps onto the sd card");
 
         try {
@@ -251,7 +260,9 @@
      * <p/>
      * Assumes adb is running as root in device under test.
      */
-    public void testInstallManyAppsOnSD() throws IOException, InterruptedException {
+    public void testInstallManyAppsOnSD() throws IOException, InterruptedException,
+            InstallException, TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException {
         Log.i(LOG_TAG, "Test installing 500 small apps onto SD");
 
         try {
diff --git a/docs/html/guide/topics/resources/animation-resource.jd b/docs/html/guide/topics/resources/animation-resource.jd
index e0ce051..972dd72 100644
--- a/docs/html/guide/topics/resources/animation-resource.jd
+++ b/docs/html/guide/topics/resources/animation-resource.jd
@@ -65,10 +65,10 @@
         android:pivotX="<em>float</em>"
         android:pivotY="<em>float</em>" /&gt;
     &lt;<a href="#translate-element">translate</a>
-        android:fromX="<em>float</em>"
-        android:toX="<em>float</em>"
-        android:fromY="<em>float</em>"
-        android:toY="<em>float</em>" /&gt;
+        android:fromXDelta="<em>float</em>"
+        android:toXDelta="<em>float</em>"
+        android:fromYDelta="<em>float</em>"
+        android:toYDelta="<em>float</em>" /&gt;
     &lt;<a href="#rotate-element">rotate</a>
         android:fromDegrees="<em>float</em>"
         android:toDegrees="<em>float</em>"
@@ -212,10 +212,10 @@
     android:shareInterpolator="false">
     &lt;scale
         android:interpolator="@android:anim/accelerate_decelerate_interpolator"
-        android:fromXScale="1.0" 
-        android:toXScale="1.4" 
-        android:fromYScale="1.0" 
-        android:toYScale="0.6" 
+        android:fromXScale="1.0"
+        android:toXScale="1.4"
+        android:fromYScale="1.0"
+        android:toYScale="0.6"
         android:pivotX="50%"
         android:pivotY="50%"
         android:fillAfter="false"
@@ -224,18 +224,18 @@
         android:interpolator="@android:anim/accelerate_interpolator"
         android:startOffset="700">
         &lt;scale
-            android:fromXScale="1.4" 
+            android:fromXScale="1.4"
             android:toXScale="0.0"
             android:fromYScale="0.6"
-            android:toYScale="0.0" 
-            android:pivotX="50%" 
-            android:pivotY="50%" 
+            android:toYScale="0.0"
+            android:pivotX="50%"
+            android:pivotY="50%"
             android:duration="400" />
         &lt;rotate
-            android:fromDegrees="0" 
+            android:fromDegrees="0"
             android:toDegrees="-45"
-            android:toYScale="0.0" 
-            android:pivotX="50%" 
+            android:toYScale="0.0"
+            android:pivotX="50%"
             android:pivotY="50%"
             android:duration="400" />
     &lt;/set>
diff --git a/media/mediaserver/Android.mk b/media/mediaserver/Android.mk
index a92cea8..0559812 100644
--- a/media/mediaserver/Android.mk
+++ b/media/mediaserver/Android.mk
@@ -14,8 +14,8 @@
 base := $(LOCAL_PATH)/../..
 
 LOCAL_C_INCLUDES := \
-    $(base)/libs/audioflinger \
-    $(base)/camera/libcameraservice \
+    $(base)/services/audioflinger \
+    $(base)/services/camera/libcameraservice \
     $(base)/media/libmediaplayerservice
 
 LOCAL_MODULE:= mediaserver
diff --git a/libs/audioflinger/A2dpAudioInterface.cpp b/services/audioflinger/A2dpAudioInterface.cpp
similarity index 100%
rename from libs/audioflinger/A2dpAudioInterface.cpp
rename to services/audioflinger/A2dpAudioInterface.cpp
diff --git a/libs/audioflinger/A2dpAudioInterface.h b/services/audioflinger/A2dpAudioInterface.h
similarity index 100%
rename from libs/audioflinger/A2dpAudioInterface.h
rename to services/audioflinger/A2dpAudioInterface.h
diff --git a/libs/audioflinger/Android.mk b/services/audioflinger/Android.mk
similarity index 100%
rename from libs/audioflinger/Android.mk
rename to services/audioflinger/Android.mk
diff --git a/libs/audioflinger/AudioBufferProvider.h b/services/audioflinger/AudioBufferProvider.h
similarity index 100%
rename from libs/audioflinger/AudioBufferProvider.h
rename to services/audioflinger/AudioBufferProvider.h
diff --git a/libs/audioflinger/AudioDumpInterface.cpp b/services/audioflinger/AudioDumpInterface.cpp
similarity index 100%
rename from libs/audioflinger/AudioDumpInterface.cpp
rename to services/audioflinger/AudioDumpInterface.cpp
diff --git a/libs/audioflinger/AudioDumpInterface.h b/services/audioflinger/AudioDumpInterface.h
similarity index 100%
rename from libs/audioflinger/AudioDumpInterface.h
rename to services/audioflinger/AudioDumpInterface.h
diff --git a/libs/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
similarity index 100%
rename from libs/audioflinger/AudioFlinger.cpp
rename to services/audioflinger/AudioFlinger.cpp
diff --git a/libs/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
similarity index 100%
rename from libs/audioflinger/AudioFlinger.h
rename to services/audioflinger/AudioFlinger.h
diff --git a/libs/audioflinger/AudioHardwareGeneric.cpp b/services/audioflinger/AudioHardwareGeneric.cpp
similarity index 100%
rename from libs/audioflinger/AudioHardwareGeneric.cpp
rename to services/audioflinger/AudioHardwareGeneric.cpp
diff --git a/libs/audioflinger/AudioHardwareGeneric.h b/services/audioflinger/AudioHardwareGeneric.h
similarity index 100%
rename from libs/audioflinger/AudioHardwareGeneric.h
rename to services/audioflinger/AudioHardwareGeneric.h
diff --git a/libs/audioflinger/AudioHardwareInterface.cpp b/services/audioflinger/AudioHardwareInterface.cpp
similarity index 100%
rename from libs/audioflinger/AudioHardwareInterface.cpp
rename to services/audioflinger/AudioHardwareInterface.cpp
diff --git a/libs/audioflinger/AudioHardwareStub.cpp b/services/audioflinger/AudioHardwareStub.cpp
similarity index 100%
rename from libs/audioflinger/AudioHardwareStub.cpp
rename to services/audioflinger/AudioHardwareStub.cpp
diff --git a/libs/audioflinger/AudioHardwareStub.h b/services/audioflinger/AudioHardwareStub.h
similarity index 100%
rename from libs/audioflinger/AudioHardwareStub.h
rename to services/audioflinger/AudioHardwareStub.h
diff --git a/libs/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
similarity index 100%
rename from libs/audioflinger/AudioMixer.cpp
rename to services/audioflinger/AudioMixer.cpp
diff --git a/libs/audioflinger/AudioMixer.h b/services/audioflinger/AudioMixer.h
similarity index 100%
rename from libs/audioflinger/AudioMixer.h
rename to services/audioflinger/AudioMixer.h
diff --git a/libs/audioflinger/AudioPolicyManagerBase.cpp b/services/audioflinger/AudioPolicyManagerBase.cpp
similarity index 100%
rename from libs/audioflinger/AudioPolicyManagerBase.cpp
rename to services/audioflinger/AudioPolicyManagerBase.cpp
diff --git a/libs/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
similarity index 100%
rename from libs/audioflinger/AudioPolicyService.cpp
rename to services/audioflinger/AudioPolicyService.cpp
diff --git a/libs/audioflinger/AudioPolicyService.h b/services/audioflinger/AudioPolicyService.h
similarity index 100%
rename from libs/audioflinger/AudioPolicyService.h
rename to services/audioflinger/AudioPolicyService.h
diff --git a/libs/audioflinger/AudioResampler.cpp b/services/audioflinger/AudioResampler.cpp
similarity index 100%
rename from libs/audioflinger/AudioResampler.cpp
rename to services/audioflinger/AudioResampler.cpp
diff --git a/libs/audioflinger/AudioResampler.h b/services/audioflinger/AudioResampler.h
similarity index 100%
rename from libs/audioflinger/AudioResampler.h
rename to services/audioflinger/AudioResampler.h
diff --git a/libs/audioflinger/AudioResamplerCubic.cpp b/services/audioflinger/AudioResamplerCubic.cpp
similarity index 100%
rename from libs/audioflinger/AudioResamplerCubic.cpp
rename to services/audioflinger/AudioResamplerCubic.cpp
diff --git a/libs/audioflinger/AudioResamplerCubic.h b/services/audioflinger/AudioResamplerCubic.h
similarity index 100%
rename from libs/audioflinger/AudioResamplerCubic.h
rename to services/audioflinger/AudioResamplerCubic.h
diff --git a/libs/audioflinger/AudioResamplerSinc.cpp b/services/audioflinger/AudioResamplerSinc.cpp
similarity index 100%
rename from libs/audioflinger/AudioResamplerSinc.cpp
rename to services/audioflinger/AudioResamplerSinc.cpp
diff --git a/libs/audioflinger/AudioResamplerSinc.h b/services/audioflinger/AudioResamplerSinc.h
similarity index 100%
rename from libs/audioflinger/AudioResamplerSinc.h
rename to services/audioflinger/AudioResamplerSinc.h
diff --git a/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
similarity index 100%
rename from camera/libcameraservice/Android.mk
rename to services/camera/libcameraservice/Android.mk
diff --git a/camera/libcameraservice/CameraHardwareStub.cpp b/services/camera/libcameraservice/CameraHardwareStub.cpp
similarity index 100%
rename from camera/libcameraservice/CameraHardwareStub.cpp
rename to services/camera/libcameraservice/CameraHardwareStub.cpp
diff --git a/camera/libcameraservice/CameraHardwareStub.h b/services/camera/libcameraservice/CameraHardwareStub.h
similarity index 100%
rename from camera/libcameraservice/CameraHardwareStub.h
rename to services/camera/libcameraservice/CameraHardwareStub.h
diff --git a/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
similarity index 100%
rename from camera/libcameraservice/CameraService.cpp
rename to services/camera/libcameraservice/CameraService.cpp
diff --git a/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
similarity index 100%
rename from camera/libcameraservice/CameraService.h
rename to services/camera/libcameraservice/CameraService.h
diff --git a/camera/libcameraservice/CannedJpeg.h b/services/camera/libcameraservice/CannedJpeg.h
similarity index 100%
rename from camera/libcameraservice/CannedJpeg.h
rename to services/camera/libcameraservice/CannedJpeg.h
diff --git a/camera/libcameraservice/FakeCamera.cpp b/services/camera/libcameraservice/FakeCamera.cpp
similarity index 100%
rename from camera/libcameraservice/FakeCamera.cpp
rename to services/camera/libcameraservice/FakeCamera.cpp
diff --git a/camera/libcameraservice/FakeCamera.h b/services/camera/libcameraservice/FakeCamera.h
similarity index 100%
rename from camera/libcameraservice/FakeCamera.h
rename to services/camera/libcameraservice/FakeCamera.h
diff --git a/camera/tests/CameraServiceTest/Android.mk b/services/camera/tests/CameraServiceTest/Android.mk
similarity index 100%
rename from camera/tests/CameraServiceTest/Android.mk
rename to services/camera/tests/CameraServiceTest/Android.mk
diff --git a/camera/tests/CameraServiceTest/CameraServiceTest.cpp b/services/camera/tests/CameraServiceTest/CameraServiceTest.cpp
similarity index 100%
rename from camera/tests/CameraServiceTest/CameraServiceTest.cpp
rename to services/camera/tests/CameraServiceTest/CameraServiceTest.cpp
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 88463b0..68787cd 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -2149,6 +2149,7 @@
     private void removeWindowInnerLocked(Session session, WindowState win) {
         mKeyWaiter.finishedKey(session, win.mClient, true,
                 KeyWaiter.RETURN_NOTHING);
+        mKeyWaiter.releaseMotionTarget(win);
         mKeyWaiter.releasePendingPointerLocked(win.mSession);
         mKeyWaiter.releasePendingTrackballLocked(win.mSession);
 
@@ -6120,6 +6121,12 @@
             }
         }
 
+        void releaseMotionTarget(WindowState win) {
+            if (mMotionTarget == win) {
+                mMotionTarget = null;
+            }
+        }
+
         MotionEvent finishedKey(Session session, IWindow client, boolean force,
                 int returnWhat) {
             if (DEBUG_INPUT) Slog.v(
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 0c11940..a388311 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -52,6 +52,7 @@
 import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.IIntentReceiver;
@@ -1176,7 +1177,7 @@
                 d.setCancelable(false);
                 d.setTitle("System UIDs Inconsistent");
                 d.setMessage("UIDs on the system are inconsistent, you need to wipe your data partition or your device will be unstable.");
-                d.setButton("I'm Feeling Lucky",
+                d.setButton(DialogInterface.BUTTON_POSITIVE, "I'm Feeling Lucky",
                         mHandler.obtainMessage(IM_FEELING_LUCKY_MSG));
                 mUidAlert = d;
                 d.show();
@@ -5879,10 +5880,12 @@
                 String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
                 if (pkgs != null) {
                     for (String pkg : pkgs) {
-                        if (forceStopPackageLocked(pkg, -1, false, false, false)) {
-                            setResultCode(Activity.RESULT_OK);
-                            return;
-                        }
+                        synchronized (ActivityManagerService.this) {
+                          if (forceStopPackageLocked(pkg, -1, false, false, false)) {
+                              setResultCode(Activity.RESULT_OK);
+                              return;
+                          }
+                       }
                     }
                 }
             }
diff --git a/services/java/com/android/server/am/AppWaitingForDebuggerDialog.java b/services/java/com/android/server/am/AppWaitingForDebuggerDialog.java
index 8e9818d..9fb48b3 100644
--- a/services/java/com/android/server/am/AppWaitingForDebuggerDialog.java
+++ b/services/java/com/android/server/am/AppWaitingForDebuggerDialog.java
@@ -17,6 +17,7 @@
 package com.android.server.am;
 
 import android.content.Context;
+import android.content.DialogInterface;
 import android.os.Handler;
 import android.os.Message;
 
@@ -49,7 +50,7 @@
         text.append(" is waiting for the debugger to attach.");
 
         setMessage(text.toString());
-        setButton("Force Close", mHandler.obtainMessage(1, app));
+        setButton(DialogInterface.BUTTON_POSITIVE, "Force Close", mHandler.obtainMessage(1, app));
         setTitle("Waiting For Debugger");
         getWindow().setTitle("Waiting For Debugger: " + app.info.processName);
     }
diff --git a/services/java/com/android/server/am/FactoryErrorDialog.java b/services/java/com/android/server/am/FactoryErrorDialog.java
index 2e25474..b19bb5ca 100644
--- a/services/java/com/android/server/am/FactoryErrorDialog.java
+++ b/services/java/com/android/server/am/FactoryErrorDialog.java
@@ -17,6 +17,7 @@
 package com.android.server.am;
 
 import android.content.Context;
+import android.content.DialogInterface;
 import android.os.Handler;
 import android.os.Message;
 
@@ -26,7 +27,8 @@
         setCancelable(false);
         setTitle(context.getText(com.android.internal.R.string.factorytest_failed));
         setMessage(msg);
-        setButton(context.getText(com.android.internal.R.string.factorytest_reboot),
+        setButton(DialogInterface.BUTTON_POSITIVE,
+                context.getText(com.android.internal.R.string.factorytest_reboot),
                 mHandler.obtainMessage(0));
         getWindow().setTitle("Factory Error");
     }
diff --git a/libs/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk
similarity index 100%
rename from libs/surfaceflinger/Android.mk
rename to services/surfaceflinger/Android.mk
diff --git a/libs/surfaceflinger/Barrier.h b/services/surfaceflinger/Barrier.h
similarity index 100%
rename from libs/surfaceflinger/Barrier.h
rename to services/surfaceflinger/Barrier.h
diff --git a/libs/surfaceflinger/BlurFilter.cpp b/services/surfaceflinger/BlurFilter.cpp
similarity index 100%
rename from libs/surfaceflinger/BlurFilter.cpp
rename to services/surfaceflinger/BlurFilter.cpp
diff --git a/libs/surfaceflinger/BlurFilter.h b/services/surfaceflinger/BlurFilter.h
similarity index 100%
rename from libs/surfaceflinger/BlurFilter.h
rename to services/surfaceflinger/BlurFilter.h
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp
similarity index 100%
rename from libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp
rename to services/surfaceflinger/DisplayHardware/DisplayHardware.cpp
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.h b/services/surfaceflinger/DisplayHardware/DisplayHardware.h
similarity index 100%
rename from libs/surfaceflinger/DisplayHardware/DisplayHardware.h
rename to services/surfaceflinger/DisplayHardware/DisplayHardware.h
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
similarity index 100%
rename from libs/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
rename to services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardwareBase.h b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
similarity index 100%
rename from libs/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
rename to services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
diff --git a/libs/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
similarity index 100%
rename from libs/surfaceflinger/Layer.cpp
rename to services/surfaceflinger/Layer.cpp
diff --git a/libs/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
similarity index 100%
rename from libs/surfaceflinger/Layer.h
rename to services/surfaceflinger/Layer.h
diff --git a/libs/surfaceflinger/LayerBase.cpp b/services/surfaceflinger/LayerBase.cpp
similarity index 100%
rename from libs/surfaceflinger/LayerBase.cpp
rename to services/surfaceflinger/LayerBase.cpp
diff --git a/libs/surfaceflinger/LayerBase.h b/services/surfaceflinger/LayerBase.h
similarity index 100%
rename from libs/surfaceflinger/LayerBase.h
rename to services/surfaceflinger/LayerBase.h
diff --git a/libs/surfaceflinger/LayerBlur.cpp b/services/surfaceflinger/LayerBlur.cpp
similarity index 100%
rename from libs/surfaceflinger/LayerBlur.cpp
rename to services/surfaceflinger/LayerBlur.cpp
diff --git a/libs/surfaceflinger/LayerBlur.h b/services/surfaceflinger/LayerBlur.h
similarity index 100%
rename from libs/surfaceflinger/LayerBlur.h
rename to services/surfaceflinger/LayerBlur.h
diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/services/surfaceflinger/LayerBuffer.cpp
similarity index 100%
rename from libs/surfaceflinger/LayerBuffer.cpp
rename to services/surfaceflinger/LayerBuffer.cpp
diff --git a/libs/surfaceflinger/LayerBuffer.h b/services/surfaceflinger/LayerBuffer.h
similarity index 100%
rename from libs/surfaceflinger/LayerBuffer.h
rename to services/surfaceflinger/LayerBuffer.h
diff --git a/libs/surfaceflinger/LayerDim.cpp b/services/surfaceflinger/LayerDim.cpp
similarity index 100%
rename from libs/surfaceflinger/LayerDim.cpp
rename to services/surfaceflinger/LayerDim.cpp
diff --git a/libs/surfaceflinger/LayerDim.h b/services/surfaceflinger/LayerDim.h
similarity index 100%
rename from libs/surfaceflinger/LayerDim.h
rename to services/surfaceflinger/LayerDim.h
diff --git a/libs/surfaceflinger/MODULE_LICENSE_APACHE2 b/services/surfaceflinger/MODULE_LICENSE_APACHE2
similarity index 100%
rename from libs/surfaceflinger/MODULE_LICENSE_APACHE2
rename to services/surfaceflinger/MODULE_LICENSE_APACHE2
diff --git a/libs/surfaceflinger/MessageQueue.cpp b/services/surfaceflinger/MessageQueue.cpp
similarity index 100%
rename from libs/surfaceflinger/MessageQueue.cpp
rename to services/surfaceflinger/MessageQueue.cpp
diff --git a/libs/surfaceflinger/MessageQueue.h b/services/surfaceflinger/MessageQueue.h
similarity index 100%
rename from libs/surfaceflinger/MessageQueue.h
rename to services/surfaceflinger/MessageQueue.h
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
similarity index 100%
rename from libs/surfaceflinger/SurfaceFlinger.cpp
rename to services/surfaceflinger/SurfaceFlinger.cpp
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
similarity index 100%
rename from libs/surfaceflinger/SurfaceFlinger.h
rename to services/surfaceflinger/SurfaceFlinger.h
diff --git a/libs/surfaceflinger/Tokenizer.cpp b/services/surfaceflinger/Tokenizer.cpp
similarity index 100%
rename from libs/surfaceflinger/Tokenizer.cpp
rename to services/surfaceflinger/Tokenizer.cpp
diff --git a/libs/surfaceflinger/Tokenizer.h b/services/surfaceflinger/Tokenizer.h
similarity index 100%
rename from libs/surfaceflinger/Tokenizer.h
rename to services/surfaceflinger/Tokenizer.h
diff --git a/libs/surfaceflinger/Transform.cpp b/services/surfaceflinger/Transform.cpp
similarity index 100%
rename from libs/surfaceflinger/Transform.cpp
rename to services/surfaceflinger/Transform.cpp
diff --git a/libs/surfaceflinger/Transform.h b/services/surfaceflinger/Transform.h
similarity index 100%
rename from libs/surfaceflinger/Transform.h
rename to services/surfaceflinger/Transform.h
diff --git a/libs/surfaceflinger/clz.cpp b/services/surfaceflinger/clz.cpp
similarity index 100%
rename from libs/surfaceflinger/clz.cpp
rename to services/surfaceflinger/clz.cpp
diff --git a/libs/surfaceflinger/clz.h b/services/surfaceflinger/clz.h
similarity index 100%
rename from libs/surfaceflinger/clz.h
rename to services/surfaceflinger/clz.h
diff --git a/libs/surfaceflinger/tests/Android.mk b/services/surfaceflinger/tests/Android.mk
similarity index 100%
rename from libs/surfaceflinger/tests/Android.mk
rename to services/surfaceflinger/tests/Android.mk
diff --git a/libs/surfaceflinger/tests/overlays/Android.mk b/services/surfaceflinger/tests/overlays/Android.mk
similarity index 100%
rename from libs/surfaceflinger/tests/overlays/Android.mk
rename to services/surfaceflinger/tests/overlays/Android.mk
diff --git a/libs/surfaceflinger/tests/overlays/overlays.cpp b/services/surfaceflinger/tests/overlays/overlays.cpp
similarity index 100%
rename from libs/surfaceflinger/tests/overlays/overlays.cpp
rename to services/surfaceflinger/tests/overlays/overlays.cpp
diff --git a/libs/surfaceflinger/tests/resize/Android.mk b/services/surfaceflinger/tests/resize/Android.mk
similarity index 100%
rename from libs/surfaceflinger/tests/resize/Android.mk
rename to services/surfaceflinger/tests/resize/Android.mk
diff --git a/libs/surfaceflinger/tests/resize/resize.cpp b/services/surfaceflinger/tests/resize/resize.cpp
similarity index 100%
rename from libs/surfaceflinger/tests/resize/resize.cpp
rename to services/surfaceflinger/tests/resize/resize.cpp
diff --git a/telephony/java/com/android/internal/telephony/AdnRecordCache.java b/telephony/java/com/android/internal/telephony/AdnRecordCache.java
index c8c0658..a175d49 100644
--- a/telephony/java/com/android/internal/telephony/AdnRecordCache.java
+++ b/telephony/java/com/android/internal/telephony/AdnRecordCache.java
@@ -186,7 +186,12 @@
         }
 
         ArrayList<AdnRecord>  oldAdnList;
-        oldAdnList = getRecordsIfLoaded(efid);
+
+        if (efid == EF_PBR) {
+            oldAdnList = mUsimPhoneBookManager.loadEfFilesFromUsim();
+        } else {
+            oldAdnList = getRecordsIfLoaded(efid);
+        }
 
         if (oldAdnList == null) {
             sendErrorResponse(response, "Adn list not exist for EF:" + efid);
@@ -208,6 +213,17 @@
             return;
         }
 
+        if (efid == EF_PBR) {
+            AdnRecord foundAdn = oldAdnList.get(index-1);
+            efid = foundAdn.efid;
+            extensionEF = foundAdn.extRecord;
+            index = foundAdn.recordNumber;
+
+            newAdn.efid = efid;
+            newAdn.extRecord = extensionEF;
+            newAdn.recordNumber = index;
+        }
+
         Message pendingResponse = userWriteResponse.get(efid);
 
         if (pendingResponse != null) {
@@ -331,6 +347,7 @@
 
                 if (ar.exception == null) {
                     adnLikeFiles.get(efid).set(index - 1, adn);
+                    mUsimPhoneBookManager.invalidateCache();
                 }
 
                 Message response = userWriteResponse.get(efid);
diff --git a/telephony/java/com/android/internal/telephony/IccCard.java b/telephony/java/com/android/internal/telephony/IccCard.java
index d3a34ec..90f9e8c 100644
--- a/telephony/java/com/android/internal/telephony/IccCard.java
+++ b/telephony/java/com/android/internal/telephony/IccCard.java
@@ -672,12 +672,11 @@
      * @return true if a ICC card is present
      */
     public boolean hasIccCard() {
-        boolean isIccPresent;
-        if (mPhone.getPhoneName().equals("GSM")) {
-            return mIccCardStatus.getCardState().isCardPresent();
-        } else {
-            // TODO: Make work with a CDMA device with a RUIM card.
+        if (mIccCardStatus == null) {
             return false;
+        } else {
+            // Returns ICC card status for both GSM and CDMA mode
+            return mIccCardStatus.getCardState().isCardPresent();
         }
     }
 
diff --git a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
index 48257cc..2f22d74 100644
--- a/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
+++ b/telephony/java/com/android/internal/telephony/IccPhoneBookInterfaceManager.java
@@ -144,6 +144,9 @@
         if (DBG) logd("updateAdnRecordsInEfBySearch: efid=" + efid +
                 " ("+ oldTag + "," + oldPhoneNumber + ")"+ "==>" +
                 " ("+ newTag + "," + newPhoneNumber + ")"+ " pin2=" + pin2);
+
+        efid = updateEfForIccType(efid);
+
         synchronized(mLock) {
             checkThread();
             success = false;
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 2833d56..d79a89e 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -3406,6 +3406,8 @@
         RILRequest rr = RILRequest.obtain(
                 RILConstants.RIL_REQUEST_QUERY_TTY_MODE, response);
 
+        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
+
         send(rr);
     }
 
@@ -3419,6 +3421,9 @@
         rr.mp.writeInt(1);
         rr.mp.writeInt(ttyMode);
 
+        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest)
+                + " : " + ttyMode);
+
         send(rr);
     }
 
diff --git a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
index d99a348..30f38bd 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
@@ -560,6 +560,13 @@
                 break;
             case EVENT_GET_CPHS_MAILBOX_DONE:
             case EVENT_GET_MBDN_DONE:
+                //Resetting the voice mail number and voice mail tag to null
+                //as these should be updated from the data read from EF_MBDN.
+                //If they are not reset, incase of invalid data/exception these
+                //variables are retaining their previous values and are
+                //causing invalid voice mailbox info display to user.
+                voiceMailNum = null;
+                voiceMailTag = null;
                 isRecordLoadResponse = true;
 
                 ar = (AsyncResult)msg.obj;
diff --git a/telephony/java/com/android/internal/telephony/gsm/UsimPhoneBookManager.java b/telephony/java/com/android/internal/telephony/gsm/UsimPhoneBookManager.java
old mode 100644
new mode 100755
index 41e527c..b642541
--- a/telephony/java/com/android/internal/telephony/gsm/UsimPhoneBookManager.java
+++ b/telephony/java/com/android/internal/telephony/gsm/UsimPhoneBookManager.java
@@ -53,6 +53,7 @@
     private ArrayList<byte[]> mIapFileRecord;
     private ArrayList<byte[]> mEmailFileRecord;
     private Map<Integer, ArrayList<String>> mEmailsForAdnRec;
+    private boolean mRefreshCache = false;
 
     private static final int EVENT_PBR_LOAD_DONE = 1;
     private static final int EVENT_USIM_ADN_LOAD_DONE = 2;
@@ -91,11 +92,19 @@
         mEmailFileRecord = null;
         mPbrFile = null;
         mIsPbrPresent = true;
+        mRefreshCache = false;
     }
 
     public ArrayList<AdnRecord> loadEfFilesFromUsim() {
         synchronized (mLock) {
-            if (!mPhoneBookRecords.isEmpty()) return mPhoneBookRecords;
+            if (!mPhoneBookRecords.isEmpty()) {
+                if (mRefreshCache) {
+                    mRefreshCache = false;
+                    refreshCache();
+                }
+                return mPhoneBookRecords;
+            }
+
             if (!mIsPbrPresent) return null;
 
             // Check if the PBR file is present in the cache, if not read it
@@ -116,6 +125,20 @@
         return mPhoneBookRecords;
     }
 
+    private void refreshCache() {
+        if (mPbrFile == null) return;
+        mPhoneBookRecords.clear();
+
+        int numRecs = mPbrFile.mFileIds.size();
+        for (int i = 0; i < numRecs; i++) {
+            readAdnFileAndWait(i);
+        }
+    }
+
+    public void invalidateCache() {
+        mRefreshCache = true;
+    }
+
     private void readPbrFileAndWait() {
         mPhone.getIccFileHandler().loadEFLinearFixedAll(EF_PBR, obtainMessage(EVENT_PBR_LOAD_DONE));
         try {