add error handler for get/set ringtone path
authorMyoungJune Park <mj2004.park@samsung.com>
Sat, 11 May 2013 05:39:49 +0000 (14:39 +0900)
committerMyoungJune Park <mj2004.park@samsung.com>
Sat, 11 May 2013 05:49:49 +0000 (14:49 +0900)
- if user set an invalid path, return fails and set default path
- DCM-1416

Change-Id: Ib5d6386c352130cef5d9ea1da2bbc492ee0c04f4

TC/testcase/utc_system_settings.c
TC_gui/main.c
src/system_setting_platform.c
src/system_settings.c
src/system_settings_vconf.c

index 83c02fd..a433610 100755 (executable)
@@ -80,8 +80,6 @@ static gboolean callback(gpointer data)
 {
        /*int ret =*/ system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 1);
 
-       //printf("return : %d \n", ret);
-
        static int i = 0;
 
        i++;
@@ -95,8 +93,7 @@ static gboolean callback(gpointer data)
 
 static void utc_system_settings_changed_motion_activation(system_settings_key_e key, void *user_data)
 {
-       //printf(">>>>>>>> system_settings_changed_motion_activation key = %d \n", key);
-       //printf(">>>>>>>> THIS CALLBACK FUNCTION IS REGISTERED BY APP DEVELOPER \n");
+
 }
 
 static void utc_system_settings_set_string_p(void)
index 32778b0..7b08f6d 100644 (file)
@@ -15,6 +15,7 @@
  */
 #include "main.h"
 #include <system_settings.h>
+#include <system_settings_private.h>
 
 static void _quit_cb(void *data, Evas_Object* obj, void* event_info)
 {
@@ -132,57 +133,57 @@ void list_item_touch_handler4(void* data, Evas_Object* obj, void* event_info)
 
 void list_item_touch_handler5(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> motion activation ON (SET) \n");
+       SETTING_TRACE(">>>>>>>> motion activation ON (SET)");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 1/*ON*/);
 
        bool enableMotion = false;;
        int errorcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, &enableMotion);
-       printf(">>>>>>>> motion activation (GET TEST  1) -- %d - errorcode : %d \n", enableMotion, errorcode);
+       SETTING_TRACE(">>>>>>>> motion activation (GET TEST  1) -- %d - errorcode : %d", enableMotion, errorcode);
 
-       printf(">>>>>>>> motion activation ON (SET) \n");
+       SETTING_TRACE(">>>>>>>> motion activation ON (SET)");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 0/*ON*/);
 
        errorcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, &enableMotion);
-       printf(">>>>>>>> motion activation (GET TEST  2) -- %d - errorcode : %d \n", enableMotion, errorcode);
+       SETTING_TRACE(">>>>>>>> motion activation (GET TEST  2) -- %d - errorcode : %d ", enableMotion, errorcode);
 }
 
 void list_item_touch_handler6(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> motion activation OFF \n");
+       SETTING_TRACE(">>>>>>>> motion activation OFF ");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 0/*OFF*/);
 }
 
 void system_settings_changed_font_size(system_settings_key_e key, void *user_data)
 {
        struct appdata* ad = (struct appdata*)user_data;
-       printf(" font size -- %s \n", ad->pkgname);
-       printf(">>>>>>>> system_settings_changed_font_size key = %d \n", key);
-       printf("---------------------------------CALLED BY USER APPLICATION -FONT SIZE \n");
+       SETTING_TRACE(" font size -- %s ", ad->pkgname);
+       SETTING_TRACE(">>>>>>>> system_settings_changed_font_size key = %d ", key);
+       SETTING_TRACE("---------------------------------CALLED BY USER APPLICATION -FONT SIZE ");
 }
 
 void system_settings_changed_font_type(system_settings_key_e key, void *user_data)
 {
        struct appdata* ad = (struct appdata*)user_data;
-       printf(" font type -- %s \n", ad->pkgname);
-       printf(">>>>>>>> system_settings_changed_font_type key = %d \n", key);
-       printf("---------------------------------CALLED BY USER APPLICATION -FONT TYPE \n");
+       SETTING_TRACE(" font type -- %s ", ad->pkgname);
+       SETTING_TRACE(">>>>>>>> system_settings_changed_font_type key = %d ", key);
+       SETTING_TRACE("---------------------------------CALLED BY USER APPLICATION -FONT TYPE ");
 }
 
 void system_settings_changed_motion_activation(system_settings_key_e key, void *user_data)
 {
        struct appdata* ad = (struct appdata*)user_data;
-       printf(" motion type -- %s \n", ad->pkgname);
-       printf(">>>>>>>> system_settings_changed_motion_activation key = %d \n", key);
-       printf("---------------------------------CALLED BY USER APPLICATION-MOTION ACTIVIATION \n");
+       SETTING_TRACE(" motion type -- %s ", ad->pkgname);
+       SETTING_TRACE(">>>>>>>> system_settings_changed_motion_activation key = %d ", key);
+       SETTING_TRACE("---------------------------------CALLED BY USER APPLICATION-MOTION ACTIVIATION ");
 }
 void list_item_touch_handler7(void* data, Evas_Object* obj, void* event_info)
 {
        char* path = "/opt/usr/media/Images/image16.jpg";
        int ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, "/aaa.png");
