2010-10-19 04:31:16 +08:00
|
|
|
/*
|
|
|
|
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
|
|
|
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
2009-04-02 07:56:43 +08:00
|
|
|
*
|
2010-10-19 04:31:16 +08:00
|
|
|
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
|
|
|
* Copyright (c) 2010, IBM Corporation
|
2009-04-02 07:56:43 +08:00
|
|
|
*/
|
2010-10-19 04:31:16 +08:00
|
|
|
package com.phonegap;
|
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;
|
2010-11-06 02:10:51 +08:00
|
|
|
import com.phonegap.api.PhonegapActivity;
|
2010-09-16 03:27:46 +08:00
|
|
|
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
|
|
|
|
2011-02-03 09:45:20 +08:00
|
|
|
public static String phonegapVersion = "0.9.4"; // PhoneGap version
|
2010-09-16 03:27:46 +08:00
|
|
|
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.
|
|
|
|
*/
|
2010-11-06 02:10:51 +08:00
|
|
|
public void setContext(PhonegapActivity ctx) {
|
2010-10-05 12:58:14 +08:00
|
|
|
super.setContext(ctx);
|
2010-09-16 03:27:46 +08:00
|
|
|
Device.uuid = getUuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-06 09:35:51 +08:00
|
|
|
* Executes the request and returns PluginResult.
|
2010-09-16 03:27:46 +08:00
|
|
|
*
|
2010-10-06 09:35:51 +08:00
|
|
|
* @param action The action to execute.
|
|
|
|
* @param args JSONArry of arguments for the plugin.
|
|
|
|
* @param callbackId The callback id used when calling back into JavaScript.
|
|
|
|
* @return A PluginResult object with a status and message.
|
2010-09-16 03:27:46 +08:00
|
|
|
*/
|
2010-10-06 09:35:51 +08:00
|
|
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
2010-09-16 03:27:46 +08:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|