Include Missing Commits from gingerbread-plus-aosp

These somewhat got ignored as part of (HOW!?):

Merge remote branch 'korg/froyo' into manualmerge
C-Id: Ie74c678a6ae142d9861b6965a8ca89ff58ebfa83

A lot has changed, so its not an exact cherry-pick.

Change-Id: I5347f2c15eadf59511de11cf08e16be5f66e5b0e
diff --git a/development/ide/eclipse/.classpath b/development/ide/eclipse/.classpath
index 3f11bd1..8cba973 100644
--- a/development/ide/eclipse/.classpath
+++ b/development/ide/eclipse/.classpath
@@ -3,6 +3,7 @@
     <classpathentry kind="src" path="cts/apps/CtsVerifier/src"/>
     <classpathentry kind="src" path="cts/apps/CtsVerifier/tests/src"/>
     <classpathentry kind="src" path="cts/libs/annotation/src"/>
+    <classpathentry kind="src" path="cts/libs/vogar-expect/src"/>
     <classpathentry kind="src" path="cts/tests/ApiDemosReferenceTest/src"/>
     <classpathentry kind="src" path="cts/tests/ProcessTest/src"/>
     <classpathentry kind="src" path="cts/tests/ProcessTest/NoShareUidApp/src"/>
diff --git a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
index b08e953..bd8c260 100644
--- a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
+++ b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
@@ -147,9 +147,12 @@
         args = {java.lang.String.class, android.net.Uri.class}
     )
     public void testDialPhoneNumber() {
-        Uri uri = Uri.parse("tel:(212)5551212");
-        Intent intent = new Intent(Intent.ACTION_DIAL, uri);
-        assertCanBeHandled(intent);
+        PackageManager packageManager = mContext.getPackageManager();
+        if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            Uri uri = Uri.parse("tel:(212)5551212");
+            Intent intent = new Intent(Intent.ACTION_DIAL, uri);
+            assertCanBeHandled(intent);
+        }
     }
 
     /**
@@ -161,8 +164,11 @@
         args = {java.lang.String.class, android.net.Uri.class}
     )
     public void testDialVoicemail() {
-        Uri uri = Uri.parse("voicemail:");
-        Intent intent = new Intent(Intent.ACTION_DIAL, uri);
-        assertCanBeHandled(intent);
+        PackageManager packageManager = mContext.getPackageManager();
+        if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
+            Uri uri = Uri.parse("voicemail:");
+            Intent intent = new Intent(Intent.ACTION_DIAL, uri);
+            assertCanBeHandled(intent);
+        }
     }
 }
diff --git a/tests/tests/media/src/android/media/cts/AudioTrackTest.java b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
index 12cfcad..4adc582 100644
--- a/tests/tests/media/src/android/media/cts/AudioTrackTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
@@ -29,7 +29,7 @@
 @TestTargetClass(AudioTrack.class)
 public class AudioTrackTest extends AndroidTestCase {
     private String TAG = "AudioTrackTest";
-    private final long WAIT_MSEC = 100;
+    private final long WAIT_MSEC = 200;
     private final int OFFSET_DEFAULT = 0;
     private final int OFFSET_NEGATIVE = -10;
 
@@ -2620,4 +2620,4 @@
         }
     }
 
-}
\ No newline at end of file
+}
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java
index 42243c8..3b1a6c1 100644
--- a/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiInfoTest.java
@@ -20,7 +20,6 @@
 import dalvik.annotation.TestTargetClass;
 import dalvik.annotation.TestTargetNew;
 import dalvik.annotation.TestTargets;
-import dalvik.annotation.ToBeFixed;
 
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -168,8 +167,6 @@
             args = {}
         )
     })
-    @ToBeFixed(bug="1871573", explanation="android.net.wifi.WifiInfo#getNetworkId() return -1 when"
-        + " there is wifi connection")
     public void testWifiInfoProperties() throws Exception {
         // this test case should in Wifi environment
         WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
@@ -189,6 +186,7 @@
         Thread.sleep(DURATION);
         wifiInfo = mWifiManager.getConnectionInfo();
         assertEquals(-1, wifiInfo.getNetworkId());
+        assertEquals(WifiManager.WIFI_STATE_DISABLED, mWifiManager.getWifiState());
     }
 
 }
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
index 5344339..2cd2deb 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
@@ -31,7 +31,8 @@
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
-
+import android.webkit.WebChromeClient;
+ 
 @TestTargetClass(android.webkit.WebViewClient.class)
 public class WebViewClientTest extends ActivityInstrumentationTestCase2<WebViewStubActivity> {
     private static final long TEST_TIMEOUT = 5000;
@@ -47,6 +48,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         mWebView = getActivity().getWebView();
+        mWebView.setWebChromeClient(new WebChromeClient());
     }
 
     @Override
diff --git a/tests/tests/widget/src/android/widget/cts/AdapterViewTest.java b/tests/tests/widget/src/android/widget/cts/AdapterViewTest.java
old mode 100644
new mode 100755
index 97a5753..12815b2
--- a/tests/tests/widget/src/android/widget/cts/AdapterViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AdapterViewTest.java
@@ -310,8 +310,9 @@
         setArrayAdapter(mAdapterView);
 
         // LastVisiblePosition should be adapter's getCount - 1,by mocking method
-        // TODO: the +50 is a gross hack
-        mAdapterView.layout(0, 0, LAYOUT_WIDTH, LAYOUT_HEIGHT+50);
+        float density = mActivity.getResources().getDisplayMetrics().density;
+        int bottom = (int) (LAYOUT_HEIGHT * density);
+        mAdapterView.layout(0, 0, LAYOUT_WIDTH, bottom);
         assertEquals(FRUIT.length - 1, mAdapterView.getLastVisiblePosition());
     }
 
diff --git a/tools/utils/Android.mk b/tools/utils/Android.mk
index 0782116..ddb06c8 100644
--- a/tools/utils/Android.mk
+++ b/tools/utils/Android.mk
@@ -20,7 +20,7 @@
 
 LOCAL_MODULE := descGen
 
-LOCAL_SRC_FILES := CollectAllTests.java DescriptionGenerator.java
+LOCAL_SRC_FILES := CollectAllTests.java DescriptionGenerator.java VogarUtils.java
 
 LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR) $(LOCAL_PATH)/lib/junit.jar
 
diff --git a/tools/utils/CollectAllTests.java b/tools/utils/CollectAllTests.java
index cb109e8..c443db2 100644
--- a/tools/utils/CollectAllTests.java
+++ b/tools/utils/CollectAllTests.java
@@ -14,6 +14,15 @@
  * limitations under the License.
  */
 
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import vogar.Expectation;
+import vogar.ExpectationStore;
+import vogar.ModeId;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -40,15 +49,6 @@
 import junit.textui.ResultPrinter;
 import junit.textui.TestRunner;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import vogar.ExpectationStore;
