systemServer启动AppWidgetService

时间:2020/09/25
之前公司不允许csdn,笔记写在其它地方。最近整理过来

1、是否启动AppWidgetService

//第一个值调用PackageManager.hasSystemFeature
//第二个boolear值是false
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)
        || context.getResources().getBoolean(R.bool.config_enableAppWidgetService)) {
    
    
    traceBeginAndSlog("StartAppWidgetService");
    mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
    traceEnd();
}

2、条件判断

PackageManager.hasSystemFeature
其实走的是PackageManagerService.hasSystemFeature

public boolean hasSystemFeature(String name, int version) {
    
    
    // allow instant applications
    synchronized (mAvailableFeatures) {
    
    
        final FeatureInfo feat = mAvailableFeatures.get(name);
        if (feat == null) {
    
    
            return false;
        } else {
    
    
            return feat.version >= version;
        }
    }
}

3、功能开关来源

mAvailableFeatures里的值来自于SystemConfig

SystemConfig systemConfig = SystemConfig.getInstance();
mAvailableFeatures = systemConfig.getAvailableFeatures();

4、构造方法中读取各个目录下的配置

SystemConfig() {
    
    
    // Read configuration from system
    readPermissions(Environment.buildPath(
            Environment.getRootDirectory(), "etc", "sysconfig"), ALLOW_ALL);


    // Read configuration from the old permissions dir
    readPermissions(Environment.buildPath(
            Environment.getRootDirectory(), "etc", "permissions"), ALLOW_ALL);


    // Vendors are only allowed to customize these
    int vendorPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_PRIVAPP_PERMISSIONS
            | ALLOW_ASSOCIATIONS;
    if (Build.VERSION.FIRST_SDK_INT <= Build.VERSION_CODES.O_MR1) {
    
    
        // For backward compatibility
        vendorPermissionFlag |= (ALLOW_PERMISSIONS | ALLOW_APP_CONFIGS);
    }
    readPermissions(Environment.buildPath(
            Environment.getVendorDirectory(), "etc", "sysconfig"), vendorPermissionFlag);
    readPermissions(Environment.buildPath(
            Environment.getVendorDirectory(), "etc", "permissions"), vendorPermissionFlag);


    // Allow ODM to customize system configs as much as Vendor, because /odm is another
    // vendor partition other than /vendor.
    int odmPermissionFlag = vendorPermissionFlag;
    readPermissions(Environment.buildPath(
            Environment.getOdmDirectory(), "etc", "sysconfig"), odmPermissionFlag);
    readPermissions(Environment.buildPath(
            Environment.getOdmDirectory(), "etc", "permissions"), odmPermissionFlag);


    String skuProperty = SystemProperties.get(SKU_PROPERTY, "");
    if (!skuProperty.isEmpty()) {
    
    
        String skuDir = "sku_" + skuProperty;


        readPermissions(Environment.buildPath(
                Environment.getOdmDirectory(), "etc", "sysconfig", skuDir), odmPermissionFlag);
        readPermissions(Environment.buildPath(
                Environment.getOdmDirectory(), "etc", "permissions", skuDir),
                odmPermissionFlag);
    }

5、最终读取到/vendor/etc/permissions的handheld_core_hardware.xml

rom根路径全局搜索配置

sprocomm@Srv50:~/sdb/MTK_Q/alps$ find -type f -name '*xml'|xargs grep --color=auto -rn 'name="android.software.app_widgets"'
./frameworks/native/data/etc/tablet_core_hardware.xml:43:    <feature name="android.software.app_widgets" />
./frameworks/native/data/etc/handheld_core_hardware.xml:42:    <feature name="android.software.app_widgets" />
./frameworks/native/data/etc/android.software.app_widgets.xml:18:    <feature name="android.software.app_widgets" />

猜你喜欢

转载自blog.csdn.net/a396604593/article/details/129819860