[Service] Make application.getCurrentApplication work 82/245382/7
authorYoungsoo Choi <kenshin.choi@samsung.com>
Thu, 8 Oct 2020 04:43:49 +0000 (21:43 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Mon, 12 Oct 2020 04:22:54 +0000 (21:22 -0700)
The appInfo.id of application.getCurrentApplication()
should be its own service id, not 'org.tizen.chromium-efl.wrt-service'.

The object returned from application.getCurrentApplication()
is non re-writable. So, new object is needed to modify the id.

Btw, broadcast APIs need to have daemon id because they are working
on app id of current process.

Change-Id: I71a62f9dc0bccd68fa7e2b9269a2543e651ec64a
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
wrt_app/service/device_api_router.ts

index a9cbdde..4ccf2ef 100644 (file)
@@ -117,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 = () => {
@@ -152,8 +186,10 @@ export class DeviceAPIRouter {
       console.log(`Routing - getAppContext()`);
       if (this.hasNoneOrNull(args)) {
         const context = {"id": this.funcGetContext().id, "appId": this.getServiceId()};
-        Object.defineProperty(context, 'appId', { writable: false });
-        Object.defineProperty(context, 'id', { writable: false });
+        Object.defineProperties(context, {
+          appId: { writable: false, enumerable: true },
+          id: { writable: false, enumerable: true }
+        });
         return context;
       }
       return this.funcGetContext(args[0]);