1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,82 @@ 1.4 +/* 1.5 + * 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * 1.23 +*/ 1.24 + 1.25 + 1.26 +var cordova = require('cordova'); 1.27 +var utils = require('cordova/utils'); 1.28 + 1.29 +module.exports = { 1.30 + 1.31 + getDeviceInfo:function(win,fail,args) { 1.32 + 1.33 + // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId 1.34 + var deviceId; 1.35 + 1.36 + var localSettings = Windows.Storage.ApplicationData.current.localSettings; 1.37 + 1.38 + if (localSettings.values.deviceId) { 1.39 + deviceId = localSettings.values.deviceId; 1.40 + } 1.41 + else { 1.42 + // App-specific hardware id could be used as uuid, but it changes if the hardware changes... 1.43 + try { 1.44 + var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id; 1.45 + deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid(); 1.46 + } catch (e) { 1.47 + // Couldn't get the hardware UUID 1.48 + deviceId = createUUID(); 1.49 + } 1.50 + //...so cache it per-install 1.51 + localSettings.values.deviceId = deviceId; 1.52 + } 1.53 + 1.54 + var versionString = window.clientInformation.userAgent.match(/Windows NT ([0-9.]+)/)[1]; 1.55 + 1.56 + (function(self){ 1.57 + var ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}"; 1.58 + var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10"; 1.59 + var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10'; 1.60 + var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\""; 1.61 + var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318"; 1.62 + var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3"; 1.63 + var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject; 1.64 + pnpObject.findAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.device, [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY], ROOT_CONTAINER_QUERY).then(function(rootDevices) { 1.65 + 1.66 + for (var i = 0; i < rootDevices.length; i++) { 1.67 + var rootDevice = rootDevices[i]; 1.68 + if (!rootDevice.properties) continue; 1.69 + if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) { 1.70 + versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY]; 1.71 + break; 1.72 + } 1.73 + } 1.74 + 1.75 + setTimeout(function () { 1.76 + win({ platform: "windows8", version: versionString, uuid: deviceId, model: window.clientInformation.platform }); 1.77 + }, 0); 1.78 + }); 1.79 + })(this); 1.80 + } 1.81 + 1.82 +}; 1.83 + 1.84 +require("cordova/exec/proxy").add("Device", module.exports); 1.85 +