You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.9 KiB

7 years ago
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. var argscheck = require('cordova/argscheck'),
  22. channel = require('cordova/channel'),
  23. utils = require('cordova/utils'),
  24. exec = require('cordova/exec'),
  25. cordova = require('cordova');
  26. channel.createSticky('onCordovaInfoReady');
  27. // Tell cordova channel to wait on the CordovaInfoReady event
  28. channel.waitForInitialization('onCordovaInfoReady');
  29. /**
  30. * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
  31. * phone, etc.
  32. * @constructor
  33. */
  34. function Device() {
  35. this.available = false;
  36. this.platform = null;
  37. this.version = null;
  38. this.uuid = null;
  39. this.cordova = null;
  40. this.model = null;
  41. this.manufacturer = null;
  42. this.isVirtual = null;
  43. this.serial = null;
  44. var me = this;
  45. channel.onCordovaReady.subscribe(function() {
  46. me.getInfo(function(info) {
  47. //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
  48. //TODO: CB-5105 native implementations should not return info.cordova
  49. var buildLabel = cordova.version;
  50. me.available = true;
  51. me.platform = info.platform;
  52. me.version = info.version;
  53. me.uuid = info.uuid;
  54. me.cordova = buildLabel;
  55. me.model = info.model;
  56. me.isVirtual = info.isVirtual;
  57. me.manufacturer = info.manufacturer || 'unknown';
  58. me.serial = info.serial || 'unknown';
  59. channel.onCordovaInfoReady.fire();
  60. },function(e) {
  61. me.available = false;
  62. utils.alert("[ERROR] Error initializing Cordova: " + e);
  63. });
  64. });
  65. }
  66. /**
  67. * Get device info
  68. *
  69. * @param {Function} successCallback The function to call when the heading data is available
  70. * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
  71. */
  72. Device.prototype.getInfo = function(successCallback, errorCallback) {
  73. argscheck.checkArgs('fF', 'Device.getInfo', arguments);
  74. exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
  75. };
  76. module.exports = new Device();