-import vogar.Expectation;
-import vogar.ModeId;
-
 public class CollectAllTests extends DescriptionGenerator {
 
     static final String ATTRIBUTE_RUNNER = "runner";
@@ -103,12 +103,13 @@
     private static String MANIFESTFILE = "";
     private static String TESTSUITECLASS = "";
     private static String ANDROID_MAKE_FILE = "";
-    private static String EXPECTATION_DIR = null;
+    private static String LIBCORE_EXPECTATION_DIR = null;
 
     private static Test TESTSUITE;
 
     static XMLGenerator xmlGenerator;
-    private static ExpectationStore vogarExpectationStore;
+    private static ExpectationStore libcoreVogarExpectationStore;
+    private static ExpectationStore ctsVogarExpectationStore;
 
     public static void main(String[] args) {
         if (args.length > 2) {
@@ -116,7 +117,7 @@
             MANIFESTFILE = args [1];
             TESTSUITECLASS = args[2];
             if (args.length > 3) {
-                EXPECTATION_DIR = args[3];
+                LIBCORE_EXPECTATION_DIR = args[3];
             }
             if (args.length > 4) {
                 ANDROID_MAKE_FILE = args[4];
@@ -195,7 +196,8 @@
         }
 
         try {
-            vogarExpectationStore = provideExpectationStore(EXPECTATION_DIR);
+            libcoreVogarExpectationStore = VogarUtils.provideExpectationStore(LIBCORE_EXPECTATION_DIR);
+            ctsVogarExpectationStore = VogarUtils.provideExpectationStore(CTS_EXPECTATION_DIR);
         } catch (IOException e) {
             System.err.println("Can't initialize vogar expectation store");
             e.printStackTrace(System.err);
@@ -326,15 +328,6 @@
         return getAnnotation(testClass, testName, SIDE_EFFECT) != null;
     }
 
-    private boolean isVogarKnownFailure(final Class<? extends TestCase> testClass,
-            final String testName) {
-        if (vogarExpectationStore == null) {
-            return false;
-        }
-        String fullTestName = String.format("%s#%s", testClass.getName(), testName);
-        return vogarExpectationStore.get(fullTestName) != Expectation.SUCCESS;
-    }
-
     private String getAnnotation(final Class<? extends TestCase> testClass,
             final String testName, final String annotationName) {
         try {
@@ -385,8 +378,11 @@
         } else if (hasSideEffects(test.getClass(), testName)) {
             System.out.println("ignoring test with side effects: " + test);
             return;
-        } else if (isVogarKnownFailure(test.getClass(), testName)) {
-            System.out.println("ignoring vogar known failure: " + test);
+        } else if (VogarUtils.isVogarKnownFailure(libcoreVogarExpectationStore, test.getClass().getName(), testName)) {
+            System.out.println("ignoring libcore expectation known failure: " + test);
+            return;
+        } else if (VogarUtils.isVogarKnownFailure(ctsVogarExpectationStore, test.getClass().getName(), testName)) {
+            System.out.println("ignoring cts expectation known failure: " + test);
             return;
         }
 
@@ -416,26 +412,4 @@
             failed.add(test.getClass().getName());
         }
     }
-
-    public static ExpectationStore provideExpectationStore(String dir) throws IOException {
-        if (dir == null) {
-            return null;
-        }
-        ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE);
-        return result;
-    }
-
-    private static Set<File> getExpectationFiles(String dir) {
-        Set<File> expectSet = new HashSet<File>();
-        File[] files = new File(dir).listFiles(new FilenameFilter() {
-            // ignore obviously temporary files
-            public boolean accept(File dir, String name) {
-                return !name.endsWith("~") && !name.startsWith(".");
-            }
-        });
-        if (files != null) {
-            expectSet.addAll(Arrays.asList(files));
-        }
-        return expectSet;
-    }
 }
