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 ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}";
23
var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10";
24
var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10';
25
var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\"";
26
var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318";
27
var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3";
28
var MANU_KEY = "System.Devices.Manufacturer";
29
 
30
module.exports = {
31
 
32
    getDeviceInfo:function(win, fail, args) {
33
 
34
        // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
35
        var deviceId;
36
        var manufacturer = "unknown";
37
 
38
        // get deviceId, or create and store one
39
        var localSettings = Windows.Storage.ApplicationData.current.localSettings;
40
        if (localSettings.values.deviceId) {
41
            deviceId = localSettings.values.deviceId;
42
        }
43
        else {
44
            // App-specific hardware id could be used as uuid, but it changes if the hardware changes...
45
            try {
46
                var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id;
47
                deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid();
48
            } catch (e) {
49
                // Couldn't get the hardware UUID
50
                deviceId = createUUID();
51
            }
52
            //...so cache it per-install
53
            localSettings.values.deviceId = deviceId;
54
        }
55
 
56
 
57
        var userAgent = window.clientInformation.userAgent;
58
            // this will report "windows" in windows8.1 and windows phone 8.1 apps
59
            // and "windows8" in windows 8.0 apps similar to cordova.js
60
            // See https://github.com/apache/cordova-js/blob/master/src/windows/platform.js#L25
61
        var devicePlatform = userAgent.indexOf("MSAppHost/1.0") == -1 ? "windows" : "windows8";
62
        var versionString = userAgent.match(/Windows (?:Phone |NT )?([0-9.]+)/)[1];
63
 
64
 
65
 
66
        var Pnp = Windows.Devices.Enumeration.Pnp;
67
 
68
        Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.deviceContainer,[MANU_KEY])
69
        .then(function (infoList) {
70
            var numDevices = infoList.length;
71
            if (numDevices) {
72
                for (var i = 0; i < numDevices; i++) {
73
                    var devContainer = infoList[i];
74
                    if (devContainer.id == ROOT_CONTAINER) {
75
                        manufacturer = devContainer.properties[MANU_KEY];
76
                        break;
77
                    }
78
                }
79
            }
80
        })
81
        .then(function () {
82
            Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.device,
83
                                    [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY],
84
                                    ROOT_CONTAINER_QUERY)
85
            .then(function (rootDevices) {
86
                    for (var i = 0; i < rootDevices.length; i++) {
87
                        var rootDevice = rootDevices[i];
88
                        if (!rootDevice.properties) continue;
89
                        if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) {
90
                            versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY];
91
                            break;
92
                        }
93
                    }
94
 
95
                    setTimeout(function () {
96
                        win({ platform: devicePlatform,
97
                              version: versionString,
98
                              uuid: deviceId,
99
                              model: window.clientInformation.platform,
100
                              manufacturer:manufacturer});
101
                    }, 0);
102
            });
103
        });
104
    }
105
 
106
}; // exports
107
 
108
require("cordova/exec/proxy").add("Device", module.exports);