[Service] Debugging condole.log with ServiceMessage 88/272288/4 accepted/tizen/unified/20220324.134420 submit/tizen/20220318.160023
authorDongHyun Song <dh81.song@samsung.com>
Mon, 14 Mar 2022 06:12:47 +0000 (15:12 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Thu, 17 Mar 2022 06:38:17 +0000 (15:38 +0900)
There is no way to get the console message with commercial products
because Tizen SDK cannot get the 'dlog' actually.
 - 'dlog' is disabled on release firmware.

Thus, this way provides a new way to catch the console message of
service application by UI application's message port
 - local message port 'wrt.message.port'
 - message format : {'service-log' : message }

Change-Id: Ia42dbecb9daa492ffe58b4b5550d804569190232
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/common/service_message.ts
wrt_app/service/service_runner.ts

index 4080701..33ceb3b 100644 (file)
@@ -1,7 +1,9 @@
 import { wrt } from '../browser/wrt';
 
+let funcConsoleLog: any = null;
 let foregroundAppMessagePort: any = null;
 let lastForegroundApp: string = '';
+const wrtCommonPort = 'wrt.message.port';
 
 export function notifyServiceMessage(type: string, message: string) {
   let foregroundApp = wrt.tv?.getForegroundApp();
@@ -11,10 +13,35 @@ export function notifyServiceMessage(type: string, message: string) {
   try {
     if (!foregroundAppMessagePort || lastForegroundApp != foregroundApp) {
       foregroundAppMessagePort =
-        global.tizen.messageport.requestRemoteMessagePort(foregroundApp, 'wrt.message.port');
+        global.tizen.messageport.requestRemoteMessagePort(foregroundApp, wrtCommonPort);
       lastForegroundApp = foregroundApp;
     }
     if (foregroundAppMessagePort)
-      foregroundAppMessagePort.sendMessage([{key: type, value: ['', message]}]);
+      foregroundAppMessagePort.sendMessage([{ key: type, value: ['', message] }]);
   } catch { }
 }
+
+export function initConsoleMessageNotification(id: string) {
+  try {
+    let mainAppId = wrt.getMainAppId(id);
+    if (!mainAppId)
+      return;
+
+    let mainAppMessagePort = global.tizen.messageport.requestRemoteMessagePort(
+      mainAppId, wrtCommonPort);
+    if (!mainAppMessagePort)
+      return;
+
+    Object.defineProperty(global, 'mainAppMessagePort',
+      { value: mainAppMessagePort, writable: false });
+
+    funcConsoleLog = console.log;
+    console.log = (log: any) => {
+      funcConsoleLog(log);
+      if (global.mainAppMessagePort) {
+        let value = [id, log.toString()];
+        global.mainAppMessagePort.sendMessage([{ key: 'service-log', value }]);
+      }
+    }
+  } catch { }
+}
\ No newline at end of file
index c7e40d2..405c9e9 100644 (file)
@@ -3,11 +3,7 @@ import * as XWalkExtension from '../common/wrt_xwalk_extension';
 import { DeviceAPIRouter } from './device_api_router';
 import { isMainThread, parentPort, workerData } from 'worker_threads';
 import { wrt } from '../browser/wrt';
-
-Object.defineProperty(global, 'serviceType', {
-  value: wrt.getServiceModel(),
-  writable: false
-});
+import * as ServiceMessage from '../common/service_message';
 
 function isServiceApplication() {
   return global['serviceType'] !== 'UI';
@@ -90,6 +86,7 @@ export function start(id: string, filename: string) {
   console.debug(`serviceType : ${global['serviceType']}`)
   new DeviceAPIRouter(id, isGlobalService());
   printAppControlData(id);
+  ServiceMessage.initConsoleMessageNotification(id);
 
   // This is for awaking up uv loop.
   if (isGlobalService()) {
@@ -146,9 +143,9 @@ function run() {
     process.exit();
   }
 
-  Object.defineProperty(global, 'internalId', {
-    value: id,
-    writable: false
+  Object.defineProperties(global, {
+    'internalId': { value: id, writable: false },
+    'serviceType': { value: wrt.getServiceModel(), writable: false }
   });
 
   let filename = workerData.filename;