• 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文件);

    二、解析

    代码路径:frameworksasecorejavacomandroidserverSystemConfig.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);
            }
        }
  • 相关阅读:
    老王python博客
    python中文分词
    python 字典(dict)get方法应用
    python yield和generators(生成器)
    python ASCII返回对应的值(chr)
    python 字符串特点
    python 包的定义,结构,导入过程
    fabric的安装和配置
    python 正则表达式re findall
    python unittest单元测试方法和用例
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/14473381.html
Copyright © 2020-2023  润新知