Skip to content

Commit

Permalink
Merge pull request intel#212 from zivchang/next
Browse files Browse the repository at this point in the history
update BT, download, notification, power priviledge
  • Loading branch information
zivchang committed Apr 11, 2013
2 parents 7b403f2 + 0d0680e commit 975d621
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 48 deletions.
3 changes: 2 additions & 1 deletion lib/ripple/platform/tizen/2.0/bluetooth.js
Expand Up @@ -43,7 +43,8 @@ var utils = require('ripple/utils'),
localServices : {},
},
_security = {
"http://tizen.org/privilege/bluetooth.admin": ["setName", "setPowered", "setVisible"],
"http://tizen.org/privilege/bluetoothmanager": ["setVisible"],
"http://tizen.org/privilege/bluetooth.admin": ["setName", "setPowered"],
"http://tizen.org/privilege/bluetooth.gap": ["getDefaultAdapter", "discoverDevices", "stopDiscovery", "getKnownDevices", "getDevice", "createBonding", "destroyBonding", "hasService"],
"http://tizen.org/privilege/bluetooth.spp": ["registerRFCOMMServiceByUUID", "connectToServiceByUUID", "writeData", "readData", "close", "unregister"],
all: true
Expand Down
67 changes: 51 additions & 16 deletions lib/ripple/platform/tizen/2.0/download.js
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
var db = require('ripple/db'),
utils = require('ripple/utils'),
event = require('ripple/event'),
errorcode = require('ripple/platform/tizen/2.0/errorcode'),
filesystem = require('ripple/platform/tizen/2.0/filesystem'),
Expand All @@ -27,6 +28,10 @@ var db = require('ripple/db'),
COMPLETED: "COMPLETED",
FAILED: "FAILED"
},
_security = {
"http://tizen.org/privilege/download": ["start"],
all: true
},
DB_DOWNLOAD_KEY = "tizen1-db-download",
DownloadItem, _isInitialized = false, INTERVAL = 1000,
_downloads = [], _resources = [], _self;
Expand Down Expand Up @@ -182,8 +187,11 @@ DownloadItem = function (download, callback) {
return _self;
};

