Android : 判断平台是否支持wifi功能
一、配置
Android4.0及以上版本的模块判断函数:getPackageManager().hasSystemFeature(String string). 通过该函数判断系统是否有特定的模块功能。
例如判断是否有wifi的具体代码:getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI);
PackageManager.FEATURE_WIFI 在PackageManager.java中的定义为:public static final String FEATURE_WIFI = "android.hardware.wifi";
而"android.hardware.wifi"字符串存在系统/system/etc/permissions/xxxx.xml文件里,它们一般从源码/framework/base/data/etc/xxx.xml复制过来(Android7.1 RK平台发现存在于frameworks/native/data/etc/xxx.xml文件);
二、解析
代码路径:\frameworks\base\core\java\com\android\server\SystemConfig.java
void readPermissions(File libraryDir, int permissionFlag) { // Read permissions from given directory. if (!libraryDir.exists() || !libraryDir.isDirectory()) { if (permissionFlag == ALLOW_ALL) { Slog.w(TAG, "No directory " + libraryDir + ", skipping"); } return; } if (!libraryDir.canRead()) { Slog.w(TAG, "Directory " + libraryDir + " cannot be read"); return; } // Iterate over the files in the directory and scan .xml files File platformFile = null; for (File f : libraryDir.listFiles()) { // We'll read platform.xml last if (f.getPath().endsWith("etc/permissions/platform.xml")) { platformFile = f; continue; } if (!f.getPath().endsWith(".xml")) { Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring"); continue; } if (!f.canRead()) { Slog.w(TAG, "Permissions library file " + f + " cannot be read"); continue; } readPermissionsFromXml(f, permissionFlag); //解析etc/permissions/下所有的.xml文件并提取支持的feature
} // Read platform permissions last so it will take precedence if (platformFile != null) { readPermissionsFromXml(platformFile, permissionFlag); } }
posted on 2021-03-03 11:19 sheldon_blogs 阅读(919) 评论(0) 编辑 收藏 举报