免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1945 | 回复: 0
打印 上一主题 下一主题

一则CTS测试错误分析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-23 01:46 |只看该作者 |倒序浏览
一则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:<false> but was:<true> 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<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);

    }

 

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

 

 

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP