[Device] Device plugin implemented.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 21 Oct 2015 07:38:20 +0000 (09:38 +0200)
committerHyunJin Park <hj.na.park@samsung.com>
Thu, 22 Oct 2015 01:31:38 +0000 (10:31 +0900)
[Verification] Test pass rate: 100% (9/9/0/0/0)

Change-Id: I1999cd1c4e8b9be37fb2b20bf560f5825b3616e5
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/device/cordova_device_api.js

index c05a4dc..371bde6 100755 (executable)
  */
 
 var _global = window || global || {};
-var _document = document || {};
 
-setTimeout(function () {
-  var device = {
-    cordova: 'dummy-cordova-version',
-    model: 'dummy-model',
-    platform: 'dummy-platform',
-    uuid: 'dummy-uuid',
-    version: 'dummy-os-version',
-  };
-  _global.device = device;
-  _document.dispatchEvent(new Event('deviceready'));
-}, 1000);
+var device = {
+  cordova: cordova.version,
+  model: tizen.systeminfo.getCapability('http://tizen.org/system/model_name'),
+  platform: tizen.systeminfo.getCapability('http://tizen.org/system/platform.name'),
+  uuid: tizen.systeminfo.getCapability('http://tizen.org/system/tizenid'),
+  version: tizen.systeminfo.getCapability('http://tizen.org/feature/platform.version'),
+  manufacturer: tizen.systeminfo.getCapability('http://tizen.org/system/manufacturer')  // not documented, but required by tests
+};
+
+Object.freeze(device);
+Object.defineProperty(_global, 'device', {
+  configurable: false,
+  enumerable: true,
+  writable: false,
+  value: device
+});
+
+
+// fire the listener only once
+// TODO: find a better way of launching the listener, allowing more 'deviceready'
+//       listeners to be registered
+var listener = function (event) {
+  if ('addEventListener' === event.fun) {
+    cordova._broker.removeEventListener('deviceready', listener);
+    event.obj.dispatchEvent(new Event('deviceready'));
+  }
+};
+
+cordova._broker.addEventListener('deviceready', listener);
 
 console.log('Loaded cordova.device API');