liblight/lights.c
/** Open a new instance of a lights device using name */
Open a new instance of a lights device using name
Open a new instance of a lights device using name
static int open_lights(const struct hw_module_t* module, char const* name,
        struct hw_device_t** device)
{
    int (*set_light)(struct light_device_t* dev,
            struct light_state_t const* state);
    if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) {
        char property[PROPERTY_VALUE_MAX];
        property_get("persist.extend.brightness", property, "0");
        if(!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
           !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
            property_get("persist.display.max_brightness", property, "255");
            g_brightness_max = atoi(property);
            set_brightness_ext_init();
            set_light = set_light_backlight_ext;
        } else
            set_light = set_light_backlight;
    } else if (0 == strcmp(LIGHT_ID_BATTERY, name))
        set_light = set_light_battery;
    else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name))
        set_light = set_light_notifications;
    else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) {
        if (!access(BUTTON_FILE, F_OK)) {
          set_light = set_light_buttons;
        } else {
          return -EINVAL;
        }
    }
    else if (0 == strcmp(LIGHT_ID_ATTENTION, name))
        set_light = set_light_attention;
    else
        return -EINVAL;
    pthread_once(&g_init, init_globals);
    struct light_device_t *dev = malloc(sizeof(struct light_device_t));
    if(!dev)
        return -ENOMEM;
    memset(dev, 0, sizeof(*dev));
    dev->common.tag = HARDWARE_DEVICE_TAG;
    dev->common.version = LIGHTS_DEVICE_API_VERSION_2_0;
    dev->common.module = (struct hw_module_t*)module;
    dev->common.close = (int (*)(struct hw_device_t*))close_lights;
    dev->set_light = set_light;
    *device = (struct hw_device_t*)dev;
    return 0;
}
static int open_lights ( const struct hw_module_t * module , char const * name , struct hw_device_t * * device ) { int ( * set_light ) ( struct light_device_t * dev , struct light_state_t const * state ) ; if ( 0 == strcmp ( LIGHT_ID_BACKLIGHT , name ) ) { char property [ PROPERTY_VALUE_MAX ] ; property_get ( " " , property , " " ) ; if ( ! ( strncmp ( property , " " , PROPERTY_VALUE_MAX ) ) || ! ( strncmp ( property , " " , PROPERTY_VALUE_MAX ) ) ) { property_get ( " " , property , " " ) ; g_brightness_max = atoi ( property ) ; set_brightness_ext_init ( ) ; set_light = set_light_backlight_ext ; } else set_light = set_light_backlight ; } else if ( 0 == strcmp ( LIGHT_ID_BATTERY , name ) ) set_light = set_light_battery ; else if ( 0 == strcmp ( LIGHT_ID_NOTIFICATIONS , name ) ) set_light = set_light_notifications ; else if ( 0 == strcmp ( LIGHT_ID_BUTTONS , name ) ) { if ( ! access ( BUTTON_FILE , F_OK ) ) { set_light = set_light_buttons ; } else { return - EINVAL ; } } else if ( 0 == strcmp ( LIGHT_ID_ATTENTION , name ) ) set_light = set_light_attention ; else return - EINVAL ; pthread_once ( & g_init , init_globals ) ; struct light_device_t * dev = malloc ( sizeof ( struct light_device_t ) ) ; if ( ! dev ) return - ENOMEM ; memset ( dev , 0 , sizeof ( * dev ) ) ; dev -> common . tag = HARDWARE_DEVICE_TAG ; dev -> common . version = LIGHTS_DEVICE_API_VERSION_2_0 ; dev -> common . module = ( struct hw_module_t * ) module ; dev -> common . close = ( int ( * ) ( struct hw_device_t * ) ) close_lights ; dev -> set_light = set_light ; * device = ( struct hw_device_t * ) dev ; return 0 ; }
Open a new instance of a lights device using name
Open a new instance of a lights device using name
// enable light button when the file is present