Merge "Revert "[Service] Apply node worker for standalone model"" into tizen
authorBot Blink <blinkbot@samsung.com>
Tue, 13 Oct 2020 08:44:20 +0000 (08:44 +0000)
committerGerrit Code Review <gerrit@review>
Tue, 13 Oct 2020 08:44:20 +0000 (08:44 +0000)
wrt_app/service/device_api_router.ts

index 5bdb1ed..4ccf2ef 100644 (file)
@@ -6,6 +6,7 @@ export class DeviceAPIRouter {
   funcRequestedAppcontrol: any;
   funcGetAppInfo: any;
   funcGetAppcerts: any;
+  funcGetContext: any;
   funcGetSharedUri: any;
   funcGetMetadata: any;
   funcGetPackageInfo: any;
@@ -22,10 +23,11 @@ export class DeviceAPIRouter {
     this.serviceId = ids[0];
     this.callerAppId = ids[1] ?? '';
     this.packageId = this.serviceId.split('.')[0];
-    this.permissions = wrt.getPrivileges(this.id);
+    this.permissions = [];
 
     this.initWebapis();
     if (isGlobal) {
+      this.permissions = wrt.getPrivileges(this.id);
       this.refineApplicationApis();
       this.refinePackageApis();
       this.refineFilesystemApis()
@@ -104,6 +106,10 @@ export class DeviceAPIRouter {
     return global.webapis.getPackageId();
   }
 
+  hasNoneOrNull(args: any[]) {
+    return !args.length || null === args[0];
+  }
+
   refineApplicationApis() {
     // tizen.application.getCurrentApplication()
     this.funcCurrentApplication = global.tizen.application.getCurrentApplication;
@@ -111,7 +117,41 @@ export class DeviceAPIRouter {
       console.log(`Routing - getCurrentApplication() : ${this.getServiceId()}`);
       if (this.currentApplication)
         return this.currentApplication;
-      this.currentApplication = this.funcCurrentApplication();
+      this.currentApplication = {};
+      const originCurrentApplication = this.funcCurrentApplication();
+      for (let key in originCurrentApplication) {
+        if (key === 'appInfo') {
+          this.currentApplication.appInfo = {};
+          for (let key in originCurrentApplication.appInfo) {
+            if (key === 'id') {
+              this.currentApplication.appInfo[key] = this.getServiceId();
+            } else {
+              this.currentApplication.appInfo[key] = originCurrentApplication.appInfo[key];
+            }
+          }
+        } else {
+          if (key === 'broadcastEvent' || key === 'broadcastTrustedEvent') {
+            this.currentApplication[key] = originCurrentApplication[key].bind(originCurrentApplication);
+          } else {
+            this.currentApplication[key] = originCurrentApplication[key];
+          }
+        }
+      }
+      Object.defineProperties(this.currentApplication.appInfo, {
+        categories: { writable: false, enumerable: true },
+        iconPath: { writable: false, enumerable: true },
+        id: { writable: false, enumerable: true },
+        installDate: { writable: false, enumerable: true },
+        name: { writable: false, enumerable: true },
+        packageId: { writable: false, enumerable: true },
+        show: { writable: false, enumerable: true },
+        size: { enumerable: true },
+        version: { writable: false, enumerable: true }
+      });
+      Object.defineProperties(this.currentApplication, {
+        appInfo: { writable: false, enumerable: true },
+        contextId: { writable: false, enumerable: true }
+      });
       // tizen.application.getCurrentApplication().getRequestedAppControl()
       this.funcRequestedAppcontrol = this.currentApplication.getRequestedAppControl;
       this.currentApplication.getRequestedAppControl = () => {
@@ -126,7 +166,7 @@ export class DeviceAPIRouter {
     this.funcGetAppInfo = global.tizen.application.getAppInfo;
     global.tizen.application.getAppInfo = (...args: any[]) => {
       let app_id = args[0];
-      if (!args.length || args[0] === null)
+      if (this.hasNoneOrNull(args))
         app_id = this.getServiceId();
       console.log(`Routing - getAppInfo()`);
       return this.funcGetAppInfo(app_id);
@@ -135,16 +175,30 @@ export class DeviceAPIRouter {
     this.funcGetAppcerts = global.tizen.application.getAppCerts;
     global.tizen.application.getAppCerts = (...args: any[]) => {
       let app_id = args[0];
-      if (!args.length || args[0] === null)
+      if (this.hasNoneOrNull(args))
         app_id = this.getServiceId();
       console.log(`Routing - getAppCerts() ` + app_id);
       return this.funcGetAppcerts(app_id);
     }
+    // tizen.application.getAppContext()
+    this.funcGetContext = global.tizen.application.getAppContext;
+    global.tizen.application.getAppContext = (...args: any[]) => {
+      console.log(`Routing - getAppContext()`);
+      if (this.hasNoneOrNull(args)) {
+        const context = {"id": this.funcGetContext().id, "appId": this.getServiceId()};
+        Object.defineProperties(context, {
+          appId: { writable: false, enumerable: true },
+          id: { writable: false, enumerable: true }
+        });
+        return context;
+      }
+      return this.funcGetContext(args[0]);
+    }
     // tizen.application.getAppSharedURI()
     this.funcGetSharedUri = global.tizen.application.getAppSharedURI;
     global.tizen.application.getAppSharedURI = (...args: any[]) => {
       let app_id = args[0];
-      if (!args.length || args[0] === null)
+      if (this.hasNoneOrNull(args))
         app_id = this.getServiceId();
       console.log(`Routing - getAppSharedURI()`);
       return this.funcGetSharedUri(app_id);
@@ -153,7 +207,7 @@ export class DeviceAPIRouter {
     this.funcGetMetadata = global.tizen.application.getAppMetaData;
     global.tizen.application.getAppMetaData = (...args: any[]) => {
       let app_id = args[0];
-      if (!args.length || args[0] === null)
+      if (this.hasNoneOrNull(args))
         app_id = this.getServiceId();
       console.log(`Routing - getAppMetaData()`);
       return this.funcGetMetadata(app_id);
@@ -165,7 +219,7 @@ export class DeviceAPIRouter {
     this.funcGetPackageInfo = global.tizen.package.getPackageInfo;
     global.tizen.package.getPackageInfo = (...args: any[]) => {
       let package_id = args[0];
-      if (!args.length || args[0] === null)
+      if (this.hasNoneOrNull(args))
         package_id = this.getPackageId();
       console.log(`Routing - getPackageInfo() : ${package_id}`);
       return this.funcGetPackageInfo(package_id);