am 54323595: Merge "Support sharding cts runs across multiple devices." into honeycomb

* commit '54323595b1253ebbf3506d5ee67bf373608e8193':
  Support sharding cts runs across multiple devices.
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 60ebf63..24e9fdc 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -21,9 +21,12 @@
       android:versionName="1.0">
       
     <uses-sdk android:minSdkVersion="5"></uses-sdk>
-    
-    <uses-permission android:name="android.permission.WAKE_LOCK" />
+
     <uses-permission android:name="android.permission.RECORD_AUDIO" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    
+    <!-- Needed by the Audio Quality Verifier to store the sound samples that will be mailed. -->
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
     <application android:label="@string/app_name">
 
@@ -58,7 +61,7 @@
         </activity>
 
         <activity android:name=".sensors.AccelerometerTestActivity" android:label="@string/snsr_accel_test"
-        android:screenOrientation="nosensor">
+                android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -67,7 +70,7 @@
         </activity>
 
         <activity android:name=".sensors.MagnetometerTestActivity" android:label="@string/snsr_mag_test"
-        android:screenOrientation="nosensor">
+                android:screenOrientation="nosensor">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -76,8 +79,7 @@
         </activity>
 
       <activity android:name=".audioquality.AudioQualityVerifierActivity"
-                android:label="@string/aq_verifier"
-                android:screenOrientation="portrait">
+              android:label="@string/aq_verifier">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.cts.intent.category.MANUAL_TEST" />
diff --git a/apps/CtsVerifier/res/layout/aq_verifier_activity.xml b/apps/CtsVerifier/res/layout/aq_verifier_activity.xml
index 12703ee..3961e92 100644
--- a/apps/CtsVerifier/res/layout/aq_verifier_activity.xml
+++ b/apps/CtsVerifier/res/layout/aq_verifier_activity.xml
@@ -41,8 +41,9 @@
     </FrameLayout>
 
     <LinearLayout
+        android:gravity="center_horizontal"
         android:orientation="horizontal"
-        android:layout_width="fill_parent"
+        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="10px"
         android:layout_marginBottom="10px"
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioAssets.java b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioAssets.java
index 9725a4c..7b7d427 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioAssets.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/AudioAssets.java
@@ -34,7 +34,7 @@
     }
 
     public static byte[] getPinkNoise(Context context, int ampl, int duration) {
-        return readAsset(context, "pink_" + ampl + "_" + duration + "s");
+        return readAsset(context, "audioquality/pink_" + ampl + "_" + duration + "s");
     }
 
     private static byte[] readAsset(Context context, String filename) {
@@ -43,7 +43,7 @@
         try {
             ais = assetManager.open(filename);
         } catch (IOException e) {
-            Log.e(TAG, "Cannot load asset " + filename);
+            Log.e(TAG, "Cannot load asset " + filename, e);
             return null;
         }
         byte[] buffer = Utils.readFile(ais);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/Utils.java b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/Utils.java
index 885e18c..5774782 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/Utils.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audioquality/Utils.java
@@ -234,7 +234,7 @@
             fos.write(data);
             fos.close();
         } catch (IOException e) {
-            Log.e(TAG, "Error writing to file " + filename);
+            Log.e(TAG, "Error writing to file " + filename, e);
         }
     }
 
diff --git a/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java b/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
index 63a65e4..1723077 100644
--- a/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
+++ b/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
@@ -408,13 +408,11 @@
         // Dispose of activity.
         ReceiveUriActivity.finishCurInstanceSync();
 
