打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
一则CTS测试错误分析

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 \

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
android CTS测试FAIL项解决集锦
Sensor传感器源码的阅读与应用开发简单实例
关于sensor在android系统framework和应用中的使用 | 卓派观点
Android之使用传感器获取相应数据
【Based Android】Android Sensor感应器介绍
10.10 传感器专题(1)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服