mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 674725 - Part O - Receiving SMS: Android backend. r=cjones
This commit is contained in:
parent
cdeea80ab9
commit
ff4a7f0cf3
@ -64,6 +64,7 @@ EXPORTS_mozilla/dom/sms = \
|
||||
SmsServiceFactory.h \
|
||||
Constants.h \
|
||||
Types.h \
|
||||
SmsMessage.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
<!-- WebSMS -->
|
||||
<uses-permission android:name="android.permission.SEND_SMS"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||
|
||||
<uses-feature android:name="android.hardware.location" android:required="false"/>
|
||||
<uses-feature android:name="android.hardware.location.gps" android:required="false"/>
|
||||
|
@ -88,6 +88,7 @@ abstract public class GeckoApp
|
||||
private IntentFilter mConnectivityFilter;
|
||||
private BroadcastReceiver mConnectivityReceiver;
|
||||
private BroadcastReceiver mBatteryReceiver;
|
||||
private BroadcastReceiver mSmsReceiver;
|
||||
|
||||
enum LaunchState {PreLaunch, Launching, WaitForDebugger,
|
||||
Launched, GeckoRunning, GeckoExiting};
|
||||
@ -413,6 +414,11 @@ abstract public class GeckoApp
|
||||
mBatteryReceiver = new GeckoBatteryManager();
|
||||
registerReceiver(mBatteryReceiver, batteryFilter);
|
||||
|
||||
IntentFilter smsFilter = new IntentFilter();
|
||||
smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
|
||||
mSmsReceiver = new GeckoSmsManager();
|
||||
registerReceiver(mSmsReceiver, smsFilter);
|
||||
|
||||
if (!checkAndSetLaunchState(LaunchState.PreLaunch,
|
||||
LaunchState.Launching))
|
||||
return;
|
||||
@ -565,6 +571,7 @@ abstract public class GeckoApp
|
||||
public void onDestroy()
|
||||
{
|
||||
Log.i(LOG_FILE_NAME, "destroy");
|
||||
|
||||
// Tell Gecko to shutting down; we'll end up calling System.exit()
|
||||
// in onXreExit.
|
||||
if (isFinishing())
|
||||
@ -572,6 +579,7 @@ abstract public class GeckoApp
|
||||
|
||||
super.onDestroy();
|
||||
|
||||
unregisterReceiver(mSmsReceiver);
|
||||
unregisterReceiver(mBatteryReceiver);
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,8 @@ public class GeckoAppShell
|
||||
|
||||
public static native void notifyBatteryChange(double aLevel, boolean aCharging, double aRemainingTime);
|
||||
|
||||
public static native void notifySmsReceived(String aSender, String aBody, long aTimestamp);
|
||||
|
||||
// A looper thread, accessed by GeckoAppShell.getHandler
|
||||
private static class LooperThread extends Thread {
|
||||
public SynchronousQueue<Handler> mHandlerQueue =
|
||||
|
@ -41,12 +41,47 @@ import java.util.ArrayList;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SmsMessage;
|
||||
|
||||
public class GeckoSmsManager
|
||||
extends BroadcastReceiver
|
||||
{
|
||||
final static int kMaxMessageSize = 160;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
|
||||
// TODO: Try to find the receiver number to be able to populate
|
||||
// SmsMessage.receiver.
|
||||
// TODO: Get the id and the date from the stock app saved message.
|
||||
// Using the stock app saved message require us to wait for it to
|
||||
// be saved which can lead to race conditions.
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
|
||||
if (bundle == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object[] pdus = (Object[]) bundle.get("pdus");
|
||||
|
||||
for (int i=0; i<pdus.length; ++i) {
|
||||
SmsMessage msg = SmsMessage.createFromPdu((byte[])pdus[i]);
|
||||
|
||||
GeckoAppShell.notifySmsReceived(msg.getDisplayOriginatingAddress(),
|
||||
msg.getDisplayMessageBody(),
|
||||
System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int getNumberOfMessagesForText(String aText) {
|
||||
return SmsManager.getDefault().divideMessage(aText).size();
|
||||
}
|
||||
|
@ -299,6 +299,7 @@ SHELL_WRAPPER1(cameraCallbackBridge, jbyteArray)
|
||||
SHELL_WRAPPER1(notifyUriVisited, jstring)
|
||||
SHELL_WRAPPER3(notifyBatteryChange, jdouble, jboolean, jdouble);
|
||||
SHELL_WRAPPER1_WITH_RETURN(canCreateFixupURI, bool, jstring);
|
||||
SHELL_WRAPPER3(notifySmsReceived, jstring, jstring, jlong);
|
||||
|
||||
static void * xul_handle = NULL;
|
||||
static time_t apk_mtime = 0;
|
||||
@ -704,6 +705,7 @@ loadLibs(const char *apkName)
|
||||
GETFUNC(notifyUriVisited);
|
||||
GETFUNC(notifyBatteryChange);
|
||||
GETFUNC(canCreateFixupURI);
|
||||
GETFUNC(notifySmsReceived);
|
||||
#undef GETFUNC
|
||||
sStartupTimeline = (uint64_t *)__wrap_dlsym(xul_handle, "_ZN7mozilla15StartupTimeline16sStartupTimelineE");
|
||||
gettimeofday(&t1, 0);
|
||||
|
@ -62,8 +62,13 @@
|
||||
#include "nsExceptionHandler.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/dom/sms/SmsMessage.h"
|
||||
#include "mozilla/dom/sms/Constants.h"
|
||||
#include "mozilla/dom/sms/Types.h"
|
||||
#include "mozilla/dom/sms/PSms.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom::sms;
|
||||
|
||||
/* Forward declare all the JNI methods as extern "C" */
|
||||
|
||||
@ -83,6 +88,7 @@ extern "C" {
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyUriVisited(JNIEnv *, jclass, jstring uri);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass, jdouble, jboolean, jdouble);
|
||||
NS_EXPORT bool JNICALL Java_org_mozilla_gecko_GeckoAppShell_canCreateFixupURI(JNIEnv* jenv, jclass, jstring text);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass, jstring, jstring, jlong);
|
||||
}
|
||||
|
||||
|
||||
@ -251,3 +257,37 @@ Java_org_mozilla_gecko_GeckoAppShell_canCreateFixupURI(JNIEnv* jenv, jclass, jst
|
||||
|
||||
return AndroidBridge::Bridge()->CanCreateFixupURI(uriString);
|
||||
}
|
||||
|
||||
NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass,
|
||||
jstring aSender,
|
||||
jstring aBody,
|
||||
jlong aTimestamp)
|
||||
{
|
||||
class NotifySmsReceivedRunnable : public nsRunnable {
|
||||
public:
|
||||
NotifySmsReceivedRunnable(const SmsMessageData& aMessageData)\
|
||||
: mMessageData(aMessageData)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP Run() {
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
||||
obs->NotifyObservers(message, kSmsReceivedObserverTopic, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
SmsMessageData mMessageData;
|
||||
};
|
||||
|
||||
SmsMessageData message(0, eDeliveryState_Received, nsJNIString(aSender, jenv), EmptyString(),
|
||||
nsJNIString(aBody, jenv), aTimestamp);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable = new NotifySmsReceivedRunnable(message);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user