Bug 674725 - Part J - Basic implementation of mozSms.send(). r=cjones

This commit is contained in:
Mounir Lamouri
2011-11-21 00:00:46 +01:00
parent d47859f828
commit 3e23760238
14 changed files with 106 additions and 4 deletions

View File

@@ -36,8 +36,9 @@
#include "nsISupports.idl"
[scriptable, function, uuid(acff4eca-ae08-4c4a-bc6d-34a960134314)]
[scriptable, function, uuid(473547ee-7a26-46d3-8476-f012985cd0c8)]
interface nsIDOMMozSmsManager : nsISupports
{
unsigned short getNumberOfMessagesForText(in DOMString text);
void send(in DOMString number, in DOMString message);
};

View File

@@ -41,9 +41,10 @@
#define SMSSERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1"
%}
[scriptable, function, uuid(abc95960-c689-4985-a226-7c96d27e2cd8)]
[scriptable, function, uuid(24edea1d-130a-4ae3-9522-0e2a7ee2885d)]
interface nsISmsService : nsISupports
{
boolean hasSupport();
boolean hasSupport();
unsigned short getNumberOfMessagesForText(in DOMString text);
void send(in DOMString number, in DOMString message);
};

View File

@@ -65,6 +65,17 @@ SmsManager::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
return NS_OK;
}
NS_IMETHODIMP
SmsManager::Send(const nsAString& aNumber, const nsAString& aMessage)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMSSERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_OK);
smsService->Send(aNumber, aMessage);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@@ -63,6 +63,17 @@ SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
return NS_OK;
}
NS_IMETHODIMP
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage)
{
if (!AndroidBridge::Bridge()) {
return NS_OK;
}
AndroidBridge::Bridge()->SendMessage(aNumber, aMessage);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@@ -58,6 +58,13 @@ SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
return NS_OK;
}
NS_IMETHODIMP
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage)
{
NS_ERROR("We should not be here!");
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@@ -53,6 +53,8 @@ parent:
sync GetNumberOfMessagesForText(nsString aText)
returns (PRUint16 aNumber);
SendMessage(nsString aNumber, nsString aMessage);
__delete__();
};

View File

@@ -74,6 +74,14 @@ SmsIPCService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aRes
return NS_OK;
}
NS_IMETHODIMP
SmsIPCService::Send(const nsAString& aNumber, const nsAString& aMessage)
{
GetSmsChild()->SendSendMessage(nsString(aNumber), nsString(aMessage));
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@@ -66,6 +66,16 @@ SmsParent::RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResu
return true;
}
bool
SmsParent::RecvSendMessage(const nsString& aNumber, const nsString& aMessage)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMSSERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, true);
smsService->Send(aNumber, aMessage);
return true;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@@ -48,6 +48,7 @@ class SmsParent : public PSmsParent
{
NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport);
NS_OVERRIDE virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult);
NS_OVERRIDE virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage);
};
} // namespace sms

View File

@@ -21,6 +21,9 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<!-- WebSMS -->
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-feature android:name="android.hardware.location" android:required="false"/>
<uses-feature android:name="android.hardware.location.gps" android:required="false"/>
<uses-feature android:name="android.hardware.touchscreen"/>

View File

@@ -1636,7 +1636,9 @@ public class GeckoAppShell
// unused
static void markUriVisited(final String uri) {}
/*
* Battery API related methods.
*/
public static void enableBatteryNotifications() {
GeckoBatteryManager.enableNotifications();
}
@@ -1649,7 +1651,14 @@ public class GeckoAppShell
return GeckoBatteryManager.getCurrentInformation();
}
/*
* WebSMS related methods.
*/
public static int getNumberOfMessagesForText(String aText) {
return GeckoSmsManager.getNumberOfMessagesForText(aText);
}
public static void sendMessage(String aNumber, String aMessage) {
GeckoSmsManager.send(aNumber, aMessage);
}
}

View File

@@ -45,7 +45,29 @@ import android.telephony.SmsManager;
public class GeckoSmsManager
{
final static int kMaxMessageSize = 160;
public static int getNumberOfMessagesForText(String aText) {
return SmsManager.getDefault().divideMessage(aText).size();
}
public static void send(String aNumber, String aMessage) {
/*
* TODO:
* This is a basic send method that doesn't handle errors, doesn't listen to
* sent and received messages. It's only calling the send method.
*/
try {
SmsManager sm = SmsManager.getDefault();
if (aMessage.length() <= kMaxMessageSize) {
sm.sendTextMessage(aNumber, "", aMessage, null, null);
} else {
ArrayList<String> parts = sm.divideMessage(aMessage);
sm.sendMultipartTextMessage(aNumber, "", parts, null, null);
}
} catch (Exception e) {
Log.i("GeckoSmsManager", "Failed to send an SMS: ", e);
}
}
}

View File

@@ -170,6 +170,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jMarkUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "markUriVisited", "(Ljava/lang/String;)V");
jNumberOfMessages = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNumberOfMessagesForText", "(Ljava/lang/String;)I");
jSendMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "sendMessage", "(Ljava/lang/String;Ljava/lang/String;)V");
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
@@ -1369,6 +1370,18 @@ AndroidBridge::GetNumberOfMessagesForText(const nsAString& aText)
return GetJNIForThread()->CallStaticIntMethod(mGeckoAppShellClass, jNumberOfMessages, jText);
}
void
AndroidBridge::SendMessage(const nsAString& aNumber, const nsAString& aMessage)
{
ALOG_BRIDGE("AndroidBridge::SendMessage");
AutoLocalJNIFrame jniFrame;
jstring jNumber = GetJNIForThread()->NewString(PromiseFlatString(aNumber).get(), aNumber.Length());
jstring jMessage = GetJNIForThread()->NewString(PromiseFlatString(aMessage).get(), aMessage.Length());
GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSendMessage, jNumber, jMessage);
}
void *
AndroidBridge::LockBitmap(jobject bitmap)
{

View File

@@ -319,6 +319,7 @@ public:
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
PRUint16 GetNumberOfMessagesForText(const nsAString& aText);
void SendMessage(const nsAString& aNumber, const nsAString& aText);
protected:
static AndroidBridge *sBridge;
@@ -403,7 +404,9 @@ protected:
jmethodID jCheckUriVisited;
jmethodID jMarkUriVisited;
jmethodID jEmitGeckoAccessibilityEvent;
jmethodID jNumberOfMessages;
jmethodID jSendMessage;
// stuff we need for CallEglCreateWindowSurface
jclass jEGLSurfaceImplClass;