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