Bug 674725 - Part AQ - Read the next message in the list (Android backend). r=cjones

This commit is contained in:
Mounir Lamouri 2011-12-22 23:16:59 +01:00
Родитель 9a5b88b84e
Коммит f3348601f1
12 изменённых файлов: 165 добавлений и 1 удалений

Просмотреть файл

@ -230,6 +230,13 @@ SmsRequestManager::NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId,
NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
}
void
SmsRequestManager::NotifyGotNextMessage(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
{
// TODO: implement
printf_stderr("\nHERE\n\n");
}
} // namespace sms
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -72,6 +72,7 @@ public:
void NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError);
void NotifyNoMessageInList(PRInt32 aRequestId);
void NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId, nsIDOMMozSmsMessage* aMessage);
void NotifyGotNextMessage(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
private:
static SmsRequestManager* sInstance;

Просмотреть файл

@ -103,7 +103,11 @@ NS_IMETHODIMP
SmsDatabaseService::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId,
PRUint64 aProcessId)
{
// TODO: implement
if (!AndroidBridge::Bridge()) {
return NS_OK;
}
AndroidBridge::Bridge()->GetNextMessageInList(aListId, aRequestId, aProcessId);
return NS_OK;
}

Просмотреть файл

@ -94,6 +94,8 @@ child:
NotifyRequestCreateMessageList(PRInt32 aListId, SmsMessageData aMessageData, PRInt32 aRequestId, PRUint64 aProcessId);
NotifyRequestGotNextMessage(SmsMessageData aMessageData, PRInt32 aRequestId, PRUint64 aProcessId);
parent:
sync HasSupport()
returns (bool aHasSupport);

Просмотреть файл

@ -206,6 +206,20 @@ SmsChild::RecvNotifyRequestCreateMessageList(const PRInt32& aListId,
return true;
}
bool
SmsChild::RecvNotifyRequestGotNextMessage(const SmsMessageData& aMessageData,
const PRInt32& aRequestId,
const PRUint64& aProcessId)
{
if (ContentChild::GetSingleton()->GetID() != aProcessId) {
return true;
}
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(aMessageData);
SmsRequestManager::GetInstance()->NotifyGotNextMessage(aRequestId, message);
return true;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -58,6 +58,7 @@ public:
NS_OVERRIDE virtual bool RecvNotifyRequestSmsDeleteFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestNoMessageInList(const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestCreateMessageList(const PRInt32& aListId, const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestGotNextMessage(const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
};
} // namespace sms

Просмотреть файл

@ -132,6 +132,7 @@ public class GeckoAppShell
public static native void notifySmsDeleteFailed(int aError, int aRequestId, long aProcessId);
public static native void notifyNoMessageInList(int aRequestId, long aProcessId);
public static native void notifyListCreated(int aListId, int aMessageId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
public static native void notifyGotNextMessage(int aMessageId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
// A looper thread, accessed by GeckoAppShell.getHandler
private static class LooperThread extends Thread {
@ -1722,6 +1723,10 @@ public class GeckoAppShell
GeckoSmsManager.createMessageList(aStartDate, aEndDate, aNumbers, aNumbersCount, aDeliveryState, aReverse, aRequestId, aProcessId);
}
public static void getNextMessageInList(int aListId, int aRequestId, long aProcessId) {
GeckoSmsManager.getNextMessageInList(aListId, aRequestId, aProcessId);
}
public static boolean isTablet() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Configuration config = GeckoApp.mAppContext.getResources().getConfiguration();

Просмотреть файл

@ -853,6 +853,65 @@ public class GeckoSmsManager
}
}
public static void getNextMessageInList(int aListId, int aRequestId, long aProcessId) {
class GetNextMessageInListRunnable implements Runnable {
private int mListId;
private int mRequestId;
private long mProcessId;
GetNextMessageInListRunnable(int aListId, int aRequestId, long aProcessId) {
mListId = aListId;
mRequestId = aRequestId;
mProcessId = aProcessId;
}
@Override
public void run() {
class UnexpectedDeliveryStateException extends Exception { };
try {
Cursor cursor = MessagesListManager.getInstance().get(mListId);
if (!cursor.moveToNext()) {
MessagesListManager.getInstance().remove(mListId);
GeckoAppShell.notifyNoMessageInList(mRequestId, mProcessId);
return;
}
int type = cursor.getInt(cursor.getColumnIndex("type"));
String sender = "";
String receiver = "";
if (type == kSmsTypeInbox) {
sender = cursor.getString(cursor.getColumnIndex("address"));
} else if (type == kSmsTypeSentbox) {
receiver = cursor.getString(cursor.getColumnIndex("address"));
} else {
throw new UnexpectedDeliveryStateException();
}
int listId = MessagesListManager.getInstance().add(cursor);
GeckoAppShell.notifyGotNextMessage(cursor.getInt(cursor.getColumnIndex("_id")),
receiver, sender,
cursor.getString(cursor.getColumnIndex("body")),
cursor.getLong(cursor.getColumnIndex("date")),
mRequestId, mProcessId);
} catch (UnexpectedDeliveryStateException e) {
Log.e("GeckoSmsManager", "Unexcepted delivery state type: " + e);
// TODO: send an error notification
} catch (Exception e) {
Log.e("GeckoSmsManager", "Error while trying to get the next message of a list: " + e);
// TODO: send an error notification
}
}
}
if (!SmsIOThread.getInstance().execute(new GetNextMessageInListRunnable(aListId, aRequestId, aProcessId))) {
Log.e("GeckoSmsManager", "Failed to add GetNextMessageInListRunnable to the SmsIOThread");
// TODO: send an error notification
}
}
public static void shutdown() {
SmsIOThread.getInstance().interrupt();
MessagesListManager.getInstance().clear();

Просмотреть файл

@ -298,6 +298,7 @@ SHELL_WRAPPER3(notifySmsDeleted, jboolean, jint, jlong);
SHELL_WRAPPER3(notifySmsDeleteFailed, jint, jint, jlong);
SHELL_WRAPPER2(notifyNoMessageInList, jint, jlong);
SHELL_WRAPPER8(notifyListCreated, jint, jint, jstring, jstring, jstring, jlong, jint, jlong);
SHELL_WRAPPER7(notifyGotNextMessage, jint, jstring, jstring, jstring, jlong, jint, jlong);
static void * xul_handle = NULL;
static time_t apk_mtime = 0;
@ -695,6 +696,7 @@ loadLibs(const char *apkName)
GETFUNC(notifySmsDeleteFailed);
GETFUNC(notifyNoMessageInList);
GETFUNC(notifyListCreated);
GETFUNC(notifyGotNextMessage);
#undef GETFUNC
sStartupTimeline = (uint64_t *)__wrap_dlsym(xul_handle, "_ZN7mozilla15StartupTimeline16sStartupTimelineE");
gettimeofday(&t1, 0);

Просмотреть файл

@ -173,6 +173,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
jGetMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getMessage", "(IIJ)V");
jDeleteMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "deleteMessage", "(IIJ)V");
jCreateMessageList = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "createMessageList", "(JJ[Ljava/lang/String;IIZIJ)V");
jGetNextMessageinList = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNextMessageInList", "(IIJ)V");
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
@ -1411,6 +1412,14 @@ AndroidBridge::CreateMessageList(const dom::sms::SmsFilterData& aFilter, bool aR
aProcessId);
}
void
AndroidBridge::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, PRUint64 aProcessId)
{
ALOG_BRIDGE("AndroidBridge::GetNextMessageInList");
JNI()->CallStaticVoidMethod(mGeckoAppShellClass, jGetNextMessageinList, aListId, aRequestId, aProcessId);
}
void *
AndroidBridge::LockBitmap(jobject bitmap)
{

Просмотреть файл

@ -346,6 +346,7 @@ public:
void GetMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
void DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
void CreateMessageList(const dom::sms::SmsFilterData& aFilter, bool aReverse, PRInt32 aRequestId, PRUint64 aProcessId);
void GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, PRUint64 aProcessId);
bool IsTablet();
@ -440,6 +441,7 @@ protected:
jmethodID jGetMessage;
jmethodID jDeleteMessage;
jmethodID jCreateMessageList;
jmethodID jGetNextMessageinList;
// stuff we need for CallEglCreateWindowSurface
jclass jEGLSurfaceImplClass;

