System-info Sample Overview

Mobile native

The System Info sample application demonstrates how you can get information about the system.

The following figure illustrates the main screen of the application.

Figure: System Info screens

System info screens System info screens System Info screens

The application opens with the main screen of system information categories. To check the information, touch the list item.

Implementation

To implement the application:

  1. To use the device-specific information-related features of the System Information API, include the <system_info.h> header file in your application:
    #include <system_info.h>
    
  2. Initialize the application using a common Tizen application structure:
    int 
    main(int argc, char *argv[])
    {
       appdata_s ad = {0,};
       int ret = 0;
    
       ui_app_lifecycle_callback_s event_callback = {0,};
       app_event_handler_h handlers[5] = {NULL,};
    
       event_callback.create = app_create;
       event_callback.terminate = app_terminate;
       event_callback.pause = app_pause;
       event_callback.resume = app_resume;
       event_callback.app_control = app_control;
    
       ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
       ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &d);
       ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
       ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
       ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
       ui_app_remove_event_handler(handlers[APP_EVENT_LOW_MEMORY]);
    
       ret = ui_app_main(argc, argv, &event_callback, &ad);
       if (ret != APP_ERROR_NONE) 
       {
          _E("ui_app_main() failed. err = %d", ret);
       }
    
       return ret;
    }
    

    The initialization is done with the _create_base_gui() function:

    static void 
    _create_base_gui(appdata_s *ad)
    {
       Evas_Object *bg = NULL;
       Evas_Object *list = NULL;
    
       // Window 
       ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
       elm_win_conformant_set(ad->win, EINA_TRUE);
       elm_win_autodel_set(ad->win, EINA_TRUE);
    
       if (elm_win_wm_rotation_supported_get(ad->win)) 
       {
          int rots[4] = {0, 90, 180, 270};
          elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
       }
    
       evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
    
       // Conformant
       ad->conform = elm_conformant_add(ad->win);
       elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
       elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
       evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       elm_win_resize_object_add(ad->win, ad->conform);
       evas_object_show(ad->conform);
    
       // Indicator BG
       bg = elm_bg_add(ad->conform);
       elm_object_style_set(bg, "indicator/headerbg");
       elm_object_part_content_set(ad->conform, "elm.swallow.indicator_bg", bg);
       evas_object_show(bg);
    
       // Naviframe
       ad->navi = elm_naviframe_add(ad->conform);
       evas_object_size_hint_weight_set(ad->navi, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       elm_object_content_set(ad->conform, ad->navi);
       evas_object_show(ad->navi);
       eext_object_event_callback_add(ad->navi, EEXT_CALLBACK_BACK, layout_back_cb, ad);
    
       // Base layout
       list = _create_main_list(ad);
    
       // Push the main layout to the naviframe
       elm_naviframe_item_push(ad->navi, "System Info", NULL, NULL, list, NULL);
    
       // Show the window after the base GUI is set up
       evas_object_show(ad->win);
    }
    
  3. Create the main list menu.

    Each main menu list item has a callback function for getting the system information. If an item is clicked, the information about the category is illustrated in a genlist.

    Evas_Object 
    *_create_main_list(appdata_s *ad)
    {
       Evas_Object *list = NULL;
    
       list = elm_list_add(ad->navi);
       evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
    
       elm_list_item_append(list, "Camera", NULL, NULL, camera_list_cb, ad);
       elm_list_item_append(list, "Keyboard", NULL, NULL, input_list_cb, ad);
       elm_list_item_append(list, "Location", NULL, NULL, location_list_cb, ad);
       elm_list_item_append(list, "Network", NULL, NULL, network_list_cb, ad);
       elm_list_item_append(list, "OpenGL", NULL, NULL, opengl_list_cb, ad);
       elm_list_item_append(list, "Platform", NULL, NULL, platform_list_cb, ad);
       elm_list_item_append(list, "Screen", NULL, NULL, screen_list_cb, ad);
       elm_list_item_append(list, "Sensors", NULL, NULL, sensors_list_cb, ad);
       elm_list_item_append(list, "Speech", NULL, NULL, speech_list_cb, ad);
       elm_list_item_append(list, "Usb", NULL, NULL, usb_list_cb, ad);
       elm_list_item_append(list, "Vision", NULL, NULL, vision_list_cb, ad);
       elm_list_item_append(list, "System", NULL, NULL, system_list_cb, ad);
       elm_list_item_append(list, "Others", NULL, NULL, others_list_cb, ad);
    
       evas_object_show(list);
    
       return list;
    }
    
  4. Create the function to call when the list item is clicked.

    The following code example is the callback function of the camera, which is a default double label list. The codes of others are similar.

    void 
    camera_list_cb(void *data, Evas_Object *obj, void *event_info)
    {
       appdata_s *ad = (appdata_s *)data;
       Evas_Object *clist = NULL;
       Evas_Object *navi = ad->navi;
       Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
    
       clist = elm_genlist_add(navi);
    
       itc->item_style = "double_label";
       itc->func.content_get = NULL;
       itc->func.text_get = _gl_text_get_cb;
       itc->func.del = gc_gl_del_cb;
    
       elm_genlist_block_count_set(clist, 14);
       elm_genlist_mode_set(clist, ELM_LIST_COMPRESS);
       evas_object_smart_callback_add(clist, "selected", gc_gl_selected_cb, NULL);
    
       for (i = 0; i < 5; i++) 
       {
          item_data_s *id = malloc(sizeof(item_data_s));
          id->index = i;
          item = elm_genlist_item_append(clist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, NULL, id);
          id->item = item;
       }
    
       elm_genlist_item_class_free(itc);
    
       elm_naviframe_item_push(navi, "Camera", NULL, NULL, clist, NULL);
    }
    

    The following snippet shows the camera definitions. For more information, see the static struct camera_info {    char *description;    char *feature_key; } s_camera_info[] = {    {"Camera", "http://tizen.org/feature/camera"},    {"Back Camera", "http://tizen.org/feature/camera.back"},    {"Back Camera Flash", "http://tizen.org/feature/camera.back.flash"},    {"Front Camera", "http://tizen.org/feature/camera.front"},    {"Front Camera Flash", "http://tizen.org/feature/camera.front.flash"} };

    This genlist makes the list with a style, double_label, to distinguish a title and a content. The items of the list are illustrated by the _gl_text_get_cb() function, which uses the header file, system_info.h. To get information about the system, you can get the boolean data with the system_info_get_platform_bool() function of the System Information API.

    static char 
    *_gl_text_get_cb(void *data, Evas_Object *obj, const char *part)
    {
       item_data_s *id = (item_data_s *)data;
       char buf[MAX_STR] = {0,};
       int ret = -1;
       bool value = 0;
    
       if (!strcmp(part, "elm.text")) 
       {
          return strdup(s_camera_info[id->index].description);
       } 
       else if (!strcmp(part, "elm.text.sub")) 
       {
          ret = system_info_get_platform_bool(s_camera_info[id->index].feature_key, &value);
    
          if (ret != SYSTEM_INFO_ERROR_NONE) 
          {
             return NULL;
          }
    
          snprintf(buf, MAX_STR, "%s", value ? "Supported" : "Not Supported");
    
          return strdup(buf);
       }
    
       return NULL;
    }