Touchgui/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

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

mercurial