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