-        if (false) {
-            synchronized (this) {
-                Log.i("**", "******************************* WAITING!!!");
-                try {
-                    wait(10000);
-                } catch (InterruptedException e) {
-                }
+        synchronized (this) {
+            Log.i("**", "******************************* WAITING!!!");
+            try {
+                wait(100);
+            } catch (InterruptedException e) {
             }
         }
 
@@ -495,13 +493,11 @@
         // Dispose of activity.
         ReceiveUriActivity.finishCurInstanceSync();
 
-        if (false) {
-            synchronized (this) {
-                Log.i("**", "******************************* WAITING!!!");
-                try {
-                    wait(10000);
-                } catch (InterruptedException e) {
-                }
+        synchronized (this) {
+            Log.i("**", "******************************* WAITING!!!");
+            try {
+                wait(100);
+            } catch (InterruptedException e) {
             }
         }
 
diff --git a/tests/src/android/text/format/cts/LocaleUtils.java b/tests/src/android/text/format/cts/LocaleUtils.java
index d6001c4..131d745 100644
--- a/tests/src/android/text/format/cts/LocaleUtils.java
+++ b/tests/src/android/text/format/cts/LocaleUtils.java
@@ -22,14 +22,10 @@
 
 public class LocaleUtils {
 
-    /** Return whether or not the specified locale is available on the system. */
-    public static boolean isSupportedLocale(Context context, Locale locale) {
-        String[] locales = context.getAssets().getLocales();
-        for (String availableLocale : locales) {
-            if (locale.toString().equals(availableLocale)) {
-                return true;
-            }
-        }
-        return false;
+    /** Return whether or not the given locale is the device's current locale. */
+    public static boolean isCurrentLocale(Context context, Locale locale) {
+        // TODO: Change the locale on the device using public API if it becomes available.
+        Locale currentLocale = context.getResources().getConfiguration().locale;
+        return locale.equals(currentLocale);
     }
 }
diff --git a/tests/tests/app/src/android/app/cts/AlarmManagerTest.java b/tests/tests/app/src/android/app/cts/AlarmManagerTest.java
index dc2ff92..7c03a75 100644
--- a/tests/tests/app/src/android/app/cts/AlarmManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/AlarmManagerTest.java
@@ -16,28 +16,19 @@
 
 package android.app.cts;
 
-import java.util.TimeZone;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.ToBeFixed;
 
 import android.app.AlarmManager;
 import android.app.PendingIntent;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.os.IBinder;
 import android.os.SystemClock;
-import android.app.cts.ISecondary;
 import android.test.AndroidTestCase;
 
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestStatus;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.ToBeFixed;
-
 @TestTargetClass(AlarmManager.class)
 public class AlarmManagerTest extends AndroidTestCase {
     private AlarmManager mAlarmManager;
@@ -52,11 +43,8 @@
     private long mWakeupTime;
     private MockAlarmReceiver mMockAlarmReceiver;
 
-    private Sync mSync;
-
     private final int TIME_DELTA = 200;
     private final int TIME_DELAY = 2000;
-    private ISecondary mSecondaryService = null;
 
     class Sync {
         public boolean mIsConnected;
@@ -83,79 +71,6 @@
     }
 
     @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "setTimeZone",
-        args = {java.lang.String.class}
-    )
-    @BrokenTest("Broken by CL148448. Default timezone of the test and the service differ.")
-    public void testSetTimeZone() throws Exception {
-        mSync = new Sync();
-        final String ACTION = "android.app.REMOTESERVICE";
-        mServiceIntent = new Intent(ACTION);
-        mContext.startService(mServiceIntent);
-        mContext.bindService(new Intent(ISecondary.class.getName()), mSecondaryConnection,
-                Context.BIND_AUTO_CREATE);
-
-        synchronized (mSync) {
-            if (!mSync.mIsConnected) {
-                mSync.wait();
-            }
-        }
-        final TimeZone currentZone = TimeZone.getDefault();
-
-        // test timeZone is null, timeZone won't be set
-        String timeZone = null;
-        mAlarmManager.setTimeZone(timeZone);
-        TimeZone values = TimeZone.getDefault();
-        assertEquals(currentZone.getID(), values.getID());
-        // test another process's timezone
-
-        assertEquals(currentZone.getID(), mSecondaryService.getTimeZoneID());
-
-        // nothing in timZone, timeZone won't be set
-        timeZone = "";
-        mAlarmManager.setTimeZone(timeZone);
-        values = TimeZone.getDefault();
-        assertEquals(currentZone.getID(), values.getID());
-        // test timeZone as different time zone
-        String[] timeZones = TimeZone.getAvailableIDs();
-        // set different time zone
-        timeZone = currentZone.getID().equals(timeZones[0]) ? timeZones[1] : timeZones[0];
-        mAlarmManager.setTimeZone(timeZone);
-        Thread.sleep(TIME_DELAY);
-        values = TimeZone.getDefault();
-        TimeZone zone = TimeZone.getTimeZone(timeZone);
-        assertEquals(zone.getID(), values.getID());
-
-        // test another process's timezone
-        assertEquals(zone.getID(), mSecondaryService.getTimeZoneID());
-
-        // set time zone as origin time zone
-        TimeZone.setDefault(currentZone);
-
-        mContext.stopService(mServiceIntent);
-        mServiceIntent = null;
-    }
-
-    private ServiceConnection mSecondaryConnection = new ServiceConnection() {
-        public void onServiceConnected(ComponentName className, IBinder service) {
-            mSecondaryService = ISecondary.Stub.asInterface(service);
-            synchronized (mSync) {
-                mSync.mIsConnected = true;
-                mSync.notify();
-            }
-        }
-
-        public void onServiceDisconnected(ComponentName className) {
-            mSecondaryService = null;
-            synchronized (mSync) {
-                mSync.mIsDisConnected = true;
-                mSync.notify();
-            }
-        }
-    };
-
-    @TestTargetNew(
         level = TestLevel.PARTIAL,
         method = "set",
         args = {int.class, long.class, android.app.PendingIntent.class}
@@ -216,7 +131,7 @@
         Thread.sleep(TIME_DELAY);
         assertTrue(mMockAlarmReceiver.alarmed);
     }
-    
+
     @TestTargetNew(
         level = TestLevel.PARTIAL,
         method = "setRepeating",
diff --git a/tests/tests/content/src/android/content/cts/ContextWrapperTest.java b/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
index ac402ef..65bdc47 100644
--- a/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
+++ b/tests/tests/content/src/android/content/cts/ContextWrapperTest.java
@@ -18,7 +18,6 @@
 
 import com.android.cts.stub.R;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -247,7 +246,6 @@
             args = {int.class}
         )
     })
-    @BrokenTest("needs investigation")
     public void testAccessTheme() {
         mContextWrapper.setTheme(R.style.Test_Theme);
         final Theme testTheme = mContextWrapper.getTheme();
@@ -258,11 +256,18 @@
             android.R.attr.panelColorForeground,
             android.R.attr.panelColorBackground
         };
-        TypedArray attrArray = testTheme.obtainStyledAttributes(attrs);
-
-        assertTrue(attrArray.getBoolean(0, false));
-        assertEquals(0xff000000, attrArray.getColor(1, 0));
-        assertEquals(0xffffffff, attrArray.getColor(2, 0));
+        TypedArray attrArray = null;
+        try {
+            attrArray = testTheme.obtainStyledAttributes(attrs);
+            assertTrue(attrArray.getBoolean(0, false));
+            assertEquals(0xff000000, attrArray.getColor(1, 0));
+            assertEquals(0xffffffff, attrArray.getColor(2, 0));
+        } finally {
+            if (attrArray != null) {
+                attrArray.recycle();
+                attrArray = null;
+            }
+        }
 
         // setTheme only works for the first time
         mContextWrapper.setTheme(android.R.style.Theme_Black);
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
index f038c4b..cb420a6 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
@@ -17,235 +17,35 @@
 package android.dpi.cts;
 
 import android.content.Context;
-import android.content.res.Configuration;
 import android.test.AndroidTestCase;
+import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.WindowManager;
-import android.util.DisplayMetrics;
-
-import java.lang.Integer;
-import java.util.EnumSet;
 
 /**
- * This is verifying that the device under test is running a supported
- * resolution, and is being classified as the right Screen Layout
- * Size.
+ * Test for verifying a device's screen configuration.
  */
 public class ConfigurationTest extends AndroidTestCase {
 
-    private enum Density {
-        // It is important to keep these sorted
-        INVALID_LOW(Integer.MIN_VALUE, 99),
-        LOW (100, 140),
-        MEDIUM (141, 190),
-        HIGH (191, 250),
-        INVALID_HIGH(251, Integer.MAX_VALUE);
+    public void testScreenConfiguration() {
+        WindowManager windowManager =
+            (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
+        Display display = windowManager.getDefaultDisplay();
+        DisplayMetrics metrics = new DisplayMetrics();
+        display.getMetrics(metrics);
 
-        private int low;
-        private int high;
+        double xInches = (double) metrics.widthPixels / metrics.xdpi;
+        double yInches = (double) metrics.heightPixels / metrics.ydpi;
+        double diagonalInches = Math.sqrt(Math.pow(xInches, 2) + Math.pow(yInches, 2));
+        assertTrue("Screen diagonal must be at least 2.5 inches: " + diagonalInches,
+                diagonalInches >= 2.5d);
 
-        Density(int low, int high) {
-            this.low = low;
-            this.high = high;
-        }
+        double density = 160.0d * metrics.density;
+        assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d);
 
-        public static Density findDensity(int value) {
-            Density density = INVALID_LOW;
-            for (Density d : EnumSet.range(Density.INVALID_LOW, Density.INVALID_HIGH)) {
-                if (value >= d.low && value <= d.high) {
-                    density = d;
-                    break;
-                }
-            }
-            return density;
-        }
-    };
-
-    /**
-     * Holds information on the current active screen's configuration.
-     */
-    private static class ActiveScreenConfiguration {
-        private final int width;
-        private final int height;
-        private final Density density;
-
-        /**
-         * Create a new ActiveScreenConfiguration.
-         *
-         * @param width the width of the screen
-         * @param height the height of the screen
-         * @param density the scaling factor for DIP from standard
-         * density (160.0)
-         */
-        public ActiveScreenConfiguration(int width,
-                                         int height,
-                                         float density) {
-            // 160 DIP is the "standard" density
-            this(width, height, Density.findDensity((int) (160.0f * density)));
-        }
-
-        protected ActiveScreenConfiguration(int width,
-                                            int height,
-                                            Density density) {
-            this.width = width;
-            this.height = height;
-            this.density = density;
-        }
-
-        public Density getDensity() {
-            return density;
-        }
-
-        public int getWidth() {
-            return width;
-        }
-
-        public int getHeight() {
-            return height;
-        }
-    }
-
-    private static class ScreenConfiguration extends ActiveScreenConfiguration {
-        private final int screenLayout;
-        private final boolean isWide;
-
-        public ScreenConfiguration(int width,
-                                   int height,
-                                   Density density,
-                                   int screenLayout,
-                                   boolean isWide) {
-            super(width, height, density);
-            this.screenLayout = screenLayout;
-            this.isWide = isWide;
-        }
-
-        public ScreenConfiguration(int width,
-                                   int height,
-                                   Density density,
-                                   int screenLayout) {
-            this(width, height, density, screenLayout, false);
-        }
-
-        public int getScreenLayout() {
-            return screenLayout;
-        }
-
-        public boolean isWide() {
-            return isWide;
-        }
-    };
-
-    private static boolean areConfigsEqual(ActiveScreenConfiguration active,
-                                           ScreenConfiguration screenConfig) {
-        if (screenConfig.isWide()) {
-            // For widescreen configs, the height is fixed but the
-            // width only specifies a minimum.  But since the device
-            // can be both landscape and portrait, we have to search
-            // for which way it is.
-            if (active.getHeight() == screenConfig.getHeight()) {
-                // active height matches config height.  Make sure
-                // that the active width is at least the config width.
-                return active.getWidth() >= screenConfig.getWidth();
-            } else if (active.getWidth() == screenConfig.getHeight()) {
-                // directions are swapped
-                return active.getHeight() >= screenConfig.getWidth();
-            } else {
-                return false;
-            }
-        } else {
-            if (active.getWidth() == screenConfig.getWidth() &&
-                active.getHeight() == screenConfig.getHeight() &&
-                active.getDensity().equals(screenConfig.getDensity())) {
-                return true;
-            }
-            // It is also possible that the device is in landscape
-            // mode, which flips the active w/h.
-            if (active.getHeight() == screenConfig.getWidth() &&
-                active.getWidth() == screenConfig.getHeight() &&
-                active.getDensity().equals(screenConfig.getDensity())) {
-                return true;
-            }
-            // nope.
-            return false;
-        }
-    }
-
-    /**
-     * Here's the current configuration table:
-     *
-     * Resoluion | Density          | Size
-     * QVGA      | low (100-140)    | small
-     * WQVGA     | low (100-140)    | normal
-     * HVGA      | medium (141-190) | normal
-     * WVGA      | high (191-250)   | normal
-     * FWVGA     | high (191-250)   | normal
-     * WSVGA     | high (191-250)   | large
-
-     * VGA       | medium (141-190) | large
-     * WVGA      | medium (141-190) | large
-     * FWVGA     | medium (141-190) | large
-     *
-     * Any changes to allow additional resolutions will need to update this table
-     */
-
-    private static final ScreenConfiguration[] SUPPORTED_SCREEN_CONFIGS = {
-        // QVGA      | low (100-140)    | small
-        new ScreenConfiguration(240, 320, Density.LOW, Configuration.SCREENLAYOUT_SIZE_SMALL),
-        // WQVGA     | low (100-140)    | normal
-        new ScreenConfiguration(240, 320, Density.LOW, Configuration.SCREENLAYOUT_SIZE_SMALL, true),
-        // HVGA      | medium (141-190) | normal
-        new ScreenConfiguration(480, 320, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_NORMAL),
-        new ScreenConfiguration(640, 240, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_NORMAL),
-        // WVGA      | high (191-250)   | normal
-        new ScreenConfiguration(640, 480, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_NORMAL, true),
-        // FWVGA     | high (191-250)   | normal
-        new ScreenConfiguration(864, 480, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_NORMAL),
-        // WSVGA     | high (191-250)   | large
-        new ScreenConfiguration(1024, 600, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_LARGE),
-
-        // VGA       | medium (141-190) | large
-        new ScreenConfiguration(640, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE),
-        // WVGA      | medium (141-190) | large
-        new ScreenConfiguration(640, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE, true),
-        // FWVGA     | medium (141-190) | large
-        new ScreenConfiguration(864, 480, Density.MEDIUM, Configuration.SCREENLAYOUT_SIZE_LARGE),
-
-    };
-
-    private ActiveScreenConfiguration getCurrentScreenConfig() {
-        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
-        Display display = wm.getDefaultDisplay();
-        DisplayMetrics dm = new DisplayMetrics();
-        display.getMetrics(dm);
-        return new ActiveScreenConfiguration(display.getWidth(),
-                                             display.getHeight(),
-                                             dm.density);
-    }
-
-    /**
-     * Get the current screen configuration, make sure it is a
-     * supported screen configuration and that the screenlayout size
-     * is being set correctly according to the compatibility
-     * definition.
-     */
-    public void testScreenLayoutSize() {
-        ActiveScreenConfiguration currentScreenConfig = getCurrentScreenConfig();
-        // Make sure we have a valid density for the current screent.
-        assertFalse(Density.INVALID_LOW.equals(currentScreenConfig.getDensity()));
-        assertFalse(Density.INVALID_HIGH.equals(currentScreenConfig.getDensity()));
-
-        // Look up the ScreenConfig in the supported table and make
-        // sure we find a match.
-        for (ScreenConfiguration screenConfig: SUPPORTED_SCREEN_CONFIGS) {
-            if (areConfigsEqual(currentScreenConfig, screenConfig)) {
-                Configuration config = getContext().getResources().getConfiguration();
-                int size = config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
-                if (screenConfig.getScreenLayout() == size) {
-                    // we have a match, this is a supported device.
-                    return;
-                }
-            }
-        }
-        fail("Current screen configuration is not supported.");
+        double aspectRatio = (double) Math.max(metrics.widthPixels, metrics.heightPixels)
+                / (double) Math.min(metrics.widthPixels, metrics.heightPixels);
+        assertTrue("Aspect ratio must be between 1.333 (4:3) and 1.779 (16:9): " + aspectRatio,
+                aspectRatio >= 1.333d && aspectRatio <= 1.779d);
     }
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index 944de6c..6a13ab2 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -410,6 +410,13 @@
             waitForPreviewDone();
             assertTrue(mPreviewCallbackResult);
             mCamera.stopPreview();
+            try {
+                // Wait for a while to throw away the remaining preview frames.
+                Thread.sleep(1000);
+            } catch(Exception e) {
+                // ignore
+            }
+            mPreviewDone.close();
         }
         terminateMessageLooper();
     }
diff --git a/tests/tests/media/src/android/media/cts/AudioManagerTest.java b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
index b4b8da4..4b68540 100644
--- a/tests/tests/media/src/android/media/cts/AudioManagerTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioManagerTest.java
@@ -39,7 +39,6 @@
 
 import com.android.cts.stub.R;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -48,7 +47,6 @@
 
 import android.app.cts.CTSResult;
 import android.content.Context;
-import android.content.Intent;
 import android.media.AudioManager;
 import android.media.MediaPlayer;
 import android.provider.Settings;
@@ -88,32 +86,6 @@
     @TestTargets({
         @TestTargetNew(
             level = TestLevel.COMPLETE,
-            method = "setStreamMute",
-            args = {int.class, boolean.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "setStreamSolo",
-            args = {int.class, boolean.class}
-        )
-    })
-    @BrokenTest("flaky")
-    public void testMuteSolo() throws Exception {
-        /**
-         * this test must be run on screen unlocked model
-         */
-        AudioManagerStub.setCTSResult(this);
-        Intent intent = new Intent();
-        intent.setClass(mContext, AudioManagerStub.class);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        mContext.startActivity(intent);
-        mSync.waitForResult();
-        assertEquals(CTSResult.RESULT_OK, mResultCode);
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
             method = "setMicrophoneMute",
             args = {boolean.class}
         ),
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index db9c5be..a9e1c33 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -15,7 +15,6 @@
  */
 package android.media.cts;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -27,6 +26,7 @@
 import android.media.MediaRecorder.OnInfoListener;
 import android.os.Environment;
 import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
 import android.view.Surface;
 
 import java.io.File;
@@ -89,6 +89,7 @@
         }
         if (mCamera != null)  {
             mCamera.release();
+            mCamera = null;
         }
         super.tearDown();
     }
@@ -159,10 +160,10 @@
         method = "setCamera",
         args = {Camera.class}
     )
-    @BrokenTest(value="No longer works in Donut. CameraService reports: " +
-            "Attempt to use locked camera from different process")
+    @UiThreadTest
     public void testSetCamera() throws Exception {
         mCamera = Camera.open();
+        mCamera.unlock();
         mMediaRecorder.setCamera(mCamera);
         mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
diff --git a/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
index 258ac4d..f125550 100644
--- a/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
+++ b/tests/tests/net/src/android/net/cts/SSLCertificateSocketFactoryTest.java
@@ -102,11 +102,10 @@
             args = {int.class}
         )
     })
