michael@0: /* michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: module.exports = { michael@0: michael@0: getDeviceInfo:function(win, fail, args) { michael@0: michael@0: // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId michael@0: var deviceId; michael@0: var localSettings = Windows.Storage.ApplicationData.current.localSettings; michael@0: if (localSettings.values.deviceId) { michael@0: deviceId = localSettings.values.deviceId; michael@0: } michael@0: else { michael@0: // App-specific hardware id could be used as uuid, but it changes if the hardware changes... michael@0: try { michael@0: var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id; michael@0: deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid(); michael@0: } catch (e) { michael@0: // Couldn't get the hardware UUID michael@0: deviceId = createUUID(); michael@0: } michael@0: //...so cache it per-install michael@0: localSettings.values.deviceId = deviceId; michael@0: } michael@0: michael@0: var userAgent = window.clientInformation.userAgent, michael@0: // this will report "windows" in windows8.1 and windows phone 8.1 apps michael@0: // and "windows8" in windows 8.0 apps similar to cordova.js michael@0: // See https://github.com/apache/cordova-js/blob/master/src/windows/platform.js#L25 michael@0: devicePlatform = userAgent.indexOf("MSAppHost/1.0") == -1 ? "windows" : "windows8", michael@0: versionString = userAgent.match(/Windows (?:Phone |NT )?([0-9.]+)/)[1]; michael@0: michael@0: var ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"; michael@0: var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10"; michael@0: var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10'; michael@0: var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\""; michael@0: var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318"; michael@0: var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3"; michael@0: var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject; michael@0: pnpObject.findAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.device, michael@0: [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY], ROOT_CONTAINER_QUERY) michael@0: .then(function(rootDevices) { michael@0: for (var i = 0; i < rootDevices.length; i++) { michael@0: var rootDevice = rootDevices[i]; michael@0: if (!rootDevice.properties) continue; michael@0: if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) { michael@0: versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY]; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: setTimeout(function () { michael@0: win({ platform: devicePlatform, version: versionString, michael@0: uuid: deviceId, model: window.clientInformation.platform }); michael@0: }, 0); michael@0: }); michael@0: } michael@0: michael@0: }; michael@0: michael@0: require("cordova/exec/proxy").add("Device", module.exports);