Allow Null widget instance ID 86/246886/2
authorhyunho <hhstark.kang@samsung.com>
Thu, 5 Nov 2020 03:31:25 +0000 (12:31 +0900)
committerhyunho <hhstark.kang@samsung.com>
Thu, 5 Nov 2020 05:12:13 +0000 (14:12 +0900)
trigger update API allows Null instance ID
Widget updates every running instance
when it receives the update command with Null instance ID

Change-Id: I318d11af87232ccb548203a2fa2cbd280fcc56de
Signed-off-by: hyunho <hhstark.kang@samsung.com>
src/modules/widget/src/amd_widget.c

index eb7317de63bcb89bc4e2a219fc74b01275239df9..d1c25dbd14b3bd95d85dd0e5297ca8516b8796eb 100644 (file)
@@ -607,6 +607,7 @@ static int __widget_verify_cmd(amd_request_h req)
        const char *widget_id;
        widget_t *widget;
        char *error_desc;
+       int cnt;
 
        if (!kb) {
                LOGE("invalid argument");
@@ -621,13 +622,6 @@ static int __widget_verify_cmd(amd_request_h req)
                goto error;
        }
 
-       instance_id = bundle_get_val(kb, AUL_K_WIDGET_INSTANCE_ID);
-       if (!instance_id) {
-               LOGE("widget instance is NULL");
-               error_desc = "instance id";
-               goto error;
-       }
-
        command = bundle_get_val(kb, AUL_K_WIDGET_OPERATION);
        if (!command) {
                LOGE("widget command is NULL");
@@ -638,6 +632,28 @@ static int __widget_verify_cmd(amd_request_h req)
        if (strcmp(command, "create") == 0)
                return 0;
 
+       instance_id = bundle_get_val(kb, AUL_K_WIDGET_INSTANCE_ID);
+       if (instance_id == NULL) {
+               /*
+               Only the update command allows NULL instance ID.
+               Null instance ID means update all running instances.
+               */
+               if (strcmp(command, "update") == 0) {
+                       cnt = __widget_count(widget_id,
+                                       amd_request_get_uid(req));
+                       if (cnt == 0) {
+                               LOGE("invalid update: %s - no running instance",
+                                       widget_id);
+                               error_desc = "invalid command";
+                               goto error;
+                       }
+                       return 0;
+               }
+               LOGE("widget instance is NULL");
+               error_desc = "instance id";
+               goto error;
+       }
+
        widget = __find_instance(widget_id, instance_id);
        if (!widget) {
                LOGE("invalid command: %s - target instance %s is not exist",