2 * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Yunjin Lee (yunjin-.lee@samsung.com)
24 #include <app_manager.h>
26 #include <bundle_internal.h>
28 #include "common_utils.h"
31 static void win_delete_request_cb(void *data, Evas_Object * obj, void *event_info)
37 static void app_start(void* data)
40 app_data_s* ad = (app_data_s*)data;
42 /* Add conformant to window */
43 ad->conform = elm_conformant_add(ad->win);
44 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
45 elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
46 evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
47 elm_win_resize_object_add(ad->win, ad->conform);
48 evas_object_show(ad->conform);
50 evas_object_show(ad->win);
55 static bool app_create(void * data)
58 app_data_s *ad = (app_data_s*)data;
60 elm_app_base_scale_set(1.8);
62 ad->win = elm_win_add(NULL, "askuser-popup", ELM_WIN_BASIC);
63 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
64 elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
66 if (elm_win_wm_rotation_supported_get(ad->win)) {
67 int rots[4] = { 0, 90, 180, 270 };
68 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
70 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
77 static void app_control(app_control_h app_control, void *data)
79 LOGD("app_control()");
81 /* Handle the launch request. */
82 app_data_s *ad = (app_data_s *)data;
83 if (ad->popup_num >= MAX_POPUP_NUM) {
84 LOGE("Requested popup num exceed MAX_POPUP_NUM. Ignore.");
90 char* caller_appid = NULL;
91 ret = app_control_get_caller(app_control, &caller_appid);
92 if (ret != APP_CONTROL_ERROR_NONE) {
93 LOGE("app_control_get_caller() failed. Can't get caller info. Terminate. ret = %d", ret);
97 LOGD("caller appid = %s", caller_appid);
99 ret = app_control_get_launch_mode(app_control, &(ad->mode));
100 if (ret != APP_CONTROL_ERROR_NONE) {
101 LOGE("app_control_get_launch_mode() failed. Terminate. ret = %d", ret);
106 ret = app_info_create(caller_appid, &app_info);
108 if (ret != APP_MANAGER_ERROR_NONE) {
109 LOGE("app_info_create() failed. ret = %d", ret);
113 char* caller_pkgid = NULL;
115 ret = app_info_get_package(app_info, &caller_pkgid);
116 if (ret != APP_MANAGER_ERROR_NONE) {
117 LOGE("app_info_get_package() failed. ret = %d", ret);
121 if (!ad->caller_pkgid) {
122 ad->caller_pkgid = strdup(caller_pkgid);
125 if (strcmp(caller_pkgid, ad->caller_pkgid) != 0) {
126 LOGE("Received data isn't from the same caller app! Orig: %s, New: %s", ad->caller_pkgid, caller_pkgid);
133 if (ad->caller_pkgid == NULL) {
134 LOGE("Failed to get caller_pkgid");
138 init_popup_data(&(ad->popups[ad->popup_num]));
142 ret = app_control_to_bundle(app_control, &b);
143 if (ret != APP_CONTROL_ERROR_NONE) {
144 LOGE("caller pkgid [%s]: app_control_to_bundle() failed. ret = %d", ad->caller_pkgid, ret);
148 size_t popup_id_size;
151 ret = bundle_get_byte(b, "popup_id", (void**)&popup_id, &popup_id_size);
152 if (ret == BUNDLE_ERROR_NONE) {
153 ad->popups[ad->popup_num].popup_id = *popup_id;
154 LOGD("popup_id = %d", *popup_id);
156 LOGE("caller pkgid [%s]: bundle_get_byte() failed. ret = %d", ad->caller_pkgid, ret);
161 const char** privacy_list = bundle_get_str_array(b, "privacy_list", &privacy_num);
162 if (privacy_list == NULL) {
163 LOGE("caller pkgid [%s]: key 'privacy_list' not found.", ad->caller_pkgid);
166 if (privacy_num < 1) {
167 LOGE("caller_pkgid [%s]: key 'privacy_list' len: %d < 1", ad->caller_pkgid, ad->popups[ad->popup_num].privacy_num);
171 ad->popups[ad->popup_num].privacy_num = privacy_num;
172 LOGD("privacy num = %d", ad->popups[ad->popup_num].privacy_num);
174 for (i = 0; i < ad->popups[ad->popup_num].privacy_num; ++i) {
175 LOGD("privacy_list: %s", privacy_list[i]);
176 privacy_data_s *pd = new_privacy_data();
177 pd->privacy = strdup(privacy_list[i]);
178 ad->popups[ad->popup_num].privacy_list = g_list_append(ad->popups[ad->popup_num].privacy_list, pd);
181 if (ad->popups[ad->popup_num].privacy_num > 1) {
182 ad->popups[ad->popup_num].launch_type = strdup("multi");
184 ad->popups[ad->popup_num].launch_type = strdup("single");
187 if (!ad->popups[ad->popup_num].launch_type) {
188 LOGE("caller pkgid [%s]: strdup of 'launch_type' failed.", ad->caller_pkgid);
192 LOGD("launch_type : %s", ad->popups[ad->popup_num].launch_type);
194 if (ad->popup_num == 1) {
200 static void app_pause(void *data)
205 static void app_resume(void *data)
207 LOGD("app_resume()");
208 /* Take necessary actions when application becomes visible. */
211 static bool send_response(app_data_s* ad, int idx)
215 char *privacies[ad->popups[idx].privacy_num];
216 ppm_popup_response_e responses[ad->popups[idx].privacy_num];
219 for (i = 0; i < ad->popups[idx].privacy_num; ++i) {
220 privacy_data_s *pd = (privacy_data_s*)g_list_nth_data(ad->popups[idx].privacy_list, i);
221 privacies[i] = strdup(pd->privacy);
222 responses[i] = pd->response;
224 ret = ppm_popup_send_response(ad->popups[idx].popup_id, (const char**)privacies, responses, ad->popups[idx].privacy_num);
226 for (i = 0; i < ad->popups[idx].privacy_num; ++i) {
230 if (ret != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
231 LOGE("ppm_popup_send_response() failed. ret = %d", ret);
237 static void app_terminate(void *data)
239 LOGD("app_terminate()");
241 app_data_s *ad = (app_data_s*)data;
243 for (i = 0; i < ad->popup_num; ++i) {
244 if (!send_response(ad, i))
245 LOGE("send_response() failed.");
250 LOGD("app_terminate() end");
253 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
255 /*APP_EVENT_LANGUAGE_CHANGED*/
257 app_event_get_language(event_info, &lang);
259 elm_language_set(lang);
262 LOGE("app_event_get_language() failed");
266 int main(int argc, char *argv[])
270 memset(&ad, 0x0, sizeof(app_data_s));
273 ui_app_lifecycle_callback_s event_callback = {0, };
274 app_event_handler_h handler = NULL;
276 ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
278 event_callback.create = app_create;
279 event_callback.terminate = app_terminate;
280 event_callback.pause = app_pause;
281 event_callback.resume = app_resume;
282 event_callback.app_control = app_control;
284 ret = ui_app_main(argc, argv, &event_callback, &ad);
285 if (ret != APP_ERROR_NONE)
286 LOGD("ui_app_main() is failed. err = %d", ret);