-    @BrokenTest("flaky")
     public void testCreateSocket() throws Exception {
         new SSLCertificateSocketFactory(100);
         int port = 443;
-        String host = "www.fortify.net";
+        String host = "www.google.com";
         InetAddress inetAddress = null;
         inetAddress = InetAddress.getLocalHost();
         try {
diff --git a/tests/tests/os/src/android/os/cts/MessageQueueTest.java b/tests/tests/os/src/android/os/cts/MessageQueueTest.java
index 95441ae..c7b549a 100644
--- a/tests/tests/os/src/android/os/cts/MessageQueueTest.java
+++ b/tests/tests/os/src/android/os/cts/MessageQueueTest.java
@@ -16,10 +16,7 @@
 
 package android.os.cts;
 
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
 
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -30,77 +27,92 @@
 import android.os.MessageQueue.IdleHandler;
 import android.test.AndroidTestCase;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
 @TestTargetClass(MessageQueue.class)
 public class MessageQueueTest extends AndroidTestCase {
 
-    private boolean mResult;
-    // Action flag: true means addIdleHanlder, false means removeIdleHanlder
-    private boolean mActionFlag;
     private static final long TIMEOUT = 1000;
-    private static final long INTERVAL = 50;
-    private IdleHandler mIdleHandler = new IdleHandler() {
-        public boolean queueIdle() {
-            MessageQueueTest.this.mResult = true;
-            return true;
-        }
-    };
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mResult = false;
-    }
+    public void testAddIdleHandler() throws InterruptedException {
+        TestLooperThread looperThread = new TestLooperThread(Test.ADD_IDLE_HANDLER);
+        looperThread.start();
 
-    /**
-     * After calling addIdleHandler (called by MessageQueueTestHelper#doTest), the size of
-     * idleHanlder list is not 0 (before calling addIdleHandler, there is no idleHanlder in
-     * the test looper we started, that means no idleHanlder with flag mResult), and in doTest,
-     * we start a looper, which will queueIdle (Looper.loop()) if idleHanlder list has element,
-     * then mResult will be set true. It can make sure addIdleHandler works. If no idleHanlder
-     * with flag mResult, mResult will be false.
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "addIdleHandler",
-        args = {android.os.MessageQueue.IdleHandler.class}
-    )
-    @BrokenTest("needs investigation")
-    public void testAddIdleHandler() throws RuntimeException, InterruptedException {
         try {
-            Looper.myQueue().addIdleHandler(null);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // expected
+            if (!looperThread.hasIdleHandlerBeenCalled()) {
+                fail("IdleHandler#queueIdle was NOT called: " + looperThread.getTestProgress());
+            }
+        } finally {
+            assertTrue("The looper should have been running.", looperThread.quit());
         }
-        // If mActionFlag is true, doTest will call addIdleHandler
-        mActionFlag = true;
-        mResult = false;
-        MessageQueueTestHelper tester = new MessageQueueTestHelper();
-        tester.doTest(TIMEOUT, INTERVAL);
-
-        tester.quit();
-        assertTrue(mResult);
     }
 
-    /**
-     * In this test method, at the beginning of the LooperThread, we call addIdleHandler then
-     * removeIdleHandler, there should be no element in idleHanlder list. So the Looper.loop()
-     * will not call queueIdle(), mResult will not be set true.
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "removeIdleHandler",
-        args = {android.os.MessageQueue.IdleHandler.class}
-    )
-    @BrokenTest("needs investigation")
-    public void testRemoveIdleHandler() throws RuntimeException, InterruptedException {
-        mActionFlag = false;
-        mResult = false;
-        MessageQueueTestHelper tester = new MessageQueueTestHelper();
-        tester.doTest(TIMEOUT, INTERVAL);
+    public void testRemoveIdleHandler() throws InterruptedException {
+        TestLooperThread looperThread = new TestLooperThread(Test.REMOVE_IDLE_HANDLER);
+        looperThread.start();
 
-        tester.quit();
-        assertFalse(mResult);
+        try {
+            if (looperThread.hasIdleHandlerBeenCalled()) {
+                fail("IdleHandler#queueIdle was called: " + looperThread.getTestProgress());
+            }
+        } finally {
+            assertTrue("The looper should have been running.", looperThread.quit());
+        }
+    }
+
+    private enum Test {ADD_IDLE_HANDLER, REMOVE_IDLE_HANDLER};
+
+    /**
+     * {@link HandlerThread} that adds or removes an idle handler depending on the {@link Test}
+     * given. It uses a {@link CountDownLatch} with an initial count of 2. The first count down
+     * occurs right before the looper's run thread had started running. The final count down
+     * occurs when the idle handler was executed. Tests can call {@link #hasIdleHandlerBeenCalled()}
+     * to see if the countdown reached to 0 or not.
+     */
+    private static class TestLooperThread extends HandlerThread {
+
+        private final Test mTestMode;
+
+        private final CountDownLatch mIdleLatch = new CountDownLatch(2);
+
+        TestLooperThread(Test testMode) {
+            super("TestLooperThread");
+            mTestMode = testMode;
+        }
+
+        @Override
+        protected void onLooperPrepared() {
+            super.onLooperPrepared();
+
+            IdleHandler idleHandler = new IdleHandler() {
+                public boolean queueIdle() {
+                    mIdleLatch.countDown();
+                    return false;
+                }
+            };
+
+            if (mTestMode == Test.ADD_IDLE_HANDLER) {
+                Looper.myQueue().addIdleHandler(idleHandler);
+            } else {
+                Looper.myQueue().addIdleHandler(idleHandler);
+                Looper.myQueue().removeIdleHandler(idleHandler);
+            }
+        }
+
+        @Override
+        public void run() {
+            mIdleLatch.countDown();
+            super.run();
+        }
+
+        public boolean hasIdleHandlerBeenCalled() throws InterruptedException {
+            return mIdleLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
+        }
+
+        public long getTestProgress() {
+            return mIdleLatch.getCount();
+        }
     }
 
     /**
@@ -155,68 +167,6 @@
     }
 
     /**
-     * Helper class used to test addIdleHandler, removeIdleHandler
-     */
-    private class MessageQueueTestHelper {
-
-        private boolean mDone;
-        private Looper mLooper;
-
-        public void doTest(long timeout, long interval) throws InterruptedException {
-            (new LooperThread()).start();
-            synchronized (this) {
-                long now = System.currentTimeMillis();
-                long endTime = now + timeout;
-                // Wait and frequently check if mDone is set.
-                while (!mDone && now < endTime) {
-                    wait(interval);
-                    now = System.currentTimeMillis();
-                }
-            }
-            mLooper.quit();
-            if (!mDone) {
-                throw new RuntimeException("test timed out");
-            }
-        }
-
-        private class LooperThread extends HandlerThread {
-            public LooperThread() {
-                super("MessengeQueueLooperThread");
-            }
-
-            public void onLooperPrepared() {
-                mLooper = getLooper();
-                if (mActionFlag) {
-                    // If mActionFlag is true, just addIdleHandler, and
-                    // Looper.loop() will set mResult true.
-                    Looper.myQueue().addIdleHandler(mIdleHandler);
-                } else {
-                    // If mActionFlag is false, addIdleHandler and remove it, then Looper.loop()
-                    // will not set mResult true because the idleHandler list is empty.
-                    Looper.myQueue().addIdleHandler(mIdleHandler);
-                    Looper.myQueue().removeIdleHandler(mIdleHandler);
-                }
-            }
-
-            @Override
-            public void run() {
-                super.run();
-                synchronized (MessageQueueTestHelper.this) {
-                    mDone = true;
-                    MessageQueueTestHelper.this.notifyAll();
-                }
-            }
-        }
-
-        public void quit() {
-            synchronized (this) {
-                mDone = true;
-                notifyAll();
-            }
-        }
-    }
-
-    /**
      * Helper class used to test sending message to message queue.
      */
     private class OrderTestHelper {
diff --git a/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java
index 1e12455..fab9cf6 100644
--- a/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/NoActivityRelatedPermissionTest.java
@@ -16,7 +16,6 @@
 
 package android.permission.cts;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestTargetClass;
 
 import android.app.Activity;
diff --git a/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java
deleted file mode 100644
index 6e86967..0000000
--- a/tests/tests/permission/src/android/permission/cts/NoCallPermissionTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.permission.cts;
-
-import android.content.Intent;
-import android.net.Uri;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.SmallTest;
-
-/**
- * Verify Phone calling related methods without specific Phone/Call permissions.
- */
-public class NoCallPermissionTest extends AndroidTestCase {
-
-    /**
-     * Verify that Intent.ACTION_CALL requires permissions.
-     * <p>Requires Permission:
-     *   {@link android.Manifest.permission#CALL_PHONE}.
-     */
-    @SmallTest
-    public void testActionCall() {
-        Uri uri = Uri.parse("tel:123456");
-        Intent intent = new Intent(Intent.ACTION_CALL, uri);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        try {
-            mContext.startActivity(intent);
-            fail("startActivity(Intent.ACTION_CALL) did not throw SecurityException as expected");
-        } catch (SecurityException e) {
-            // expected
-        }
-    }
-
-    /**
-     * Verify that Intent.ACTION_CALL_PRIVILEGED requires permissions.
-     * <p>Requires Permission:
-     *   {@link android.Manifest.permission#CALL_PRIVILEGED}.
-     */
-    @SmallTest
-    public void testCallVoicemail() {
-        try {
-            //Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED,
-            Intent intent = new Intent("android.intent.action.CALL_PRIVILEGED",
-                    Uri.fromParts("voicemail", "", null));
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            mContext.startActivity(intent);
-            fail("startActivity(Intent.ACTION_CALL_PRIVILEGED) did not throw SecurityException as expected");
-        } catch (SecurityException e) {
-            // expected
-        }
-    }
-
-    /**
-     * Verify that Intent.ACTION_CALL_PRIVILEGED requires permissions.
-     * <p>Requires Permission:
-     *   {@link android.Manifest.permission#CALL_PRIVILEGED}.
-     */
-    @SmallTest
-    public void testCall911() {
-        //Intent intent = new Intent(Intent.ACTION_CALL_PRIVILEGED, Uri.parse("tel:911"));
-        Intent intent = new Intent("android.intent.action.CALL_PRIVILEGED", Uri.parse("tel:911"));
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        try {
-            mContext.startActivity(intent);
-            fail("startActivity(Intent.ACTION_CALL_PRIVILEGED) did not throw SecurityException as expected");
-        } catch (SecurityException e) {
-            // expected
-        }
-    }
-
-}
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsTest.java b/tests/tests/provider/src/android/provider/cts/ContactsTest.java
index 2b0786c..fa1e431 100644
--- a/tests/tests/provider/src/android/provider/cts/ContactsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/ContactsTest.java
@@ -16,18 +16,14 @@
 
 package android.provider.cts;
 
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
+
 import dalvik.annotation.TestTargetClass;
 
 import android.content.ContentResolver;
-import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.IContentProvider;
 import android.database.Cursor;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
 import android.os.RemoteException;
@@ -48,7 +44,6 @@
 import android.telephony.PhoneNumberUtils;
 import android.test.InstrumentationTestCase;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
@@ -153,29 +148,17 @@
      * Test case for the behavior of the ContactsProvider's groups table
      * It does not test any APIs in android.provider.Contacts.java
      */
-    @BrokenTest("Throws NPE in call to update(). uri parameter null?")
     public void testGroupsTable() {
         final String[] GROUPS_PROJECTION = new String[] {
-                Groups._ID, Groups.NAME, Groups.NOTES, Groups.SHOULD_SYNC,
-                Groups.SYSTEM_ID, Groups._SYNC_ACCOUNT, Groups._SYNC_ACCOUNT_TYPE, Groups._SYNC_ID,
-                Groups._SYNC_TIME, Groups._SYNC_VERSION, Groups._SYNC_LOCAL_ID,
-                Groups._SYNC_DIRTY};
+                Groups._ID, Groups.NAME, Groups.NOTES,
+                Groups.SYSTEM_ID};
         final int ID_INDEX = 0;
         final int NAME_INDEX = 1;
         final int NOTES_INDEX = 2;
-        final int SHOULD_SYNC_INDEX = 3;
-        final int SYSTEM_ID_INDEX = 4;
-        final int SYNC_ACCOUNT_NAME_INDEX = 5;
-        final int SYNC_ACCOUNT_TYPE_INDEX = 6;
-        final int SYNC_ID_INDEX = 7;
-        final int SYNC_TIME_INDEX = 8;
-        final int SYNC_VERSION_INDEX = 9;
-        final int SYNC_LOCAL_ID_INDEX = 10;
-        final int SYNC_DIRTY_INDEX = 11;
+        final int SYSTEM_ID_INDEX = 3;
 
         String insertGroupsName = "name_insert";
         String insertGroupsNotes = "notes_insert";
-        String updateGroupsName = "name_update";
         String updateGroupsNotes = "notes_update";
         String updateGroupsSystemId = "system_id_update";
 
@@ -188,40 +171,30 @@
 
             Uri uri = mProvider.insert(Groups.CONTENT_URI, value);
             Cursor cursor = mProvider.query(Groups.CONTENT_URI,
-                    GROUPS_PROJECTION, GroupsColumns.NAME + " = ?",
-                    new String[] {insertGroupsName}, null);
+                    GROUPS_PROJECTION, Groups._ID + " = ?",
+                    new String[] {uri.getPathSegments().get(1)}, null);
             assertTrue(cursor.moveToNext());
             assertEquals(insertGroupsName, cursor.getString(NAME_INDEX));
             assertEquals(insertGroupsNotes, cursor.getString(NOTES_INDEX));
-            assertEquals(0, cursor.getInt(SHOULD_SYNC_INDEX));
             assertEquals(Groups.GROUP_MY_CONTACTS, cursor.getString(SYSTEM_ID_INDEX));
-            // TODO: Figure out what can be tested for the SYNC_* columns
             int id = cursor.getInt(ID_INDEX);
             cursor.close();
 
             // Test: update
             value.clear();
-            value.put(GroupsColumns.NAME, updateGroupsName);
             value.put(GroupsColumns.NOTES, updateGroupsNotes);
             value.put(GroupsColumns.SYSTEM_ID, updateGroupsSystemId);
-            value.put(GroupsColumns.SHOULD_SYNC, 1);
 
-            mProvider.update(uri, value, null, null);
+            assertEquals(1, mProvider.update(uri, value, null, null));
             cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
                     Groups._ID + " = " + id, null, null);
             assertTrue(cursor.moveToNext());
-            assertEquals(updateGroupsName, cursor.getString(NAME_INDEX));
             assertEquals(updateGroupsNotes, cursor.getString(NOTES_INDEX));
-            assertEquals(1, cursor.getInt(SHOULD_SYNC_INDEX));
             assertEquals(updateGroupsSystemId, cursor.getString(SYSTEM_ID_INDEX));
-            // TODO: Figure out what can be tested for the SYNC_* columns
             cursor.close();
 
             // Test: delete
-            mProvider.delete(uri, null, null);
-            cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
-                    Groups._ID + " = " + id, null, null);
-            assertEquals(0, cursor.getCount());
+            assertEquals(1, mProvider.delete(uri, null, null));
         } catch (RemoteException e) {
             fail("Unexpected RemoteException");
         }
