systemServer starts AppWidgetService

Time:
Before 2020/09/25, the company does not allow csdn, and the notes are written elsewhere. recently tidied up

1. Whether to start 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. Condition judgment

PackageManager.hasSystemFeature
actually takes thePackageManagerService.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. Function switch source

The values ​​in mAavailableFeatures come fromSystemConfig

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

4. Read the configuration in each directory in the construction method

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. Finally read the handheld_core_hardware.xml of /vendor/etc/permissions

rom root path global search configuration

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" />

Guess you like

Origin blog.csdn.net/a396604593/article/details/129819860