int
emulator_window_init( EmulatorWindow*       emulator,
                AConfig*         aconfig,
                const char*      basepath,
                int              x,
                int              y,
                AndroidOptions*  opts )
{
    static const SkinFramebufferFuncs skin_fb_funcs = {
        .create_framebuffer = &emulator_window_framebuffer_create,
        .free_framebuffer = &emulator_window_framebuffer_free,
        .get_pixels = &emulator_window_framebuffer_get_pixels,
        .get_depth = &emulator_window_framebuffer_get_depth,
    };

    emulator->aconfig = aconfig;
    emulator->layout_file =
            skin_file_create_from_aconfig(aconfig,
                                          basepath,
                                          &skin_fb_funcs);
    emulator->ui = NULL;
    emulator->win_x = x;
    emulator->win_y = y;
    emulator->opts[0] = opts[0];

    /* register as a framebuffer clients for all displays defined in the skin file */
    SKIN_FILE_LOOP_PARTS( emulator->layout_file, part )
        SkinDisplay*  disp = part->display;
        if (disp->valid) {
            qframebuffer_add_client( disp->framebuffer,
                                    emulator,
                                    emulator_window_fb_update,
                                    emulator_window_fb_rotate,
                                    emulator_window_fb_poll,
                                    NULL );
        }
    SKIN_FILE_LOOP_END_PARTS

    /* initialize hardware control support */
    AndroidHwControlFuncs funcs;
    funcs.light_brightness = emulator_window_light_brightness;
    android_hw_control_set(emulator, &funcs);

    return 0;
}
int
uiCmdProxy_create(int fd)
{
    
    _uiCmdProxy.sock = fd;
    _uiCmdProxy.looper = looper_newCore();
    loopIo_init(&_uiCmdProxy.io, _uiCmdProxy.looper, _uiCmdProxy.sock,
                _uiCmdProxy_io_func, &_uiCmdProxy);
    loopIo_wantRead(&_uiCmdProxy.io);
    _uiCmdProxy.sync_writer = syncsocket_init(fd);
    if (_uiCmdProxy.sync_writer == NULL) {
        derror("Unable to initialize UICmdProxy writer: %s\n", errno_str);
        uiCmdProxy_destroy();
        return -1;
    }
    {
        
        
        AndroidHwControlFuncs  funcs;
        funcs.light_brightness = _uiCmdProxy_brightness_change_callback;
        android_hw_control_set(&_uiCmdProxy, &funcs);
    }
    return 0;
}