Merge "[Feature] modify the package name from com.samsung.setting to org.tizen.settin...
[apps/core/preloaded/settings.git] / setting-password / include / setting-password.h
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #ifndef _SETTING_PASSWORD_H_
22 #define _SETTING_PASSWORD_H_
23
24 #include <glib.h>
25 #include <Elementary.h>
26 #include <Ecore_IMF.h>
27
28 #include <ITapiSim.h>
29 #include <TelSim.h>
30 #include <TelErr.h>
31 #include <TapiUtility.h>
32
33 #include <glib-object.h>
34
35 #include <setting-common-draw-widget.h>
36 #include <setting-common-view.h>
37 #include <setting-debug.h>
38
39 #include <security-server.h>
40
41 #ifdef SUPPORT_MDM
42 #include <mdm.h>
43 #define MAX_DESC_BUF_SIZE       2048
44 #define DESC_BUF1_SIZE          256
45 #define DESC_BUF2_SIZE          128
46
47 #define NEW_PASSWORD_NECESSARY                  "New password is necessary because of new security policy."
48 #define PASSWORD_MUST_DIGITS                    "Password must consist of at least %d digit(s)."
49 #define PASSWORD_MUST_ALPHANUMERIC              "Password must consist of at least %d alphanumeric character(s)."
50 #define PASSWORD_MUST_NOT_MATCH_PREV    "Password must not match previous passwords."
51 #define ENTER_ANOTHER_PASSWORD                  "Enter another password."
52 #define PASSWORD_EXPIRED                                "Password expired."
53 #define MAX_NUM_REACHED                                 "Maxinum number of password entry attempts reached."
54 #endif
55
56 #define SETTING_PW_UG_NORMAL_PASSWORD_MIN_LENGTH 4
57 #define SETTING_PW_UG_NORMAL_PASSWORD_MAX_LENGTH 16
58 #define SETTING_PW_UG_PRIVACY_PASSWORD_MIN_LENGTH 4
59 #define SETTING_PW_UG_PRIVACY_PASSWORD_MAX_LENGTH 16
60 #define SETTING_PW_UG_SIM_MIN_LENGTH 4
61 #define SETTING_PW_UG_SIM_MAX_LENGTH 8
62 #define SETTING_PW_UG_PIN_MIN_LENGTH 4
63 #define SETTING_PW_UG_PIN_MAX_LENGTH 8
64 #define SETTING_PW_UG_PUK_MIN_LENGTH 4
65 #define SETTING_PW_UG_PUK_MAX_LENGTH 8
66 #define SETTING_PW_MAX_TITLE_LENGTH MAX_DISPLAY_NAME_LEN_ON_UI
67
68 #define PASSWORD_EMPTY  _("IDS_ST_BODY_PASSWORD_EMPTY")
69 #define ATTEMPT_DESC    _("IDS_ST_POP_PD_ATTEMPT_LEFT")                 /* "%d attempt left" */
70 #define ATTEMPTS_DESC   _("IDS_ST_POP_PD_ATTEMPTS_LEFT")                /* "%d attempts left" */
71 #define PIN_ERR_DESC    _("IDS_ST_POP_INCORRECT_PIN_PD_ATTEMPTS_LEFT") /* "Incorrect PIN. %d attempts left" */
72 #define PUK1_ERR_DESC   _("IDS_ST_POP_INCORRECT_PUK1_PD_ATTEMPTS_LEFT") /* "Incorrect PUK1. %d attempts left" */
73 #define PUK2_ERR_DESC   _("IDS_ST_POP_INCORRECT_PUK2_PD_ATTEMPTS_LEFT") /* "Incorrect PUK2. %d attempts left" */
74 #define PW_ERR_DESC     _("IDS_ST_POP_INCORRECT_PASSWORD")      /* "Incorrect password" */
75 #define PW_ERR_DELAY_DESC _("IDS_ST_BODY_ENTER_PASSWORD_AGAIN_AFTER_PD_SECONDS") /* "Please enter password again after %d seconds" */
76 #define PW_ERR_DELAY_TIME       30
77 #define ATTEMPT_INFINITE        999999
78
79 #define PW_SHORT_GUIDE_CURRENT          "IDS_ST_BODY_CURRENT"
80 #define PW_SHORT_GUIDE_NEW                      "IDS_ST_BODY_NEW"
81 #define PW_SHORT_GUIDE_CONFIRM          "IDS_ST_BODY_CONFIRM"
82
83 typedef enum {
84         SETTING_PW_TYPE_PASSWORD,
85         SETTING_PW_TYPE_SET_PASSWORD,
86         SETTING_PW_TYPE_CHANGE_PASSWORD,
87         SETTING_PW_TYPE_SIMPLE_PASSWORD,
88         SETTING_PW_TYPE_SET_SIMPLE_PASSWORD,
89         SETTING_PW_TYPE_CHANGE_SIMPLE_PASSWORD,
90         SETTING_PW_TYPE_ENTER_LOCK_TYPE,
91         SETTING_PW_TYPE_SIM_LOCK_ON, 
92         SETTING_PW_TYPE_SIM_LOCK_OFF,
93         SETTING_PW_TYPE_PIN_LOCK_ON,
94         SETTING_PW_TYPE_PIN_LOCK_OFF,
95         SETTING_PW_TYPE_CHANGE_PIN1,
96         SETTING_PW_TYPE_CHANGE_PIN2,
97         SETTING_PW_TYPE_PIN1_BLOCKED,
98         SETTING_PW_TYPE_PIN2_BLOCKED,
99         SETTING_PW_TYPE_RESET, 
100 #ifdef SUPPORT_MDM
101         SETTING_PW_TYPE_MDM_NEW_POLICY,                 /* for setting password according to new policy */
102         SETTING_PW_TYPE_MDM_CHANGE_PASSWORD,    /* for changing password by force : mdm_enforce_password_change() */
103         SETTING_PW_TYPE_MDM_TO_SIMPLE,
104 #endif
105         SETTING_PW_TYPE_MAX,
106 } setting_pw_type;
107
108
109 #ifdef SUPPORT_MDM
110 typedef enum {
111         SETTING_PW_ERROR_INVALID_LENGTH = -1,                   /* if length of password is wrong, */
112         SETTING_PW_ERROR_INCLUDE_NO_LETTER = -2,                /* if password that user enter has no letter, */
113         SETTING_PW_ERROR_NO_MATCH_WITH_POLICY = -3,             /* if password that user enter does not match with policy, */
114         SETTING_PW_ERROR_NO_MATCH_MIN_COMPLEX = -4,             /* if password that user enter has no letter, */
115 } setting_pw_errors_for_mdm;
116
117 typedef enum {
118         SETTING_PW_STATUS_OK = 0,
119         SETTING_PW_STATUS_EXPIRED,
120         SETTING_PW_STATUS_MAX_FAILED,
121         SETTING_PW_STATUS_MAX,
122 } setting_pw_status_for_mdm;
123 #endif
124
125 struct _pw_item {
126         int pw_type_num;
127         char *pw_type_string;
128 };
129
130 /* For Tapi */
131 typedef enum {
132         SIM_OPERATION_OK,
133         SIM_ERROR,
134         SIM_REQ_PIN,
135         SIM_OPERATION_OFF,
136         SIM_LOCK_ON_SUCCESS,
137         SIM_LOCK_OFF_SUCCESS,
138         SIM_PIN_LOCK_ON_SUCCESS,
139         SIM_PIN_LOCK_OFF_SUCCESS,
140         SIM_LOCK_ON_FAIL,
141         SIM_LOCK_INCORRECT_PASSWORD,
142         SIM_INCORRECT_PIN1_CODE,
143         SIM_INCORRECT_PIN2_CODE,
144         SIM_INCORRECT_PUK1_CODE,
145         SIM_INCORRECT_PUK2_CODE,
146         SIM_PIN1_CHANGE_SUCCESS,
147         SIM_PIN2_CHANGE_SUCCESS,
148         SIM_PIN1_CHANGE_FAIL,
149         SIM_PIN2_CHANGE_FAIL,
150         SIM_PIN1_BLOCKED,
151         SIM_PIN2_BLOCKED,
152         SIM_PIN1_UNBLOCKED,
153         SIM_PIN2_UNBLOCKED,
154         SIM_PUK1_BLOCKED,
155         SIM_PUK2_BLOCKED,
156         SIM_REQUIRED_PUK_CODE,
157         SIM_OPERATION_UNAVAILABLE,
158         SIM_UNKNOWN_ERROR,
159 } sim_stat_value;
160
161 typedef enum {
162         SETTING_PW_NAVIBAR_WITH_NO_BTN,
163         SETTING_PW_NAVIBAR_WITH_LEFT_BTN,
164         SETTING_PW_NAVIBAR_WITH_RIGHT_BTN,
165         SETTING_PW_NAVIBAR_WITH_BOTH_BTN,
166 } setting_pw_navibar_style_t;
167
168 typedef struct _tapi_request_event {
169         unsigned int sid;
170         int event;
171 } tapi_request_event;
172
173 typedef struct _tapi_receive_info {
174         sim_stat_value stat;
175         int retry_cnt;
176 } tapi_receive_info;
177
178 typedef struct _tapi_request_tapi_info {
179         tapi_request_event *evt;
180         int evt_sz;
181
182         void *cb_data;
183         void (*cb) (tapi_receive_info *, void *);
184 } tapi_request_tapi_info;
185
186 /**
187  * Setting Password UG context
188  * all UG function has void* as an agument. this is casted back to SettingPasswordUG
189  * and the functions access app context.
190  */
191 typedef struct _SettingPasswordUG {
192         ui_gadget_h ug;
193         TapiHandle *handle;
194         TelSimSecResult_t *verify_puks_result;
195
196         /* add more variables here (move your appdata to here) */
197         Evas *evas;
198         Evas_Object *win_main_layout;
199         Evas_Object *win_get;
200         Evas_Object *ly_main;
201
202         setting_pw_type view_type;
203         char *view_type_string;
204
205         Setting_GenGroupItem_Data *ed_pw1;
206         Setting_GenGroupItem_Data *ed_pw2;
207         Setting_GenGroupItem_Data *ed_pw3;
208         Setting_GenGroupItem_Data *focus_data;
209         Evas_Object *setpw_notify;
210         Evas_Object *notify;
211
212         Elm_Object_Item *err_desc;
213         Elm_Genlist_Item_Class itc_err_desc;
214
215         Elm_Object_Item *navi_it;
216         Evas_Object *controllbar;
217         tapi_request_tapi_info *t_info;
218         Evas_Object *navi_bar;
219         Elm_Genlist_Item_Class itc_variable_height;
220         Elm_Genlist_Item_Class itc_seperator;
221         Elm_Genlist_Item_Class itc_layout;
222         Elm_Genlist_Item_Class itc_group_item;
223         Evas_Object *scroller;
224         int disable_item_type;
225
226 #ifdef SUPPORT_MDM
227         int is_expired;
228         Elm_Object_Item *mdm_desc;
229         Elm_Genlist_Item_Class itc_mdm_desc;
230         /* for support mdm policy */
231         mdm_result_t mdm_status;
232         mdm_data_t *mdm_data;
233         mdm_password_policy_t *mdm_policy;
234         Ecore_Event_Handler *event_handler;
235         char *guide_str;
236         char *step1_str;
237 #endif
238
239         /* for simple password */
240         Elm_Genlist_Item_Class itc_title;
241         Elm_Genlist_Item_Class itc_sp_bg_1icon;
242         Elm_Object_Item *sp_item;
243         Evas_Object *sp_entry1;
244         Evas_Object *sp_entry2;
245         Evas_Object *sp_entry3;
246         Evas_Object *sp_entry4;
247         Evas_Object *sp_focused;
248
249         int sp_title_index;
250         char *cur_pwd;
251
252         //int is_simple_password_on;
253         int screen_lock_type;
254         int is_description;
255         int is_empty;
256
257         bool destroy;
258         Ecore_Timer *remove_timer;
259         Ecore_Timer *set_history_timer;
260         /* end */
261
262 } SettingPasswordUG;
263
264 extern setting_view setting_view_password_main;
265
266 void setting_sim_change_pins_cb(TapiHandle *handle, int result, void *data, void *user_data);
267 void setting_sim_verify_puks_cb(TapiHandle *handle, int result, void *data, void *user_data);
268 void setting_sim_facility_enable_cb(TapiHandle *handle, int result, void *data, void *user_data);
269 void setting_sim_facility_disable_cb(TapiHandle *handle, int result, void *data, void *user_data);
270
271 void setting_password_ug_popup_resp_cb(void *data, Evas_Object *obj, void *event_info);
272 void setting_password_ug_create_popup_notitle_nobtn(void *data, char *str, int destroy);
273
274 void setting_password_ug_display_desc(void *data, char *desc, int destroy);
275 #ifdef SUPPORT_MDM
276 void setting_password_ug_display_mdm_desc(void *data, const char* guide_text);
277 #endif
278
279 extern void setting_password_ug_check_attemps_left(void *data);
280
281 int setting_password_is_password_empty();
282 int setting_password_check_password(const char *challenge,  unsigned int *remain_attempt, unsigned int *valid_sec);
283 int setting_password_set_password(const char *cur_pwd, const char *new_pwd, void *data);
284
285 #endif