summaryrefslogtreecommitdiff
path: root/plugins/org.apache.cordova.device/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.apache.cordova.device/src')
-rw-r--r--plugins/org.apache.cordova.device/src/android/Device.java161
-rw-r--r--plugins/org.apache.cordova.device/src/blackberry10/index.js69
-rw-r--r--plugins/org.apache.cordova.device/src/browser/DeviceProxy.js82
-rw-r--r--plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js79
-rw-r--r--plugins/org.apache.cordova.device/src/ios/CDVDevice.h30
-rw-r--r--plugins/org.apache.cordova.device/src/ios/CDVDevice.m99
-rw-r--r--plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js39
-rw-r--r--plugins/org.apache.cordova.device/src/ubuntu/device.cpp64
-rw-r--r--plugins/org.apache.cordova.device/src/ubuntu/device.h47
-rw-r--r--plugins/org.apache.cordova.device/src/ubuntu/device.js34
-rw-r--r--plugins/org.apache.cordova.device/src/windows/DeviceProxy.js108
-rw-r--r--plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js82
-rw-r--r--plugins/org.apache.cordova.device/src/wp/Device.cs135
13 files changed, 1029 insertions, 0 deletions
diff --git a/plugins/org.apache.cordova.device/src/android/Device.java b/plugins/org.apache.cordova.device/src/android/Device.java
new file mode 100644
index 00000000..5eded907
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/android/Device.java
@@ -0,0 +1,161 @@
+/*
+ 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 (action.equals("getDeviceInfo")) {
+ 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());
+ 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;
+ }
+ /**
+ * 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;
+ }
+
+}
diff --git a/plugins/org.apache.cordova.device/src/blackberry10/index.js b/plugins/org.apache.cordova.device/src/blackberry10/index.js
new file mode 100644
index 00000000..77f25a9e
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/blackberry10/index.js
@@ -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);
+ }
+};
diff --git a/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js b/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js
new file mode 100644
index 00000000..fcaed20c
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/browser/DeviceProxy.js
@@ -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);
diff --git a/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js b/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js
new file mode 100644
index 00000000..79f3a2b0
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/firefoxos/DeviceProxy.js
@@ -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);
diff --git a/plugins/org.apache.cordova.device/src/ios/CDVDevice.h b/plugins/org.apache.cordova.device/src/ios/CDVDevice.h
new file mode 100644
index 00000000..a146d882
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/ios/CDVDevice.h
@@ -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
diff --git a/plugins/org.apache.cordova.device/src/ios/CDVDevice.m b/plugins/org.apache.cordova.device/src/ios/CDVDevice.m
new file mode 100644
index 00000000..5a3f4708
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/ios/CDVDevice.m
@@ -0,0 +1,99 @@
+/*
+ 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>
+
+#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";
+
+ 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;
+}
+
+- (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"];
+
+ NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
+ return devReturn;
+}
+
++ (NSString*)cordovaVersion
+{
+ return CDV_VERSION;
+}
+
+@end
diff --git a/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js b/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js
new file mode 100644
index 00000000..2afc3243
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/tizen/DeviceProxy.js
@@ -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);
diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.cpp b/plugins/org.apache.cordova.device/src/ubuntu/device.cpp
new file mode 100644
index 00000000..eb5a012d
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/ubuntu/device.cpp
@@ -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));
+}
diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.h b/plugins/org.apache.cordova.device/src/ubuntu/device.h
new file mode 100644
index 00000000..91cb9377
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/ubuntu/device.h
@@ -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
diff --git a/plugins/org.apache.cordova.device/src/ubuntu/device.js b/plugins/org.apache.cordova.device/src/ubuntu/device.js
new file mode 100644
index 00000000..3adb110b
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/ubuntu/device.js
@@ -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);
diff --git a/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js b/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js
new file mode 100644
index 00000000..69ed4446
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/windows/DeviceProxy.js
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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";
+var MANU_KEY = "System.Devices.Manufacturer";
+
+module.exports = {
+
+ getDeviceInfo:function(win, fail, args) {
+
+ // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
+ var deviceId;
+ var manufacturer = "unknown";
+
+ // 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 Pnp = Windows.Devices.Enumeration.Pnp;
+
+ Pnp.PnpObject.findAllAsync(Pnp.PnpObjectType.deviceContainer,[MANU_KEY])
+ .then(function (infoList) {
+ var numDevices = infoList.length;
+ if (numDevices) {
+ for (var i = 0; i < numDevices; i++) {
+ var devContainer = infoList[i];
+ if (devContainer.id == ROOT_CONTAINER) {
+ manufacturer = devContainer.properties[MANU_KEY];
+ break;
+ }
+ }
+ }
+ })
+ .then(function () {
+ 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,
+ model: window.clientInformation.platform,
+ manufacturer:manufacturer});
+ }, 0);
+ });
+ });
+ }
+
+}; // exports
+
+require("cordova/exec/proxy").add("Device", module.exports);
diff --git a/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js b/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js
new file mode 100644
index 00000000..3ddc9b2b
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/windows8/DeviceProxy.js
@@ -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 cordova = require('cordova');
+var utils = require('cordova/utils');
+
+module.exports = {
+
+ getDeviceInfo:function(win,fail,args) {
+
+ // deviceId aka uuid, stored in Windows.Storage.ApplicationData.current.localSettings.values.deviceId
+ var deviceId;
+
+ 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 versionString = window.clientInformation.userAgent.match(/Windows NT ([0-9.]+)/)[1];
+
+ (function(self){
+ 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";
+ var pnpObject = Windows.Devices.Enumeration.Pnp.PnpObject;
+ pnpObject.findAllAsync(Windows.Devices.Enumeration.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: "windows8", version: versionString, uuid: deviceId, model: window.clientInformation.platform });
+ }, 0);
+ });
+ })(this);
+ }
+
+};
+
+require("cordova/exec/proxy").add("Device", module.exports);
+
diff --git a/plugins/org.apache.cordova.device/src/wp/Device.cs b/plugins/org.apache.cordova.device/src/wp/Device.cs
new file mode 100644
index 00000000..897a35af
--- /dev/null
+++ b/plugins/org.apache.cordova.device/src/wp/Device.cs
@@ -0,0 +1,135 @@
+/*
+ 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 System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using Microsoft.Phone.Info;
+using System.IO.IsolatedStorage;
+using System.Windows.Resources;
+using System.IO;
+using System.Diagnostics;
+
+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}\"",
+ this.name,
+ this.platform,
+ this.uuid,
+ this.version,
+ this.model,
+ this.manufacturer);
+
+ res = "{" + res + "}";
+ //Debug.WriteLine("Result::" + res);
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res));
+ }
+
+ public string model
+ {
+ get
+ {
+ return DeviceStatus.DeviceName;
+ //return String.Format("{0},{1},{2}", DeviceStatus.DeviceManufacturer, DeviceStatus.DeviceHardwareVersion, DeviceStatus.DeviceFirmwareVersion);
+ }
+ }
+
+ public string manufacturer
+ {
+ get
+ {
+ return DeviceStatus.DeviceManufacturer;
+ }
+ }
+
+ public string name
+ {
+ get
+ {
+ return DeviceStatus.DeviceName;
+
+ }
+ }
+
+ public string platform
+ {
+ get
+ {
+ return Environment.OSVersion.Platform.ToString();
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public string version
+ {
+ get
+ {
+ return Environment.OSVersion.Version.ToString();
+ }
+ }
+
+ }
+}