[Service] Fix DeviceApiRouter with "new Service" 88/263488/6 submit/tizen/20210907.160018
authorDongHyun Song <dh81.song@samsung.com>
Fri, 3 Sep 2021 09:10:40 +0000 (18:10 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Tue, 7 Sep 2021 00:59:49 +0000 (09:59 +0900)
1)
Fix JavaScript error from DeviceApiRouter in case of global service
app created by "new Service".
There are wrong usage with 'id', which should have set 'internelId',
not 'serviceId'.

2)
If there is an exception on onStart() or onRequest(), there is no
change to call finishStartingService().
Thus, it moves finishStartingService on finally section.

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

index 1c4f610..98cbe03 100644 (file)
@@ -25,7 +25,7 @@ export class DeviceAPIRouter {
     let ids = id.split(':');
     this.serviceId = ids[0];
     this.callerAppId = ids[1] ?? '';
-    this.packageId = this.serviceId.split('.')[0];
+    this.packageId = wrt.getPackageId(id);
     this.permissions = [];
     this.pkgApiVersion = '';
 
@@ -42,11 +42,6 @@ export class DeviceAPIRouter {
   }
 
   initWebapis() {
-    let app_info = global.tizen.application.getAppInfo(this.serviceId);
-    if (app_info) {
-      this.packageId = app_info.packageId;
-    }
-
     global.webapis = global.webapis ?? {};
     global.webapis.getCallerAppId = () => {
       return this.callerAppId;
@@ -307,7 +302,7 @@ export class DeviceAPIRouter {
     try {
       let virtualPath = ['wgt-private', 'wgt-private-tmp', 'wgt-package'];
       virtualPath.forEach(name => {
-        let realPath = wrt.resolveVirtualRoot(this.getServiceId(), name);
+        let realPath = wrt.resolveVirtualRoot(this.id, name);
         global.tizen.filesystem.setVirtualPath(name, realPath, 'INTERVAL', 'MOUNTED');
       });
     } catch (e) {
index b4b3fe1..e3cb9bd 100644 (file)
@@ -69,7 +69,7 @@ let checkLauncherAlive = (id: string) => {
 export function start(id: string, filename: string) {
   let ids = id.split(':');
   let serviceId = ids[0];
-  let packageId = wrt.getPackageId(serviceId);
+  let packageId = wrt.getPackageId(id);
   wrt.setServiceAppId(id);
   wrt.security?.dropThreadPrivilege(packageId, serviceId);
 
@@ -106,12 +106,13 @@ export function start(id: string, filename: string) {
     if (app.onRequest !== undefined) {
       app.onRequest();
     }
-    if (isGlobalService()) {
-      wrt.finishStartingService(id);
-    }
   } catch (e) {
     console.debug(`exception on start: ${e}`);
     requestStopService(id);
+  } finally {
+    if (isGlobalService()) {
+      wrt.finishStartingService(id);
+    }
   }
 }