-       printf(">>>>>>>> home screen - error case :: %d \n", ret);
+       SETTING_TRACE(">>>>>>>> home screen - error case :: %d ", ret);
 
        ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, path);
-       printf(">>>>>>>> home screen - error case :: %d \n", ret);
+       SETTING_TRACE(">>>>>>>> home screen - error case :: %d ", ret);
 
 }
 
@@ -190,10 +191,10 @@ void list_item_touch_handler8(void* data, Evas_Object* obj, void* event_info)
 {
        char* path = "/opt/usr/media/Images/image16.jpg";
        int ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, "aaa.png");
-       printf(">>>>>>>> lock screen - error case  : %d \n", ret);
+       SETTING_TRACE(">>>>>>>> lock screen - error case  : %d ", ret);
 
        ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, path);
-       printf(">>>>>>>> lock screen - error case  : %d \n", ret);
+       SETTING_TRACE(">>>>>>>> lock screen - error case  : %d ", ret);
 }
 
 //     SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED,  /**< Indicates whether the usb debugging is enabled */
@@ -202,20 +203,20 @@ void list_item_touch_handler9(void* data, Evas_Object* obj, void* event_info)
 {
        bool state = false;;
        int errorcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, &state);
-       printf(">>>>>>>> 3G data network (GET TEST) -- %d - errorcode : %d \n", state, errorcode);
+       SETTING_TRACE(">>>>>>>> 3G data network (GET TEST) -- %d - errorcode : %d ", state, errorcode);
 }
 
 // set 3g data network to ON
 void list_item_touch_handler10(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> set 3G data network to ON \n");
+       SETTING_TRACE(">>>>>>>> set 3G data network to ON ");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 1/*ON*/);
 }
 
 // set 3g data network to OFF
 void list_item_touch_handler11(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> set 3G data network to OFF \n");
+       SETTING_TRACE(">>>>>>>> set 3G data network to OFF ");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_3G_DATA_NETWORK_ENABLED, 0/*OFF*/);
 }
 
@@ -224,23 +225,50 @@ void list_item_touch_handler12(void* data, Evas_Object* obj, void* event_info)
 {
        bool state = false;;
        int errorcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, &state);
-       printf(">>>>>>>> USB Debugging (GET TEST) -- %d - errorcode : %d \n", state, errorcode);
+       SETTING_TRACE(">>>>>>>> USB Debugging (GET TEST) -- %d - errorcode : %d ", state, errorcode);
 }
 
 // set USB debugging to ON
 void list_item_touch_handler13(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> set USB debugging to ON \n");
+       SETTING_TRACE(">>>>>>>> set USB debugging to ON ");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 1/*ON*/);
 }
 
 // set USB debugging to OFF
 void list_item_touch_handler14(void* data, Evas_Object* obj, void* event_info)
 {
-       printf(">>>>>>>> set USB debugging to OFF \n");
+       SETTING_TRACE(">>>>>>>> set USB debugging to OFF ");
        system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_USB_DEBUGGING_ENABLED, 0/*OFF*/);
 }
 