@@ -231,27 +204,17 @@
      * Test case for the behavior of the ContactsProvider's photos table
      * It does not test any APIs in android.provider.Contacts.java
      */
-    @BrokenTest("Should not test EXISTS_ON_SERVER_INDEX?")
     public void testPhotosTable() {
         final String[] PHOTOS_PROJECTION = new String[] {
                 Photos._ID, Photos.EXISTS_ON_SERVER, Photos.PERSON_ID,
-                Photos.LOCAL_VERSION, Photos.DATA, Photos._SYNC_ACCOUNT, Photos._SYNC_ACCOUNT_TYPE,
-                Photos._SYNC_ID, Photos._SYNC_TIME, Photos._SYNC_VERSION,
-                Photos._SYNC_LOCAL_ID, Photos._SYNC_DIRTY,
+                Photos.LOCAL_VERSION, Photos.DATA,
                 Photos.SYNC_ERROR};
         final int ID_INDEX = 0;
         final int EXISTS_ON_SERVER_INDEX = 1;
         final int PERSON_ID_INDEX = 2;
         final int LOCAL_VERSION_INDEX = 3;
         final int DATA_INDEX = 4;
-        final int SYNC_ACCOUNT_NAME_INDEX = 5;
-        final int SYNC_ACCOUNT_TYPE_INDEX = 6;
-        final int SYNC_ID_INDEX = 7;
-        final int SYNC_TIME_INDEX = 8;
-        final int SYNC_VERSION_INDEX = 9;
-        final int SYNC_LOCAL_ID_INDEX = 10;
-        final int SYNC_DIRTY_INDEX = 11;
-        final int SYNC_ERROR_INDEX = 12;
+        final int SYNC_ERROR_INDEX = 5;
 
         String updatePhotosLocalVersion = "local_version1";
 
@@ -275,54 +238,6 @@
             } catch (UnsupportedOperationException e) {
                 // Don't support direct insert operation to photos URI.
             }
