From f4c247f30995f5a2f9ffa2d311a3703660b33a49 Mon Sep 17 00:00:00 2001 From: DongHyun Song Date: Tue, 7 Jul 2020 14:19:06 +0900 Subject: [PATCH] [Service] Routing API - tizen.application 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 --- wrt_app/common/service_manager.ts | 25 ++++++------ wrt_app/service/device_api_router.ts | 76 ++++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 25 deletions(-) diff --git a/wrt_app/common/service_manager.ts b/wrt_app/common/service_manager.ts index 9ef1d29..7552e81 100644 --- a/wrt_app/common/service_manager.ts +++ b/wrt_app/common/service_manager.ts @@ -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); } diff --git a/wrt_app/service/device_api_router.ts b/wrt_app/service/device_api_router.ts index cbdb948..934f57d 100644 --- a/wrt_app/service/device_api_router.ts +++ b/wrt_app/service/device_api_router.ts @@ -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 -- 2.7.4