+// get ringtone path
+void list_item_touch_handler15(void* data, Evas_Object* obj, void* event_info)
+{
+       SETTING_TRACE(">>>>>>>> get ringtone path ");
+       char *ringtonepath = NULL;
+       int ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &ringtonepath);
+       SETTING_TRACE("current ringtone path : (%s) ", ringtonepath);
+
+}
+
+// get ringtone path - exception case
+void list_item_touch_handler16(void* data, Evas_Object* obj, void* event_info)
+{
+       SETTING_TRACE(">>>>>>>> get ringtone path - exception case ");
+       int ret;
+       char *ringtonepath = NULL;
+       //opt/share/settings/Ringtones/Over the horizon.mp3
+       ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/share/settings/Ringtones/Over the horizon.mp3");
+       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &ringtonepath);
+       SETTING_TRACE(" 1 current ringtone path : (%s) ", ringtonepath);
+       // set the key to the wrong value
+       ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "aaa.wav");
+
+       ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &ringtonepath);
+       SETTING_TRACE("2 current ringtone path : (%s) ", ringtonepath);
+}
+
 static Evas_Object* _create_list_winset(Evas_Object* parent, struct appdata* ad)
 {
        Evas_Object *li;
@@ -251,17 +279,17 @@ static Evas_Object* _create_list_winset(Evas_Object* parent, struct appdata* ad)
 
        ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_FONT_TYPE, system_settings_changed_font_type, ad);
        if (ret < 0) {
-               printf("SYSTEM_SETTINGS_KEY_FONT_TYPE returns negative values = %d \n", ret);
+               SETTING_TRACE("SYSTEM_SETTINGS_KEY_FONT_TYPE returns negative values = %d ", ret);
        } else {
-               printf("SYSTEM_SETTINGS_KEY_FONT_TYPE returns positive values = %d, means successful return. \n", ret);
+               SETTING_TRACE("SYSTEM_SETTINGS_KEY_FONT_TYPE returns positive values = %d, means successful return. ", ret);
        }
 
        // callback registration
        ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, system_settings_changed_motion_activation, ad);
        if (ret < 0) {
-                       printf("SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION returns negative values = %d \n", ret);
+                       SETTING_TRACE("SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION returns negative values = %d ", ret);
        } else {
-                       printf("SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION returns positive values = %d, means successful return. \n", ret);
+                       SETTING_TRACE("SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION returns positive values = %d, means successful return. ", ret);
        }
 
        li = elm_list_add(parent);
@@ -284,6 +312,9 @@ static Evas_Object* _create_list_winset(Evas_Object* parent, struct appdata* ad)
        elm_list_item_append( li, "usb debugging GET ", NULL, NULL, list_item_touch_handler12, ad);
        elm_list_item_append( li, "usb debugging SET - ON ", NULL, NULL, list_item_touch_handler13, ad);
        elm_list_item_append( li, "usb debugging SET - OFF ", NULL, NULL, list_item_touch_handler14, ad);
+
+       elm_list_item_append( li, "get call ringtone ", NULL, NULL, list_item_touch_handler15, ad);
+       elm_list_item_append( li, "get call ringtone - exception ", NULL, NULL, list_item_touch_handler16, ad);
        elm_list_go(li);
        return li;
 }
index 1824cbc..8b5d1a2 100755 (executable)
@@ -54,13 +54,28 @@ static int __font_size_get();
 static void font_config_set(char *font_name);
 static void font_config_set_notification();
 