-
-            // Insert a people to insert a row in photos table.
-            value.clear();
-            value.put(PeopleColumns.NAME, "name_photos_test_stub");
-            Uri peopleUri = mProvider.insert(People.CONTENT_URI, value);
-            int peopleId = Integer.parseInt(peopleUri.getPathSegments().get(1));
-
-            Cursor cursor = mProvider.query(Photos.CONTENT_URI,
-                    PHOTOS_PROJECTION, Photos.PERSON_ID + " = " + peopleId,
-                    null, null);
-            assertTrue(cursor.moveToNext());
-            assertEquals(0, cursor.getInt(EXISTS_ON_SERVER_INDEX));
-            assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
-            assertNull(cursor.getString(LOCAL_VERSION_INDEX));
-            assertNull(cursor.getString(DATA_INDEX));
-            // TODO: Figure out what can be tested for the SYNC_* columns
-            int id = cursor.getInt(ID_INDEX);
-            cursor.close();
-
-            // Test: update
-            value.clear();
-            value.put(Photos.LOCAL_VERSION, updatePhotosLocalVersion);
-            value.put(Photos.DATA, data);
-            value.put(Photos.EXISTS_ON_SERVER, 1);
-
-            Uri uri = ContentUris.withAppendedId(Photos.CONTENT_URI, id);
-            mProvider.update(uri, value, null, null);
-            cursor = mProvider.query(Photos.CONTENT_URI, PHOTOS_PROJECTION,
-                    Photos._ID + " = " + id, null, null);
-            assertTrue(cursor.moveToNext());
-            assertEquals(1, cursor.getInt(EXISTS_ON_SERVER_INDEX));
-            assertEquals(peopleId, cursor.getInt(PERSON_ID_INDEX));
-            assertEquals(updatePhotosLocalVersion, cursor.getString(LOCAL_VERSION_INDEX));
-            byte resultData[] = cursor.getBlob(DATA_INDEX);
-            InputStream resultInputStream = new ByteArrayInputStream(resultData);
-            Bitmap bitmap = BitmapFactory.decodeStream(resultInputStream, null, null);
-            assertEquals(sourceDrawable.getIntrinsicWidth(), bitmap.getWidth());
-            assertEquals(sourceDrawable.getIntrinsicHeight(), bitmap.getHeight());
-            // TODO: Figure out what can be tested for the SYNC_* columns
-            cursor.close();
-
-            // Test: delete
-            mProvider.delete(peopleUri, null, null);
-            cursor = mProvider.query(Photos.CONTENT_URI, PHOTOS_PROJECTION,
-                    Groups._ID + " = " + id, null, null);
-            assertEquals(0, cursor.getCount());
-
-            mProvider.delete(peopleUri, null, null);
         } catch (RemoteException e) {
             fail("Unexpected RemoteException");
         } catch (IOException e) {
diff --git a/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java b/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
index 230a541..732e75d 100644
--- a/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Contacts_PeopleTest.java
@@ -16,6 +16,11 @@
 
 package android.provider.cts;
 
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
 import android.content.ContentResolver;
 import android.content.ContentUris;
 import android.content.ContentValues;
@@ -31,12 +36,6 @@
 import android.provider.Contacts.People;
 import android.test.InstrumentationTestCase;
 
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -58,7 +57,7 @@
     private static final int PEOPLE_LAST_CONTACTED_INDEX = 1;
 
     private static final int MEMBERSHIP_PERSON_ID_INDEX = 1;
-    private static final int MEMBERSHIP_GROUP_ID_INDEX = 7;
+    private static final int MEMBERSHIP_GROUP_ID_INDEX = 5;
 
     private static final String[] GROUPS_PROJECTION = new String[] {
         Groups._ID,
@@ -146,7 +145,6 @@
             args = {android.content.ContentResolver.class, android.content.ContentValues.class}
         )
     })
