support 3rd party lock
[apps/core/preloaded/settings.git] / setting-security / src / setting-security-main.c
1 /*
2  * setting
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Flora License, Version 1.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <setting-common-data-type.h>
19 #include <setting-common-data-slp-setting.h>
20 #include <setting-common-draw-widget.h>
21 #include <setting-common-view.h>
22
23 #include <setting-security-main.h>
24 #include <setting-debug.h>
25 #include <app.h>
26
27 static int setting_security_main_create(void *cb);
28 static int setting_security_main_destroy(void *cb);
29 static int setting_security_main_update(void *cb);
30 static int setting_security_main_cleanup(void *cb);
31
32 setting_view setting_view_security_main = {
33         .create = setting_security_main_create,
34         .destroy = setting_security_main_destroy,
35         .update = setting_security_main_update,
36         .cleanup = setting_security_main_cleanup,
37 };
38
39 static void setting_security_main_click_softkey_back_cb(void *data,
40                                                         Evas_Object *obj,
41                                                         void *event_info);
42 #if DISABLED_CODE
43 static void setting_security_main_chk_btn_cb(void *data, Evas_Object *obj,
44                                                 void *event_info);
45 #endif
46 static void setting_security_main_mouse_up_Gendial_list_cb(void *data,
47                                                         Evas_Object *obj,
48                                                         void *event_info);
49 #if DISABLED_CODE
50 static void setting_security_main_update_view(void *data, char *keyStr);
51 static void setting_security_main_create_timer(void *data);
52 static Eina_Bool setting_security_main_timer_update_cb(void *data);
53 #endif
54
55 static void setting_security_main_check_vconf_value(void *data);
56
57
58 /* ***************************************************
59  **
60  **basic func
61  **
62  ****************************************************/
63
64 char *get_pa_screen_lock_type_str()
65 {
66         int lock_type = 0;
67
68         vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &lock_type);
69
70         switch(lock_type)
71         {
72                 case SETTING_SCREEN_LOCK_TYPE_SWIPE:
73                         return setting_gettext("IDS_ST_MBODY_SWIPE");
74                 case SETTING_SCREEN_LOCK_TYPE_OTHER:
75                         return vconf_get_str(VCONFKEY_SETAPPL_3RD_LOCK_PKG_NAME_STR);
76                 default:
77                         return NULL;
78         }
79 }
80
81 static int setting_security_main_create(void *cb)
82 {
83         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
84         SETTING_TRACE_BEGIN;
85         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
86
87         Evas_Object *scroller;
88
89         int ret = 0;
90         int value = 0;
91         int err = 0;
92
93         gboolean b_status = FALSE;
94         int tapi_ret;
95
96         /* add basic layout */
97         char setBtnStr[MAX_DISPLAY_NAME_LEN_ON_UI];
98         snprintf(setBtnStr, sizeof(setBtnStr), "%s",
99                  (char *)dgettext("sys_string", "IDS_COM_BODY_BACK"));
100         ad->ly_main =
101             setting_create_layout_navi_bar_genlist(ad->win_main_layout,
102                                                    ad->win_get,
103                                                    _("IDS_ST_BODY_SECURITY"),
104                                                    setBtnStr, NULL,
105                                                    setting_security_main_click_softkey_back_cb,
106                                                    NULL, ad, &scroller,
107                                                    &ad->navi_bar);
108
109         Elm_Object_Item *item = NULL;
110
111         /* Screen lock type */
112         ad->data_screen_lock_type = setting_create_Gendial_field_def(scroller, &(ad->itc_2text_2),
113                                                                 setting_security_main_mouse_up_Gendial_list_cb,ad,
114                                                                 SWALLOW_Type_INVALID,
115                                                                 NULL, NULL,
116                                                                 0, Keystr_ScreenLockType, get_pa_screen_lock_type_str(ad), NULL);
117         if(ad->data_screen_lock_type)
118                 ad->data_screen_lock_type->userdata = ad;
119
120         /* SIM settings */
121         if(ad->handle && !isEmulBin())
122         {
123                 /* check status of sim and tapi */
124                 ret = setting_get_int_slp_key(INT_SLP_SETTING_SIM_SLOT, &value, &err);
125                 tapi_ret = tel_check_modem_power_status(ad->handle, &b_status);
126
127                 if ((tapi_ret == TAPI_API_SUCCESS) && (b_status == TAPI_PHONE_POWER_STATUS_ON) && (value == VCONFKEY_TELEPHONY_SIM_INSERTED))
128                 {
129                         /* separator */
130                         item = elm_genlist_item_append(scroller, &(ad->itc_seperator), NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL);
131                         elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
132
133                         setting_create_Gendial_field_def(scroller, &(ad->itc_1text),
134                                                                 setting_security_main_mouse_up_Gendial_list_cb,ad,
135                                                                 SWALLOW_Type_INVALID,
136                                                                 NULL, NULL,
137                                                                 0,"IDS_ST_BODY_SIM_CARD_SETTINGS", NULL, NULL);
138                 }
139         }
140
141         /* update info */
142
143         setting_view_security_main.is_create = 1;
144
145         g_ad = (SettingSecurityUG *) malloc(sizeof(SettingSecurityUG) *1);
146         retv_if(!g_ad, -1);
147         memcpy(g_ad, ad, sizeof(SettingSecurityUG));
148
149         SETTING_TRACE_END;
150         return SETTING_RETURN_SUCCESS;
151 }
152
153 static int setting_security_main_destroy(void *cb)
154 {
155         SETTING_TRACE_BEGIN;
156         /* error check */
157         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
158
159         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
160
161         if (ad->update_view_timer) {
162                 ecore_timer_del(ad->update_view_timer);
163                 ad->update_view_timer = NULL;
164         }
165
166         if (ad->ly_main != NULL) {
167                 evas_object_del(ad->ly_main);
168
169                 FREE(g_ad);
170         }
171         if(ad->input_pwd)
172                 FREE(ad->input_pwd);
173
174         setting_view_security_main.is_create = 0;
175
176         return SETTING_RETURN_SUCCESS;
177 }
178
179 static int setting_security_main_update(void *cb)
180 {
181         SETTING_TRACE_BEGIN;
182         /* error check */
183         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
184
185         SettingSecurityUG *ad = (SettingSecurityUG *) cb;
186
187         evas_object_show(ad->ly_main);
188
189         return SETTING_RETURN_SUCCESS;
190 }
191
192 static int setting_security_main_cleanup(void *cb)
193 {
194         SETTING_TRACE_BEGIN;
195         /* error check */
196         retv_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
197
198         return SETTING_RETURN_SUCCESS;
199 }
200
201 /* ***************************************************
202  **
203  **call back func
204  **
205  ****************************************************/
206 static void
207 setting_security_main_click_softkey_back_cb(void *data, Evas_Object *obj,
208                                             void *event_info)
209 {
210         SETTING_TRACE_BEGIN;
211         /* error check */
212         retm_if(data == NULL, "[Setting > Security] Data parameter is NULL");
213
214         SettingSecurityUG *ad = (SettingSecurityUG *) data;
215
216         /* Send destroy request */
217         ug_destroy_me(ad->ug);
218 }
219
220 int _handle_sim_exception(void *data, int sim_status)
221 {
222         retv_if(data == NULL, SETTING_RETURN_FAIL);
223
224         SettingSecurityUG *ad = (SettingSecurityUG *) data;
225
226         switch (sim_status) {
227                 case VCONFKEY_TELEPHONY_SIM_INSERTED:
228                         break;
229
230                 case VCONFKEY_TELEPHONY_SIM_NOT_PRESENT:
231
232                         setting_create_simple_popup(NULL, ad->win_get,
233                                                     NULL, _("IDS_ST_SECURITY_BODY_NOIMSI"));
234                         SETTING_TRACE_DEBUG
235                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
236                              SETTING_FONT_RED, sim_status, SETTING_FONT_BLACK);
237                         return SETTING_RETURN_FAIL;
238
239                         break;
240
241                 case VCONFKEY_TELEPHONY_SIM_CARD_ERROR:
242                 case VCONFKEY_TELEPHONY_SIM_UNKNOWN:
243
244                         setting_create_simple_popup(NULL, ad->win_get,
245                                                     NULL, _("IDS_COM_BODY_INVALID_SIM_CARD"));
246                         SETTING_TRACE_DEBUG
247                             ("%s*** [ERR] INCORRECTED SIM. sim_slot_type=%d ***%s",
248                              SETTING_FONT_RED, sim_status, SETTING_FONT_BLACK);
249                         return SETTING_RETURN_FAIL;
250
251                         break;
252                 default:
253                         break;
254         }
255         return SETTING_RETURN_SUCCESS;
256 }
257
258 static void
259 setting_security_main_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj,
260                                                void *event_info)
261 {
262         SETTING_TRACE_BEGIN;
263         /* error check */
264         setting_retm_if(data == NULL, "Data parameter is NULL");
265
266         retm_if(event_info == NULL, "Invalid argument: event info is NULL");
267         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
268         elm_genlist_item_selected_set(item, 0);
269         Setting_GenGroupItem_Data *list_item =
270             (Setting_GenGroupItem_Data *) elm_object_item_data_get(item);
271
272         SettingSecurityUG *ad = (SettingSecurityUG *) data;
273
274         SETTING_TRACE("clicking item[%s]", _(list_item->keyStr));
275
276         if(!safeStrCmp("IDS_ST_BODY_SIM_CARD_SETTINGS", list_item->keyStr)) {
277                 setting_view_change(&setting_view_security_main, &setting_view_security_sim_settings, ad);      
278         }
279         else if(!safeStrCmp(Keystr_ScreenLockType, list_item->keyStr)) {
280                 setting_view_change(&setting_view_security_main, &setting_view_security_locktype, ad);
281         }
282 }