2 * Tizen Krate Keyguard application
4 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 static app_control_h __req_app_control;
24 void _launch_req_app()
26 app_control_send_launch_request(__req_app_control, NULL, NULL);
27 app_control_destroy(__req_app_control);
30 bool _check_password(const char *password)
32 unsigned int attempt, max_attempt, expire_sec;
35 ret = auth_passwd_check_passwd(AUTH_PWD_NORMAL, password, &attempt, &max_attempt, &expire_sec);
37 return ret == AUTH_PASSWD_API_SUCCESS;
42 unsigned int attempt, max_attempt, expire_sec;
45 ret = auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
47 return ret != AUTH_PASSWD_API_ERROR_NO_PASSWORD;
50 unsigned int _get_left_attempts()
52 unsigned int attempt = 0, max_attempt = 0, expire_sec;
54 auth_passwd_check_passwd_state(AUTH_PWD_NORMAL, &attempt, &max_attempt, &expire_sec);
56 if (max_attempt == 0) {
60 return max_attempt - attempt;
63 static void __launch_krate_app(const char *krate_name, app_control_h app_control)
65 krate_manager_h krate_mgr;
66 krate_app_proxy_h krate_app;
68 krate_manager_create(&krate_mgr);
69 krate_app_proxy_create(krate_mgr, krate_name, &krate_app);
70 krate_app_proxy_send_launch_request(krate_app, app_control);
71 krate_app_proxy_destroy(krate_app);
72 krate_manager_destroy(krate_mgr);
75 static void __add_shortcut(const char *krate_name)
79 snprintf(uri, sizeof(uri), "krate://enter/%s", krate_name);
80 shortcut_add_to_home(krate_name, LAUNCH_BY_URI, uri, ICON_PATH "/shortcut_icon.png", 0, NULL, NULL);
83 static void __remove_shortcut(const char *krate_name)
85 shortcut_remove_from_home(krate_name, NULL, NULL);
88 static bool __app_create(void *data)
93 static void __app_pause(void *data)
98 static void __app_resume(void *data)
103 static void __app_terminate(void *data)
108 static void __app_control(app_control_h app_control, void *data)
113 ret = app_control_get_uri(app_control, &uri);
114 if (ret != APP_CONTROL_ERROR_NONE) {
115 dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get URI");
120 if (strncmp(uri, "krate://", sizeof("krate://") - 1) != 0) {
121 dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI");
127 tmp = uri + sizeof("krate://") - 1;
129 if (strncmp(tmp, "setup/", sizeof("setup/") - 1) == 0) {
132 krate_name = tmp + sizeof("setup/") - 1;
133 __add_shortcut(krate_name);
136 } else if (strncmp(tmp, "cleanup/", sizeof("cleanup/") - 1) == 0) {
139 krate_name = tmp + sizeof("cleanup/") - 1;
140 __remove_shortcut(krate_name);
143 } else if (strncmp(tmp, "enter/", sizeof("enter/") - 1) == 0) {
144 char *krate_name, *launch_parameter;
145 char new_uri[PATH_MAX];
147 krate_name = tmp + sizeof("enter/") - 1;
148 launch_parameter = strchr(krate_name, '/');
149 if (launch_parameter != NULL) {
150 *(launch_parameter++) = '\0';
151 if (launch_parameter[0] == '\0') {
152 launch_parameter = KASKIT_PACKAGE;
155 launch_parameter = KASKIT_PACKAGE;
157 snprintf(new_uri, PATH_MAX, "krate://launch/%s", launch_parameter);
158 app_control_set_uri(app_control, new_uri);
159 app_control_set_app_id(app_control, PACKAGE);
161 dlog_print(DLOG_ERROR, LOG_TAG, PACKAGE);
162 dlog_print(DLOG_ERROR, LOG_TAG, new_uri);
163 dlog_print(DLOG_ERROR, LOG_TAG, krate_name);
165 __launch_krate_app(krate_name, app_control);
168 } else if (strncmp(tmp, "launch/", sizeof("launch/") - 1) == 0) {
171 app_id = tmp + sizeof("launch/") - 1;
172 uri = strchr(app_id, '?');
175 if (strncmp(uri, "uri=", sizeof("uri=") - 1) == 0) {
176 tmp += sizeof("uri=") - 1;
179 app_control_clone(&__req_app_control, app_control);
180 app_control_set_uri(__req_app_control, uri);
181 app_control_set_app_id(__req_app_control, app_id);
183 if (_has_password()) {
184 _create_keyguard_window();
190 dlog_print(DLOG_ERROR, LOG_TAG, "Invalid URI");
196 int main(int argc, char *argv[])
200 ui_app_lifecycle_callback_s event_callback = {0, };
202 event_callback.create = __app_create;
203 event_callback.terminate = __app_terminate;
204 event_callback.pause = __app_pause;
205 event_callback.resume = __app_resume;
206 event_callback.app_control = __app_control;
208 ret = ui_app_main(argc, argv, &event_callback, NULL);
209 if (ret != APP_ERROR_NONE)
210 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main is failed. err = %d", ret);