11
Spring 2015
Soo Dong Kim, Ph.D.Professor, Department of Computer Science
Software Engineering Laboratory
Soongsil UniversityOffice 02-820-0909 Mobile [email protected] http://soft.ssu.ac.kr
Key Modules of System API
2© 2015 Soo Dong KimSW Design Principles
What is System API? To get system information and manage devices
Key Modules
Device
Storage
33
Unit 7-1. Device
4© 2015 Soo Dong KimSW Design Principles
Overview of Device To manage features of Tizen Device
Battery information
Display settings
LED settings
Etc.
5© 2015 Soo Dong KimSW Design Principles
Battery Information (1) Required Header
device/battery.h
device/callback.h
device_battery_get_percent ()
To get the battery charge percentage
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int * percent The remaining battery charge percentage (0 ~ 100)
6© 2015 Soo Dong KimSW Design Principles
Battery Information (2) device_battery_is_charging ()
To get the charging state
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
bool * charging The battery charging state
7© 2015 Soo Dong KimSW Design Principles
Display Settings (1) Required Header
device/display.h
device/callback.h
Required Privilege
http://tizen.org/privilege/display
8© 2015 Soo Dong KimSW Design Principles
Display Settings (2) device_display_get_max_brightness ()
To get the maximum brightness value that can be set
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int display_index The index of the displayThe index zero is always assigned to the main display.
int * max_brightness The maximum brightness value of the display
9© 2015 Soo Dong KimSW Design Principles
Display Settings (3) device_display_get_brightness ()
To get the display brightness value
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int display_index The index of the displayThe index zero is always assigned to the main display.
int * max_brightness The current brightness value of the display
10© 2015 Soo Dong KimSW Design Principles
Display Settings (4) device_display_set_brightness ()
To get the display brightness value
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int display_index The index of the displayThe index zero is always assigned to the main display.
int brightness The new brightness value to set
11© 2015 Soo Dong KimSW Design Principles
LED Settings (1) Required Header
device/led.h
Required Privilege
http://tizen.org/privilege/led
12© 2015 Soo Dong KimSW Design Principles
LED Settings (2) device_flash_get_max_brightness ()
To get the max brightness value of a LED that is located next to the camera
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int * max_brightness The max brightness value of the LED
13© 2015 Soo Dong KimSW Design Principles
LED Settings (3) device_flash_get_brightness ()
To get the brightness value of a LED that is located next to the camera
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int * brightness The brightness value of LED (0 ~ MAX)
14© 2015 Soo Dong KimSW Design Principles
LED Settings (4) device_flash_set_brightness ()
To set the brightness value of a LED that is located next to the camera
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int brightness The brightness value of LED (0 ~ MAX)
15© 2015 Soo Dong KimSW Design Principles
Example To retrieve battery information
To control display brightness
To control LED
int pct;bool charging;device_battery_get_percent(&pct); //Retrieves battery charge percentagedevice_battery_is_charging(&charging); // Retrieves battery charging state
int max, brt;device_display_get_max_brightness(0, &max); // Retrieves maximum display brightnessdevice_display_get_brightness(0, &brt); // Retrieves current display brightnessdevice_display_set_brightness(0, max); // Sets display brightness as maximum
int val, max;device_flash_get_max_brightness(&max); // Retrieves maximum LED brightnessdevice_flash_get_brightness(&val); // Retrieves current LED brightnessdevice_flash_set_brightness(max); // Retrieves LED brightness as maximum
1616
Unit 7-2. Storage
17© 2015 Soo Dong KimSW Design Principles
Overview of Storage To get storage information and manage directories
To access to accessible directories of the file system
Represented as virtual root
Required Header File
storage.h
18© 2015 Soo Dong KimSW Design Principles
Virtual Root List of Virtual Roots
Virtual Root Description
images Location for storing images
sounds Location for storing sound files
videos Location for storing videos
camera Location for storing camera files
downloads Location for storing downloaded items
music Location for storing audio files
documentation Location for storing documents
others Location for storing other files
ringtones Location for storing ringtones
19© 2015 Soo Dong KimSW Design Principles
Enumeration Type in Storage API Used as parameter types in Storage APIs
storage_type_e
storage_directory_e
storage_state_e
20© 2015 Soo Dong KimSW Design Principles
Storage Type List of Enumeration for Storage Types
Enumeration Type Name Description
STORAGE_TYPE_INTERNAL Internal device storage(Built-in storage in a device, non-removable)
STORAGE_TYPE_EXTERNAL External device storage
21© 2015 Soo Dong KimSW Design Principles
Storage Directory List of Enumeration for Storage Directory
Enumeration Type Name Description
STORAGE_DIRECTORY_IMAGES Image directory
STORAGE_DIRECTORY_SOUNDS Sounds directory
STORAGE_DIRECTORY_VIDEOS Videos directory
STORAGE_DIRECTORY_CAMERA Camera directory
STORAGE_DIRECTORY_DOWNLOADS Download directory
STORAGE_DIRECTORY_MUSIC Music directory
STORAGE_DIRECTORY_DOCUMENTS Document directory
STORAGE_DIRECTORY_OTHERS Others directory
STORAGE_DIRECTORY_SYSTEM_RINGTONES System ringtones directory(Only available for internal storage)
22© 2015 Soo Dong KimSW Design Principles
Storage State List of Enumeration for Storage State
Enumeration Type Name Description
STORAGE_STATE_UNMOUNTABLE Storage is present but cannot be mounted.
STORAGE_STATE_REMOVED Storage is not present.
STORAGE_STATE_MOUNTED Storage is present and mounted with read/write access.
STORAGE_STATE_MOUNTED_READ_ONLY Storage is present and mounted with read only access.
23© 2015 Soo Dong KimSW Design Principles
Categories of Storage API Storage Management
To manage different storages on the device
Storage Space Management
To retrieve available and total space size of the storage
24© 2015 Soo Dong KimSW Design Principles
Storage Management (1) storage_foreach_device_supported ()
To retrieve all storage in a device
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
storage_device_supported_cb callback The iteration callback function
void * user_data The user data to be passed to the callback function
25© 2015 Soo Dong KimSW Design Principles
Storage Management (2) storage_get_root_directory ()
To get the absolute path to the root directory of the given storage.
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int storage_id The unique storage ID
char ** path The absolute path to the storage directory
26© 2015 Soo Dong KimSW Design Principles
Storage Management (3) storage_get_directory ()
To get the absolute path to the each directory of the given storage
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int storage_id The unique storage ID
stoarge_directory_e type The directory type
char ** path The absolute path to the directory type
27© 2015 Soo Dong KimSW Design Principles
Storage Management (4) storage_get_type ()
To get the type of the given storage
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int storage_id The unique storage ID
stoarge_type_e type The type of the storage
28© 2015 Soo Dong KimSW Design Principles
Storage Space Management (1) storage_get_total_space ()
To get the total space of the given storage in bytes
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int storage_id The unique storage ID
unsigned long long * bytes The total space size of the storage
29© 2015 Soo Dong KimSW Design Principles
Storage Space Management (2) storage_get_available_space()
To get the available space size of the given storage in bytes
Parameters
Return 0 on success, otherwise a negative error value
Type Name Description
int storage_id The unique storage ID
unsigned long long * bytes The available space size of the storage
30© 2015 Soo Dong KimSW Design Principles
Example To retrieve storage information
To define a callback function to get information once for each supported storage If the function returns false, the iteration is finished.
To retrieve all storage in a device
static bool storage_cb(int storage_id, storage_type_e type, storage_state_e state, const char *path, void *user_data){
if (type == STORAGE_TYPE_INTERNAL) {
internal_storage_id = storage_id;// Codes go here.return false; //The iteration is finished
}return true;
}
int error;error = storage_foreach_device_supported(storage_cb, NULL);
31© 2015 Soo Dong KimSW Design Principles
Thank You !
Top Related