Closed Bug 906164 Opened 11 years ago Closed 10 years ago

mozHasPendingMessage() should queue messages even when app is running

Categories

(Core :: DOM: Device Interfaces, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla31
blocking-b2g 1.3T+
Tracking Status
b2g-v1.3T --- fixed

People

(Reporter: nsm, Assigned: hchang)

References

Details

(Whiteboard: [ft:ril][p=1])

Attachments

(4 files, 1 obsolete file)

mozHasPendingMessage() only checks for pending messages in the SystemMessageInternal queue. But when a SystemMessageManager is present for a page, but it has no handler set for a particular message, it seems sensible to queue up messages and say they are queued. For example:

function A() {
  mozSetMessageHandler('alarm', function() {
    B()
  });
  navigator.mozAlarms.add(new Date(), "honorTimezone", {});
}

function B() {
  // unset the handler
  mozSetMessageHandler('alarm', null);
  // wait for alarm to go off
  setTimeout(function() {
     console.log(mozHasPendingMessage('alarm'));
  }, 1000);
  navigator.mozAlarms.add(new Date(), "honorTimezone", {});
}

It should print true, but it won't.

The thing is SystemMessageManager will receive a message, find no handler and throw the message away, when the page might want to set a handler on the basis of message availability.

Gene: Do you think this is valid. How would this additional queuing affect the delivery guarantees and especially do we need any extra wakelock behaviour because of this?

Bug 802876 reported similar behaviour, and was closed as WORKSFORME based on (what seems to me) insufficient comments in the bug about exactly what was going wrong. I believe this is what that bug originally intended to state.
Flags: needinfo?(gene.lian)
Nice catch! Nikhil!

This is indeed a bug. If there exists any system message that has not yet been handled by the handler, we should queue it and the mozHasPendingMessage() must return true.

Regarding the CPU wake lock mechanism, I think it is still working well because the manager will return "SMM:HandleMessagesDone" in any way to release the CPU wake lock even if the handler is not set to handle the system message.

The real issue is "SMM:Message:Return:OK", we shouldn't return it to the central to cancel the queued message when the handler is not set. If so, I feel "SMM:Message:Return:OK" is working very similar to the meaning of "SMM:HandleMessagesDone" and we could even have a chance to combine them into one message.

To do so, maybe we can add a flag like "isHandlerSet": true/false in the JSON object of the combined message. The central can only cancel the queuing system message when "isHandlerSet" is true, but will release the CPU wake lock no matter "isHandlerSet" is true or false.
Flags: needinfo?(gene.lian)
OS: Linux → All
Hardware: x86_64 → All
This is a wrong API behaviour. In theory, we should fix it soon. It seems mozHasPendingMessage() has not yet been widely or correctly used in the apps by far.
I met this wrong API behavior in bug 975950 as well.
Assignee: nobody → echen
(In reply to Edgar Chen [:edgar][:echen] from comment #3)
> I met this wrong API behavior in bug 975950 as well.

We need to correct the API behavior for bug 975950 which is a DSDS bug. So mark as 1.4?.
blocking-b2g: --- → 1.4?
See Also: → 975950
Andrew,

Can this be moved to DSDS?
Flags: needinfo?(overholt)
Attached patch WIP, patch, v1 (obsolete) — Splinter Review
Just a quick patch to fix this issue, didn't combine the "SMM:Message:Return:OK" and "SMM:HandleMessagesDone" together.
Assignee: echen → hchang
Without applying the attached patch, this gaia-ui-test won't pass.
(In reply to Preeti Raghunath(:Preeti) from comment #6)
> Andrew,
> 
> Can this be moved to DSDS?

No, I don't think so.
Flags: needinfo?(overholt)
Attached patch Bug906164.patchSplinter Review
Comment on attachment 8384434 [details] [diff] [review]
Bug906164.patch

https://tbpl.mozilla.org/?tree=Try&rev=e5ba91cbc0c4

The idea is to ack the received system message right before handling it. If the DOM side SystemMessageManager is created but the handler is not set, the message will be kept in the queue in SystemMessageInternal until we "GetPendingMessage".

https://bugzilla.mozilla.org/attachment.cgi?id=8382916 is a gaia-ui-test test case. The test won't pass unless we apply this patch.
Attachment #8384434 - Flags: review?(gene.lian)
(In reply to Edgar Chen [:edgar][:echen] from comment #5)
> (In reply to Edgar Chen [:edgar][:echen] from comment #3)
> > I met this wrong API behavior in bug 975950 as well.
> 
> We need to correct the API behavior for bug 975950 which is a DSDS bug. So
> mark as 1.4?.

The bug cited here is not a blocker, which means this isn't going to block either.
blocking-b2g: 1.4? → ---
Comment on attachment 8384434 [details] [diff] [review]
Bug906164.patch

Review of attachment 8384434 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/messages/SystemMessageManager.js
@@ +213,5 @@
>      let dispatcher = this._dispatchers[msg.type];
>      if (dispatcher) {
> +      if (aMessage.name == "SystemMessageManager:Message") {
> +        // Send an acknowledgement to parent to clean up the pending message
> +        // after we dispatched the message to app, so a re-launched app won't

a/after we dispatched/before dispatching/
Attachment #8384434 - Flags: review?(gene.lian) → review+
try server result for rebased version: 
https://tbpl.mozilla.org/?tree=Try&rev=aa1abe7ba75e
Keywords: checkin-needed
Hi echen,

Should it be merged into v1.3t for bug935802?

Thanks!
Flags: needinfo?(echen)
https://hg.mozilla.org/mozilla-central/rev/f94df8c36ab3
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla31
(In reply to sam.hua from comment #17)
> Hi echen,
> 
> Should it be merged into v1.3t for bug935802?
> 
> Thanks!

Do we still meet the issue in v1.3t? (I mean Bug 935802)
If yes, please nominate Bug 935802 for 1.3t.
Let PM to triage it.
Thank you.
Flags: needinfo?(echen)
Depends on: 993470
Depends on: 993462
So this patch apparently broke the dialer entirely - no notifications of incoming calls & dialing a call is no longer working.

Henry & Gene - Can you guys confirm this & backout asap if that's the case? Trunk testing of the dialer is entirely blocked here right now due to this.
Flags: needinfo?(hchang)
Flags: needinfo?(gene.lian)
Depends on: 993464
Depends on: 993713
Depends on: 993732
(In reply to Jason Smith [:jsmith] from comment #21)
> So this patch apparently broke the dialer entirely - no notifications of
> incoming calls & dialing a call is no longer working.
> 
> Henry & Gene - Can you guys confirm this & backout asap if that's the case?
> Trunk testing of the dialer is entirely blocked here right now due to this.

I found the root cause and will attach the patch in bug 993732.
Flags: needinfo?(hchang)
Flags: needinfo?(gene.lian)
No longer depends on: 993462
No longer depends on: 993464
No longer depends on: 993470
No longer depends on: 993713
Whiteboard: [ft:ril][p=1]
Whiteboard: [ft:ril][p=1] → [ft:ri][p=1]
Whiteboard: [ft:ri][p=1] → [ft:ril][p=1]
See Also: → 995834
v1.3t also need it
blocking-b2g: --- → 1.3T?
Be careful the patch here is actually wrong. Needs bug 993732 as the follow-up.
If this one is marked as v1.3t, bug 993732 should be too.
(In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #25)
> If this one is marked as v1.3t, bug 993732 should be too.

Actually the wrong patch will perfectly suit 1.3T because the renaming was not applied to it:

http://hg.mozilla.org/releases/mozilla-b2g28_v1_3t/file/9ef12c19ddc9/dom/messages/SystemMessageManager.js#l209
(In reply to Henry Chang [:henry] from comment #26)
> (In reply to Gene Lian [:gene] (needinfo? encouraged) from comment #25)
> > If this one is marked as v1.3t, bug 993732 should be too.
> 
> Actually the wrong patch will perfectly suit 1.3T because the renaming was
> not applied to it:
> 
> http://hg.mozilla.org/releases/mozilla-b2g28_v1_3t/file/9ef12c19ddc9/dom/
> messages/SystemMessageManager.js#l209

But anyway, the patch may conflict to 1.3T so I will provide another patch for 1.3T.
Thanks.
(In reply to Henry Chang [:henry] from comment #26)
> Actually the wrong patch will perfectly suit 1.3T because the renaming was
> not applied to it:
> 
> http://hg.mozilla.org/releases/mozilla-b2g28_v1_3t/file/9ef12c19ddc9/dom/
> messages/SystemMessageManager.js#l209

Oh, yes. You're right. :)
Attachment #8382030 - Attachment is obsolete: true
Henry's working on bug 995834, lets track bug 995834
blocking-b2g: 1.3T? → ---
(In reply to Joe Cheng [:jcheng] from comment #30)
> Henry's working on bug 995834, lets track bug 995834
I think we should do a uplift to 1.3T for this bug, and the patch of this bug is not a solution of bug 995834.
Set it as 1.3T+ and add checkin-needed flag.
blocking-b2g: --- → 1.3T+
Keywords: checkin-needed
(In reply to Fabrice Desré [:fabrice] from comment #32)
>  https://hg.mozilla.org/releases/mozilla-b2g28_v1_3t/rev/32bb713e6d0d

Uh oh. We needed to uplift bug 993732 with this patch to ensure that we don't cause that large wave of smoketest regressions again.

Can you get bug 993732 uplifted with this?
Flags: needinfo?(fabrice)
(In reply to Jason Smith [:jsmith] from comment #33)
> (In reply to Fabrice Desré [:fabrice] from comment #32)
> >  https://hg.mozilla.org/releases/mozilla-b2g28_v1_3t/rev/32bb713e6d0d
> 
> Uh oh. We needed to uplift bug 993732 with this patch to ensure that we
> don't cause that large wave of smoketest regressions again.
> 
> Can you get bug 993732 uplifted with this?

No need. The patch that Fabrice uplifted has fixed that issue as well. ;)
Flags: needinfo?(fabrice)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: