Merge "DO NOT MERGE Update CTS Version to 2.2_r2" into froyo
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index cdddffc..1c79ece 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -930,6 +930,8 @@
<activity android:name="android.opengl.cts.GLSurfaceViewStubActivity"
android:label="GLSurfaceViewStub"/>
+ <activity android:name="android.opengl.cts.OpenGlEsVersionStubActivity"/>
+
</application>
<!--Test for PackageManager, please put this at the very beginning-->
diff --git a/tests/src/android/opengl/cts/OpenGlEsVersionStubActivity.java b/tests/src/android/opengl/cts/OpenGlEsVersionStubActivity.java
new file mode 100644
index 0000000..488c8bd
--- /dev/null
+++ b/tests/src/android/opengl/cts/OpenGlEsVersionStubActivity.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 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.opengl.cts;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * {@link Activity} that queries the device's display attributes to determine what version of
+ * OpenGL ES is supported and returns what the GL version string reports.
+ */
+public class OpenGlEsVersionStubActivity extends Activity {
+
+ private static final String EGL_CONTEXT_CLIENT_VERSION = "eglContextClientVersion";
+
+ /** Timeout to wait for the surface to be created and the version queried. */
+ private static final int TIMEOUT_SECONDS = 10;
+
+ /** Version string reported by glGetString. */
+ private String mVersionString;
+
+ /** Latch that is unlocked when the activity is done finding the version. */
+ private CountDownLatch mSurfaceCreatedLatch = new CountDownLatch(1);
+
+ public static Intent createIntent(int eglContextClientVersion) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.putExtra(EGL_CONTEXT_CLIENT_VERSION, eglContextClientVersion);
+ return intent;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ GLSurfaceView view = new GLSurfaceView(this);
+
+ Intent intent = getIntent();
+ int eglContextClientVersion = intent.getIntExtra(EGL_CONTEXT_CLIENT_VERSION, -1);
+ if (eglContextClientVersion > 0) {
+ view.setEGLContextClientVersion(eglContextClientVersion);
+ }
+
+ view.setRenderer(new Renderer());
+ setContentView(view);
+ }
+
+ public String getVersionString() throws InterruptedException {
+ mSurfaceCreatedLatch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ synchronized (this) {
+ return mVersionString;
+ }
+ }
+
+ private class Renderer implements GLSurfaceView.Renderer {
+
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ synchronized (OpenGlEsVersionStubActivity.this) {
+ try {
+ mVersionString = gl.glGetString(GL10.GL_VERSION);
+ } finally {
+ mSurfaceCreatedLatch.countDown();
+ }
+ }
+ }
+
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ }
+
+ public void onDrawFrame(GL10 gl) {
+ }
+ }
+}
diff --git a/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java b/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java
new file mode 100644
index 0000000..58575ee
--- /dev/null
+++ b/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2010 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.app.cts;
+
+import android.app.ActivityManager;
+import android.app.Instrumentation;
+import android.app.WallpaperManager;
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ConfigurationInfo;
+import android.content.pm.FeatureInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Configuration;
+import android.hardware.Camera;
+import android.hardware.Sensor;
+import android.hardware.SensorManager;
+import android.hardware.Camera.Parameters;
+import android.location.LocationManager;
+import android.net.wifi.WifiManager;
+import android.telephony.TelephonyManager;
+import android.test.InstrumentationTestCase;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Test for checking that the {@link PackageManager} is reporting the correct features.
+ */
+public class SystemFeaturesTest extends InstrumentationTestCase {
+
+ private Context mContext;
+ private PackageManager mPackageManager;
+ private HashSet<String> mAvailableFeatures;
+
+ private ActivityManager mActivityManager;
+ private LocationManager mLocationManager;
+ private SensorManager mSensorManager;
+ private TelephonyManager mTelephonyManager;
+ private WifiManager mWifiManager;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Instrumentation instrumentation = getInstrumentation();
+ mContext = instrumentation.getContext();
+ mPackageManager = mContext.getPackageManager();
+ mAvailableFeatures = new HashSet<String>();
+ if (mPackageManager.getSystemAvailableFeatures() != null) {
+ for (FeatureInfo feature : mPackageManager.getSystemAvailableFeatures()) {
+ mAvailableFeatures.add(feature.name);
+ }
+ }
+ mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
+ mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
+ mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+ mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
+ }
+
+ /**
+ * Check for features improperly prefixed with "android." that are not defined in
+ * {@link PackageManager}.
+ */
+ public void testFeatureNamespaces() throws IllegalArgumentException, IllegalAccessException {
+ Set<String> officialFeatures = getFeatureConstantsNames("FEATURE_");
+ assertFalse(officialFeatures.isEmpty());
+
+ Set<String> notOfficialFeatures = new HashSet<String>(mAvailableFeatures);
+ notOfficialFeatures.removeAll(officialFeatures);
+
+ for (String featureName : notOfficialFeatures) {
+ if (featureName != null) {
+ assertFalse("Use a different namespace than 'android' for " + featureName,
+ featureName.startsWith("android"));
+ }
+ }
+ }
+
+ public void testCameraFeatures() {
+ Camera camera = null;
+ try {
+ // Try getting a camera. This is unlikely to fail but implentations without a camera
+ // could return null or throw an exception.
+ camera = Camera.open();
+ if (camera != null) {
+ assertAvailable(PackageManager.FEATURE_CAMERA);
+
+ Camera.Parameters params = camera.getParameters();
+ if (!Parameters.FOCUS_MODE_FIXED.equals(params.getFocusMode())) {
+ assertAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
+ }
+
+ if (params.getFlashMode() != null) {
+ assertAvailable(PackageManager.FEATURE_CAMERA_FLASH);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
+ }
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_CAMERA);
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
+ }
+ } catch (RuntimeException e) {
+ assertNotAvailable(PackageManager.FEATURE_CAMERA);
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
+ assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
+ } finally {
+ if (camera != null) {
+ camera.release();
+ }
+ }
+ }
+
+ public void testLiveWallpaperFeature() {
+ try {
+ Intent intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ assertAvailable(PackageManager.FEATURE_LIVE_WALLPAPER);
+ } catch (ActivityNotFoundException e) {
+ assertNotAvailable(PackageManager.FEATURE_LIVE_WALLPAPER);
+ }
+ }
+
+ public void testLocationFeatures() {
+ if (mLocationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
+ assertAvailable(PackageManager.FEATURE_LOCATION);
+ assertAvailable(PackageManager.FEATURE_LOCATION_GPS);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_LOCATION_GPS);
+ }
+
+ if (mLocationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
+ assertAvailable(PackageManager.FEATURE_LOCATION);
+ assertAvailable(PackageManager.FEATURE_LOCATION_NETWORK);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_LOCATION_NETWORK);
+ }
+ }
+
+ /**
+ * Check that the sensor features reported by the PackageManager correspond to the sensors
+ * returned by {@link SensorManager#getSensorList(int)}.
+ */
+ public void testSensorFeatures() throws Exception {
+ Set<String> featuresLeft = getFeatureConstantsNames("FEATURE_SENSOR_");
+
+ assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_ACCELEROMETER,
+ Sensor.TYPE_ACCELEROMETER);
+ assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_COMPASS,
+ Sensor.TYPE_MAGNETIC_FIELD);
+ assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_LIGHT,
+ Sensor.TYPE_LIGHT);
+ assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_PROXIMITY,
+ Sensor.TYPE_PROXIMITY);
+
+ assertTrue("Assertions need to be added to this test for " + featuresLeft,
+ featuresLeft.isEmpty());
+ }
+
+ /** Get a list of feature constants in PackageManager matching a prefix. */
+ private static Set<String> getFeatureConstantsNames(String prefix)
+ throws IllegalArgumentException, IllegalAccessException {
+ Set<String> features = new HashSet<String>();
+ Field[] fields = PackageManager.class.getFields();
+ for (Field field : fields) {
+ if (field.getName().startsWith(prefix)) {
+ String feature = (String) field.get(null);
+ features.add(feature);
+ }
+ }
+ return features;
+ }
+
+ /**
+ * Check that if the PackageManager declares a sensor feature that the device has at least
+ * one sensor that matches that feature. Also check that if a PackageManager does not declare
+ * a sensor that the device also does not have such a sensor.
+ *
+ * @param featuresLeft to check in order to make sure the test covers all sensor features
+ * @param expectedFeature that the PackageManager may report
+ * @param expectedSensorType that that {@link SensorManager#getSensorList(int)} may have
+ */
+ private void assertFeatureForSensor(Set<String> featuresLeft, String expectedFeature,
+ int expectedSensorType) {
+ assertTrue("Features left " + featuresLeft + " to check did not include "
+ + expectedFeature, featuresLeft.remove(expectedFeature));
+
+ boolean hasSensorFeature = mPackageManager.hasSystemFeature(expectedFeature);
+
+ List<Sensor> sensors = mSensorManager.getSensorList(expectedSensorType);
+ List<String> sensorNames = new ArrayList<String>(sensors.size());
+ for (Sensor sensor : sensors) {
+ sensorNames.add(sensor.getName());
+ }
+ boolean hasSensorType = !sensors.isEmpty();
+
+ String message = "PackageManager#hasSystemFeature(" + expectedFeature + ") returns "
+ + hasSensorFeature
+ + " but SensorManager#getSensorList(" + expectedSensorType + ") shows sensors "
+ + sensorNames;
+
+ assertEquals(message, hasSensorFeature, hasSensorType);
+ }
+
+ /**
+ * Check that the {@link TelephonyManager#getPhoneType()} matches the reported features.
+ */
+ public void testTelephonyFeatures() {
+ int phoneType = mTelephonyManager.getPhoneType();
+ switch (phoneType) {
+ case TelephonyManager.PHONE_TYPE_GSM:
+ assertTelephonyFeatures(PackageManager.FEATURE_TELEPHONY,
+ PackageManager.FEATURE_TELEPHONY_GSM);
+ break;
+
+ case TelephonyManager.PHONE_TYPE_CDMA:
+ assertTelephonyFeatures(PackageManager.FEATURE_TELEPHONY,
+ PackageManager.FEATURE_TELEPHONY_CDMA);
+ break;
+
+ case TelephonyManager.PHONE_TYPE_NONE:
+ assertTelephonyFeatures();
+ break;
+
+ default:
+ throw new IllegalArgumentException("Did you add a new phone type? " + phoneType);
+ }
+ }
+
+ /**
+ * Checks that the given features are enabled and also that all the other telephony features
+ * are disabled.
+ *
+ * @param expectedFeaturesEnabled that {@link PackageManager} should report
+ */
+ private void assertTelephonyFeatures(String... expectedFeaturesEnabled) {
+ // Create sets of enabled and disabled features.
+ Set<String> enabledFeatures = new HashSet<String>();
+ Collections.addAll(enabledFeatures, expectedFeaturesEnabled);
+
+ Set<String> disabledFeatures = new HashSet<String>();
+ Collections.addAll(disabledFeatures,
+ PackageManager.FEATURE_TELEPHONY,
+ PackageManager.FEATURE_TELEPHONY_GSM,
+ PackageManager.FEATURE_TELEPHONY_CDMA);
+ disabledFeatures.removeAll(enabledFeatures);
+
+ // Get all available features to test not only hasFeature but getSystemAvailableFeatures.
+ PackageManager packageManager = mContext.getPackageManager();
+ Set<String> availableFeatures = new HashSet<String>();
+ for (FeatureInfo featureInfo : packageManager.getSystemAvailableFeatures()) {
+ availableFeatures.add(featureInfo.name);
+ }
+
+ for (String feature : enabledFeatures) {
+ assertAvailable(feature);
+ }
+
+ for (String feature : disabledFeatures) {
+ assertNotAvailable(feature);
+ }
+ }
+
+ public void testTouchScreenFeatures() {
+ ConfigurationInfo configInfo = mActivityManager.getDeviceConfigurationInfo();
+ if (configInfo.reqTouchScreen != Configuration.TOUCHSCREEN_NOTOUCH) {
+ assertAvailable(PackageManager.FEATURE_TOUCHSCREEN);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_TOUCHSCREEN);
+ }
+
+ // TODO: Add tests for the other touchscreen features.
+ }
+
+
+ public void testWifiFeature() throws Exception {
+ boolean enabled = mWifiManager.isWifiEnabled();
+ try {
+ // WifiManager is hard-coded to return true, but in other implementations this could
+ // return false for devices that don't have WiFi.
+ if (mWifiManager.setWifiEnabled(true)) {
+ assertAvailable(PackageManager.FEATURE_WIFI);
+ } else {
+ assertNotAvailable(PackageManager.FEATURE_WIFI);
+ }
+ } finally {
+ if (!enabled) {
+ mWifiManager.setWifiEnabled(false);
+ }
+ }
+ }
+
+ private void assertAvailable(String feature) {
+ assertTrue("PackageManager#hasSystemFeature should return true for " + feature,
+ mPackageManager.hasSystemFeature(feature));
+ assertTrue("PackageManager#getSystemAvailableFeatures should have " + feature,
+ mAvailableFeatures.contains(feature));
+ }
+
+ private void assertNotAvailable(String feature) {
+ assertFalse("PackageManager#hasSystemFeature should NOT return true for " + feature,
+ mPackageManager.hasSystemFeature(feature));
+ assertFalse("PackageManager#getSystemAvailableFeatures should NOT have " + feature,
+ mAvailableFeatures.contains(feature));
+ }
+}
diff --git a/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java b/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java
index 4f55f96..26a90b9 100644
--- a/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java
+++ b/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java
@@ -16,13 +16,13 @@
package android.opengl.cts;
+import dalvik.annotation.TestTargetClass;
+
import android.opengl.GLSurfaceView;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.util.Log;
-import dalvik.annotation.TestTargetClass;
-
/**
* Tests for the GLSurfaceView class.
*/
diff --git a/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
new file mode 100644
index 0000000..f1acd87
--- /dev/null
+++ b/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2010 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.opengl.cts;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ConfigurationInfo;
+import android.content.pm.FeatureInfo;
+import android.content.pm.PackageManager;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import java.util.regex.Pattern;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLContext;
+import javax.microedition.khronos.egl.EGLDisplay;
+
+/**
+ * Test for checking whether the ro.opengles.version property is set to the correct value.
+ */
+public class OpenGlEsVersionTest
+ extends ActivityInstrumentationTestCase2<OpenGlEsVersionStubActivity> {
+
+ private static final String TAG = OpenGlEsVersionTest.class.getSimpleName();
+
+ private static final int EGL_OPENGL_ES2_BIT = 0x0004;
+
+ private OpenGlEsVersionStubActivity mActivity;
+
+ public OpenGlEsVersionTest() {
+ super("com.android.cts.stub", OpenGlEsVersionStubActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ public void testOpenGlEsVersion() throws InterruptedException {
+ int detectedVersion = getDetectedVersion();
+ int reportedVersion = getVersionFromActivityManager(mActivity);
+
+ assertEquals("Detected OpenGL ES major version " + detectedVersion
+ + " but Activity Manager is reporting " + reportedVersion
+ + " (Check ro.opengles.version)", detectedVersion, reportedVersion);
+ assertEquals("Reported OpenGL ES version from ActivityManager differs from PackageManager",
+ reportedVersion, getVersionFromPackageManager(mActivity));
+
+ assertGlVersionString(1);
+ if (detectedVersion >= 2) {
+ restartActivityWithClientVersion(2);
+ assertGlVersionString(2);
+ }
+ }
+
+ /** @return OpenGL ES major version 1 or 2 or some negative number for error */
+ private static int getDetectedVersion() {
+
+ /*
+ * Get all the device configurations and check if any of the attributes specify the
+ * the EGL_OPENGL_ES2_BIT to determine whether the device supports 2.0.
+ */
+
+ EGL10 egl = (EGL10) EGLContext.getEGL();
+ 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;
+ }
+ } else {
+ Log.w(TAG, "Getting config attribute with "
+ + "EGL10#eglGetConfigAttrib failed "
+ + "(" + i + "/" + numConfigs[0] + "): "
+ + egl.eglGetError());
+ }
+ }
+ return 1;
+ } else {
+ 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;
+ }
+ }
+
+ private static int getVersionFromActivityManager(Context context) {
+ ActivityManager activityManager =
+ (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
+ if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) {
+ return getMajorVersion(configInfo.reqGlEsVersion);
+ } else {
+ return 1; // Lack of property means OpenGL ES version 1
+ }
+ }
+
+ private static int getVersionFromPackageManager(Context context) {
+ PackageManager packageManager = context.getPackageManager();
+ FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
+ if (featureInfos != null && featureInfos.length > 0) {
+ for (FeatureInfo featureInfo : featureInfos) {
+ // Null feature name means this feature is the open gl es version feature.
+ if (featureInfo.name == null) {
+ if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
+ return getMajorVersion(featureInfo.reqGlEsVersion);
+ } else {
+ return 1; // Lack of property means OpenGL ES version 1
+ }
+ }
+ }
+ }
+ return 1;
+ }
+
+ /** @see FeatureInfo#getGlEsVersion() */
+ private static int getMajorVersion(int glEsVersion) {
+ return ((glEsVersion & 0xffff0000) >> 16);
+ }
+
+ /**
+ * Check that the version string has some form of "Open GL ES X.Y" in it where X is the major
+ * version and Y must be some digit.
+ */
+ private void assertGlVersionString(int majorVersion) throws InterruptedException {
+ String message = "OpenGL version string '" + mActivity.getVersionString()
+ + "' is not " + majorVersion + ".0+.";
+ assertTrue(message, Pattern.matches(".*OpenGL.*ES.*" + majorVersion + "\\.\\d.*",
+ mActivity.getVersionString()));
+ }
+
+ /** Restart {@link GLSurfaceViewStubActivity} with a specific client version. */
+ private void restartActivityWithClientVersion(int version) {
+ mActivity.finish();
+ setActivity(null);
+
+ try {
+ Intent intent = OpenGlEsVersionStubActivity.createIntent(version);
+ setActivityIntent(intent);
+ mActivity = getActivity();
+ } finally {
+ setActivityIntent(null);
+ }
+ }
+}
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorManagerTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorManagerTest.java
index 73c32af..136d077 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorManagerTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorManagerTest.java
@@ -23,7 +23,6 @@
import dalvik.annotation.ToBeFixed;
import android.content.Context;
-import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
@@ -32,13 +31,7 @@
import android.test.AndroidTestCase;
import android.util.Log;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
@SuppressWarnings("deprecation")
@TestTargetClass(SensorManager.class)
@@ -311,75 +304,4 @@
assertTrue(Math.abs(orientation[2]) <= TWO_PI);
}
}
-
- /**
- * Check that the sensor features reported by the PackageManager correspond to the sensors
- * returned by {@link SensorManager#getSensorList(int)}.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getSensorList",
- args = {int.class}
- )
- public void testGetSensorList() throws Exception {
- Set<String> featuresLeft = getAllSensorFeatures();
-
- assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_ACCELEROMETER,
- Sensor.TYPE_ACCELEROMETER);
- assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_COMPASS,
- Sensor.TYPE_MAGNETIC_FIELD);
- assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_LIGHT,
- Sensor.TYPE_LIGHT);
- assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_PROXIMITY,
- Sensor.TYPE_PROXIMITY);
-
- assertTrue("Assertions need to be added to this test for " + featuresLeft,
- featuresLeft.isEmpty());
- }
-
- /** Get a list of all the sensor features to make sure the test checks them all. */
- private static Set<String> getAllSensorFeatures()
- throws IllegalArgumentException, IllegalAccessException {
- Set<String> sensorFeatures = new HashSet<String>();
- Field[] fields = PackageManager.class.getFields();
- for (Field field : fields) {
- if (field.getName().startsWith("FEATURE_SENSOR_")) {
- String feature = (String) field.get(null);
- sensorFeatures.add(feature);
- }
- }
- return sensorFeatures;
- }
-
- /**
- * Check that if the PackageManager declares a sensor feature that the device has at least
- * one sensor that matches that feature. Also check that if a PackageManager does not declare
- * a sensor that the device also does not have such a sensor.
- *
- * @param featuresLeft to check in order to make sure the test covers all sensor features
- * @param expectedFeature that the PackageManager may report
- * @param expectedSensorType that that {@link SensorManager#getSensorList(int)} may have
- */
- private void assertFeatureForSensor(Set<String> featuresLeft, String expectedFeature,
- int expectedSensorType) {
- assertTrue("Features left " + featuresLeft + " to check did not include "
- + expectedFeature, featuresLeft.remove(expectedFeature));
-
- PackageManager packageManager = mContext.getPackageManager();
- boolean hasSensorFeature = packageManager.hasSystemFeature(expectedFeature);
-
- List<Sensor> sensors = mSensorManager.getSensorList(expectedSensorType);
- List<String> sensorNames = new ArrayList<String>(sensors.size());
- for (Sensor sensor : sensors) {
- sensorNames.add(sensor.getName());
- }
- boolean hasSensorType = !sensors.isEmpty();
-
- String message = "PackageManager#hasSystemFeature(" + expectedFeature + ") returns "
- + hasSensorFeature
- + " but SensorManager#getSensorList(" + expectedSensorType + ") shows sensors "
- + sensorNames;
-
- assertEquals(message, hasSensorFeature, hasSensorType);
- }
}
diff --git a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
index c07c557..9ecbf20 100644
--- a/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/TelephonyManagerTest.java
@@ -22,8 +22,6 @@
import dalvik.annotation.TestTargets;
import android.content.Context;
-import android.content.pm.FeatureInfo;
-import android.content.pm.PackageManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Looper;
@@ -33,9 +31,6 @@
import android.telephony.TelephonyManager;
import android.test.AndroidTestCase;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
import java.util.regex.Pattern;
@TestTargetClass(TelephonyManager.class)
@@ -408,71 +403,4 @@
}
}
}
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "getPhoneType",
- args = {}
- )
- public void testGetPhoneType() {
- int phoneType = mTelephonyManager.getPhoneType();
- switch (phoneType) {
- case TelephonyManager.PHONE_TYPE_GSM:
- assertTelephonyFeatures(PackageManager.FEATURE_TELEPHONY,
- PackageManager.FEATURE_TELEPHONY_GSM);
- break;
-
- case TelephonyManager.PHONE_TYPE_CDMA:
- assertTelephonyFeatures(PackageManager.FEATURE_TELEPHONY,
- PackageManager.FEATURE_TELEPHONY_CDMA);
- break;
-
- case TelephonyManager.PHONE_TYPE_NONE:
- assertTelephonyFeatures();
- break;
-
- default:
- throw new IllegalArgumentException("Did you add a new phone type? " + phoneType);
- }
- }
-
- /**
- * Checks that the given features are enabled and also that all the other telephony features
- * are disabled.
- *
- * @param expectedFeaturesEnabled that {@link PackageManager} should report
- */
- private void assertTelephonyFeatures(String... expectedFeaturesEnabled) {
- // Create sets of enabled and disabled features.
- Set<String> enabledFeatures = new HashSet<String>();
- Collections.addAll(enabledFeatures, expectedFeaturesEnabled);
-
- Set<String> disabledFeatures = new HashSet<String>();
- Collections.addAll(disabledFeatures,
- PackageManager.FEATURE_TELEPHONY,
- PackageManager.FEATURE_TELEPHONY_GSM,
- PackageManager.FEATURE_TELEPHONY_CDMA);
- disabledFeatures.removeAll(enabledFeatures);
-
- // Get all available features to test not only hasFeature but getSystemAvailableFeatures.
- PackageManager packageManager = getContext().getPackageManager();
- Set<String> availableFeatures = new HashSet<String>();
- for (FeatureInfo featureInfo : packageManager.getSystemAvailableFeatures()) {
- availableFeatures.add(featureInfo.name);
- }
-
- for (String feature : enabledFeatures) {
- assertTrue("PackageManager#hasSystemFeature should return true for " + feature,
- packageManager.hasSystemFeature(feature));
- assertTrue("PackageManager#getSystemAvailableFeatures should have " + feature,
- availableFeatures.contains(feature));
- }
-
- for (String feature : disabledFeatures) {
- assertFalse("PackageMangaer#hasSystemFeature should NOT return true for " + feature,
- packageManager.hasSystemFeature(feature));
- assertFalse("PackageManage#getSystemAvailableFeatures should NOT have " + feature,
- availableFeatures.contains(feature));
- }
- }
}