new cordova plugins

This commit is contained in:
Marc Wäckerlin
2016-01-10 22:23:05 +00:00
parent 787eefc67c
commit 1c3765955b
61 changed files with 8688 additions and 0 deletions

View File

@@ -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");
}
}

View File

@@ -0,0 +1,69 @@
/*
*
* 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.
*
*/
function getModelName () {
var modelName = window.qnx.webplatform.device.modelName;
//Pre 10.2 (meaning Z10 or Q10)
if (typeof modelName === "undefined") {
if (window.screen.height === 720 && window.screen.width === 720) {
if ( window.matchMedia("(-blackberry-display-technology: -blackberry-display-oled)").matches) {
modelName = "Q10";
} else {
modelName = "Q5";
}
} else if ((window.screen.height === 1280 && window.screen.width === 768) ||
(window.screen.height === 768 && window.screen.width === 1280)) {
modelName = "Z10";
} else {
modelName = window.qnx.webplatform.deviceName;
}
}
return modelName;
}
function getUUID () {
var uuid = "";
try {
//Must surround by try catch because this will throw if the app is missing permissions
uuid = window.qnx.webplatform.device.devicePin;
} catch (e) {
//DO Nothing
}
return uuid;
}
module.exports = {
getDeviceInfo: function (success, fail, args, env) {
var result = new PluginResult(args, env),
modelName = getModelName(),
uuid = getUUID(),
info = {
manufacturer: 'BlackBerry',
platform: "blackberry10",
version: window.qnx.webplatform.device.scmBundle,
model: modelName,
uuid: uuid
};
result.ok(info);
}
};

View File

@@ -0,0 +1,82 @@
/*
*
* 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');
var cordova = require('cordova');
function getPlatform() {
return "browser";
}
function getModel() {
return getBrowserInfo(true);
}
function getVersion() {
return getBrowserInfo(false);
}
function getBrowserInfo(getModel) {
var userAgent = navigator.userAgent;
var returnVal = '';
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
});
}, 0);
}
};
require("cordova/exec/proxy").add("Device", module.exports);

View File

@@ -0,0 +1,79 @@
/*
*
* 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.
*
*/
//example UA String for Firefox OS
//Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0
var firefoxos = require('cordova/platform');
var cordova = require('cordova');
//UA parsing not recommended but currently this is the only way to get the Firefox OS version
//https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
//Should be replaced when better conversion to Firefox OS Version is available
function convertVersionNumber(ver) {
var hashVersion = {
'18.0': '1.0.1',
'18.1': '1.1',
'26.0': '1.2',
'28.0': '1.3',
'30.0': '1.4',
'32.0': '2.0'
};
var rver = ver;
var sStr = ver.substring(0, 4);
if (hashVersion[sStr]) {
rver = hashVersion[sStr];
}
return (rver);
}
function getVersion() {
if (navigator.userAgent.match(/(mobile|tablet)/i)) {
var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
if (ffVersionArray.length === 2) {
return (convertVersionNumber(ffVersionArray[1]));
}
}
return (null);
}
function getModel() {
var uaArray = navigator.userAgent.split(/\s*[;)(]\s*/);
if (navigator.userAgent.match(/(mobile|tablet)/i)) {
if (uaArray.length === 5) {
return (uaArray[2]);
}
}
return (null);
}
module.exports = {
getDeviceInfo: function (success, error) {
setTimeout(function () {
success({
platform: 'firefoxos',
model: getModel(),
version: getVersion(),
uuid: null
});
}, 0);
}
};
require("cordova/exec/proxy").add("Device", module.exports);

View File

@@ -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

View File

