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

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,80 @@
     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 +module.exports = {
    1.26 +
    1.27 +    getDeviceInfo:function(win, fail, args) {
    1.28 +
    1.29 +        // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
    1.30 +        var deviceId;
    1.31 +        var localSettings = Windows.Storage.ApplicationData.current.localSettings;
    1.32 +        if (localSettings.values.deviceId) {
    1.33 +            deviceId = localSettings.values.deviceId;
    1.34 +        }
    1.35 +        else {
    1.36 +            // App-specific hardware id could be used as uuid, but it changes if the hardware changes...
    1.37 +            try {
    1.38 +                var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id;
    1.39 +                deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid();
    1.40 +            } catch (e) {
    1.41 +                // Couldn't get the hardware UUID
    1.42 +                deviceId = createUUID();
    1.43 +            }
    1.44 +            //...so cache it per-install
    1.45 +            localSettings.values.deviceId = deviceId;
    1.46 +        }
    1.47 +
    1.48 +        var userAgent = window.clientInformation.userAgent,
    1.49 +            // this will report "windows" in windows8.1 and windows phone 8.1 apps
    1.50 +            // and "windows8" in windows 8.0 apps similar to cordova.js
    1.51 +            // See https://github.com/apache/cordova-js/blob/master/src/windows/platform.js#L25
    1.52 +            devicePlatform = userAgent.indexOf("MSAppHost/1.0") == -1 ? "windows" : "windows8",
    1.53 +            versionString = userAgent.match(/Windows (?:Phone |NT )?([0-9.]+)/)[1];
    1.54 +        
    1.55 +        var ROOT_CONTAINER = "{00000000-0000-0000-FFFF-FFFFFFFFFFFF}";
    1.56 +        var DEVICE_CLASS_KEY = "{A45C254E-DF1C-4EFD-8020-67D146A850E0},10";
    1.57 +        var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10';
    1.58 +        var ROOT_CONTAINER_QUERY = "System.Devices.ContainerId:=\"" + ROOT_CONTAINER + "\"";
    1.59 +        var HAL_DEVICE_CLASS = "4d36e966-e325-11ce-bfc1-08002be10318";
    1.60 +        var DEVICE_DRIVER_VERSION_KEY = "{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3";
    1.61 +        var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject;
    1.62 +        pnpObject.findAllAsync(Windows.Devices.Enumeration.Pnp.PnpObjectType.device,
    1.63 +            [DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY], ROOT_CONTAINER_QUERY)
    1.64 +        .then(function(rootDevices) {
    1.65 +            for (var i = 0; i < rootDevices.length; i++) {
    1.66 +                var rootDevice = rootDevices[i];
    1.67 +                if (!rootDevice.properties) continue;
    1.68 +                if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] == HAL_DEVICE_CLASS) {
    1.69 +                    versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY];
    1.70 +                    break;
    1.71 +                }
    1.72 +            }
    1.73 +
    1.74 +            setTimeout(function () {
    1.75 +                win({ platform: devicePlatform, version: versionString,
    1.76 +                    uuid: deviceId, model: window.clientInformation.platform });
    1.77 +            }, 0);
    1.78 +        });
    1.79 +    }
    1.80 +
    1.81 +};
    1.82 +
    1.83 +require("cordova/exec/proxy").add("Device", module.exports);

mercurial