[M108 Migration][WRTjs][VD] Apply setpriority() and early mount 24/289324/6
authorDongHyun Song <dh81.song@samsung.com>
Mon, 6 Mar 2023 08:42:39 +0000 (17:42 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Tue, 7 Mar 2023 04:03:02 +0000 (13:03 +0900)
1)
To reduce the time of wrt-loader ready, this will apply setpriority()
with high priority niceness.
2)
If yet there is no chromium-efl.img mount point, wrt-loader will mount
by itself.
3)
Update as latest manifest

Reference:
https://review.tizen.org/gerrit/279510/
https://review.tizen.org/gerrit/286399/
https://review.tizen.org/gerrit/288395/
https://review.tizen.org/gerrit/289324/

Change-Id: Ie4cf98f6381f745c06457abea94ad123e14b68da
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
packaging/org.tizen.chromium-efl-vd.xml.in
tizen_src/downloadable/BUILD.gn
tizen_src/downloadable/chromium_efl_install.cc
tizen_src/downloadable/ewk_interface_main.cc

index 1873543..86ed901 100644 (file)
     <ui-application appid="@PACKAGE_ID@.wrt-service-launcher" exec="/usr/bin/wrt-service-launcher" nodisplay="true" multiple="false" type="capp" taskmanage="false">
         <label>Tizen Web Service Launcher</label>
         <label xml:lang="en-us">Tizen Web Service Launcher</label>
+        <metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
     </ui-application>
     <tv-info api-version="1.0.0"><infolink>T-INFOLINK2019-1000</infolink></tv-info>
     <ui-application appid="@PACKAGE_ID@.wrt-service" exec="/usr/bin/wrt-service" nodisplay="true" multiple="false" type="capp" taskmanage="false">
         <label>Tizen Web Service Daemon</label>
         <label xml:lang="en-us">Tizen Web Service Daemon</label>
         <background-category value="iot-communication"/>
+        <metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
     </ui-application>
     <privileges>
         <privilege>http://tizen.org/privilege/alarm.get</privilege>
@@ -38,7 +40,9 @@
         <privilege>http://tizen.org/privilege/packagemanager.admin</privilege>
         <privilege>http://tizen.org/privilege/packagemanager.clearcache</privilege>
         <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
+        <privilege>http://tizen.org/privilege/push</privilege>
         <privilege>http://tizen.org/privilege/telephony</privilege>
         <privilege>http://tizen.org/privilege/telephony.admin</privilege>
+        <privilege>http://tizen.org/privilege/tv.inputdevice</privilege>
     </privileges>
 </manifest>
index 670a4c3..a402650 100644 (file)
@@ -20,6 +20,7 @@ shared_library("ewk-interface") {
     "//tizen_src/ewk/efl_integration/public",
   ]
   defines = [
+    "APP_RO_ROOT_DIR=\"$app_ro_root_dir\"",
     "LIB_RO_ROOT_DIR=\"$lib_ro_root_dir\"",
     "CHROMIUM_IMPL_LIB_FILE=\"$chromium_impl_lib_name\"",
   ]
@@ -38,6 +39,7 @@ shared_library("ewk-interface") {
     defines += [
       "LIB_UPGRADE_ROOT_DIR=\"$lib_upgrade_root_dir\"",
     ]
+    configs += [ "//tizen_src/build:privileged-service" ]
     libs += [ "lwipc", "ttrace" ]
   }
 }
