Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15747 anikendra 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
 
22
var argscheck = require('cordova/argscheck'),
23
    channel = require('cordova/channel'),
24
    utils = require('cordova/utils'),
25
    exec = require('cordova/exec'),
26
    cordova = require('cordova');
27
 
28
channel.createSticky('onCordovaInfoReady');
29
// Tell cordova channel to wait on the CordovaInfoReady event
30
channel.waitForInitialization('onCordovaInfoReady');
31
 
32
/**
33
 * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
34
 * phone, etc.
35
 * @constructor
36
 */
37
function Device() {
38
    this.available = false;
39
    this.platform = null;
40
    this.version = null;
41
    this.uuid = null;
42
    this.cordova = null;
43
    this.model = null;
44
    this.manufacturer = null;
45
 
46
    var me = this;
47
 
48
    channel.onCordovaReady.subscribe(function() {
49
        me.getInfo(function(info) {
50
            //ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
51
            //TODO: CB-5105 native implementations should not return info.cordova
52
            var buildLabel = cordova.version;
53
            me.available = true;
54
            me.platform = info.platform;
55
            me.version = info.version;
56
            me.uuid = info.uuid;
57
            me.cordova = buildLabel;
58
            me.model = info.model;
59
            me.manufacturer = info.manufacturer || 'unknown';
60
            channel.onCordovaInfoReady.fire();
61
        },function(e) {
62
            me.available = false;
63
            utils.alert("[ERROR] Error initializing Cordova: " + e);
64
        });
65
    });
66
}
67
 
68
/**
69
 * Get device info
70
 *
71
 * @param {Function} successCallback The function to call when the heading data is available
72
 * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
73
 */
74
Device.prototype.getInfo = function(successCallback, errorCallback) {
75
    argscheck.checkArgs('fF', 'Device.getInfo', arguments);
76
    exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
77
};
78
 
79
module.exports = new Device();