LightService

frameworks\base\services\core\java\com\android\server\lights\LightsService.java

构造方法

    public LightsService(Context context) {
        this(context, new VintfHalCache(), Looper.myLooper());
        Log.e("LightsService","LightsService");
    }

    @VisibleForTesting
    LightsService(Context context, Supplier<ILights> service, Looper looper) {
        super(context);
        mH = new Handler(looper);
        mVintfLights = service.get() != null ? service : null;
        populateAvailableLights(context);
        mManagerService = new LightsManagerBinderService();
    }
populateAvailableLights
    private void populateAvailableLights(Context context) {if (mVintfLights != null) {
            populateAvailableLightsFromAidl(context); //执行这里
        } else {
            populateAvailableLightsFromHidl(context);
        }for (int i = mLightsById.size() - 1; i >= 0; i--) {
            final int type = mLightsById.keyAt(i);
            if (0 <= type && type < mLightsByType.length) {
                mLightsByType[type] = mLightsById.valueAt(i);
            }
        }
    }
populateAvailableLightsFromAidl
 private void populateAvailableLightsFromAidl(Context context) {
        try {for (HwLight hwLight : mVintfLights.get().getLights()) {
                mLightsById.put(hwLight.id, new LightImpl(context, hwLight));
            }
        } catch (RemoteException ex) {
            Slog.e(TAG, "Unable to get lights from HAL", ex);
        }
    }

private final Supplier<ILights> mVintfLights;

mVintfLights是ILights类型的 

ILight定义在 hardware\interfaces\light\aidl\android\hardware\light\ILights.aidl

具体实现在hardware\rockchip\light_aidl\Lights.cpp

static int access_backlight() {
    std::string backlight_path(getDriverPath(LightType::BACKLIGHT));
    ALOGV("backlight_path: %s", backlight_path.c_str());
    if (access(backlight_path.c_str(), F_OK) < 0) {
        ALOGE("error: %s", strerror(errno));
        return -errno;
    }
    return 0;
}
const char* getDriverPath(LightType type) {
    switch (type) {
        case LightType::BACKLIGHT:
            return "/sys/class/backlight/backlight/brightness";
        case LightType::BUTTONS:
            return "/sys/class/leds/button-backlight/brightness";
        case LightType::BATTERY:
        case LightType::NOTIFICATIONS:
        case LightType::ATTENTION:
            return "/sys/class/leds";
        case LightType::BLUETOOTH:
        case LightType::WIFI:
        case LightType::MICROPHONE:
        case LightType::KEYBOARD:
        default:
            return "/not_supported";
    }
}

 

posted @ 2023-08-08 16:32  xiaowang_lj  阅读(19)  评论(0编辑  收藏  举报