分类: 嵌入式
2011-10-17 14:43:56
CTS测试传感器发现失败,具体错误是PackageManager找不到,SensorManager确能找到 cts_host > start --plan CTS -t android.app.cts.SystemFeaturesTest#testSensorFeatures start test android.app.cts.SystemFeaturesTest#testSensorFeatures ============================================================== Test package: android.app android.app.cts.SystemFeaturesTest#testSensorFeatures...(fail) junit.framework.AssertionFailedError: PackageManager#hasSystemFeature(android.hardware.sensor.accelerometer) returns false but SensorManager#getSensorList(1) shows sensors [3-axis Accelerometer] expected: at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295) at android.app.cts.SystemFeaturesTest.testSensorFeatures(SystemFeaturesTest.java:213) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448) at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295) at android.app.cts.SystemFeaturesTest.testSensorFeatures(SystemFeaturesTest.java:213) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
============================================================== Time: 5177129.236s
cts_host >
PackageManager找不到传感器,说明错误出在PM身上。 查看CTS测试代码,如红色所示,当expectedFeature为FEATURE_SENSOR_ACCELEROMETER时,返回错误。
private void assertFeatureForSensor(Set int expectedSensorType) { assertTrue("Features left " + featuresLeft + " to check did not include " + expectedFeature, featuresLeft.remove(expectedFeature));
boolean hasSensorFeature = mPackageManager.hasSystemFeature(expectedFeature);
List List 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); }
这个字串系统中是有的,但是hasSystemFeature需要检查权限,需要将frameworks/base/data/etc/android.hardware.sensor.accelerometer.xml文件添加进目标板。 frameworks/base/core/java/android/content/pm/PackageManager.java:727: public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
最终在mk中添加以下内容解决问题。 frameworks/base/data/etc/android.hardware.sensor.accelerometer.xml:system/etc/permissions/android.hardware.sensor.accelerometer.xml \
|