From e26f544368ed26c5f425e8bef07fffa3998d470f Mon Sep 17 00:00:00 2001 From: Gabriel Dumitrescu Date: Mon, 8 Sep 2014 23:57:26 +0000 Subject: [PATCH] Added basic Android support for hardware serial number --- README.md | 10 ++++++++++ src/android/Device.java | 11 +++++++++-- tests/tests.js | 6 ++++++ www/device.js | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6b5f922..b439f123 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Although the object is in the global scope, it is not available until after the - device.platform - device.uuid - device.version +- device.serial ## device.cordova @@ -218,3 +219,12 @@ Get the operating system version. // Tizen: returns "TIZEN_20120425_2" var deviceVersion = device.version; +## device.serial + +Get the device hardware serial number ([SERIAL](http://developer.android.com/reference/android/os/Build.html#SERIAL)). + + var string = device.serial; + +### Supported Platforms + +- Android diff --git a/src/android/Device.java b/src/android/Device.java index 5eded907..305ed66f 100644 --- a/src/android/Device.java +++ b/src/android/Device.java @@ -74,6 +74,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo r.put("platform", this.getPlatform()); r.put("model", this.getModel()); r.put("manufacturer", this.getManufacturer()); + r.put("serial", this.getSerialNumber()); callbackContext.success(r); } else { @@ -88,7 +89,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo /** * Get the OS name. - * + * * @return */ public String getPlatform() { @@ -125,6 +126,12 @@ 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. * @@ -148,7 +155,7 @@ public String getTimeZoneID() { /** * Function to check if the device is manufactured by Amazon - * + * * @return */ public boolean isAmazonDevice() { diff --git a/tests/tests.js b/tests/tests.js index 1f49d7e1..a9544a9d 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -67,6 +67,12 @@ exports.defineAutoTests = function() { expect(window.device.manufacturer).toBeDefined(); expect((new String(window.device.manufacturer)).length > 0).toBe(true); }); + + it("should contain a serial number specification that is a string", function() { + expect(window.device.serial).toBeDefined(); + expect((new String(window.device.serial)).length > 0).toBe(true); + }); + }); }; diff --git a/www/device.js b/www/device.js index b1d0d25d..55af80cb 100644 --- a/www/device.js +++ b/www/device.js @@ -42,6 +42,7 @@ function Device() { this.cordova = null; this.model = null; this.manufacturer = null; + this.serial = null; var me = this; @@ -57,6 +58,7 @@ function Device() { me.cordova = buildLabel; me.model = info.model; me.manufacturer = info.manufacturer || 'unknown'; + me.serial = info.serial || 'unknown'; channel.onCordovaInfoReady.fire(); },function(e) { me.available = false;