Add workaround for ContetxtImpl.setTheme(), verify test setup

Bug: 20230451
Change-Id: Ie8a495c64d26244ffb1c6a83965ab8850ab5a500
diff --git a/tests/tests/graphics/res/values/styles.xml b/tests/tests/graphics/res/values/styles.xml
index 20c80f8..31ed175 100644
--- a/tests/tests/graphics/res/values/styles.xml
+++ b/tests/tests/graphics/res/values/styles.xml
@@ -163,6 +163,7 @@
         <item name="themeNinePatch">@drawable/ninepatch_0</item>
         <item name="themeGravity">48</item>
         <item name="themeTileMode">2</item>
+        <item name="themeType">0</item>
     </style>
 
     <style name="Theme_NoSwipeDismiss">
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
index e7a38c5..eeda22c 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
@@ -22,10 +22,8 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.res.Resources;
-import android.content.res.Resources.Theme;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
-import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.drawable.GradientDrawable;
 import android.graphics.drawable.Drawable.ConstantState;
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/ThemedDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/ThemedDrawableTest.java
index a967f95..d7becc6 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/ThemedDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/ThemedDrawableTest.java
@@ -17,6 +17,8 @@
 package android.graphics.drawable.cts;
 
 import android.annotation.TargetApi;
+import android.content.res.Resources.Theme;
+import android.content.res.TypedArray;
 import android.graphics.Color;
 import android.graphics.Rect;
 import android.graphics.Shader.TileMode;
@@ -26,6 +28,7 @@
 import android.graphics.drawable.LayerDrawable;
 import android.graphics.drawable.NinePatchDrawable;
 import android.graphics.drawable.RippleDrawable;
+import android.os.Debug;
 import android.test.AndroidTestCase;
 import android.view.Gravity;
 
@@ -38,7 +41,17 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        mContext.setTheme(R.style.Theme_ThemedDrawableTest);
+        // Workaround for ContextImpl.setTheme() being broken.
+        final Theme theme = mContext.getResources().newTheme();
+        theme.applyStyle(R.style.Theme_ThemedDrawableTest, true);
+        final Theme ctxTheme = mContext.getTheme();
+        ctxTheme.setTo(theme);
+    }
+
+    @Override
+    public void testAndroidTestCaseSetupProperly() {
+        final TypedArray t = mContext.obtainStyledAttributes(new int[]{R.attr.themeType});
+        assertTrue("Theme was applied correctly", t.getInt(0, -1) == 0);
     }
 
     public void testBitmapDrawable() {