4 * Nokia Web Runtime Service API emulation
7 * Copyright 2009 Nokia Corporation. All rights reserved.
13 var provider = 'Service.SysInfo' ,
14 Interface = 'ISysInfo';
16 var supportedEntitiesAndKeys = {
18 "batterystrength":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
19 "chargingstatus":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true}
22 "bluetooth":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
23 "infrared":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
24 "activeconnections":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":false},
25 "connectionstatus":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
26 "wlanmacaddress":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true}
29 "firmwareversion":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
30 "platformversion":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
31 "producttype":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
32 "manufacturer":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
33 "machineid":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
34 "phonemodel":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
35 "imei":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true}
38 "brightness":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
39 "screensavertimeout":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
40 "userinactivity":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
41 "keyguardtime":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
42 "autolocktime":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
43 "autolockstatus":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
44 "wallpaper":{"GetInfo":false,"SetInfo":true,"GetNotification":false,"GetInfoModeSync":false,"InputDataType":"string"},
45 "lighttimeout":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
46 "displayresolution":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
47 "displayorientation":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true}
50 "bluetooth":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
51 "infrared":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
52 "camera":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
53 "memorycard":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
54 "fmradio":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
55 "qwerty":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
56 "wlan":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
57 "usb":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
58 "pen":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
59 "led":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
60 "coverui":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
61 "sidevolumekeys":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
62 "vibra":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true}
65 "accessorystatus":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
66 "connectedaccessories":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
67 "inputlanguage":{"GetInfo":true,"SetInfo":true,"GetNotification":true,"GetInfoModeSync":true},
68 "supportedlanguages":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
69 "predictivetext":{"GetInfo":true,"SetInfo":true,"GetNotification":true,"GetInfoModeSync":true},
70 "vibraactive":{"GetInfo":true,"SetInfo":true,"GetNotification":true,"GetInfoModeSync":true},
71 "availableusbmodes":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
72 "activeusbmode":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
73 "flipstatus":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
74 "gripstatus":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
78 "driveinfo":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
79 "listdrives":{"GetInfo":true,"SetInfo":false,"GetNotification":false,"GetInfoModeSync":true},
80 "criticalmemory":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
81 "memorycard":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true}
84 "signalstrength":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
85 "registrationstatus":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
86 "networkmode":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":true},
87 "currentnetwork":{"GetInfo":true,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
88 "locationarea":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false},
89 "cellid":{"GetInfo":false,"SetInfo":false,"GetNotification":true,"GetInfoModeSync":false}
96 var SysInfoService = function(){
97 this.GetInfo = __GetInfo;
98 this.SetInfo = __SetInfo;
99 this.GetNotification = __GetNotification;
100 this.Cancel = __Cancel;
103 device.implementation.extend(provider, Interface, new SysInfoService() );
105 var context = device.implementation.context,
110 default_device = 'default';
114 * @param {Object} criteria
115 * @param {function} callback function for async call (optional)
117 function __GetInfo(criteria, callback){
118 var retVal = ValidateArguments("GetInfo",criteria,callback);
119 if(retVal.ErrorCode != 0)
124 if (typeof callback == 'function') {
125 return context.callAsync(this, arguments.callee, criteria, callback);
128 DBase = context.getData(provider);
129 var returnValue = DBase;
130 returnValue = returnValue[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()];
131 returnValue.Key = criteria.Key;
132 returnValue.Entity = criteria.Entity;
134 if(/^Connectivity$/i.test(criteria.Entity)&& /^ActiveConnections$/i.test(criteria.Key))
136 var temp = returnValue.ConnectionList;
137 returnValue.ConnectionList = context.Iterator(temp);
139 else if(/^General$/i.test(criteria.Entity)&& /^ConnectedAccessories$/i.test(criteria.Key))
141 var temp = returnValue.AccessoryList;
142 returnValue.AccessoryList = context.Iterator(temp);
144 else if(/^Memory$/i.test(criteria.Entity)&& /^DriveInfo$/i.test(criteria.Key))
147 var temp = criteria.SystemData.Drive;
150 temp = temp.substring(0,3);
152 temp= returnValue.Drive[temp.toUpperCase()];
154 return error(device.implementation.ERR_BAD_ARGUMENT_TYPE, msg.no_msg);
156 var driveInfo = new Object();
157 driveInfo.Key = returnValue.Key;
158 driveInfo.Entity = returnValue.Entity;
159 driveInfo.DriveInfo = temp;
160 return context.Result(driveInfo);
164 return error(device.implementation.ERR_BAD_ARGUMENT_TYPE, msg.no_msg);
168 return context.Result(returnValue);
174 * @param {Object} criteria
175 * @param {function} callback function for async call (optional)
177 function __SetInfo(criteria, callback){
178 var retVal = ValidateArguments("SetInfo",criteria,callback);
179 if(retVal.ErrorCode != 0)
184 // Current implementation support only for 'General' -> 'InputLanguage' || 'PredictiveText'
185 if (/^General$/i.test(criteria.Entity) && ( /^InputLanguage$/i.test(criteria.Key) || /^PredictiveText/i.test(criteria.Key) || /^VibraActive/i.test(criteria.Key))) {
186 // get the DBase data
187 DBase = context.getData(provider);
188 var returnValue = DBase;
190 // Check the 'SupportedLanguages' entries for Setting the new Status
191 if (/^InputLanguage$/i.test(criteria.Key)) {
193 var languageList = returnValue['general']['supportedlanguages']['LanguageList'];
194 for (var key in languageList) {
195 if (languageList[key] == criteria.SystemData.Status) {
199 // Update the 'InputLanguage' if the value value found in the ['SupportedLanguages']
201 returnValue[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()]['Status'] = criteria.SystemData.Status;
203 return error(device.implementation.ERR_SERVICE_NOT_SUPPORTED, msg.not_supported);
205 else if (/^PredictiveText$/i.test(criteria.Key)) {
206 if (criteria.SystemData.Status == 0 || criteria.SystemData.Status == 1)
207 returnValue[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()]['Status'] = criteria.SystemData.Status;
209 return error(device.implementation.ERR_NOT_FOUND, msg.badType);
211 else if (/^VibraActive$/i.test(criteria.Key)) {
212 if (criteria.SystemData.Status == 0 || criteria.SystemData.Status == 1)
213 returnValue[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()]['Status'] = criteria.SystemData.Status;
216 return error(device.implementation.ERR_SERVICE_NOT_SUPPORTED, msg.not_supported);
219 else if(/^Display/i.test(criteria.Entity) && /^Wallpaper/i.test(criteria.Key)) {
220 if(typeof criteria.SystemData.StringData == 'undefined')
221 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.missingArgs);
222 returnValue[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()]['StringData'] = criteria.SystemData.StringData;
223 return context.ErrorResult(device.implementation.ERR_SUCCESS);
225 return context.Result(result);
230 * SysInfo: GetNotification
231 * @param {Object} criteria
232 * @param {function} callback function for async call
234 function __GetNotification(criteria, callback){
235 var retVal = ValidateArguments("GetNotification",criteria,callback);
236 if(retVal.ErrorCode != 0)
242 if (!/^(Battery|Memory)$/i.test(criteria.Entity) ||
243 !/^(BatteryStrength|ChargingStatus|MemoryCard)$/i.test(criteria.Key)) {
244 context.notify(_t('%s:: GetNotification : entity %s, key %s not implemented in preview.').arg(provider, criteria.Entity, criteria.Key));
245 // register callback anyway so Cancel works.
248 // evenType = 'entity.key'
249 var eventType = criteria.Entity+'.'+criteria.Key;
252 return context.addListener(provider, eventType, criteria, callback, notifyHandler);
255 function notifyHandler(transactionID, criteria, callback, data){
258 eventCode = {completed:2, error:4, progress:9},
259 code = eventCode.progress;
261 DBase = context.getData(provider);
262 var entity = criteria.Entity.toLowerCase(),
263 key = criteria.Key.toLowerCase();
265 // make a copy of return value
266 var returnValue = context.extend({},DBase[entity][key]);
269 context.extend(returnValue, data);
271 result = context.Result(returnValue);
274 code = eventCode.error;
276 callback(transactionID, code, result);
283 * @param {Object} criteria
285 function __Cancel(criteria){
288 if (!criteria || !criteria.TransactionID)
289 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.missingTID);
291 var found = context.removeListener(provider, null, criteria.TransactionID);
293 return error(device.implementation.ERR_NOT_FOUND);
295 return context.ErrorResult(device.implementation.ERR_SUCCESS);
300 /*******************************
302 *******************************/
304 function error(code, msg /*, args...*/){
306 var args = ['SysInfo',method].concat([].slice.call(arguments,2));
307 msg = msg ? _t().arg.apply(msg,args) : undefined;
308 return context.ErrorResult(code, msg);
311 function cancelRegisteredNotify(result)
313 __Cancel({'TransactionID':result.TransactionID});
314 method = 'GetNotification';
319 * order of %s args: Service name, method name, parameter name
322 badType : '%s: %s: Type is invalid',
323 badSysInfo : '%s: %s: SysInfoName is invalid',
324 missingSysInfo : '%s: %s: SysInfoName is missing',
325 missingTID : '%s: %s: Transaction ID missing',
326 not_supported : '%s: %s: Not Supported',
327 is_invalid : '%s: %s: Is invalid',
328 missingArgs : '%s: %s: SystemData Argument Missing',
329 inSufficientArgs : '%s: %s: Insufficient Arguments to process',
330 missingInputParam : '%s: %s: Input Parameter Missing',
331 not_supportedSyncVer: '%s: %s: Sync Version Not Supported',
332 noEntity : '%s: %s: Entity: Input Parameter Missing',
333 noKey : '%s: %s: Key: Input Parameter Missing',
334 IncorrectSytemData : '%s: %s: Incorrect SystemData Type, SystemData Must be a Map',
335 callbackNotFound : '%s: %s: Callback object not found',
336 commandNotFound : '%s: %s: Command Not Supported',
337 unsupInterface : 'SysInfo:Requested interface not supported by the provider',
342 * Common validator for all functions
345 * @param {arguments} function name and arguments of calling function
346 * @return {Result} Error object
348 function ValidateArguments(funName,criteria,callback)
353 if (/^GetNotification$/i.test(funName) && typeof callback != "function") {
354 return error(device.implementation.ERR_BAD_ARGUMENT_TYPE, msg.not_supportedSyncVer);
357 if (typeof criteria == "undefined" || typeof criteria.Entity == "undefined" || typeof criteria.Key == "undefined") {
358 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.inSufficientArgs);
361 if (criteria.Entity == "") {
362 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.noEntity);
365 if (criteria.Key == "") {
366 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.noKey);
369 if (/^SetInfo$/i.test(funName)) {
370 if (typeof criteria.SystemData == "undefined" || criteria.SystemData == '') {
371 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.missingArgs);
373 if (typeof criteria.SystemData.StringData == "undefined" && typeof criteria.SystemData.Status == "undefined") {
374 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.missingArgs);
378 if (typeof supportedEntitiesAndKeys[criteria.Entity.toLowerCase()] == 'undefined' || typeof supportedEntitiesAndKeys[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()] == 'undefined') {
379 return error(device.implementation.ERR_NOT_FOUND, msg.no_msg);
382 if (!supportedEntitiesAndKeys[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()][funName]) {
383 return error(device.implementation.ERR_NOT_FOUND, msg.no_msg);
386 if (funName == "GetInfo" && !supportedEntitiesAndKeys[criteria.Entity.toLowerCase()][criteria.Key.toLowerCase()]["GetInfoModeSync"] && typeof callback != "function") {
387 return error(device.implementation.ERR_MISSING_ARGUMENT, msg.not_supportedSyncVer);
390 return context.ErrorResult(device.implementation.ERR_SUCCESS, "");
393 return error(device.implementation.ERR_BAD_ARGUMENT_TYPE, msg.badType);