runtime-info: Battery keys regard as disconnected in no battery model
[platform/core/api/runtime-info.git] / src / runtime_info_system.c
index f244772..90b31fd 100644 (file)
@@ -32,8 +32,8 @@
 
 static const char *VCONF_FLIGHT_MODE = VCONFKEY_TELEPHONY_FLIGHT_MODE;
 static const char *VCONF_AUDIO_JACK = VCONFKEY_SYSMAN_EARJACK;
-static const char *VCONF_SILENT_MODE = "db/setting/sound/sound_on";
-static const char *VCONF_VIBRATION_ENABLED = "db/setting/sound/vibration_on";
+static const char *VCONF_SOUND_ENABLED = VCONFKEY_SETAPPL_SOUND_STATUS_BOOL;
+static const char *VCONF_VIBRATION_ENABLED = VCONFKEY_SETAPPL_VIBRATION_STATUS_BOOL;
 static const char *VCONF_ROTATION_LOCK_ENABLED = VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL;
 static const char *VCONF_BATTERY_CHARGING = VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW;
 static const char *VCONF_TVOUT_CONNECTED = VCONFKEY_SYSMAN_EARJACK;
@@ -45,12 +45,12 @@ static const char *VCONF_CHARGER_CONNECTED = VCONFKEY_SYSMAN_CHARGER_STATUS;
 
 int runtime_info_flightmode_get_value(runtime_info_value_h value)
 {
-       bool vconf_value;
+       int vconf_value;
 
        if (runtime_info_vconf_get_value_bool(VCONF_FLIGHT_MODE, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = 0;
 
-       value->b = vconf_value;
+       value->b = (bool)vconf_value;
 
        return RUNTIME_INFO_ERROR_NONE;
 }
@@ -70,7 +70,7 @@ int runtime_info_audiojack_get_value(runtime_info_value_h value)
        int vconf_value;
 
        if (runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = VCONFKEY_SYSMAN_EARJACK_REMOVED;
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_EARJACK_3WIRE:
@@ -98,34 +98,51 @@ void runtime_info_audiojack_unset_event_cb(void)
 
 int runtime_info_silent_mode_get_value(runtime_info_value_h value)
 {
-       bool vconf_value;
+       int sound, vib;
 
-       if (runtime_info_vconf_get_value_bool(VCONF_SILENT_MODE, &vconf_value))
+       if (runtime_info_vconf_get_value_bool(VCONF_SOUND_ENABLED, &sound))
                return RUNTIME_INFO_ERROR_IO_ERROR;
 
-       value->b = vconf_value;
+       if (runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vib))
+               return RUNTIME_INFO_ERROR_IO_ERROR;
+
+       if (sound == 0 && vib == 0)
+               value->b = true;
+       else
+               value->b = false;
 
        return RUNTIME_INFO_ERROR_NONE;
 }
 
 int runtime_info_silent_mode_set_event_cb(void)
 {
-       return runtime_info_vconf_set_event_cb(VCONF_SILENT_MODE, RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, 0);
+       int ret;
+
+       ret = runtime_info_vconf_set_event_cb(VCONF_SOUND_ENABLED, RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, 0);
+       if (ret != RUNTIME_INFO_ERROR_NONE)
+               return ret;
+
+       ret = runtime_info_vconf_set_event_cb(VCONF_VIBRATION_ENABLED, RUNTIME_INFO_KEY_SILENT_MODE_ENABLED, 1);
+       if (ret != RUNTIME_INFO_ERROR_NONE)
+               runtime_info_vconf_unset_event_cb(VCONF_SOUND_ENABLED, 0);
+
+       return ret;
 }
 
 void runtime_info_silent_mode_unset_event_cb(void)
 {
-       runtime_info_vconf_unset_event_cb(VCONF_SILENT_MODE, 0);
+       runtime_info_vconf_unset_event_cb(VCONF_SOUND_ENABLED, 0);
+       runtime_info_vconf_unset_event_cb(VCONF_VIBRATION_ENABLED, 1);
 }
 
 int runtime_info_vibration_enabled_get_value(runtime_info_value_h value)
 {
-       bool vconf_value;
+       int vconf_value;
 
        if (runtime_info_vconf_get_value_bool(VCONF_VIBRATION_ENABLED, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = 0;
 
-       value->b = vconf_value;
+       value->b = (bool)vconf_value;
 
        return RUNTIME_INFO_ERROR_NONE;
 }
@@ -142,12 +159,12 @@ void runtime_info_vibration_enabled_unset_event_cb(void)
 
 int runtime_info_auto_rotation_enabled_get_value(runtime_info_value_h value)
 {
-       bool vconf_value;
+       int vconf_value;
 
        if (runtime_info_vconf_get_value_bool(VCONF_ROTATION_LOCK_ENABLED, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = 0;
 
-       value->b = vconf_value;
+       value->b = (bool)vconf_value;
 
        return RUNTIME_INFO_ERROR_NONE;
 }
@@ -169,6 +186,10 @@ int runtime_info_battery_charging_get_value(runtime_info_value_h value)
        if (runtime_info_vconf_get_value_int(VCONF_BATTERY_CHARGING, &vconf_value))
                return RUNTIME_INFO_ERROR_IO_ERROR;
 
+       /* regard not supported as disconnected */
+       if (vconf_value == -ENOTSUP)
+               vconf_value = false;
+
        value->b = vconf_value;
 
        return RUNTIME_INFO_ERROR_NONE;
@@ -190,7 +211,7 @@ int runtime_info_tvout_connected_get_value(runtime_info_value_h value)
        int vconf_value;
 
        if (runtime_info_vconf_get_value_int(VCONF_TVOUT_CONNECTED, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = VCONFKEY_SYSMAN_EARJACK_REMOVED;
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_EARJACK_TVOUT:
@@ -221,7 +242,7 @@ int runtime_info_audio_jack_status_get_value(runtime_info_value_h value)
        int vconf_value;
 
        if (runtime_info_vconf_get_value_int(VCONF_AUDIO_JACK_STATUS, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = VCONFKEY_SYSMAN_EARJACK_REMOVED;
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_EARJACK_3WIRE:
@@ -256,7 +277,7 @@ int runtime_info_sliding_keyboard_opened_get_value(runtime_info_value_h value)
        int vconf_value;
 
        if (runtime_info_vconf_get_value_int(VCONF_SLIDING_KEYBOARD_STATUS, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_SUPPORTED;
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_SLIDING_KEYBOARD_NOT_AVAILABE:
@@ -294,7 +315,7 @@ int runtime_info_usb_connected_get_value(runtime_info_value_h value)
        int vconf_value;
 
        if (runtime_info_vconf_get_value_int(VCONF_USB_CONNECTED, &vconf_value))
-               return RUNTIME_INFO_ERROR_IO_ERROR;
+               vconf_value = VCONFKEY_SYSMAN_USB_DISCONNECTED;
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_USB_DISCONNECTED:
@@ -335,6 +356,8 @@ int runtime_info_charger_connected_get_value(runtime_info_value_h value)
 
        switch (vconf_value) {
        case VCONFKEY_SYSMAN_CHARGER_DISCONNECTED:
+       /* regard not supported as disconnected */
+       case -ENOTSUP:
                value->b = false;
                break;
 
@@ -367,7 +390,7 @@ int runtime_info_vibration_level_haptic_feedback_get_value(runtime_info_value_h
        if (runtime_info_vconf_get_value_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &vconf_value))
                return RUNTIME_INFO_ERROR_IO_ERROR;
 
-               value->i = vconf_value;
+       value->i = vconf_value;
 
        return RUNTIME_INFO_ERROR_NONE;
 }