Merge "The test branches to alphabetic or numeric one" into froyo
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
index 413f6a7..069cf80 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
@@ -179,6 +179,7 @@
      * HVGA      | medium (141-190) | normal
      * WVGA      | high (191-250)   | normal
      * FWVGA     | high (191-250)   | normal
+     * QHD       | high (191-250)   | normal
      * WSVGA     | high (191-250)   | large
 
      * VGA       | medium (141-190) | large
@@ -200,6 +201,8 @@
         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),
+        // QHD     | high (191-250)   | normal
+        new ScreenConfiguration(960, 540, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_NORMAL),
         // WSVGA     | high (191-250)   | large
         new ScreenConfiguration(1024, 600, Density.HIGH, Configuration.SCREENLAYOUT_SIZE_LARGE),
 
diff --git a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
index f1acd87..3ebc567 100644
--- a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
+++ b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
@@ -83,33 +83,42 @@
         EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
         int[] numConfigs = new int[1];
 
-        if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
-            EGLConfig[] configs = new EGLConfig[numConfigs[0]];
-            if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
-                int[] value = new int[1];
-                for (int i = 0; i < numConfigs[0]; i++) {
-                    if (egl.eglGetConfigAttrib(display, configs[i],
-                            EGL10.EGL_RENDERABLE_TYPE, value)) {
-                        if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
-                            return 2;
+        if (egl.eglInitialize(display, null)) {
+            try {
+                if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
+                    EGLConfig[] configs = new EGLConfig[numConfigs[0]];
+                    if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
+                        int[] value = new int[1];
+                        for (int i = 0; i < numConfigs[0]; i++) {
+                            if (egl.eglGetConfigAttrib(display, configs[i],
+                                    EGL10.EGL_RENDERABLE_TYPE, value)) {
+                                if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
+                                    return 2;
+                                }
+                            } else {
+                                Log.w(TAG, "Getting config attribute with "
+                                        + "EGL10#eglGetConfigAttrib failed "
+                                        + "(" + i + "/" + numConfigs[0] + "): "
+                                        + egl.eglGetError());
+                            }
                         }
+                        return 1;
                     } else {
-                        Log.w(TAG, "Getting config attribute with "
-                                + "EGL10#eglGetConfigAttrib failed "
-                                + "(" + i + "/" + numConfigs[0] + "): "
+                        Log.e(TAG, "Getting configs with EGL10#eglGetConfigs failed: "
                                 + egl.eglGetError());
+                        return -1;
                     }
+                } else {
+                    Log.e(TAG, "Getting number of configs with EGL10#eglGetConfigs failed: "
+                            + egl.eglGetError());
+                    return -2;
                 }
-                return 1;
-            } else {
-                Log.e(TAG, "Getting configs with EGL10#eglGetConfigs failed: "
-                        + egl.eglGetError());
-                return -1;
-            }
+              } finally {
+                  egl.eglTerminate(display);
+              }
         } else {
-            Log.e(TAG, "Getting number of configs with EGL10#eglGetConfigs failed: "
-                    + egl.eglGetError());
-            return -2;
+            Log.e(TAG, "Couldn't initialize EGL.");
+            return -3;
         }
     }
 
diff --git a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
old mode 100644
new mode 100755
index 175047e..d9bf6d9
--- a/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
+++ b/tests/tests/text/src/android/text/method/cts/MultiTapKeyListenerTest.java
@@ -176,8 +176,7 @@
         callOnKeyDown(keyListener, KeyEvent.KEYCODE_1, 1);
         assertEquals("Hi.", mTextView.getText().toString());
 
-        callOnKeyDown(keyListener, KeyEvent.KEYCODE_POUND, 1);
-        assertEquals("Hi. ", mTextView.getText().toString());
+        addSpace();
 
         callOnKeyDown(keyListener, KeyEvent.KEYCODE_2, 2);
         assertEquals("Hi. B", mTextView.getText().toString());
@@ -201,8 +200,7 @@
         callOnKeyDown(keyListener, KeyEvent.KEYCODE_4, 3);
         assertEquals("Hi", mTextView.getText().toString());
 
-        callOnKeyDown(keyListener, KeyEvent.KEYCODE_POUND, 1);
-        assertEquals("Hi ", mTextView.getText().toString());
+        addSpace();
 
         callOnKeyDown(keyListener, KeyEvent.KEYCODE_2, 2);
         assertEquals("Hi B", mTextView.getText().toString());
@@ -245,6 +243,15 @@
         }
     }
 
+    private void addSpace() {
+        mActivity.runOnUiThread(new Runnable() {
+            public void run() {
+                mTextView.append(" ");
+            }
+        });
+        mInstrumentation.waitForIdleSync();
+    }
+
     @TestTargetNew(
         level = TestLevel.COMPLETE,
         method = "getInstance",
diff --git a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
old mode 100644
new mode 100755
index 6058cdd..ed7be70
--- a/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/PasswordTransformationMethodTest.java
@@ -28,6 +28,7 @@
 import android.test.ActivityInstrumentationTestCase2;
 import android.text.Editable;
 import android.text.method.PasswordTransformationMethod;
+import android.view.KeyCharacterMap;
 import android.view.View;
 import android.view.animation.cts.DelayedCheck;
 import android.widget.Button;
@@ -145,7 +146,16 @@
         });
 
         mMethod.reset();
