[Service] Check privilege of systeminfo device api 15/239015/5
authorChunling Ye <chunling.ye@samsung.com>
Tue, 21 Jul 2020 05:10:22 +0000 (13:10 +0800)
committerChunling Ye <chunling.ye@samsung.com>
Tue, 28 Jul 2020 07:06:19 +0000 (15:06 +0800)
1. change apply to call function for undefined 1 error
2. add privilege check for others api: getPropertyValueArray/
addPropertyValueChangeListener/addPropertyValueArrayChangeListener.

Change-Id: Ic136c5a9307cfac218f219060b7fdf55a237c568
Signed-off-by: Chunling Ye <chunling.ye@samsung.com>
wrt_app/service/access_control_manager.ts

index 6a55946..4517cbe 100644 (file)
@@ -1,5 +1,16 @@
 import * as vm from 'vm';
 
+function checkSystemInfoApiPrivilege(func: any, permissions: string[]) {
+  let override_func  = func;
+  return (type: string, onSuccess: any, onError: any) => {
+    if (type === "CELLULAR_NETWORK" && !permissions.includes("http://tizen.org/privilege/telephony")) {
+      console.log('The telephony permission is missing.');
+      return ;
+    }
+    override_func.call(global.tizen.systeminfo, type, onSuccess, onError);
+  }
+}
+
 export function initialize(permissions: string[], sandbox: vm.Context) {
   let tizen = sandbox.tizen;
   if (!permissions.includes("http://tizen.org/privilege/alarm")) {
@@ -106,12 +117,13 @@ export function initialize(permissions: string[], sandbox: vm.Context) {
     }
   }
   // systeminfo : Runtime privilege validation is required, based on parameters
-  let getPropertyValue = tizen.systeminfo.getPropertyValue;
-  tizen.systeminfo.getPropertyValue = (type: string, onSuccessCallback: any, onErrorCallback: any) => {
-    if (type === "CELLULAR_NETWORK" && !permissions.includes("http://tizen.org/privilege/telephony")) {
-      console.log('The telephony permission is missing.');
-      return;
-    }
-    getPropertyValue.apply(tizen.systeminfo, arguments);
-  };
+  tizen.systeminfo.getPropertyValue =
+    checkSystemInfoApiPrivilege(tizen.systeminfo.getPropertyValue, permissions);
+  tizen.systeminfo.getPropertyValueArray =
+    checkSystemInfoApiPrivilege(tizen.systeminfo.getPropertyValueArray, permissions);
+  tizen.systeminfo.addPropertyValueChangeListener =
+    checkSystemInfoApiPrivilege(tizen.systeminfo.addPropertyValueChangeListener, permissions);
+  tizen.systeminfo.addPropertyValueArrayChangeListener =
+    checkSystemInfoApiPrivilege(tizen.systeminfo.addPropertyValueArrayChangeListener, permissions);
+
 }