[Service] Routing API - tizen.application 70/237970/8 accepted/tizen/unified/20200715.002102 submit/tizen/20200714.080140
authorDongHyun Song <dh81.song@samsung.com>
Tue, 7 Jul 2020 05:19:06 +0000 (14:19 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Tue, 14 Jul 2020 05:52:24 +0000 (14:52 +0900)
This is for overriding layer of tizen.application object to support
global wrt-service.

Base patch:
  https://review.tizen.org/gerrit/229772/

Change-Id: I066fb2121f3caaaa0d8226b3d15f627d360df716
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/common/service_manager.ts
wrt_app/service/device_api_router.ts

index 9ef1d29..7552e81 100644 (file)
@@ -38,19 +38,16 @@ export function startService(id: string, filename?: string) {
     sandbox[id].module.exports.onStop = () => {
       callFunctionInContext('module.exports.onExit', sandbox[id]);
     };
-    if (wrt.tv) {
-      sandbox[id].webapis = global.webapis;
-      sandbox[id].webapis.getServiceId = () => {
-        let service_id = id.split(':')[0];
-        return service_id;
-      }
-      sandbox[id].webapis.getPackageId = () => {
-        let service_id = id.split(':')[0];
-        let app_info = global.tizen.application.getAppInfo(service_id);
-        if (app_info)
-          return app_info.packageId;
-        return '';
-      }
+    let service_id = id.split(':')[0];
+    sandbox[id].webapis = wrt.tv ? global.webapis : {};
+    sandbox[id].webapis.getServiceId = () => {
+      return service_id;
+    }
+    sandbox[id].webapis.getPackageId = () => {
+      let app_info = global.tizen.application.getAppInfo(service_id);
+      if (app_info)
+        return app_info.packageId;
+      return '';
     }
 
     if (service_type !== 'UI') {
@@ -101,7 +98,7 @@ export function startService(id: string, filename?: string) {
     }
     code = `const app = require('${filename}')`;
     if (service_type === 'DAEMON') {
-      internal_handler[id].deivce_api_router = new DeviceAPIRouter(id, sandbox);
+      internal_handler[id].deivce_api_router = new DeviceAPIRouter();
     }
     vm.runInNewContext(code, sandbox[id], options);
   }
index cbdb948..934f57d 100644 (file)
@@ -1,17 +1,71 @@
 import { wrt } from '../browser/wrt';
 
 export class DeviceAPIRouter {
-  service_id?: string;
-  package_id?: string;
-  current_application?: any;
+  currentApplication: any;
+  funcCurrentApplication: any;
+  funcRequestedAppcontrol: any;
+  funcGetAppinfo: any;
+  funcGetAppcerts: any;
+  funcGetSharedUri: any;
+  funcGetMetadata: any;
 
-  constructor(id: string, sandbox: any) {
-    let tizen = global.tizen;
-    this.service_id = id.split(':')[0];
-    let app_info = tizen.application.getAppInfo(this.service_id);
-    if (app_info)
-      this.package_id = app_info.packageId;
-    console.log(`DeviceAPIRouter created for ${this.service_id} ${this.package_id}`);
-    // TODO
+  constructor() {
+    this.RefineApplicationApis();
+  }
+
+  GetServiceId() {
+    return global.webapis.getServiceId();
+  }
+
+  RefineApplicationApis() {
+    // tizen.application.getCurrentApplication()
+    this.funcCurrentApplication = global.tizen.application.getCurrentApplication;
+    global.tizen.application.getCurrentApplication = () => {
+      console.log(`getCurrentApplication() : ${this.GetServiceId()}`);
+      if (this.currentApplication)
+        return this.currentApplication;
+      this.currentApplication = this.funcCurrentApplication();
+      // tizen.application.getCurrentApplication().getRequestedAppControl()
+      this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl;
+      this.currentApplication.getRequestedAppControl = () => {
+        console.log(`getRequestedAppControl() : ${this.GetServiceId()}`);
+        if (wrt.tv)
+          wrt.tv.setCurrentApplication(this.GetServiceId());
+        return this.funcRequestedAppcontrol();
+      }
+      return this.currentApplication;
+    }
+    // tizen.application.getAppInfo()
+    this.funcGetAppinfo = global.tizen.application.getAppInfo;
+    global.tizen.application.getAppInfo = (app_id?: string) => {
+      console.log(`getAppInfo()`);
+      if (!app_id)
+        app_id = this.GetServiceId();
+      return this.funcGetAppinfo(app_id);
+    }
+    // tizen.application.getAppCerts()
+    this.funcGetAppcerts = global.tizen.application.getAppCerts;
+    global.tizen.application.getAppCerts = (app_id?: string) => {
+      console.log(`getAppCerts()`);
+      if (!app_id)
+        app_id = this.GetServiceId();
+      return this.funcGetAppcerts(app_id);
+    }
+    // tizen.application.getAppSharedURI()
+    this.funcGetSharedUri = global.tizen.application.getAppSharedURI;
+    global.tizen.application.getAppSharedURI = (app_id?: string) => {
+      console.log(`getAppSharedURI()`);
+      if (!app_id)
+        app_id = this.GetServiceId();
+      return this.funcGetSharedUri(app_id);
+    }
+    // tizen.application.getAppMetaData()
+    this.funcGetMetadata = global.tizen.application.getAppMetaData;
+    global.tizen.application.getAppMetaData = (app_id?: string) => {
+      console.log(`getAppMetaData()`);
+      if (!app_id)
+        app_id = this.GetServiceId();
+      return this.funcGetMetadata(app_id);
+    }
   }
 }
\ No newline at end of file