-        sendKeys("H E 2*L O");
+        // 12-key support
+        KeyCharacterMap keymap
+                = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+        if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+            // "HELLO" in case of 12-key(NUMERIC) keyboard
+            sendKeys("6*4 6*3 7*5 DPAD_RIGHT 7*5 7*6 DPAD_RIGHT");
+        }
+        else {
+            sendKeys("H E 2*L O");
+        }
         assertTrue(mMethod.hasCalledBeforeTextChanged());
         assertTrue(mMethod.hasCalledOnTextChanged());
         assertTrue(mMethod.hasCalledAfterTextChanged());
diff --git a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
old mode 100644
new mode 100755
index f5f2286..1ec2003
--- a/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
+++ b/tests/tests/view/src/android/view/inputmethod/cts/BaseInputConnectionTest.java
@@ -31,6 +31,7 @@
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.TextUtils;
+import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.Window;
@@ -325,7 +326,17 @@
         args = {KeyEvent.class}
     )
     public void testSendKeyEvent() {
-        mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Q));
+        // 12-key support
+        KeyCharacterMap keymap
+                = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+        if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+            // 'Q' in case of 12-key(NUMERIC) keyboard
+            mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
+            mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_7));
+        }
+        else {
+            mConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Q));
+        }
         new DelayedCheck() {
             @Override
             protected boolean check() {
diff --git a/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
index 3e9a073..5a62c9b 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CacheManagerTest.java
@@ -32,6 +32,7 @@
 
 @TestTargetClass(android.webkit.CacheManager.class)
 public class CacheManagerTest extends ActivityInstrumentationTestCase2<WebViewStubActivity> {
+    private static final long CACHEMANAGER_INIT_TIMEOUT = 5000l;
     private static final long NETWORK_OPERATION_DELAY = 10000l;
 
     private WebView mWebView;
@@ -96,6 +97,14 @@
         mWebServer = new CtsTestServer(getActivity());
         final String url = mWebServer.getAssetUrl(TestHtmlConstants.EMBEDDED_IMG_URL);
 
+        // Wait for CacheManager#init() finish.
+        new DelayedCheck(CACHEMANAGER_INIT_TIMEOUT) {
+            @Override
+            protected boolean check() {
+                return CacheManager.getCacheFileBaseDir() != null;
+            }
+        }.run();
+
         mWebView.clearCache(true);
         new DelayedCheck(NETWORK_OPERATION_DELAY) {
             @Override
diff --git a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
old mode 100644
new mode 100755
index a8c9ae0..8bf0c5b
--- a/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/AutoCompleteTextViewTest.java
@@ -29,6 +29,7 @@
 import android.test.UiThreadTest;
 import android.util.AttributeSet;
 import android.util.Xml;
+import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.ViewGroup;
@@ -64,6 +65,7 @@
     /** The m instrumentation. */
     private Instrumentation mInstrumentation;
     private AutoCompleteTextView mAutoCompleteTextView;
+    private boolean mNumeric = false;
     ArrayAdapter<String> mAdapter;
     private final String[] WORDS = new String[] { "testOne", "testTwo", "testThree", "testFour" };
     boolean isOnFilterComplete = false;
@@ -95,6 +97,11 @@
                 .findViewById(R.id.autocompletetv_edit);
         mAdapter = new ArrayAdapter<String>(mActivity,
                 android.R.layout.simple_dropdown_item_1line, WORDS);
+        KeyCharacterMap keymap
+                = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+        if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+            mNumeric = true;
+        }
     }
 
     @TestTargets({
@@ -501,7 +508,13 @@
 
         inflatePopup();
         assertTrue(mAutoCompleteTextView.isPopupShowing());
-        String testString = "tes";
+        String testString = "";
+        if (mNumeric) {
+            // "tes" in case of 12-key(NUMERIC) keyboard
+            testString = "8337777";
+        } else {
+            testString = "tes";
+        }
         // Test the filter if the input string is not long enough to threshold
         runTestOnUiThread(new Runnable() {
             public void run() {
@@ -517,7 +530,12 @@
 
         inflatePopup();
         assertTrue(mAutoCompleteTextView.isPopupShowing());
-        testString = "that";
+        if (mNumeric) {
+            // "that" in case of 12-key(NUMERIC) keyboard
+            testString = "84428";
+        } else {
+            testString = "that";
+        }
         mInstrumentation.sendStringSync(testString);
         assertFalse(mAutoCompleteTextView.isPopupShowing());
 
@@ -529,7 +547,12 @@
                 mAutoCompleteTextView.setText("");
             }
         });
-        mInstrumentation.sendStringSync("test");
+        if (mNumeric) {
+            // "test" in case of 12-key(NUMERIC) keyboard
+            mInstrumentation.sendStringSync("83377778");
+        } else {
+            mInstrumentation.sendStringSync("test");
+        }
         assertTrue(mAutoCompleteTextView.hasFocus());
         assertTrue(mAutoCompleteTextView.hasWindowFocus());
         // give some time for UI to settle
@@ -594,7 +617,16 @@
 
         // performFiltering will be indirectly invoked by onKeyDown
         assertNull(filter.getResult());
-        mInstrumentation.sendStringSync(STRING_TEST);
+        // 12-key support
+        if (mNumeric) {
+            // "To be teste" in case of 12-key(NUMERIC) keyboard
+            mInstrumentation.sendStringSync("8888866600022330008337777833");
+            mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
+            // "d" in case of 12-key(NUMERIC) keyboard
+            mInstrumentation.sendStringSync("3");
+        } else {
+            mInstrumentation.sendStringSync(STRING_TEST);
+        }
         // give some time for UI to settle
         Thread.sleep(100);
         assertEquals(STRING_TEST, filter.getResult());
diff --git a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
old mode 100644
new mode 100755
index 0b436b2..661d257
--- a/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/DialerFilterTest.java
@@ -37,6 +37,7 @@
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.Xml;
+import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.widget.DialerFilter;
 import android.widget.EditText;
@@ -129,7 +130,16 @@
         });
         mInstrumentation.waitForIdleSync();
 
-        mInstrumentation.sendStringSync("adg");
+        // 12-key support
+        KeyCharacterMap keymap
+                = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
+        if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+            // "adg" in case of 12-key(NUMERIC) keyboard
+            mInstrumentation.sendStringSync("234");
+        }
+        else {
+            mInstrumentation.sendStringSync("adg");
+        }
         assertEquals("ADG", mDialerFilter.getLetters().toString());
         assertEquals("", mDialerFilter.getDigits().toString());
 
@@ -141,7 +151,14 @@
         });
         mInstrumentation.waitForIdleSync();
 