-    @BrokenTest("GROUP_MY_CONTACTS does not exist")
     public void testAddToGroup() {
         Cursor cursor;
         try {
@@ -158,9 +156,8 @@
             cursor.close();
             mRowsAdded.add(People.addToMyContactsGroup(mContentResolver, personId));
             cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
-                    Groups.NAME + "='" + Groups.GROUP_MY_CONTACTS + "'", null, null);
+                    Groups.SYSTEM_ID + "='" + Groups.GROUP_MY_CONTACTS + "'", null, null);
             cursor.moveToFirst();
-            // TODO: this throws an exception because no rows were found
             int groupId = cursor.getInt(GROUPS_ID_INDEX);
             cursor.close();
             cursor = People.queryGroups(mContentResolver, personId);
@@ -183,7 +180,7 @@
             mRowsAdded.add(ContentUris.withAppendedId(People.CONTENT_URI, personId));
             cursor.close();
             cursor = mProvider.query(Groups.CONTENT_URI, GROUPS_PROJECTION,
-                    Groups.NAME + "='" + Groups.GROUP_MY_CONTACTS + "'", null, null);
+                    Groups.SYSTEM_ID + "='" + Groups.GROUP_MY_CONTACTS + "'", null, null);
             cursor.moveToFirst();
             groupId = cursor.getInt(GROUPS_ID_INDEX);
             cursor.close();
@@ -281,7 +278,7 @@
             level = TestLevel.COMPLETE,
             notes = "Test methods access the photo data of person",
             method = "loadContactPhoto",
-            args = {android.content.Context.class, android.net.Uri.class, int.class, 
+            args = {android.content.Context.class, android.net.Uri.class, int.class,
                     android.graphics.BitmapFactory.Options.class}
         ),
         @TestTargetNew(
@@ -291,7 +288,6 @@
             args = {android.content.ContentResolver.class, android.net.Uri.class}
         )
     })
-    @BrokenTest("photoStream is null after setting photo data")
     public void testAccessPhotoData() {
         Context context = getInstrumentation().getTargetContext();
         try {
@@ -308,10 +304,6 @@
             Bitmap bitmap = BitmapFactory.decodeStream(photoStream, null, null);
             assertEquals(212, bitmap.getWidth());
             assertEquals(142, bitmap.getHeight());
-            // NOTE: this data we added can't be deleted, will be garbage data.
-//            Uri photoUri = Uri.withAppendedPath(mPeopleRowsAdded.get(0),
-//                    Contacts.Photos.CONTENT_DIRECTORY);
-//            mRowsAdded.add(photoUri);
 
             photoStream = People.openContactPhotoInputStream(mContentResolver,
                     mPeopleRowsAdded.get(1));
@@ -324,8 +316,7 @@
 
             bitmap = People.loadContactPhoto(context, null,
                     com.android.cts.stub.R.drawable.size_48x48, null);
-            assertEquals(48, bitmap.getWidth());
-            assertEquals(48, bitmap.getHeight());
+            assertNotNull(bitmap);
         } catch (IOException e) {
             fail("Unexpected IOException");
         }
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
index 4c29f97..c53393f 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Audio_Playlists_MembersTest.java
@@ -16,7 +16,6 @@
 
 package android.provider.cts;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -24,7 +23,6 @@
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.database.Cursor;
-import android.database.SQLException;
 import android.net.Uri;
 import android.provider.MediaStore.Audio.Media;
 import android.provider.MediaStore.Audio.Playlists;
@@ -128,42 +126,13 @@
       method = "getContentUri",
       args = {String.class, long.class}
     )
