cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [1/8] cordova-plugin-device git commit: add isSimulator for iOS & Android device
Date Thu, 22 Oct 2015 22:31:07 GMT
Repository: cordova-plugin-device
Updated Branches:
  refs/heads/master 08bf01d66 -> 38b01b83f


add isSimulator for iOS & Android device


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/commit/50abd1a7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/tree/50abd1a7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/diff/50abd1a7

Branch: refs/heads/master
Commit: 50abd1a7c39ca628d7c63689aa9f93f04ca7ddaf
Parents: 960e600
Author: Andy Chen <chenyulong1@gmail.com>
Authored: Fri Apr 10 14:55:25 2015 +0800
Committer: Andy Chen <chenyulong1@gmail.com>
Committed: Thu Jul 9 10:30:12 2015 +0800

----------------------------------------------------------------------
 README.md               | 10 ++++++++++
 src/android/Device.java | 12 +++++++++---
 src/ios/CDVDevice.m     |  8 +++++++-
 www/device.js           |  4 +++-
 4 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/50abd1a7/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index e6b5f92..4ab4baf 100644
--- a/README.md
+++ b/README.md
@@ -218,3 +218,13 @@ Get the operating system version.
     // Tizen: returns "TIZEN_20120425_2"
     var deviceVersion = device.version;
 
+## device.isSimulator
+
+whether the device is running on a simulator.
+
+    var isSimulator = device.isSimulator;
+
+### Supported Platforms
+
+- Android 2.1+
+- iOS

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/50abd1a7/src/android/Device.java
----------------------------------------------------------------------
diff --git a/src/android/Device.java b/src/android/Device.java
index 5eded90..780c927 100644
--- a/src/android/Device.java
+++ b/src/android/Device.java
@@ -67,13 +67,14 @@ public class Device extends CordovaPlugin {
      * @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")) {
+        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("isSimulator", this.isSimulator());
             callbackContext.success(r);
         }
         else {
@@ -88,7 +89,7 @@ public class Device extends CordovaPlugin {
 
     /**
      * Get the OS name.
-     * 
+     *
      * @return
      */
     public String getPlatform() {
@@ -148,7 +149,7 @@ public class Device extends CordovaPlugin {
 
     /**
      * Function to check if the device is manufactured by Amazon
-     * 
+     *
      * @return
      */
     public boolean isAmazonDevice() {
@@ -158,4 +159,9 @@ public class Device extends CordovaPlugin {
         return false;
     }
 
+    public boolean isSimulator() {
+	return android.os.Build.FINGERPRINT.contains("generic") ||
+	    android.os.Build.PRODUCT.contains("sdk");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/50abd1a7/src/ios/CDVDevice.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m
index 5a3f470..9db8d11 100644
--- a/src/ios/CDVDevice.m
+++ b/src/ios/CDVDevice.m
@@ -19,6 +19,7 @@
 
 #include <sys/types.h>
 #include <sys/sysctl.h>
+#include "TargetConditionals.h"
 
 #import <Cordova/CDV.h>
 #import "CDVDevice.h"
@@ -86,7 +87,7 @@
     [devProps setObject:[device systemVersion] forKey:@"version"];
     [devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"];
     [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
-
+    [devProps setObject:@([self isSimulator]) forKey:@"isSimulator"];
     NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
     return devReturn;
 }
@@ -96,4 +97,9 @@
     return CDV_VERSION;
 }
 
+- (BOOL)isSimulator
+{
+    return TARGET_IPHONE_SIMULATOR;
+}
+
 @end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device/blob/50abd1a7/www/device.js
----------------------------------------------------------------------
diff --git a/www/device.js b/www/device.js
index b1d0d25..2300be9 100644
--- a/www/device.js
+++ b/www/device.js
@@ -41,7 +41,8 @@ function Device() {
     this.uuid = null;
     this.cordova = null;
     this.model = null;
-    this.manufacturer = null;
+  this.manufacturer = null;
+  this.isSimulator = null;
 
     var me = this;
 
@@ -56,6 +57,7 @@ function Device() {
             me.uuid = info.uuid;
             me.cordova = buildLabel;
             me.model = info.model;
+	    me.isSimulator = info.isSimulator || false;
             me.manufacturer = info.manufacturer || 'unknown';
             channel.onCordovaInfoReady.fire();
         },function(e) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message