2009-11-10 09:45:02 +08:00
|
|
|
package com.phonegap;
|
2009-04-02 07:56:43 +08:00
|
|
|
/* License (MIT)
|
|
|
|
* Copyright (c) 2008 Nitobi
|
|
|
|
* website: http://phonegap.com
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* Software), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2009-09-12 05:30:24 +08:00
|
|
|
|
2009-04-02 07:56:43 +08:00
|
|
|
import java.util.TimeZone;
|
2010-09-16 03:27:46 +08:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import com.phonegap.api.Plugin;
|
|
|
|
import com.phonegap.api.PluginResult;
|
2009-04-02 07:56:43 +08:00
|
|
|
import android.content.Context;
|
2009-12-16 02:38:38 +08:00
|
|
|
import android.provider.Settings;
|
2009-04-02 07:56:43 +08:00
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
2010-10-05 12:58:14 +08:00
|
|
|
public class Device extends Plugin {
|
2010-09-16 03:27:46 +08:00
|
|
|
|
|
|
|
public static String phonegapVersion = "pre-0.92 EDGE"; // PhoneGap version
|
|
|
|
public static String platform = "Android"; // Device OS
|
|
|
|
public static String uuid; // Device UUID
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 ctx The context of the main Activity.
|
|
|
|
*/
|
|
|
|
public void setContext(DroidGap ctx) {
|
2010-10-05 12:58:14 +08:00
|
|
|
super.setContext(ctx);
|
2010-09-16 03:27:46 +08:00
|
|
|
Device.uuid = getUuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the request and returns CommandResult.
|
|
|
|
*
|
|
|
|
* @param action The command to execute.
|
|
|
|
* @param args JSONArry of arguments for the command.
|
|
|
|
* @return A CommandResult object with a status and message.
|
|
|
|
*/
|
|
|
|
public PluginResult execute(String action, JSONArray args) {
|
|
|
|
PluginResult.Status status = PluginResult.Status.OK;
|
|
|
|
String result = "";
|
2009-04-02 07:56:43 +08:00
|
|
|
|
2010-09-16 03:27:46 +08:00
|
|
|
try {
|
|
|
|
if (action.equals("getDeviceInfo")) {
|
|
|
|
JSONObject r = new JSONObject();
|
|
|
|
r.put("uuid", Device.uuid);
|
|
|
|
r.put("version", this.getOSVersion());
|
|
|
|
r.put("platform", Device.platform);
|
|
|
|
r.put("name", this.getProductName());
|
|
|
|
r.put("phonegap", Device.phonegapVersion);
|
|
|
|
//JSONObject pg = new JSONObject();
|
|
|
|
//pg.put("version", Device.phonegapVersion);
|
|
|
|
//r.put("phonegap", pg);
|
|
|
|
return new PluginResult(status, r);
|
|
|
|
}
|
|
|
|
return new PluginResult(status, result);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Identifies if action to be executed returns a value and should be run synchronously.
|
|
|
|
*
|
|
|
|
* @param action The action to execute
|
|
|
|
* @return T=returns value
|
2009-04-02 07:56:43 +08:00
|
|
|
*/
|
2010-09-16 03:27:46 +08:00
|
|
|
public boolean isSynch(String action) {
|
|
|
|
if (action.equals("getDeviceInfo")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// LOCAL METHODS
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the OS name.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getPlatform() {
|
|
|
|
return Device.platform;
|
2009-04-02 07:56:43 +08:00
|
|
|
}
|
|
|
|
|
2010-09-16 03:27:46 +08:00
|
|
|
/**
|
|
|
|
* Get the device's Universally Unique Identifier (UUID).
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getUuid() {
|
|
|
|
String uuid = Settings.Secure.getString(this.ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
2009-04-02 07:56:43 +08:00
|
|
|
return uuid;
|
|
|
|
}
|
2010-04-23 16:49:47 +08:00
|
|
|
|
2010-09-16 03:27:46 +08:00
|
|
|
/**
|
|
|
|
* Get the PhoneGap version.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getPhonegapVersion() {
|
|
|
|
return Device.phonegapVersion;
|
|
|
|
}
|
|
|
|
|
2010-06-09 07:30:20 +08:00
|
|
|
public String getLine1Number(){
|
2010-09-16 03:27:46 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
2010-04-23 16:49:47 +08:00
|
|
|
return operator.getLine1Number();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:49:47 +08:00
|
|
|
public String getDeviceId(){
|
2010-09-16 03:27:46 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
2010-04-23 16:49:47 +08:00
|
|
|
return operator.getDeviceId();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
|
|
|
|
2010-04-23 16:49:47 +08:00
|
|
|
public String getSimSerialNumber(){
|
2010-09-16 03:27:46 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
2010-04-23 16:49:47 +08:00
|
|
|
return operator.getSimSerialNumber();
|
|
|
|
}
|
2010-06-09 07:30:20 +08:00
|
|
|
|
|
|
|
public String getSubscriberId(){
|
2010-09-16 03:27:46 +08:00
|
|
|
TelephonyManager operator = (TelephonyManager)this.ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
2010-04-23 16:49:47 +08:00
|
|
|
return operator.getSubscriberId();
|
2010-06-09 07:30:20 +08:00
|
|
|
}
|
2009-04-02 07:56:43 +08:00
|
|
|
|
|
|
|
public String getModel()
|
|
|
|
{
|
|
|
|
String model = android.os.Build.MODEL;
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
public String getProductName()
|
|
|
|
{
|
|
|
|
String productname = android.os.Build.PRODUCT;
|
|
|
|
return productname;
|
|
|
|
}
|
2010-09-16 03:27:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the OS version.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public String getOSVersion() {
|
2009-04-02 07:56:43 +08:00
|
|
|
String osversion = android.os.Build.VERSION.RELEASE;
|
|
|
|
return osversion;
|
|
|
|
}
|
2010-09-16 03:27:46 +08:00
|
|
|
|
2009-04-02 07:56:43 +08:00
|
|
|
public String getSDKVersion()
|
|
|
|
{
|
|
|
|
String sdkversion = android.os.Build.VERSION.SDK;
|
|
|
|
return sdkversion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getTimeZoneID() {
|
|
|
|
TimeZone tz = TimeZone.getDefault();
|
|
|
|
return(tz.getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|