-    @BrokenTest("brittle test")
     public void testGetContentUri() {
-        // this verification seems brittle - will break if there happens to be a playlist with Id 1
-        // present in external volume
-        // setUp should create a playlist which this method should verify can be queried
-        Cursor c = mContentResolver.query(
-                Members.getContentUri(MediaStoreAudioTestHelper.EXTERNAL_VOLUME_NAME, 1),
-                mMembersProjection, null, null, Members.DEFAULT_SORT_ORDER);
-        assertEquals(0, c.getCount());
-        c.close();
-
-        // test querying media provider with null projection, should return all columns
-        c = mContentResolver.query(
-                Members.getContentUri(MediaStoreAudioTestHelper.EXTERNAL_VOLUME_NAME, 1), null,
-                Members.ALBUM + "=?", new String[] { Audio1.ALBUM },
-                Members.DEFAULT_SORT_ORDER);
-        assertEquals(0, c.getCount());
-        // TODO: need a way to verify all expected columns are returned. Purely testing for number
-        // of columns returned is brittle
-        assertEquals(31, c.getColumnCount());
-        c.close();
-
-        try {
-            mContentResolver.query(
-                    Members.getContentUri(MediaStoreAudioTestHelper.INTERNAL_VOLUME_NAME, 1),
-                    mMembersProjection, null, null, Members.DEFAULT_SORT_ORDER);
-            fail("Should throw SQLException as the internal datatbase has no playlist");
-        } catch (SQLException e) {
-            // expected
-        }
-
-        String volume = "fakeVolume";
-        assertNull(mContentResolver.query(Members.getContentUri(volume, 1), null, null, null,
-                null));
+        assertEquals("content://media/external/audio/playlists/1337/members",
+                Members.getContentUri("external", 1337).toString());
+        assertEquals("content://media/internal/audio/playlists/3007/members",
+                Members.getContentUri("internal", 3007).toString());
     }
-    @BrokenTest("needs investigation")
+
     public void testStoreAudioPlaylistsMembersExternal() {
         ContentValues values = new ContentValues();
         values.put(Playlists.NAME, "My favourites");
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index a5dd335..6d034b9 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -37,7 +37,6 @@
     private static final long HOUR_DURATION = 2 * 60 * 60 * 1000;
     private static final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
     private long mBaseTime;
-    private Locale mDefaultLocale;
     private Context mContext;
 
     @Override
@@ -45,18 +44,6 @@
         super.setUp();
         mContext = getContext();
         mBaseTime = System.currentTimeMillis();
-        mDefaultLocale = Locale.getDefault();
-        if (!mDefaultLocale.equals(Locale.US)) {
-            Locale.setDefault(Locale.US);
-        }
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        if (!Locale.getDefault().equals(mDefaultLocale)) {
-            Locale.setDefault(mDefaultLocale);
-        }
-        super.tearDown();
     }
 
     @TestTargetNew(
@@ -65,6 +52,10 @@
         args = {int.class, int.class}
     )
     public void testGetDayOfWeekString() {
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
+            return;
+        }
+
         assertEquals("Sunday",
                 DateUtils.getDayOfWeekString(Calendar.SUNDAY, DateUtils.LENGTH_LONG));
         assertEquals("Sun",
@@ -86,6 +77,9 @@
         args = {int.class, int.class}
     )
     public void testGetMonthString() {
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
+            return;
+        }
         assertEquals("January", DateUtils.getMonthString(Calendar.JANUARY, DateUtils.LENGTH_LONG));
         assertEquals("Jan",
                 DateUtils.getMonthString(Calendar.JANUARY, DateUtils.LENGTH_MEDIUM));
@@ -104,6 +98,9 @@
         args = {int.class}
     )
     public void testGetAMPMString() {
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
+            return;
+        }
         assertEquals("am", DateUtils.getAMPMString(Calendar.AM));
         assertEquals("pm", DateUtils.getAMPMString(Calendar.PM));
     }
@@ -142,6 +139,9 @@
     })
 
     public void testGetSpanString() {
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
+            return;
+        }
         assertEquals("0 minutes ago",
                 DateUtils.getRelativeTimeSpanString(mBaseTime - MIN_DURATION).toString());
         assertEquals("in 0 minutes",
@@ -198,8 +198,7 @@
     })
     @SuppressWarnings("deprecation")
     public void testFormatMethods() {
-        if (!LocaleUtils.isSupportedLocale(mContext, Locale.US)) {
-            // Locale is set to US in setUp method.
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
         }
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index ff10ca5..cf20217 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -115,6 +115,42 @@
     @TestTargets({
         @TestTargetNew(
             level = TestLevel.COMPLETE,
+            method = "onReceivedIcon",
+            args = {WebView.class, Bitmap.class}
+        )
+    })
+    public void testOnReceivedIcon() throws Throwable {
+        final MockWebChromeClient webChromeClient = new MockWebChromeClient();
+        mWebView.setWebChromeClient(webChromeClient);
+
+        runTestOnUiThread(new Runnable() {
+
+            @Override
+            public void run() {
+                // getInstance must run on the UI thread
+                WebIconDatabase mIconDb = WebIconDatabase.getInstance();
+                String dbPath = getActivity().getFilesDir().toString() + "/icons";
+                mIconDb.open(dbPath);
+                mIconDb.removeAllIcons();
+            }
+        });
+
+        assertFalse(webChromeClient.hadOnReceivedIcon());
+
+        String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
+        mWebView.loadUrl(url);
+
+        new DelayedCheck(TEST_TIMEOUT) {
+            @Override
+            protected boolean check() {
+                return webChromeClient.hadOnReceivedIcon();
+            }
+        }.run();
+    }
+
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
             method = "onCreateWindow",
             args = {WebView.class, boolean.class, boolean.class, Message.class}
         ),
diff --git a/tests/tests/widget/src/android/widget/cts/ProgressBarTest.java b/tests/tests/widget/src/android/widget/cts/ProgressBarTest.java
index 4c5c717..1b9b517 100644
--- a/tests/tests/widget/src/android/widget/cts/ProgressBarTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ProgressBarTest.java
@@ -18,7 +18,6 @@
 
 import com.android.cts.stub.R;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -26,7 +25,6 @@
 import dalvik.annotation.ToBeFixed;
 
 import android.content.Context;
-import android.content.res.Resources.NotFoundException;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.drawable.Drawable;
@@ -34,7 +32,6 @@
 import android.test.InstrumentationTestCase;
 import android.view.View;
 import android.view.animation.AccelerateDecelerateInterpolator;
-import android.view.animation.CycleInterpolator;
 import android.view.animation.Interpolator;
 import android.view.animation.LinearInterpolator;
 import android.widget.ProgressBar;
@@ -72,7 +69,7 @@
 
         new ProgressBar(mContext, null);
 
-        new ProgressBar(mContext, null, com.android.internal.R.attr.progressBarStyle);
+        new ProgressBar(mContext, null, android.R.attr.progressBarStyle);
     }
 
     @TestTargets({
@@ -98,8 +95,7 @@
         // because default is Indeterminate only progressBar, can't change the status
         assertTrue(progressBar.isIndeterminate());
 
-        progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+        progressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleHorizontal);
         assertFalse(progressBar.isIndeterminate());
 
         progressBar.setIndeterminate(true);
@@ -152,7 +148,7 @@
     })
     public void testAccessProgressDrawable() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                        com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
 
         // set ProgressDrawable
         // normal value
