Initial Commit ...
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova.device;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CordovaInterface;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.provider.Settings;
|
||||
|
||||
public class Device extends CordovaPlugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String platform; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
private static final String ANDROID_PLATFORM = "Android";
|
||||
private static final String AMAZON_PLATFORM = "amazon-fireos";
|
||||
private static final String AMAZON_DEVICE = "Amazon";
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Device() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the context of the Command. This can then be used to do things like
|
||||
* get file paths associated with the Activity.
|
||||
*
|
||||
* @param cordova The context of the main Activity.
|
||||
* @param webView The CordovaWebView Cordova is running in.
|
||||
*/
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
Device.uuid = getUuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackContext The callback id used when calling back into JavaScript.
|
||||
* @return True if the action was valid, false if not.
|
||||
*/
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
if ("getDeviceInfo".equals(action)) {
|
||||
JSONObject r = new JSONObject();
|
||||
r.put("uuid", Device.uuid);
|
||||
r.put("version", this.getOSVersion());
|
||||
r.put("platform", this.getPlatform());
|
||||
r.put("model", this.getModel());
|
||||
r.put("manufacturer", this.getManufacturer());
|
||||
r.put("isVirtual", this.isVirtual());
|
||||
r.put("serial", this.getSerialNumber());
|
||||
callbackContext.success(r);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// LOCAL METHODS
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the OS name.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPlatform() {
|
||||
String platform;
|
||||
if (isAmazonDevice()) {
|
||||
platform = AMAZON_PLATFORM;
|
||||
} else {
|
||||
platform = ANDROID_PLATFORM;
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the device's Universally Unique Identifier (UUID).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUuid() {
|
||||
String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
String model = android.os.Build.MODEL;
|
||||
return model;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
String productname = android.os.Build.PRODUCT;
|
||||
return productname;
|
||||
}
|
||||
|
||||
public String getManufacturer() {
|
||||
String manufacturer = android.os.Build.MANUFACTURER;
|
||||
return manufacturer;
|
||||
}
|
||||
|
||||
public String getSerialNumber() {
|
||||
String serial = android.os.Build.SERIAL;
|
||||
return serial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the OS version.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getOSVersion() {
|
||||
String osversion = android.os.Build.VERSION.RELEASE;
|
||||
return osversion;
|
||||
}
|
||||
|
||||
public String getSDKVersion() {
|
||||
@SuppressWarnings("deprecation")
|
||||
String sdkversion = android.os.Build.VERSION.SDK;
|
||||
return sdkversion;
|
||||
}
|
||||
|
||||
public String getTimeZoneID() {
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
return (tz.getID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check if the device is manufactured by Amazon
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAmazonDevice() {
|
||||
if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isVirtual() {
|
||||
return android.os.Build.FINGERPRINT.contains("generic") ||
|
||||
android.os.Build.PRODUCT.contains("sdk");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
var browser = require('cordova/platform');
|
||||
|
||||
function getPlatform () {
|
||||
return 'browser';
|
||||
}
|
||||
|
||||
function getModel () {
|
||||
return getBrowserInfo(true);
|
||||
}
|
||||
|
||||
function getVersion () {
|
||||
return getBrowserInfo(false);
|
||||
}
|
||||
|
||||
function getBrowserInfo (getModel) {
|
||||
var userAgent = navigator.userAgent;
|
||||
var returnVal = '';
|
||||
var offset;
|
||||
|
||||
if ((offset = userAgent.indexOf('Edge')) !== -1) {
|
||||
returnVal = (getModel) ? 'Edge' : userAgent.substring(offset + 5);
|
||||
} else if ((offset = userAgent.indexOf('Chrome')) !== -1) {
|
||||
returnVal = (getModel) ? 'Chrome' : userAgent.substring(offset + 7);
|
||||
} else if ((offset = userAgent.indexOf('Safari')) !== -1) {
|
||||
if (getModel) {
|
||||
returnVal = 'Safari';
|
||||
} else {
|
||||
returnVal = userAgent.substring(offset + 7);
|
||||
|
||||
if ((offset = userAgent.indexOf('Version')) !== -1) {
|
||||
returnVal = userAgent.substring(offset + 8);
|
||||
}
|
||||
}
|
||||
} else if ((offset = userAgent.indexOf('Firefox')) !== -1) {
|
||||
returnVal = (getModel) ? 'Firefox' : userAgent.substring(offset + 8);
|
||||
} else if ((offset = userAgent.indexOf('MSIE')) !== -1) {
|
||||
returnVal = (getModel) ? 'MSIE' : userAgent.substring(offset + 5);
|
||||
} else if ((offset = userAgent.indexOf('Trident')) !== -1) {
|
||||
returnVal = (getModel) ? 'MSIE' : '11';
|
||||
}
|
||||
|
||||
if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) {
|
||||
returnVal = returnVal.substring(0, offset);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDeviceInfo: function (success, error) {
|
||||
setTimeout(function () {
|
||||
success({
|
||||
cordova: browser.cordovaVersion,
|
||||
platform: getPlatform(),
|
||||
model: getModel(),
|
||||
version: getVersion(),
|
||||
uuid: null,
|
||||
isVirtual: false
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
require('cordova/exec/proxy').add('Device', module.exports);
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
|
||||
@interface CDVDevice : CDVPlugin
|
||||
{}
|
||||
|
||||
+ (NSString*)cordovaVersion;
|
||||
|
||||
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
#import <Cordova/CDV.h>
|
||||
#import "CDVDevice.h"
|
||||
|
||||
@implementation UIDevice (ModelVersion)
|
||||
|
||||
- (NSString*)modelVersion
|
||||
{
|
||||
size_t size;
|
||||
|
||||
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
||||
char* machine = malloc(size);
|
||||
sysctlbyname("hw.machine", machine, &size, NULL, 0);
|
||||
NSString* platform = [NSString stringWithUTF8String:machine];
|
||||
free(machine);
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVDevice () {}
|
||||
@end
|
||||
|
||||
@implementation CDVDevice
|
||||
|
||||
- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
|
||||
{
|
||||
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
|
||||
static NSString* UUID_KEY = @"CDVUUID";
|
||||
|
||||
// Check user defaults first to maintain backwards compaitibility with previous versions
|
||||
// which didn't user identifierForVendor
|
||||
NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
|
||||
if (app_uuid == nil) {
|
||||
if ([device respondsToSelector:@selector(identifierForVendor)]) {
|
||||
app_uuid = [[device identifierForVendor] UUIDString];
|
||||
} else {
|
||||
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
||||
app_uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid);
|
||||
CFRelease(uuid);
|
||||
}
|
||||
|
||||
[userDefaults setObject:app_uuid forKey:UUID_KEY];
|
||||
[userDefaults synchronize];
|
||||
}
|
||||
|
||||
return app_uuid;
|
||||
}
|
||||
|
||||
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
NSDictionary* deviceProperties = [self deviceProperties];
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
|
||||
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (NSDictionary*)deviceProperties
|
||||
{
|
||||
UIDevice* device = [UIDevice currentDevice];
|
||||
|
||||
return @{
|
||||
@"manufacturer": @"Apple",
|
||||
@"model": [device modelVersion],
|
||||
@"platform": @"iOS",
|
||||
@"version": [device systemVersion],
|
||||
@"uuid": [self uniqueAppInstanceIdentifier:device],
|
||||
@"cordova": [[self class] cordovaVersion],
|
||||
@"isVirtual": @([self isVirtual])
|
||||
};
|
||||
}
|
||||
|
||||
+ (NSString*)cordovaVersion
|
||||
{
|
||||
return CDV_VERSION;
|
||||
}
|
||||
|
||||
- (BOOL)isVirtual
|
||||
{
|
||||
#if TARGET_OS_SIMULATOR
|
||||
return true;
|
||||
#elif TARGET_IPHONE_SIMULATOR
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
|
||||
@interface CDVDevice : CDVPlugin
|
||||
|
||||
+ (NSString*) cordovaVersion;
|
||||
|
||||
- (void) getDeviceInfo:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#import "CDVDevice.h"
|
||||
|
||||
#define SYSTEM_VERSION_PLIST @"/System/Library/CoreServices/SystemVersion.plist"
|
||||
|
||||
@implementation CDVDevice
|
||||
|
||||
- (NSString*) modelVersion {
|
||||
size_t size;
|
||||
|
||||
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
||||
char* machine = malloc(size);
|
||||
sysctlbyname("hw.machine", machine, &size, NULL, 0);
|
||||
NSString* modelVersion = [NSString stringWithUTF8String:machine];
|
||||
free(machine);
|
||||
|
||||
return modelVersion;
|
||||
}
|
||||
|
||||
|
||||
- (NSString*) getSerialNr {
|
||||
NSString* serialNr;
|
||||
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
|
||||
if (platformExpert) {
|
||||
CFTypeRef serialNumberAsCFString =
|
||||
IORegistryEntryCreateCFProperty(platformExpert,
|
||||
CFSTR(kIOPlatformSerialNumberKey),
|
||||
kCFAllocatorDefault, 0);
|
||||
if (serialNumberAsCFString) {
|
||||
serialNr = (__bridge NSString*) serialNumberAsCFString;
|
||||
}
|
||||
IOObjectRelease(platformExpert);
|
||||
}
|
||||
return serialNr;
|
||||
}
|
||||
|
||||
- (NSString*) uniqueAppInstanceIdentifier {
|
||||
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
|
||||
static NSString* UUID_KEY = @"CDVUUID";
|
||||
|
||||
NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
|
||||
|
||||
if (app_uuid == nil) {
|
||||
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
|
||||
CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
|
||||
|
||||
app_uuid = [NSString stringWithString:(__bridge NSString*) uuidString];
|
||||
[userDefaults setObject:app_uuid forKey:UUID_KEY];
|
||||
[userDefaults synchronize];
|
||||
|
||||
CFRelease(uuidString);
|
||||
CFRelease(uuidRef);
|
||||
}
|
||||
|
||||
return app_uuid;
|
||||
}
|
||||
|
||||
- (NSString*) platform {
|
||||
return [NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST][@"ProductName"];
|
||||
}
|
||||
|
||||
- (NSString*) systemVersion {
|
||||
return [NSDictionary dictionaryWithContentsOfFile:SYSTEM_VERSION_PLIST][@"ProductVersion"];
|
||||
}
|
||||
|
||||
- (void) getDeviceInfo:(CDVInvokedUrlCommand*) command {
|
||||
NSDictionary* deviceProperties = [self deviceProperties];
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
|
||||
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (NSDictionary*) deviceProperties {
|
||||
NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
|
||||
|
||||
devProps[@"manufacturer"] = @"Apple";
|
||||
devProps[@"model"] = [self modelVersion];
|
||||
devProps[@"platform"] = [self platform];
|
||||
devProps[@"version"] = [self systemVersion];
|
||||
devProps[@"uuid"] = [self uniqueAppInstanceIdentifier];
|
||||
devProps[@"cordova"] = [[self class] cordovaVersion];
|
||||
devProps[@"serial"] = [self getSerialNr];
|
||||
devProps[@"isVirtual"] = @NO;
|
||||
|
||||
NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
|
||||
return devReturn;
|
||||
}
|
||||
|
||||
+ (NSString*) cordovaVersion {
|
||||
return CDV_VERSION;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/* global Windows, createUUID */
|
||||
|
||||
var ROOT_CONTAINER = '{00000000-0000-0000-FFFF-FFFFFFFFFFFF}';
|
||||
var DEVICE_CLASS_KEY = '{A45C254E-DF1C-4EFD-8020-67D146A850E0},10';
|
||||
var DEVICE_CLASS_KEY_NO_SEMICOLON = '{A45C254E-DF1C-4EFD-8020-67D146A850E0}10';
|
||||
var ROOT_CONTAINER_QUERY = 'System.Devices.ContainerId:="' + ROOT_CONTAINER + '"';
|
||||
var HAL_DEVICE_CLASS = '4d36e966-e325-11ce-bfc1-08002be10318';
|
||||
var DEVICE_DRIVER_VERSION_KEY = '{A8B865DD-2E3D-4094-AD97-E593A70C75D6},3';
|
||||
|
||||
module.exports = {
|
||||
|
||||
getDeviceInfo: function (win, fail, args) {
|
||||
|
||||
// deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
|
||||
var deviceId;
|
||||
// get deviceId, or create and store one
|
||||
var localSettings = Windows.Storage.ApplicationData.current.localSettings;
|
||||
if (localSettings.values.deviceId) {
|
||||
deviceId = localSettings.values.deviceId;
|
||||
} else {
|
||||
// App-specific hardware id could be used as uuid, but it changes if the hardware changes...
|
||||
try {
|
||||
var ASHWID = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null).id;
|
||||
deviceId = Windows.Storage.Streams.DataReader.fromBuffer(ASHWID).readGuid();
|
||||
} catch (e) {
|
||||
// Couldn't get the hardware UUID
|
||||
deviceId = createUUID();
|
||||
}
|
||||
// ...so cache it per-install
|
||||
localSettings.values.deviceId = deviceId;
|
||||
}
|
||||
|
||||
var userAgent = window.clientInformation.userAgent;
|
||||
// this will report "windows" in windows8.1 and windows phone 8.1 apps
|
||||
// and "windows8" in windows 8.0 apps similar to cordova.js
|
||||
// See https://github.com/apache/cordova-js/blob/master/src/windows/platform.js#L25
|
||||
var devicePlatform = userAgent.indexOf('MSAppHost/1.0') === -1 ? 'windows' : 'windows8';
|
||||
var versionString = userAgent.match(/Windows (?:Phone |NT )?([0-9.]+)/)[1];
|
||||
|
||||
var deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
|
||||
// Running in the Windows Simulator is a remote session.
|
||||
// Running in the Windows Phone Emulator has the systemProductName set to "Virtual"
|
||||
var isVirtual = Windows.System.RemoteDesktop.InteractiveSession.isRemote || deviceInfo.systemProductName === 'Virtual';
|
||||
var manufacturer = deviceInfo.systemManufacturer;
|
||||
var model = deviceInfo.systemProductName;
|
||||
|
||||
var Pnp = Windows.Devices.Enumeration.Pnp;
|
||||
|
||||
Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.device,
|
||||
[DEVICE_DRIVER_VERSION_KEY, DEVICE_CLASS_KEY],
|
||||
ROOT_CONTAINER_QUERY)
|
||||
.then(function (rootDevices) {
|
||||
for (var i = 0; i < rootDevices.length; i++) {
|
||||
var rootDevice = rootDevices[i];
|
||||
if (!rootDevice.properties) continue;
|
||||
if (rootDevice.properties[DEVICE_CLASS_KEY_NO_SEMICOLON] === HAL_DEVICE_CLASS) {
|
||||
versionString = rootDevice.properties[DEVICE_DRIVER_VERSION_KEY];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
win({ platform: devicePlatform,
|
||||
version: versionString,
|
||||
uuid: deviceId,
|
||||
isVirtual: isVirtual,
|
||||
model: model,
|
||||
manufacturer: manufacturer});
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
}; // exports
|
||||
|
||||
require('cordova/exec/proxy').add('Device', module.exports);
|
||||
Reference in New Issue
Block a user