+/**
+ * VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR has a path of the ringtone file which user choose
+ * @return the ringtone file path specified by user in normal case
+ *         if it's not accessable, return the default ringtone path
+ */
 int system_setting_get_incoming_call_ringtone(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
 {
        char* vconf_value;
        if (system_setting_vconf_get_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, &vconf_value)) {
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
-       *value = vconf_value;
+
+       // check to see if it's accessable -> OK
+       // no --> default ringtone path VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR
+       int is_load = _is_file_accessible(vconf_value);
+       if (is_load == 0) {
+               *value = vconf_value;
+       } else { // not zero on errro
+               *value = vconf_get_str(VCONFKEY_SETAPPL_CALL_RINGTONE_DEFAULT_PATH_STR);
+       }
+
+       //*value = vconf_value;
        return SYSTEM_SETTINGS_ERROR_NONE;
 }
 
@@ -165,7 +180,14 @@ int system_setting_set_incoming_call_ringtone(system_settings_key_e key, system_
 {
        char* vconf_value;
        vconf_value = (char*)value;
-       if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
+
+       int is_load = _is_file_accessible(vconf_value);
+       if (is_load == 0)
+       {
+               if (system_setting_vconf_set_value_string(VCONFKEY_SETAPPL_CALL_RINGTONE_PATH_STR, vconf_value)) {
+                       return SYSTEM_SETTINGS_ERROR_IO_ERROR;
+               }
+       } else {
                return SYSTEM_SETTINGS_ERROR_IO_ERROR;
        }
 
@@ -185,13 +207,18 @@ int system_setting_set_email_alert_ringtone(system_settings_key_e key, system_se
 }
 
 
-static int _is_file_accessible(const char * path)
+int _is_file_accessible(const char * path)
 {
     int ret = access(path ,R_OK);
     if (ret == 0)
+       {
+               SETTING_TRACE("found the file  %s", path); 
         return 0;
+       }
     else
+       {
         return errno;
+       }
 }
 
 int system_setting_set_wallpaper_home_screen(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
@@ -300,7 +327,6 @@ void *font_conf_doc_parse(char *doc_name, char *font_name)
                         {
                             xmlNodeSetContent(cur3->xmlChildrenNode, (const xmlChar *)font_name);
                             key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
-                            //printf("after changed, string is: %s \n", key);
                             xmlFree(key);
                             key = NULL;
                             is_changed = EINA_TRUE;
@@ -319,7 +345,6 @@ void *font_conf_doc_parse(char *doc_name, char *font_name)
                 {
                     xmlNodeSetContent(cur2->xmlChildrenNode, (const xmlChar *)font_name);
                     key = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
-                    //printf("after changed, string is: %s\n", key);
                     xmlFree(key);
                     key = NULL;
                     is_changed = EINA_TRUE;
@@ -552,7 +577,6 @@ static char* _get_cur_font()
                         if((!xmlStrcmp(cur3->name, (const xmlChar *)"string")))
                         {
                             key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1);
-                            //printf("string is: %s\n", key);
 
                             font_name = g_strdup((char *)key);
                             xmlFree(key);
index b8e5157..2d18438 100755 (executable)
@@ -11,7 +11,7 @@
  * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
 #include <stdio.h>
index 537bb4d..1e301d6 100644 (file)
@@ -11,7 +11,7 @@
  * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
 #include <stdio.h>
@@ -120,7 +120,6 @@ static void system_setting_vconf_event_cb0(keynode_t *node, void *event_data)
 static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
 {
        system_settings_key_e pkey = (system_settings_key_e)event_data;
-       //printf("*** system_setting_vconf_event_cb1  : %d \n",pkey );
 
     if (node != NULL)
     {
@@ -140,7 +139,6 @@ static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
 static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
 {
        system_settings_key_e pkey = (system_settings_key_e)event_data;
-       //printf("*** system_setting_vconf_event_cb2  : %d \n",pkey );
 
     if (node != NULL)
     {
@@ -160,7 +158,6 @@ static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
 static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
 {
        system_settings_key_e pkey = (system_settings_key_e)event_data;
-       //printf("*** system_setting_vconf_event_cb3  : %d \n",pkey );
 
     if (node != NULL)
     {
@@ -180,7 +177,6 @@ static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
 static void system_setting_vconf_event_cb4(keynode_t *node, void *event_data)
 {
        system_settings_key_e pkey = (system_settings_key_e)event_data;
-       //printf("*** system_setting_vconf_event_cb4  : %d \n",pkey );
 
     if (node != NULL)
     {