cts 检查系统有哪些功能
2012-05-18 12:36
274 查看
问题
cts测试时发现在result.xml头部中有很多关于手机的信息,包括当前系统有哪些功能,以及build版本等等,这些心怎么显示出来的?分析
cts 测试中会在TestDeviceSetup app中调用 getFeatures() 该方法返回所有系统的feature,该app是cts的tool源码路径为/cts/tool/device-setup.getFeature的具体实现:
StringBuilder features = new StringBuilder();
try {
Set<String> checkedFeatures = new HashSet<String>();
PackageManager packageManager = getContext().getPackageManager();
for (String featureName : getPackageManagerFeatures())
{
checkedFeatures.add(featureName);
boolean hasFeature = packageManager.hasSystemFeature(featureName);
addFeature(features, featureName, "sdk", hasFeature);
}
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
if (featureInfos != null) {
for (FeatureInfo featureInfo : featureInfos) {
if (featureInfo.name != null && !checkedFeatures.contains(featureInfo.name)) {
addFeature(features, featureInfo.name, "other", true);
}
}
}
} catch (Exception exception) {
Log.e(TAG, "Error getting features: " + exception.getMessage(), exception);
}
实现上分为两步:
1)直接从PackageManager类中获取,该类定义了系统的大部分feature的字符串常量;
private List<String> getPackageManagerFeatures() {
try {
List<String> features = new ArrayList<String>();
Field[] fields = PackageManager.class.getFields();
for (Field field : fields) {
if (field.getName().startsWith("FEATURE_")) {
String feature = (String) field.get(null);
features.add(feature);
}
}
return features;
} catch (IllegalAccessException illegalAccess) {
throw new RuntimeException(illegalAccess);
}
}
该方法是用发射机制将PackageManager类中的以FEATURE_公共常量列出来。下面是该类中的部分常量;
@SdkConstant(SdkConstantType.FEATURE)
public static final String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
/**
* Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device is capable of communicating with
* other devices via Bluetooth.
*/
@SdkConstant(SdkConstantType.FEATURE)
public static final String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
/**
* Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device has a camera facing away
* from the screen.
*/
@SdkConstant(SdkConstantType.FEATURE)
public static final String FEATURE_CAMERA = "android.hardware.camera";
/**
* Feature for {@link #getSystemAvailableFeatures} and
* {@link #hasSystemFeature}: The device's camera supports auto-focus.
*/
@SdkConstant(SdkConstantType.FEATURE)
public static final String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
/*
2)系统在启动PackageMangerService时会将对应的系统Feature加载并保存 在一个HashMap中,那通过在这个容器里找到相关feature的信息,如果有证明存在。
packageManager.getSystemAvailableFeatures(),会返回FeatureInfo的数组,保存的是一些Feature的信息。
该数组的获取就是通过前面提到的HashMap 对象有关。
系统启动的时候怎么判断是否有哪些Feature,就是通过解析获取/sys/etc下的xml来的。
该文件有很多的系统Feature的定义
相关文章推荐
- 浅谈符合SEO优化的CMS系统需要哪些功能
- 网路游侠:关于计算机安全检查取证系统中几个功能的展示
- 什么是APS高级计划排程(生产计划排产)系统主要功能模块有哪些?
- win8系统中旧版windows系统功能都有哪些不见了呢
- Win10系统新特性有哪些?Win10新功能汇总介绍
- win8系统中旧版windows系统功能都有哪些不见了呢
- 一些功能不错的开源工具(DNSPod、MailServer、Bug跟踪系统、VS代码检查、VS反翻译)
- 一个完整的系统已经具备哪些功能
- 分销管理系统的功能范畴包括哪些?
- 社交系统ThinkSNS V4后台有哪些“隐藏”不为人知的功能
- 微信分销系统的功能有哪些
- 一个灵活、好用、扩展性好的WCM系统应该包含哪些功能
- BIM运维系统应该有哪些功能(二)
- 配置 JobhistoryServer 历史服务器,日志聚集功能,HDFS 文件系统用户权限检查,取消HDFS警告提示
- 医院网站管理系统需要实现哪些功能?
- P2P网贷系统开发需要哪些功能?
- chkconfig 功能说明:检查,设置系统的各种服务。
- 一个完整的微服务系统,应该包含哪些功能?
- 一个成熟的自动化运维系统应具备哪些功能?
- BIM运维系统应该有哪些功能(一)