diff --git a/tools/utils/DescriptionGenerator.java b/tools/utils/DescriptionGenerator.java
index 2d58543..0731b49 100644
--- a/tools/utils/DescriptionGenerator.java
+++ b/tools/utils/DescriptionGenerator.java
@@ -37,6 +37,8 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import vogar.ExpectationStore;
+
 import com.sun.javadoc.AnnotationDesc;
 import com.sun.javadoc.AnnotationTypeDoc;
 import com.sun.javadoc.AnnotationValue;
@@ -67,6 +69,7 @@
     static final String BROKEN_TEST = "dalvik.annotation.BrokenTest";
     static final String SIDE_EFFECT = "dalvik.annotation.SideEffect";
     static final String SUPPRESSED_TEST = "android.test.suitebuilder.annotation.Suppress";
+    static final String CTS_EXPECTATION_DIR = "cts/tests/expectations";
 
     static final String JUNIT_TEST_CASE_CLASS_NAME = "junit.framework.testcase";
     static final String TAG_PACKAGE = "TestPackage";
@@ -117,9 +120,17 @@
             return true;
         }
 
+        ExpectationStore ctsExpectationStore = null;
+        try {
+            ctsExpectationStore = VogarUtils.provideExpectationStore("./" + CTS_EXPECTATION_DIR);
+        } catch (IOException e) {
+            Log.e("Couldn't load expectation store.", e);
+            return false;
+        }
+
         for (ClassDoc clazz : classes) {
             if ((!clazz.isAbstract()) && (isValidJUnitTestCase(clazz))) {
-                xmlGenerator.addTestClass(new TestClass(clazz));
+                xmlGenerator.addTestClass(new TestClass(clazz, ctsExpectationStore));
             }
         }
 
@@ -500,9 +511,9 @@
          *
          * @param clazz The specified ClassDoc.
          */
-        TestClass(ClassDoc clazz) {
+        TestClass(ClassDoc clazz, ExpectationStore expectationStore) {
             mName = clazz.toString();
-            mCases = getTestMethods(clazz);
+            mCases = getTestMethods(expectationStore, clazz);
         }
 
         /**
@@ -511,7 +522,7 @@
          * @param clazz The specified ClassDoc.
          * @return A collection of TestMethod.
          */
-        Collection<TestMethod> getTestMethods(ClassDoc clazz) {
+        Collection<TestMethod> getTestMethods(ExpectationStore expectationStore, ClassDoc clazz) {
             Collection<MethodDoc> methods = getAllMethods(clazz);
 
             ArrayList<TestMethod> cases = new ArrayList<TestMethod>();
@@ -541,6 +552,10 @@
                     }
                 }
 
+                if (VogarUtils.isVogarKnownFailure(expectationStore, clazz.toString(), name)) {
+                    isBroken = true;
+                }
+
                 if (name.startsWith("test")) {
                     cases.add(new TestMethod(name, method.commentText(), controller, knownFailure,
                             isBroken, isSuppressed));
diff --git a/tools/utils/VogarUtils.java b/tools/utils/VogarUtils.java
new file mode 100644
index 0000000..06b48c6
--- /dev/null
+++ b/tools/utils/VogarUtils.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+
+import vogar.Expectation;
+import vogar.ExpectationStore;
+import vogar.ModeId;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class VogarUtils {
+
+    public static boolean isVogarKnownFailure(ExpectationStore expectationStore,
+            final String testClassName,
+            final String testMethodName) {
+        String fullTestName = String.format("%s#%s", testClassName, testMethodName);
+        return expectationStore != null
+                && expectationStore.get(fullTestName) != Expectation.SUCCESS;
+    }
+
+    public static ExpectationStore provideExpectationStore(String dir) throws IOException {
+        if (dir == null) {
+            return null;
+        }
+        ExpectationStore result = ExpectationStore.parse(getExpectationFiles(dir), ModeId.DEVICE);
+        return result;
+    }
+
+    private static Set<File> getExpectationFiles(String dir) {
+        Set<File> expectSet = new HashSet<File>();
+        File[] files = new File(dir).listFiles(new FilenameFilter() {
+            // ignore obviously temporary files
+            public boolean accept(File dir, String name) {
+                return !name.endsWith("~") && !name.startsWith(".");
+            }
+        });
+        if (files != null) {
+            expectSet.addAll(Arrays.asList(files));
+        }
+        return expectSet;
+    }
+}