Просмотреть файл

@ -101,6 +101,7 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsDeleteFailed(JNIEnv* jenv, jclass, jint, jint, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass, jint, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, jint, jint, jstring, jstring, jstring, jlong, jint, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGotNextMessage(JNIEnv* jenv, jclass, jint, jstring, jstring, jstring, jlong, jint, jlong);
#ifdef MOZ_JAVA_COMPOSITOR
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_bindWidgetTexture(JNIEnv* jenv, jclass);
@ -740,6 +741,63 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass,
NS_DispatchToMainThread(runnable);
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_notifyGotNextMessage(JNIEnv* jenv, jclass,
jint aMessageId,
jstring aReceiver,
jstring aSender,
jstring aBody,
jlong aTimestamp,
jint aRequestId,
jlong aProcessId)
{
class NotifyGotNextMessageRunnable : public nsRunnable {
public:
NotifyGotNextMessageRunnable(const SmsMessageData& aMessage,
PRInt32 aRequestId, PRUint64 aProcessId)
: mMessage(aMessage)
, mRequestId(aRequestId)
, mProcessId(aProcessId)
{}
NS_IMETHODIMP Run() {
if (mProcessId == 0) { // Parent process.
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessage);
SmsRequestManager::GetInstance()->NotifyGotNextMessage(mRequestId,
message);
} else { // Content process.
nsTArray<SmsParent*> spList;
SmsParent::GetAll(spList);
for (PRUint32 i=0; i<spList.Length(); ++i) {
unused << spList[i]->SendNotifyRequestGotNextMessage(mMessage,
mRequestId,
mProcessId);
}
}
return NS_OK;
}
private:
SmsMessageData mMessage;
PRInt32 mRequestId;
PRUint64 mProcessId;
};
nsJNIString receiver = nsJNIString(aReceiver, jenv);
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
: eDeliveryState_Sent;
SmsMessageData message(aMessageId, state, nsJNIString(aSender, jenv),
receiver, nsJNIString(aBody, jenv), aTimestamp);
nsCOMPtr<nsIRunnable> runnable =
new NotifyGotNextMessageRunnable(message, aRequestId, aProcessId);
NS_DispatchToMainThread(runnable);
}
#ifdef MOZ_JAVA_COMPOSITOR
NS_EXPORT void JNICALL