Improve the readability about progress rearrangement 33/246333/1
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 28 Oct 2020 07:36:42 +0000 (16:36 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 28 Oct 2020 08:26:43 +0000 (17:26 +0900)
Change-Id: Idd92eccb52614e10b74550f03c6f3d3adda9f645
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
dmverity/verity_handler.c
src/ua.c

index 1decedad9033284cfa83ff23aa97788baf292595..fa9d9ac7eb40cb406f92eee1cec557d6c0e13eb5 100755 (executable)
@@ -129,7 +129,7 @@ update_progress:
                return;
        }
 
-       LOG("Succeed to write\n");
+       LOG("Progress : %d%%\n", percent);
 }
 
 /*-----------------------------------------------------------------------------
@@ -153,19 +153,23 @@ static void *__thread_make_hash(void *arg)
  ----------------------------------------------------------------------------*/
 static void *__thread_draw_progress(void *arg)
 {
-       int expected_duration = 45000*1000;     /* usec */
+       int expected_duration = 45;     /* sec */
        int count = 20;
-       int loop_duration = (expected_duration / count);
-       int init_progress = (80 + 2);
-       int exit_progress = (100 - 2);
-       float progress = (float)init_progress;
-       float prog_step = (float)(((float)exit_progress - (float)init_progress) / (float)count);
-
-       while (count > 0) {
-               usleep(loop_duration);
+       useconds_t period = expected_duration * 1000000 / count;
+       int from = 82;
+       int to = 98;
+       float progress = from;
+       float progress_increment = (float)(to - from) / (float)count;
+
+       /**
+        * Convert tick to progress
+        *
+        * 0 ~ count -> from ~ to
+        */
+       for (int tick = 0; tick < count; tick++) {
                fota_gui_update_progress((int)progress);
-               progress += prog_step;
-               count --;
+               progress += progress_increment;
+               usleep(period);
        }
 
        return NULL;
index cc5a7d5a7068ef8928eb8a67613e34b183f73872..bf426080c5505a09efbd4205c8adbb18e956c967 100755 (executable)
--- a/src/ua.c
+++ b/src/ua.c
@@ -140,6 +140,7 @@ update_progress:
 void fota_gui_progress(void * pbUserData, unsigned long uPercent)
 {
        int percent;
+       int from, to;
        ua_dataSS_t *ua_data = (ua_dataSS_t *)pbUserData;
        ua_update_data_t *ua_update_data = ua_data->update_data;
 
@@ -151,16 +152,27 @@ void fota_gui_progress(void * pbUserData, unsigned long uPercent)
        else
                percent = ua_update_data->weight_offset + (ua_update_data->weight * uPercent / 100);
 
-       /* re-arrange progress percentage betwen scout & update */
-       if (ua_data->ua_operation == UI_OP_SCOUT) {
-               percent = percent / 5;
-       } else if ((ua_data->ua_operation == UI_OP_SCOUT_UPDATE)
-               || (ua_data->ua_operation == UI_OP_UPDATE)) {
-               if (dm_verity_status == DM_VERITY_ENABLED)
-                       percent = 20 + percent * 3 / 5; /* 20 ~ 80 */
-               else
-                       percent = 20 + percent * 4 / 5; /* 20 ~ 100 */
+       /**
+        * re-arrange progress percentage between scout & update
+        *
+        * 0 ~ 100 -> from ~ to
+        */
+       switch (ua_data->ua_operation) {
+       case UI_OP_SCOUT:
+               from = 0;
+               to = 20;
+               break;
+       case UI_OP_SCOUT_UPDATE:
+       case UI_OP_UPDATE:
+               from = 20;
+               to = (dm_verity_status == DM_VERITY_ENABLED) ? 80 : 100;
+               break;
+       default:
+               from = 0;
+               to = 100;
+               break;
        }
+       percent = from + ((to - from) * percent / 100);
 
        if (ua_op_mode == UA_OP_MODE_FG)
                fota_gui_update_progress(percent);      /* update progress bar and text */