@@ -182,7 +178,7 @@
     })
     public void testAccessProgress() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
         assertEquals(0, progressBar.getProgress());
 
         final int maxProgress = progressBar.getMax();
@@ -221,7 +217,7 @@
     })
     public void testAccessSecondaryProgress() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
         assertEquals(0, progressBar.getSecondaryProgress());
 
         final int maxProgress = progressBar.getMax();
@@ -253,7 +249,7 @@
     )
     public void testIncrementProgressBy() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
 
         // normal value
         int increment = 1;
@@ -283,7 +279,7 @@
     )
     public void testIncrementSecondaryProgressBy() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
 
         // normal value
         int increment = 1;
@@ -319,8 +315,7 @@
         )
     })
     public void testAccessInterpolator() {
-        ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyle);
+        ProgressBar progressBar = new ProgressBar(mContext);
 
         // default should be LinearInterpolator
         assertTrue(progressBar.getInterpolator() instanceof LinearInterpolator);
@@ -329,54 +324,6 @@
         Interpolator i = new AccelerateDecelerateInterpolator();
         progressBar.setInterpolator(i);
         assertEquals(i, progressBar.getInterpolator());
-
-        // exceptional value
-        progressBar.setInterpolator(null);
-        assertNull(progressBar.getInterpolator());
-
-        // TODO: test whether setInterpolator takes effect? How to get the animation?
-    }
-
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "setInterpolator",
-            args = {android.content.Context.class, int.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            method = "getInterpolator",
-            args = {}
-        )
-    })
-    @ToBeFixed(bug = "1695243", explanation = "the javadoc for setInterpolator() is incomplete." +
-            "1. not clear what is supposed to happen if context or resID is exceptional.")
-    @BrokenTest("Initial setInterpolator() call occasionally fails with NPE. context null?")
-    public void testAccessInterpolatorContext() {
-        ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyle);
-
-        // default is LinearInterpolator
-        assertTrue(progressBar.getInterpolator() instanceof LinearInterpolator);
-
-        // normal value
-        progressBar.setInterpolator(mContext.getApplicationContext(), R.anim.move_cycle);
-        assertTrue(progressBar.getInterpolator() instanceof CycleInterpolator);
-
-        // exceptional value
-        try {
-            progressBar.setInterpolator(null, R.anim.move_ani);
-            fail("Should throw NullPointerException");
-        } catch (NullPointerException e) {
-            // issue 1695243, not clear what is supposed to happen if context is null.
-        }
-
-        try {
-            progressBar.setInterpolator(mContext.getApplicationContext(), -1);
-            fail("Should throw NotFoundException");
-        } catch (NotFoundException e) {
-            // issue 1695243, not clear what is supposed to happen if resID is exceptional.
-        }
     }
 
     @TestTargetNew(
@@ -388,7 +335,7 @@
             "1. not clear what is supposed result if visibility isn't VISIBLE, INVISIBLE or GONE.")
     public void testSetVisibility() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
 
         // set visibility
         // normal value
@@ -472,7 +419,7 @@
     })
     public void testAccessMax() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
 
         // set Progress
         int progress = 10;
@@ -612,7 +559,7 @@
     })
     public void testOnSaveAndRestoreInstanceState() {
         ProgressBar progressBar = new ProgressBar(mContext, null,
-                com.android.internal.R.attr.progressBarStyleHorizontal);
+                android.R.attr.progressBarStyleHorizontal);
         int oldProgress = 1;
         int oldSecondaryProgress = progressBar.getMax() - 1;
         progressBar.setProgress(oldProgress);
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
index aaeac6e..ddbe90d 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsTest.java
@@ -18,7 +18,6 @@
 
 import com.android.cts.stub.R;
 
-import dalvik.annotation.BrokenTest;
 import dalvik.annotation.TestLevel;
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
@@ -219,14 +218,11 @@
         method = "setImageViewUri",
         args = {int.class, android.net.Uri.class}
     )
-    @BrokenTest("needs investigation")
     public void testSetImageViewUri() throws IOException {
-        File imageFile = null;
+        String path = getTestImagePath();
+        File imageFile = new File(path);
 
         try {
-            // create the test image first
-            String path = getTestImagePath();
-            imageFile = new File(path);
             createSampleImage(imageFile, R.raw.testimage);
 
             Uri uri = Uri.parse(path);
@@ -235,15 +231,13 @@
 
             mRemoteViews.setImageViewUri(R.id.remoteView_image, uri);
             mRemoteViews.reapply(mActivity, mResult);
-            BitmapDrawable d = (BitmapDrawable) mActivity
-            .getResources().getDrawable(R.drawable.testimage);
-            WidgetTestUtils.assertEquals(d.getBitmap(),
-                    ((BitmapDrawable) image.getDrawable()).getBitmap());
+
+            Bitmap imageViewBitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
+            Bitmap expectedBitmap = WidgetTestUtils.getUnscaledAndDitheredBitmap(
+                    mActivity.getResources(), R.raw.testimage, imageViewBitmap.getConfig());
+            WidgetTestUtils.assertEquals(expectedBitmap, imageViewBitmap);
         } finally {
-            if (imageFile != null) {
-                // remove the test image file
-                imageFile.delete();
-            }
+            imageFile.delete();
         }
     }
 
@@ -597,34 +591,36 @@
         method = "setUri",
         args = {int.class, java.lang.String.class, android.net.Uri.class}
     )
-    @BrokenTest("needs investigation")
     public void testSetUri() throws IOException {
-        // create the test image first
         String path = getTestImagePath();
         File imagefile = new File(path);
-        createSampleImage(imagefile, R.raw.testimage);
 
-        Uri uri = Uri.parse(path);
-        ImageView image = (ImageView) mResult.findViewById(R.id.remoteView_image);
-        assertNull(image.getDrawable());
-
-        mRemoteViews.setUri(R.id.remoteView_image, "setImageURI", uri);
-        mRemoteViews.reapply(mActivity, mResult);
-        BitmapDrawable d = (BitmapDrawable) mActivity
-                .getResources().getDrawable(R.drawable.testimage);
-        WidgetTestUtils.assertEquals(d.getBitmap(),
-                ((BitmapDrawable) image.getDrawable()).getBitmap());
-
-        mRemoteViews.setUri(R.id.remoteView_absolute, "setImageURI", uri);
         try {
-            mRemoteViews.reapply(mActivity, mResult);
-            fail("Should throw ActionException");
-        } catch (ActionException e) {
-            // expected
-        }
+            createSampleImage(imagefile, R.raw.testimage);
 
-        // remove the test image file
-        imagefile.delete();
+            Uri uri = Uri.parse(path);
+            ImageView image = (ImageView) mResult.findViewById(R.id.remoteView_image);
+            assertNull(image.getDrawable());
+
+            mRemoteViews.setUri(R.id.remoteView_image, "setImageURI", uri);
+            mRemoteViews.reapply(mActivity, mResult);
+
+            Bitmap imageViewBitmap = ((BitmapDrawable) image.getDrawable()).getBitmap();
+            Bitmap expectedBitmap = WidgetTestUtils.getUnscaledAndDitheredBitmap(
+                    mActivity.getResources(), R.raw.testimage, imageViewBitmap.getConfig());
+            WidgetTestUtils.assertEquals(expectedBitmap, imageViewBitmap);
+
+            mRemoteViews.setUri(R.id.remoteView_absolute, "setImageURI", uri);
+            try {
+                mRemoteViews.reapply(mActivity, mResult);
+                fail("Should throw ActionException");
+            } catch (ActionException e) {
+                // expected
+            }
+        } finally {
+            // remove the test image file
+            imagefile.delete();
+        }
     }
 
     @TestTargetNew(