@@ -0,0 +1,106 @@
/*
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) {
app_uuid = [[device identifierForVendor] UUIDString];
[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];
NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
[devProps setObject:@"Apple" forKey:@"manufacturer"];
[devProps setObject:[device modelVersion] forKey:@"model"];
[devProps setObject:@"iOS" forKey:@"platform"];
[devProps setObject:[device systemVersion] forKey:@"version"];
[devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"];
[devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
[devProps setObject:@([self isVirtual]) forKey:@"isVirtual"];
NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
return devReturn;
}
+ (NSString*)cordovaVersion
{
return CDV_VERSION;
}
- (BOOL)isVirtual
{
#if TARGET_OS_SIMULATOR
return true;
#elif TARGET_IPHONE_SIMULATOR
return true;
#else
return false;
#endif
}
@end

View File

@@ -0,0 +1,39 @@
/*
*
* 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 tizen = require('cordova/platform');
var cordova = require('cordova');
module.exports = {
getDeviceInfo: function(success, error) {
setTimeout(function () {
success({
cordova: tizen.cordovaVersion,
platform: 'tizen',
model: null,
version: null,
uuid: null
});
}, 0);
}
};
require("cordova/tizen/commandProxy").add("Device", module.exports);

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2011 Wolfgang Koller - http://www.gofg.at/
*
* Licensed 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 <QDeviceInfo>
#include <QtSystemInfo>
#include"device.h"
#define CORDOVA "3.0.0"
Device::Device(Cordova *cordova) : CPlugin(cordova) {
}
static QString getOSName() {
#ifdef Q_OS_SYMBIAN
QString platform = "Symbian";
#endif
#ifdef Q_OS_WIN
QString platform = "Windows";
#endif
#ifdef Q_OS_WINCE
QString platform = "Windows CE";
#endif
#ifdef Q_OS_LINUX
QString platform = "Linux";
#endif
return platform;
}
void Device::getInfo(int scId, int ecId) {
Q_UNUSED(ecId)
QDeviceInfo systemDeviceInfo;
QDeviceInfo systemInfo;
QString platform = getOSName();
QString uuid = systemDeviceInfo.uniqueDeviceID();
if (uuid.isEmpty()) {
QString deviceDescription = systemInfo.imei(0) + ";" + systemInfo.manufacturer() + ";" + systemInfo.model() + ";" + systemInfo.productName() + ";" + platform;
QString user = qgetenv("USER");
if (user.isEmpty()) {
user = qgetenv("USERNAME");
if (user.isEmpty())
user = QDir::homePath();
}
uuid = QString(QCryptographicHash::hash((deviceDescription + ";" + user).toUtf8(), QCryptographicHash::Md5).toHex());
}
this->cb(scId, systemDeviceInfo.model(), CORDOVA, platform, uuid, systemInfo.version(QDeviceInfo::Os));
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2011 Wolfgang Koller - http://www.gofg.at/
*
* Licensed 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.
*/
#ifndef DEVICE_H_FDSAFAS
#define DEVICE_H_FDSAFAS
#include <QtCore>
#include <cplugin.h>
class Device: public CPlugin {
Q_OBJECT
public:
explicit Device(Cordova *cordova);
virtual const QString fullName() override {
return Device::fullID();
}
virtual const QString shortName() override {
return "Device";
}
static const QString fullID() {
return "com.cordova.Device";
}
signals:
public slots:
void getInfo(int scId, int ecId);
};
#endif

View File

@@ -0,0 +1,34 @@
/*
*
* 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 cordova = require('cordova');
var exec = require('cordova/exec');
module.exports = {
getInfo:function(win,fail,args) {
Cordova.exec(function (model, cordova, platform, uuid, version) {
win({name: name, model: model, cordova: cordova,
platform: platform, uuid: uuid, version: version});
}, null, "com.cordova.Device", "getInfo", []);
}
};
require("cordova/exec/proxy").add("Device", module.exports);

View File

@@ -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.
*
*/
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);

View File

@@ -0,0 +1,87 @@
/*
Licensed 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.
*/
using Microsoft.Phone.Info;
using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace WPCordovaClassLib.Cordova.Commands
{
public class Device : BaseCommand
{
public void getDeviceInfo(string notused)
{
string res = String.Format("\"name\":\"{0}\",\"platform\":\"{1}\",\"uuid\":\"{2}\",\"version\":\"{3}\",\"model\":\"{4}\",\"manufacturer\":\"{5}\",\"isVirtual\":{6}",
DeviceStatus.DeviceName,
Environment.OSVersion.Platform.ToString(),
UUID,
Environment.OSVersion.Version.ToString(),
DeviceStatus.DeviceName,
DeviceStatus.DeviceManufacturer,
IsVirtual ? "true" : "false");
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "{" + res + "}"));
}
public bool IsVirtual
{
get
{
return (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator);
}
}
public string UUID
{
get
{
object id;
UserExtendedProperties.TryGetValue("ANID", out id);
if (id != null)
{
return id.ToString().Substring(2, 32);
}
UserExtendedProperties.TryGetValue("ANID2", out id);
if (id != null)
{
return id.ToString();
}
string returnVal = "???unknown???";
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);
using (StreamReader reader = new StreamReader(fileStream))
{
returnVal = reader.ReadLine();
}
}
catch (Exception /*ex*/)
{
}
}
return returnVal;
}
}
}
}