-        mInstrumentation.sendStringSync("adg");
+        // 12-key support
+        if (keymap.getKeyboardType() == KeyCharacterMap.NUMERIC) {
+            // "adg" in case of 12-key(NUMERIC) keyboard
+            mInstrumentation.sendStringSync("234");
+        }
+        else {
+            mInstrumentation.sendStringSync("adg");
+        }
         assertEquals("ADG", mDialerFilter.getLetters().toString());
         // A, D, K may map to numbers on some keyboards. Don't test.
 
diff --git a/tools/utils/startcts b/tools/utils/startcts
index af9d503..8db950e 100755
--- a/tools/utils/startcts
+++ b/tools/utils/startcts
@@ -14,12 +14,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-if [ -z "${SDK_ROOT}" ]; then
-# CONFIGURATION
-# Set this variable to the root of your Android SDK installation.
-SDK_ROOT=NOT_CONFIGURED
-fi;
-
 if [ -z "${CTS_ROOT}" ]; then
 # CONFIGURATION
 # Set this variable to the root of unzipped CTS directory
@@ -46,26 +40,35 @@
     fi;
 }
 
+checkPath() {
+    if ! type -P $1 &> /dev/null; then
+        echo "Unable to find $1 in path."
+        exit
+    fi;
+}
+
 checkDir ${CTS_ROOT} "Error: Cannot locate CTS in \"${CTS_DIR}\". Please check your configuration in $0"
-checkDir ${SDK_ROOT} "Error: Cannot locate SDK installation in \"${SDK_ROOT}\". Please check your configuration in $0"
 
 DDM_LIB=${SDK_ROOT}/tools/lib/ddmlib.jar
 CTS_LIB=${CTS_ROOT}/tools/cts.jar
 JUNIT_LIB=${CTS_ROOT}/tools/junit.jar
 HOSTTEST_LIB=${CTS_ROOT}/tools/hosttestlib.jar
 CTS_TEST_ANNOTATIONS_HOST_LIB=${CTS_ROOT}/tools/CtsTestAnnotationsHostLib.jar
-ADB_PATH=${SDK_ROOT}/tools
-ADB_EXE=${ADB_PATH}/adb
 
 checkFile ${DDM_LIB}
 checkFile ${CTS_LIB}
 checkFile ${JUNIT_LIB}
 checkFile ${HOSTTEST_LIB}
-checkFile ${ADB_EXE}
 
 JARS=${CTS_LIB}:${DDM_LIB}:${JUNIT_LIB}:${HOSTTEST_LIB}:${CTS_TEST_ANNOTATIONS_HOST_LIB}
 
-PATH=${ADB_PATH}:${PATH}
+# Add SDK_ROOT to the PATH for backwards compatibility with prior startcts
+# commands that required SDK_ROOT to find adb.
+if [ -n "${SDK_ROOT}" ]; then
+  PATH=${SDK_ROOT}/platform-tools:${SDK_ROOT}/tools:${PATH}
+fi
+
+checkPath adb
 
 # options for the JVM
 JAVA_OPTS="-Xmx512M"