From: Piotr Kosko Date: Tue, 3 Jan 2017 11:54:30 +0000 (+0100) Subject: [HAM] - fixing pedometer listeners with correct privileges check X-Git-Tag: submit/tizen_3.0/20170105.085324~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96a2d9ba654a5cf606bd299fe42ed8071c08f9a9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [HAM] - fixing pedometer listeners with correct privileges check This reverts commit f60b0dd58d49a3cb85df7ca63aeda384abf0bcd2 and adds some special code to correctly handle privileges check. [Verification] TCT for humanactivitymonitor passrate didn't change. All TCT privilege HAM-related testcases pass. Change-Id: Ica915e1f198765ccd43d41df316804bfbcb201d2 --- diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js index d1393cdc..736b9a49 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@ -237,18 +237,20 @@ function checkPrivilegesForMethod(method, type) { } } -function stopListener(listenerId, method, data) { +function stopListener(listenerId, method, data, doRemoval) { if (!native_.isListenerSet(listenerId)) { checkPrivilegesForMethod(method, data.type); return; } - var result = native_.callSync(method, data); - if (native_.isFailure(result)) { - throw native_.getErrorObject(result); - } + if (doRemoval) { + var result = native_.callSync(method, data); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } - native_.removeListener(listenerId); + native_.removeListener(listenerId); + } } // Pedometer listener and accumulative pedometer listener are handled by a single @@ -351,12 +353,16 @@ HumanActivityMonitorManager.prototype.stop = function(type) { {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityType)} ]); - stopListener('HumanActivityMonitor_' + args.type, - 'HumanActivityMonitorManager_stop', - { type: args.type }); - if (HumanActivityType.PEDOMETER === args.type) { + stopListener('HumanActivityMonitor_PEDOMETER', + 'HumanActivityMonitorManager_stop', + { type: HumanActivityType.PEDOMETER }, + pedometerListener && !accumulativePedometerListener); pedometerListener = null; + } else { + stopListener('HumanActivityMonitor_' + args.type, + 'HumanActivityMonitorManager_stop', + { type: args.type }, true); } if (HumanActivityType.GPS === args.type) { @@ -379,13 +385,11 @@ HumanActivityMonitorManager.prototype.setAccumulativePedometerListener = functio }; HumanActivityMonitorManager.prototype.unsetAccumulativePedometerListener = function() { - var oldPedometerListener = pedometerListener; - - // calling stop() will overwrite pedometerListener, needs to be restored afterwards - this.stop(HumanActivityType.PEDOMETER); - + stopListener('HumanActivityMonitor_PEDOMETER', + 'HumanActivityMonitorManager_stop', + { type: HumanActivityType.PEDOMETER }, + accumulativePedometerListener && !pedometerListener); accumulativePedometerListener = null; - pedometerListener = oldPedometerListener; };