_self = {
start: function (downloadRequest, downloadCallback) {
_self = function () {
function start(downloadRequest, downloadCallback) {
if (!_security.all && !_security.start) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
var downloadObj, fileSize, increment, receivedSize = 0, intervalId;

_checkDownloadParamters(downloadRequest, downloadCallback);
Expand Down Expand Up @@ -213,9 +221,9 @@ _self = {
}, INTERVAL);
downloadObj.intervalId = intervalId;
return downloadObj.id;
},
}

cancel: function (downloadId) {
function cancel(downloadId) {
var downloadObj = _getDownloadObjById(downloadId);
clearInterval(downloadObj.intervalId);
if (downloadObj.state !== DownloadState.DOWNLOADING) {
Expand All @@ -224,9 +232,9 @@ _self = {
}
downloadObj.state = DownloadState.CANCELED;
_exec(downloadObj.callback, 'oncanceled', downloadObj.id);
},
}

pause: function (downloadId) {
function pause(downloadId) {
var downloadObj = _getDownloadObjById(downloadId);
clearInterval(downloadObj.intervalId);
if (downloadObj.state !== DownloadState.DOWNLOADING) {
Expand All @@ -235,9 +243,9 @@ _self = {
}
downloadObj.state = DownloadState.PAUSED;
_exec(downloadObj.callback, 'onpaused', downloadObj.id);
},
}

resume: function (downloadId) {
function resume(downloadId) {
var downloadObj, fileSize, receivedSize, increment, intervalId;

downloadObj = _getDownloadObjById(downloadId);
Expand Down Expand Up @@ -265,26 +273,26 @@ _self = {
}
}, INTERVAL);
downloadObj.intervalId = intervalId;
},
}

getState: function (downloadId) {
function getState(downloadId) {
var downloadObj = _getDownloadObjById(downloadId);
return downloadObj.state;
},
}

getDownloadRequest: function (downloadId) {
function getDownloadRequest(downloadId) {
var req, downloadObj;
downloadObj = _getDownloadObjById(downloadId);
req = new DownloadRequest(downloadObj.url, downloadObj.destination, downloadObj.fileName);
return req;
},
}

getMIMEType: function (downloadId) {
function getMIMEType(downloadId) {
var downloadObj = _getDownloadObjById(downloadId);
return downloadObj.MIMEType;
},
}

setListener: function (downloadId, callback) {
function setListener(downloadId, callback) {
var downloadObj = _getDownloadObjById(downloadId);
if (callback !== undefined && callback !== null &&
(typeof callback.onprogress !== 'function' ||
Expand All @@ -296,6 +304,33 @@ _self = {
}
downloadObj.callback = callback;
}

function handleSubFeatures(subFeatures) {
for (var subFeature in subFeatures) {
if (_security[subFeature].length === 0) {
_security.all = true;
return;
}
_security.all = false;
utils.forEach(_security[subFeature], function (method) {
_security[method] = true;
});
}
}

var download = {
start: start,
cancel: cancel,
pause: pause,
resume: resume,
getState: getState,
getDownloadRequest: getDownloadRequest,
getMIMEType: getMIMEType,
setListener: setListener,
handleSubFeatures : handleSubFeatures
};

return download;
};

event.on('downloadResourceChanged', function () {
Expand Down
8 changes: 1 addition & 7 deletions lib/ripple/platform/tizen/2.0/notification.js
Expand Up @@ -21,7 +21,7 @@ var db = require('ripple/db'),
WebAPIError = require('ripple/platform/tizen/2.0/WebAPIError'),
_notificationStack,
_security = {
"http://tizen.org/privilege/notification": ["post", "update", "remove", "removeAll", "get", "getAll"],
"http://tizen.org/privilege/notification": ["post", "update", "remove", "removeAll"],
all: true
},
_self;
Expand Down Expand Up @@ -120,9 +120,6 @@ _self = function () {
}

function get(id) {
if (!_security.all && !_security.get) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
if (typeof id !== "string") {
throw (new WebAPIError(errorcode.TYPE_MISMATCH_ERR));
}
Expand All @@ -136,9 +133,6 @@ _self = function () {

function getAll() {
var notifications = [];
if (!_security.all && !_security.getAll) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
utils.forEach(_notificationStack, function (item) {
notifications.push(utils.copy(item));
});
Expand Down
86 changes: 66 additions & 20 deletions lib/ripple/platform/tizen/2.0/power.js
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
var event = require('ripple/event'),
utils = require('ripple/utils'),
constants = require('ripple/constants'),
deviceSettings = require('ripple/deviceSettings'),
errorcode = require('ripple/platform/tizen/2.0/errorcode'),
Expand All @@ -29,6 +30,10 @@ var event = require('ripple/event'),
_isScreenOn = true,
_normalBrightness,
_minimal_screen_state = null,
_security = {
"http://tizen.org/privilege/power": ["request", "setScreenBrightness", "turnScreenOn", "turnScreenOff"],
all: true
},
_self;

/**initialize**/
Expand Down Expand Up @@ -74,8 +79,11 @@ function triggerListenerCB(stateObj) {
}
}

_self = {
request: function (resource, state) {
_self = function () {
function request(resource, state) {
if (!_security.all && !_security.request) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
if (typeof resource !== 'string' || typeof state !== 'string') {
throw new WebAPIError(errorcode.TYPE_MISMATCH_ERR);
}
Expand Down Expand Up @@ -105,9 +113,9 @@ _self = {
default:
break;
}
},
}

release: function (resource) {
function release(resource) {
switch (resource) {
case "SCREEN" :
if (_isScreenResourceOccupied) {
Expand All @@ -129,24 +137,27 @@ _self = {
throw (new WebAPIError(errorcode.TYPE_MISMATCH_ERR));
}
}
},
}

setScreenStateChangeListener: function (listener) {
function setScreenStateChangeListener(listener) {
tizen1_utils.validateArgumentType(listener, "function",
new WebAPIError(errorcode.TYPE_MISMATCH_ERR));
_listeners.push(listener);
},
}

unsetScreenStateChangeListener: function () {
function unsetScreenStateChangeListener() {
_listeners = [];
},
}

getScreenBrightness: function () {
function getScreenBrightness() {
var brightness = deviceSettings.retrieve("DISPLAY.brightness");
return brightness;
},
}

setScreenBrightness: function (brightness) {
function setScreenBrightness(brightness) {
if (!_security.all && !_security.setScreenBrightness) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
if (typeof brightness !== 'number') {
throw new WebAPIError(errorcode.TYPE_MISMATCH_ERR);
}
Expand All @@ -161,24 +172,27 @@ _self = {
event.trigger("DisplayBrightnessChangedByPower", [brightness]);
updateResourceState();
triggerListenerCB(ScreenState);
},
}

isScreenOn: function () {
function isScreenOn() {
return _isScreenOn;
},
}

restoreScreenBrightness: function () {
function restoreScreenBrightness() {
if (_isScreenResourceOccupied) {
_isScreenResourceOccupied = false;
deviceSettings.persist("DISPLAY.brightness", _originalBrightness);
event.trigger("DisplayBrightnessChangedByPower", [_originalBrightness]);
updateResourceState();
triggerListenerCB(ScreenState);
}
},
}

turnScreenOn: function () {
function turnScreenOn() {
var brightness, value, flag = false;
if (!_security.all && !_security.turnScreenOn) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
brightness = deviceSettings.retrieve("DISPLAY.brightness");
switch (_minimal_screen_state) {
case "SCREEN_DIM":
Expand Down Expand Up @@ -219,11 +233,43 @@ _self = {
triggerListenerCB(ScreenState);
}
_isScreenOn = true;
},
}

turnScreenOff: function () {
function turnScreenOff() {
if (!_security.all && !_security.turnScreenOff) {
throw new WebAPIError(errorcode.SECURITY_ERR);
}
_isScreenOn = false;
}

function handleSubFeatures(subFeatures) {
for (var subFeature in subFeatures) {
if (_security[subFeature].length === 0) {
_security.all = true;
return;
}
_security.all = false;
utils.forEach(_security[subFeature], function (method) {
_security[method] = true;
});
}
}

var power = {
request: request,
release: release,
setScreenStateChangeListener: setScreenStateChangeListener,
unsetScreenStateChangeListener: unsetScreenStateChangeListener,
getScreenBrightness: getScreenBrightness,
setScreenBrightness: setScreenBrightness,
isScreenOn: isScreenOn,
restoreScreenBrightness: restoreScreenBrightness,
turnScreenOn: turnScreenOn,
turnScreenOff: turnScreenOff,
handleSubFeatures : handleSubFeatures
};

return power;
};

initState();
Expand Down
8 changes: 5 additions & 3 deletions lib/ripple/platform/tizen/2.0/spec.js
Expand Up @@ -81,7 +81,8 @@ module.exports = {
},
download: {
path: "tizen/2.0/download",
feature: "http://tizen.org/privilege/download"
feature: "http://tizen.org/privilege/download",
handleSubfeatures: true
},
DownloadRequest: {
path: "tizen/2.0/DownloadRequest",
Expand Down Expand Up @@ -110,7 +111,7 @@ module.exports = {
},
bluetooth: {
path: "tizen/2.0/bluetooth",
feature: "http://tizen.org/privilege/bluetooth.admin|http://tizen.org/privilege/bluetooth.gap|http://tizen.org/privilege/bluetooth.spp",
feature: "http://tizen.org/privilege/bluetoothmanager|http://tizen.org/privilege/bluetooth.admin|http://tizen.org/privilege/bluetooth.gap|http://tizen.org/privilege/bluetooth.spp",
handleSubfeatures: true
},
contact: {
Expand Down Expand Up @@ -242,7 +243,8 @@ module.exports = {
},
power: {
path: "tizen/2.0/power",
feature: "http://tizen.org/privilege/power"
feature: "http://tizen.org/privilege/power",
handleSubfeatures: true
},
networkbearerselection: {
path: "tizen/2.0/networkbearerselection",
Expand Down
2 changes: 1 addition & 1 deletion lib/ripple/platform/tizen/2.0/spec/config.js
Expand Up @@ -703,7 +703,7 @@ module.exports = {
"http://tizen.org/privilege/callhistory.read", "http://tizen.org/privilege/callhistory.write",
"http://tizen.org/privilege/messaging.send",
"http://tizen.org/privilege/messaging.read", "http://tizen.org/privilege/messaging.write",
"http://tizen.org/privilege/bluetooth.admin",
"http://tizen.org/privilege/bluetoothmanager", "http://tizen.org/privilege/bluetooth.admin",
"http://tizen.org/privilege/bluetooth.gap", "http://tizen.org/privilege/bluetooth.spp",
"http://tizen.org/privilege/nfc.common", "http://tizen.org/privilege/nfc.admin",
"http://tizen.org/privilege/nfc.tag", "http://tizen.org/privilege/nfc.p2p",
Expand Down

0 comments on commit 975d621

Please sign in to comment.