Chinaunix首页 | 论坛 | 博客
  • 博客访问: 279906
  • 博文数量: 95
  • 博客积分: 2047
  • 博客等级: 大尉
  • 技术积分: 1022
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 16:18
文章分类

全部博文(95)

文章存档

2013年(1)

2011年(94)

我的朋友

分类: 嵌入式

2011-10-17 14:43:56

一则CTS测试错误分析
2011-10-17 14:43

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: but was: at android.app.cts.SystemFeaturesTest.assertFeatureForSensor(SystemFeaturesTest.java:295)

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 featuresLeft, String expectedFeature,

            int expectedSensorType) {

        assertTrue("Features left " + featuresLeft + " to check did not include "

                + expectedFeature, featuresLeft.remove(expectedFeature));

 

        boolean hasSensorFeature = mPackageManager.hasSystemFeature(expectedFeature);

 

        List sensors = mSensorManager.getSensorList(expectedSensorType);

        List sensorNames = new ArrayList(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);

    }

 

这个字串系统中是有的,但是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 \

 

 

阅读(3498) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~