index 2509910..a1694fc 100644 (file)
@@ -166,6 +166,11 @@ static int MountPatchedTPK() {
   int result = FAIL;
   if (!access(LIB_RO_ROOT_DIR "/version", F_OK)) {
     LOG(INFO) << LIB_RO_ROOT_DIR "/version file already exists.";
+    if (LwipcEventDone(kChromiumMountReady) < 0) {
+      // The Lwipc api simply calls the ioctl() inside the function.
+      // Failure of this API means that there are some kernel issues.
+      LOG(ERROR) << kChromiumMountReady << " Event Failed.";
+    }
     return SUCCESS;
   }
 
index d2e5940..6dfca49 100644 (file)
@@ -4,12 +4,25 @@
 
 #include "ewk_interface_main.h"
 
+#define TIZEN_VERSION                                        \
+  (TIZEN_VERSION_MAJOR * 10000 + TIZEN_VERSION_MINOR * 100 + \
+   TIZEN_VERSION_PATCH)
+#define TIZEN_VERSION_AT_LEAST(major, minor, patch) \
+  (TIZEN_VERSION >= (major * 10000 + minor * 100 + patch))
+
 #define CHROMIUM_PRELOAD_LIB_PATH LIB_RO_ROOT_DIR "/lib/" CHROMIUM_IMPL_LIB_FILE
 #if defined(OS_TIZEN_TV_PRODUCT)
+#define PATH_PRELOAD_CHROMIUM_EFL_IMG APP_RO_ROOT_DIR "/res/chromium-efl.img"
+#define MOUNT_ARGS_PRELOAD_CHROMIUM \
+  PATH_PRELOAD_CHROMIUM_EFL_IMG " " LIB_RO_ROOT_DIR " -t squashfs -o loop,ro"
+
 #define CHROMIUM_UPGRADE_LIB_PATH \
   LIB_UPGRADE_ROOT_DIR "/lib/" CHROMIUM_IMPL_LIB_FILE
 #include <lwipc.h>
 #include <ttrace.h>
+
+#include <privileged-service/PS_API.h>
+#include <sys/resource.h>
 #endif
 
 #include <EWebKit.h>
@@ -28,11 +41,71 @@ namespace ewk_interface {
 
 void* g_impl_lib_handle = nullptr;
 
+inline unsigned long long ConvertMilliseconds(timespec ts) {
+  return ((unsigned long long)ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+}
+
 #if defined(OS_TIZEN_TV_PRODUCT)
 bool g_upgrade_lib = false;  // conservative policy
 const char* kChromiumMountReady = "/tmp/.chromium_mount.ready";
 const char* kUWETag = "USE_UWE";
-#endif
+const char* kPSAgentReady = "/run/ps_agent.pid";
+const unsigned int kPSAgentTimeout = 30000;
+
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
+bool WaitPSAgentReady() {
+  static bool ps_agent_ready = false;
+  if (ps_agent_ready)
+    return true;
+
+  int max_retry = 20;
+  LOG(INFO) << "Waiting the ps_agent ready";
+  while (max_retry != 0) {
+    int ret = LwipcWaitEvent(kPSAgentReady, kPSAgentTimeout);
+    if (ret == 0) {
+      LOG(INFO) << "ps_agent is ready";
+      ps_agent_ready = true;
+      return true;
+    }
+
+    --max_retry;
+    LOG(ERROR) << "ps_agent is not ready : " << (ret > 0 ? "timeout" : "fail")
+               << ", remain retry [" << max_retry << "]";
+  }
+
+  return false;
+}
+
+void MountChromiumImage() {
+  if (access(CHROMIUM_PRELOAD_LIB_PATH, F_OK) == 0 ||
+      access(PATH_PRELOAD_CHROMIUM_EFL_IMG, F_OK) != 0) {
+    LOG(INFO) << "Already mounted or no chromium-efl.img";
+    return;
+  }
+
+  if (WaitPSAgentReady() == false)
+    LOG(ERROR) << "Chromium-efl mount may not work.";
+
+  int rv = 0;
+  int result = 0;
+  const char* args = MOUNT_ARGS_PRELOAD_CHROMIUM;
+
+  LOG(INFO) << "mount args: \"" << args << "\"";
+
+  rv = PS_Mount_Fast(args, strlen(args) + 1, 1, &result);
+  LOG(INFO) << "result = " << rv << ", " << result;
+  if (rv != 0 || result != 0) {
+    LOG(ERROR) << "mount failed. (" << rv << ", " << result << ")";
+    return;
+  }
+}
+
+void SetPriority(int absolute) {
+  setpriority(PRIO_PROCESS, 0, absolute);
+  LOG(INFO) << "Set process priority : " << absolute;
+}
+#endif  // TIZEN_VERSION_AT_LEAST(7, 0, 0)
+#endif  // OS_TIZEN_TV_PRODUCT
 
 void* open_library() {
   if (g_impl_lib_handle)
@@ -50,19 +123,19 @@ void* open_library() {
   traceBegin(TTRACE_TAG_WEB, "dlopen start");
 #endif
 
-  struct timeval begin, end, diff;
-  struct stat fileStat;
-  stat(path, &fileStat);
-  gettimeofday(&begin, NULL);
+  unsigned long long diff;
+  struct timespec begin, end;
+  struct stat file_stat;
 
+  stat(path, &file_stat);
+  clock_gettime(CLOCK_MONOTONIC, &begin);
   g_impl_lib_handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
-  gettimeofday(&end, NULL);
+  clock_gettime(CLOCK_MONOTONIC, &end);
   if (!g_impl_lib_handle)
     LOG(ERROR) << "dlopen error : " << dlerror();
-  timersub(&end, &begin, &diff);
-  LOG(ERROR) << "Open library done. cost:"
-             << diff.tv_sec * 1000 + diff.tv_usec / 1000 << "ms\npath:" << path
-             << " size:" << fileStat.st_size / (1024 * 1024) << "MB";
+  diff = ConvertMilliseconds(end) - ConvertMilliseconds(begin);
+  LOG(ERROR) << "Open library done. cost:" << diff << "ms\npath:" << path
+             << " size:" << file_stat.st_size / (1024 * 1024) << "MB";
 
 #if defined(USE_TTRACE)
   traceEnd(TTRACE_TAG_WEB);
@@ -219,10 +292,18 @@ __attribute__((visibility("default"))) int WRTMain(int argc, char** argv) {
   LOG(INFO) << "EWK-INTERFACE : WRTMain called..";
 
 #if defined(OS_TIZEN_TV_PRODUCT)
+#if TIZEN_VERSION_AT_LEAST(7, 0, 0)
+  if (!ewk_check_chromium_ready())
+    SetPriority(-20);
+  else
+    SetPriority(-10);
+  MountChromiumImage();
+#else
   if (access(CHROMIUM_PRELOAD_LIB_PATH, F_OK) != 0 &&
-      !ewk_wait_chromium_ready(20000))
+      !ewk_wait_chromium_ready(20000)) {
     return 0;
-
+  }
+#endif
   for (int i = 1; i < argc; ++i) {
     if (strncmp(argv[i], kUWETag, strlen(kUWETag)) == 0) {
       LOG(INFO) << "USE UWE";