Beispiel #1
0
/*static*/
void
SmsManager::NotifySmsReceived(int32_t aId,
                              jni::String::Param aSender,
                              jni::String::Param aBody,
                              int32_t aMessageClass,
                              int64_t aSentTimestamp,
                              int64_t aTimestamp)
{
    // TODO Need to correct the message `threadId` parameter value. Bug 859098
    SmsMessageData message;
    message.id() = aId;
    message.threadId() = 0;
    message.iccId() = EmptyString();
    message.delivery() = eDeliveryState_Received;
    message.deliveryStatus() = eDeliveryStatus_Success;
    message.sender() = aSender ? aSender->ToString() : EmptyString();
    message.receiver() = EmptyString();
    message.body() = aBody ? aBody->ToString() : EmptyString();
    message.messageClass() = static_cast<MessageClass>(aMessageClass);
    message.timestamp() = aTimestamp;
    message.sentTimestamp() = aSentTimestamp;
    message.deliveryTimestamp() = aTimestamp;
    message.read() = false;

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=] () {
        nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
        if (!obs) {
            return;
        }

        nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
        obs->NotifyObservers(domMessage, kSmsReceivedObserverTopic, nullptr);
    });
    NS_DispatchToMainThread(runnable);
}
Beispiel #2
0
/*static*/
void
SmsManager::NotifyThreadCursorResult(int64_t aId,
                                     jni::String::Param aLastMessageSubject,
                                     jni::String::Param aBody,
                                     int64_t aUnreadCount,
                                     jni::ObjectArray::Param aParticipants,
                                     int64_t aTimestamp,
                                     jni::String::Param aLastMessageType,
                                     int32_t aRequestId)
{
    ThreadData thread;
    thread.id() = aId;
    thread.lastMessageSubject() = aLastMessageSubject ?
                                    aLastMessageSubject->ToString() :
                                    EmptyString();
    thread.body() = aBody ? aBody->ToString() : EmptyString();
    thread.unreadCount() = aUnreadCount;
    thread.timestamp() = aTimestamp;
    thread.lastMessageType() = eMessageType_SMS;

    JNIEnv* const env = jni::GetEnvForThread();

    jobjectArray participants = aParticipants.Get();
    jsize length = env->GetArrayLength(participants);
    for (jsize i = 0; i < length; ++i) {
        jstring participant =
            static_cast<jstring>(env->GetObjectArrayElement(participants, i));
        if (participant) {
            thread.participants().AppendElement(nsJNIString(participant, env));
        }
    }

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
        nsCOMPtr<nsIMobileMessageCursorCallback> request =
            AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
        if (!request) {
            return;
        }

        nsCOMArray<nsIMobileMessageThread> arr;
        arr.AppendElement(new MobileMessageThreadInternal(thread));

        nsIMobileMessageThread** elements;
        int32_t size;
        size = arr.Forget(&elements);

        request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
                                    size);
    });
    NS_DispatchToMainThread(runnable);
}
Beispiel #3
0
/*static*/
void
SmsManager::NotifyMessageCursorResult(int32_t aMessageId,
                                      int32_t aDeliveryStatus,
                                      jni::String::Param aReceiver,
                                      jni::String::Param aSender,
                                      jni::String::Param aBody,
                                      int64_t aTimestamp,
                                      int64_t aThreadId,
                                      bool aRead,
                                      int32_t aRequestId)
{
    nsString receiver = aReceiver->ToString();
    DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
                                             : eDeliveryState_Sent;

    // TODO Need to add the message `messageClass` parameter value. Bug 804476
    SmsMessageData message;
    message.id() = aMessageId;
    message.threadId() = aThreadId;
    message.iccId() = EmptyString();
    message.delivery() = state;
    message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
    message.sender() = aSender ? aSender->ToString() : EmptyString();
    message.receiver() = receiver;
    message.body() = aBody ? aBody->ToString() : EmptyString();
    message.messageClass() = eMessageClass_Normal;
    message.timestamp() = aTimestamp;
    message.sentTimestamp() = aTimestamp;
    message.deliveryTimestamp() = aTimestamp;
    message.read() = aRead;

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
        nsCOMPtr<nsIMobileMessageCursorCallback> request =
            AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
        if (!request) {
            return;
        }

        nsCOMArray<nsISmsMessage> arr;
        arr.AppendElement(new SmsMessageInternal(message));

        nsISmsMessage** elements;
        int32_t size;
        size = arr.Forget(&elements);

        request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
                                    size);
    });
    NS_DispatchToMainThread(runnable);
}
Beispiel #4
0
/*static*/
void
SmsManager::NotifySmsSent(int32_t aId,
                          jni::String::Param aReceiver,
                          jni::String::Param aBody,
                          int64_t aTimestamp,
                          int32_t aRequestId)
{
    // TODO Need to add the message `messageClass` parameter value. Bug 804476
    // TODO Need to correct the message `threadId` parameter value. Bug 859098
    SmsMessageData message;
    message.id() = aId;
    message.threadId() = 0;
    message.iccId() = EmptyString();
    message.delivery() = eDeliveryState_Sent;
    message.deliveryStatus() = eDeliveryStatus_Pending;
    message.sender() = EmptyString();
    message.receiver() = aReceiver ? aReceiver->ToString() : EmptyString();
    message.body() = aBody ? aBody->ToString() : EmptyString();
    message.messageClass() = eMessageClass_Normal;
    message.timestamp() = aTimestamp;
    message.sentTimestamp() = aTimestamp;
    message.deliveryTimestamp() = aTimestamp;
    message.read() = true;

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
        /*
         * First, we are going to notify all SmsManager that a message has
         * been sent. Then, we will notify the SmsRequest object about it.
         */
        nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
        if (!obs) {
            return;
        }

        nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
        obs->NotifyObservers(domMessage, kSmsSentObserverTopic, nullptr);

        nsCOMPtr<nsIMobileMessageCallback> request =
            AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
        if (!request) {
            return;
        }

        request->NotifyMessageSent(domMessage);
    });
    NS_DispatchToMainThread(runnable);
}
Beispiel #5
0
/*static*/
void
SmsManager::NotifyGetSms(int32_t aId,
                         int32_t aDeliveryStatus,
                         jni::String::Param aReceiver,
                         jni::String::Param aSender,
                         jni::String::Param aBody,
                         int64_t aTimestamp,
                         bool aRead,
                         int32_t aRequestId)
{
    nsString receiver(aReceiver->ToString());
    DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
                                             : eDeliveryState_Sent;

    // TODO Need to add the message `messageClass` parameter value. Bug 804476
    // TODO Need to correct the message `threadId` parameter value. Bug 859098
    SmsMessageData message;
    message.id() = aId;
    message.threadId() = 0;
    message.iccId() = EmptyString();
    message.delivery() = state;
    message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
    message.sender() = aSender ? aSender->ToString() : EmptyString();
    message.receiver() = receiver;
    message.body() = aBody ? aBody->ToString() : EmptyString();
    message.messageClass() = eMessageClass_Normal;
    message.timestamp() = aTimestamp;
    message.sentTimestamp() = aTimestamp;
    message.deliveryTimestamp() = aTimestamp;
    message.read() = aRead;

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
        nsCOMPtr<nsIMobileMessageCallback> request =
            AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
        if (!request) {
            return;
        }

        nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
        request->NotifyMessageGot(domMessage);
    });
    NS_DispatchToMainThread(runnable);
}
void
MediaDrmJavaCallbacksSupport::OnRejectPromise(int aPromiseId, jni::String::Param aMessage)
{
  MOZ_ASSERT(NS_IsMainThread());
  nsCString reason = aMessage->ToCString();
  MDRMN_LOG("OnRejectPromise aMessage(%s) ", reason.get());
  // Current implementation assume all the reject from MediaDrm is due to invalid state.
  // Other cases should be handled before calling into MediaDrmProxy API.
  mDecryptorProxyCallback->RejectPromise(aPromiseId,
                                         NS_ERROR_DOM_INVALID_STATE_ERR,
                                         reason);
}
Beispiel #7
0
/*static*/
void
SmsManager::NotifySmsDelivery(int32_t aId,
                              int32_t aDeliveryStatus,
                              jni::String::Param aReceiver,
                              jni::String::Param aBody,
                              int64_t aTimestamp)
{
    // TODO Need to add the message `messageClass` parameter value. Bug 804476
    // TODO Need to correct the message `threadId` parameter value. Bug 859098
    SmsMessageData message;
    message.id() = aId;
    message.threadId() = 0;
    message.iccId() = EmptyString();
    message.delivery() = eDeliveryState_Sent;
    message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
    message.sender() = EmptyString();
    message.receiver() = aReceiver ? aReceiver->ToString() : EmptyString();
    message.body() = aBody ? aBody->ToString() : EmptyString();
    message.messageClass() = eMessageClass_Normal;
    message.timestamp() = aTimestamp;
    message.sentTimestamp() = aTimestamp;
    message.deliveryTimestamp() = aTimestamp;
    message.read() = true;

    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
        nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
        if (!obs) {
            return;
        }

        nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
        const char* topic = (message.deliveryStatus() == eDeliveryStatus_Success)
                            ? kSmsDeliverySuccessObserverTopic
                            : kSmsDeliveryErrorObserverTopic;
        obs->NotifyObservers(domMessage, topic, nullptr);
    });
    NS_DispatchToMainThread(runnable);
}
void
MediaDrmJavaCallbacksSupport::OnSessionError(jni::ByteArray::Param aSessionId,
                                             jni::String::Param aMessage)
{
  MOZ_ASSERT(NS_IsMainThread());
  nsCString sessionId(reinterpret_cast<char*>(aSessionId->GetElements().Elements()),
                      aSessionId->Length());
  nsCString errorMessage = aMessage->ToCString();
  MDRMN_LOG("SessionId(%s)", sessionId.get());
  // TODO: We cannot get system error code from media drm API.
  // Currently use -1 as an error code.
  mDecryptorProxyCallback->SessionError(sessionId,
                                        NS_ERROR_DOM_INVALID_STATE_ERR,
                                        -1,
                                        errorMessage);
}
Beispiel #9
0
    static void SpeculativeConnect(jni::String::Param uriStr)
    {
        if (!NS_IsMainThread()) {
            // We will be on the main thread if the call was queued on the Java
            // side during startup. Otherwise, the call was not queued, which
            // means Gecko is already sufficiently loaded, and we don't really
            // care about speculative connections at this point.
            return;
        }

        nsCOMPtr<nsIIOService> ioServ = do_GetIOService();
        nsCOMPtr<nsISpeculativeConnect> specConn = do_QueryInterface(ioServ);
        if (!specConn) {
            return;
        }

        nsCOMPtr<nsIURI> uri = ResolveURI(uriStr->ToCString());
        if (!uri) {
            return;
        }
        specConn->SpeculativeConnect(uri, nullptr);
    }