Queue data for multiple requests while single mode launching 15/235815/2
authorYunjin Lee <yunjin-.lee@samsung.com>
Wed, 10 Jun 2020 03:38:08 +0000 (12:38 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Wed, 10 Jun 2020 04:54:09 +0000 (13:54 +0900)
- It launches only once for single mode. If another request comes while
it's running, store the next and show them in order. And returns all responses
when popup dies as it has been.

- If the number of requested popup exceed max popup number then ignore
new request. In normal situation, it will not exceed the max popup
number because the askuser throw exception for duplicated requests.

Change-Id: I8812a87d2dc691123bb82e04221109cb2074bf91
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
common/include/common_utils.h
common/src/common_utils.c
packaging/org.tizen.askuser-popup.xml
ui/include/view.h
ui/src/app_main.c
ui/src/popup.c

index 3a9d61de76b6234c690191da9ad8da5db3e188d0..a99dba40a7f453e8bbab8d19056a684bd0aa52b8 100644 (file)
@@ -61,11 +61,25 @@ extern "C" {
 #define HOME_KEY "XF86Home"
 #define BACK_KEY "XF86Back"
 
+/* The number of privacy groups.
+ * Askuser determine duplicated requests and will not pass them to popup
+ * hence assume the number of requests will not exceed the number of privacy groups. */
+#define MAX_POPUP_NUM 13
+
 typedef struct {
        char* privacy;
        ppm_popup_response_e response;
 } privacy_data_s;
 
+typedef struct _popup_data_s {
+       int popup_id;
+       char* launch_type;
+
+       GList* privacy_list;
+       int privacy_num;
+       int privacy_idx;
+} popup_data_s;
+
 typedef struct _app_data_s {
        Evas_Object *win;
        Evas_Object *conform;
@@ -77,17 +91,15 @@ typedef struct _app_data_s {
        Evas_Object *btn_r;
        Evas_Object *label;
 
-       app_control_h caller;
        char* caller_pkgid;
 
        bool all_responded;
-       char* launch_type;
        app_control_launch_mode_e mode;
-       int popup_id;
+       int popup_num;
+       int popup_idx;
+
+       popup_data_s popups[MAX_POPUP_NUM];
 
-       GList* privacy_list;
-       int privacy_num;
-       int privacy_idx;
 } app_data_s;
 
 privacy_data_s* new_privacy_data();
@@ -95,6 +107,8 @@ privacy_data_s* new_privacy_data();
 void init_app_data(app_data_s *ad);
 void free_app_data(app_data_s *ad);
 
+void init_popup_data(popup_data_s *pd);
+
 #ifdef _cplusplus
 }
 #endif
index e2517f31fcc50fc7c1260a4681dee30c7631f8e5..8cd59a99179b08dc68a5524f1eb3012dfe44635e 100644 (file)
@@ -38,13 +38,19 @@ void init_app_data(app_data_s* ad)
 {
        ad->all_responded = false;
        ad->mode = APP_CONTROL_LAUNCH_MODE_GROUP;
-       ad->launch_type = NULL;
        ad->caller_pkgid = NULL;
-       ad->popup_id = 0;
 
-       ad->privacy_list = NULL;
-       ad->privacy_num = 0;
-       ad->privacy_idx = 0;
+       ad->popup_num = 0;
+       ad->popup_idx = 0;
+}
+
+void init_popup_data(popup_data_s *pd)
+{
+       pd->privacy_num = 0;
+       pd->privacy_idx = 0;
+       pd->launch_type = NULL;
+       pd->privacy_list = NULL;
+       pd->popup_id = 0;
 }
 
 void __free_privacy_data(privacy_data_s* pd)
@@ -63,8 +69,10 @@ void free_app_data(app_data_s* ad)
 {
        if (ad->caller_pkgid != NULL)
                free(ad->caller_pkgid);
-       if (ad->privacy_list != NULL)
-               g_list_free_full(ad->privacy_list, free_privacy_data);
-       if (ad->launch_type != NULL)
-               free(ad->launch_type);
+       int i = 0;
+       for (i = 0; i < ad->popup_num; ++i)
+       {
+               free(ad->popups[i].launch_type);
+               g_list_free_full(ad->popups[i].privacy_list, free_privacy_data);
+       }
 }
index 61f5517dc731f88edf7e2c3d69fa9315282e6204..8ed2808891f69939398ca492256217777856919b 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns="http://tizen.org/ns/packages" package="org.tizen.askuser-popup" api-version="5.5" version="0.1">
+<manifest xmlns="http://tizen.org/ns/packages" package="org.tizen.askuser-popup" api-version="5.5" version="0.1" support-mode="screen-reader|ultra-power-saving" removable="false">
        <ui-application appid="org.tizen.askuser-popup" launch_mode="caller" exec="org.tizen.askuser-popup" multiple="false" nodisplay="true" taskmanage="false" type="capp">
                <label>askuser popup</label>
        </ui-application>
index bdf3e184b2b3284a2b3b42cd44004e28f13ef934..c31bc73e712e52772d6f2d0400272f1a889bf52a 100755 (executable)
@@ -33,4 +33,3 @@
 #define LOG_TAG "ASKUSER_POPUP"
 
 void create_view(app_data_s *ad);
-void send_response(const char* response, app_data_s *ad);
index 3941535d7e29931311f4e498a426af0c7a279fc5..2e8e4984bca8d1130de06bb2ed4de8ebf386ac37 100644 (file)
@@ -77,8 +77,14 @@ static bool app_create(void * data)
 static void app_control(app_control_h app_control, void *data)
 {
        LOGD("app_control()");
+
        /* Handle the launch request. */
        app_data_s *ad = (app_data_s *)data;
+       if (ad->popup_num >= MAX_POPUP_NUM) {
+               LOGE("Requested popup num exceed MAX_POPUP_NUM. Ignore.");
+               return;
+       }
+
        int ret = 0;
 
        char* caller_appid = NULL;
@@ -104,17 +110,33 @@ static void app_control(app_control_h app_control, void *data)
                ui_app_exit();
        }
 
-       ret = app_info_get_package(app_info, &(ad->caller_pkgid));
+       char* caller_pkgid = NULL;
+
+       ret = app_info_get_package(app_info, &caller_pkgid);
        if (ret != APP_MANAGER_ERROR_NONE) {
                LOGE("app_info_get_package() failed. ret = %d", ret);
                ui_app_exit();
        }
 
+       if (!ad->caller_pkgid) {
+               ad->caller_pkgid = strdup(caller_pkgid);
+               free(caller_pkgid);
+       } else {
+               if (strcmp(caller_pkgid, ad->caller_pkgid) != 0) {
+                       LOGE("Received data isn't from the same caller app! Orig: %s, New: %s", ad->caller_pkgid, caller_pkgid);
+                       free(caller_pkgid);
+                       ui_app_exit();
+               }
+               free(caller_pkgid);
+       }
+
        if (ad->caller_pkgid == NULL) {
                LOGE("Failed to get caller_pkgid");
                ui_app_exit();
        }
 
+       init_popup_data(&(ad->popups[ad->popup_num]));
+
        bundle *b = NULL;
 
        ret = app_control_to_bundle(app_control, &b);
@@ -128,7 +150,7 @@ static void app_control(app_control_h app_control, void *data)
 
        ret = bundle_get_byte(b, "popup_id", (void**)&popup_id, &popup_id_size);
        if (ret == BUNDLE_ERROR_NONE) {
-               ad->popup_id = *popup_id;
+               ad->popups[ad->popup_num].popup_id = *popup_id;
                LOGD("popup_id = %d", *popup_id);
        } else {
                LOGE("caller pkgid [%s]: bundle_get_byte() failed. ret = %d", ad->caller_pkgid, ret);
@@ -142,33 +164,37 @@ static void app_control(app_control_h app_control, void *data)
                ui_app_exit();
        }
        if (privacy_num < 1) {
-               LOGE("caller_pkgid [%s]: key 'privacy_list' len: %d < 1", ad->caller_pkgid, ad->privacy_num);
+               LOGE("caller_pkgid [%s]: key 'privacy_list' len: %d < 1", ad->caller_pkgid, ad->popups[ad->popup_num].privacy_num);
                ui_app_exit();
        }
 
-       ad->privacy_num = privacy_num;
-       LOGD("privacy num = %d", ad->privacy_num);
+       ad->popups[ad->popup_num].privacy_num = privacy_num;
+       LOGD("privacy num = %d", ad->popups[ad->popup_num].privacy_num);
        int i = 0;
-       for (i = 0; i < ad->privacy_num; ++i) {
+       for (i = 0; i < ad->popups[ad->popup_num].privacy_num; ++i) {
                LOGD("privacy_list: %s", privacy_list[i]);
                privacy_data_s *pd = new_privacy_data();
                pd->privacy = strdup(privacy_list[i]);
-               ad->privacy_list = g_list_append(ad->privacy_list, pd);
+               ad->popups[ad->popup_num].privacy_list = g_list_append(ad->popups[ad->popup_num].privacy_list, pd);
        }
 
-       if (ad->privacy_num > 1) {
-               ad->launch_type = strdup("multi");
+       if (ad->popups[ad->popup_num].privacy_num > 1) {
+               ad->popups[ad->popup_num].launch_type = strdup("multi");
        } else {
-               ad->launch_type = strdup("single");
+               ad->popups[ad->popup_num].launch_type = strdup("single");
        }
 
-       if (!ad->launch_type) {
+       if (!ad->popups[ad->popup_num].launch_type) {
                LOGE("caller pkgid [%s]: strdup of 'launch_type' failed.", ad->caller_pkgid);
                ui_app_exit();
        }
 
-       LOGD("launch_type : %s", ad->launch_type);
-       create_view(ad);
+       LOGD("launch_type : %s", ad->popups[ad->popup_num].launch_type);
+       ad->popup_num++;
+       if (ad->popup_num == 1) {
+               ad->popup_idx = 0;
+               create_view(ad);
+       }
 }
 
 static void app_pause(void *data)
@@ -182,30 +208,42 @@ static void app_resume(void *data)
        /* Take necessary actions when application becomes visible. */
 }
 
-static void app_terminate(void *data)
+static bool send_response(app_data_s* ad, int idx)
 {
-       LOGD("app_terminate()");
-
-       app_data_s *ad = (app_data_s*)data;
        int ret = 0;
 
-       char *privacies[ad->privacy_num];
-       ppm_popup_response_e responses[ad->privacy_num];
+       char *privacies[ad->popups[idx].privacy_num];
+       ppm_popup_response_e responses[ad->popups[idx].privacy_num];
 
        int i = 0;
-       for (i = 0; i < ad->privacy_num; ++i) {
-               privacy_data_s *pd = (privacy_data_s*)g_list_nth_data(ad->privacy_list, i);
+       for (i = 0; i < ad->popups[idx].privacy_num; ++i) {
+               privacy_data_s *pd = (privacy_data_s*)g_list_nth_data(ad->popups[idx].privacy_list, i);
                privacies[i] = strdup(pd->privacy);
                responses[i] = pd->response;
        }
-       ret = ppm_popup_send_response(ad->popup_id, (const char**)privacies, responses, ad->privacy_num);
+       ret = ppm_popup_send_response(ad->popups[idx].popup_id, (const char**)privacies, responses, ad->popups[idx].privacy_num);
 
-       for (i = 0; i < ad->privacy_num; ++i) {
+       for (i = 0; i < ad->popups[idx].privacy_num; ++i) {
                free(privacies[i]);
        }
 
-       if (ret != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE)
+       if (ret != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
                LOGE("ppm_popup_send_response() failed. ret = %d", ret);
+               return false;
+       }
+       return true;
+}
+
+static void app_terminate(void *data)
+{
+       LOGD("app_terminate()");
+
+       app_data_s *ad = (app_data_s*)data;
+       int i = 0;
+       for (i = 0; i < ad->popup_num; ++i) {
+               if (!send_response(ad, i))
+                       LOGE("send_response() failed.");
+       }
 
        free_app_data(ad);
 
@@ -227,7 +265,6 @@ static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
 
 int main(int argc, char *argv[])
 {
-       LOGD("main");
        int ret = 0;
        app_data_s ad;
        memset(&ad, 0x0, sizeof(app_data_s));
index 86437253ace938ace21f11f064b979c8c3298316..052cc3de1ffd66559a1a983b45452e54e16344fd 100644 (file)
@@ -48,7 +48,7 @@
 
 void save_response(ppm_popup_response_e response, app_data_s *ad)
 {
-       privacy_data_s *pd = (privacy_data_s *)g_list_nth_data(ad->privacy_list, ad->privacy_idx);
+       privacy_data_s *pd = (privacy_data_s *)g_list_nth_data(ad->popups[ad->popup_idx].privacy_list, ad->popups[ad->popup_idx].privacy_idx);
        pd->response = response;
 }
 
@@ -133,15 +133,15 @@ static char* __get_message(const char* pkgid, const char* privacy)
 }
 static void __set_popup_contents(app_data_s *ad)
 {
-       privacy_data_s *pd = (privacy_data_s *)g_list_nth_data(ad->privacy_list, ad->privacy_idx);
+       privacy_data_s *pd = (privacy_data_s *)g_list_nth_data(ad->popups[ad->popup_idx].privacy_list, ad->popups[ad->popup_idx].privacy_idx);
        char* message = __get_message(ad->caller_pkgid, (const char*)pd->privacy);
        elm_object_text_set(ad->label, message);
        elm_atspi_accessible_name_set(ad->label, message);
        if (strlen(message) > 0)
                free(message);
-       if (!strcmp(ad->launch_type, "multi")) {
+       if (!strcmp(ad->popups[ad->popup_idx].launch_type, "multi")) {
                char counter[COUNTER_LEN];
-               int ret = snprintf(counter, COUNTER_LEN, "%d / %d", (ad->privacy_idx) + 1, ad->privacy_num);
+               int ret = snprintf(counter, COUNTER_LEN, "%d / %d", (ad->popups[ad->popup_idx].privacy_idx) + 1, ad->popups[ad->popup_idx].privacy_num);
                if (ret < 0 || ret >= COUNTER_LEN) {
                        LOGE("snprintf() for counter failed. ret = %d", ret);
                } else {
@@ -154,10 +154,15 @@ static void __set_popup_contents(app_data_s *ad)
 static void __check_next_privacy(app_data_s *ad)
 {
        LOGD("__check_next_privacy()");
-       ad->privacy_idx++;
-       if (ad->privacy_idx >= ad->privacy_num) {
-               ad->all_responded = true;
-               LOGD("all_responded, close the popup");
+       ad->popups[ad->popup_idx].privacy_idx++;
+       if (ad->popups[ad->popup_idx].privacy_idx >= ad->popups[ad->popup_idx].privacy_num) {
+               ad->popup_idx++;
+               if (ad->popup_idx >= ad->popup_num) {
+                       ad->all_responded = true;
+                       LOGD("all_responded, close the popup");
+               } else {
+                       __set_popup_contents(ad);
+               }
        } else {
                __set_popup_contents(ad);
        }