Skip to content
Commit 9e095e0e authored by Bernardo Rufino's avatar Bernardo Rufino
Browse files

Toast on service notification trampolines

To achieve this we have to propagate the originating token from the
pending intent. Once we have it on ServiceRecord there is additional
logic to propagate this token to ProcessRecord, where it's taken into
consideration for triggering or not notification manager's callback that
shows the toast introduced in ag/12184026.

In ServiceRecord, we only want to pass a non-null token to ProcessRecord
if it's the only token that's enabling bg activity starts. Rememeber
that service notification trampolines are started services, so if there
is an exemption due to binding, we don't progate the token. If the
exemption is only due to starts we only propagate the non-null token
if it's the only token allowing starts and there is no other grant
without an originating token. This logic is on
getExclusiveOriginatingToken().

When we get an exemption for bg activity starts we post a delayed
callback (10s) to revoke the grant. When we get another exemption with
an outstanding callback, we used to remove it first than repost the
callback (renewing the grace period). Since now we need to keep track of
the originating tokens for each grace period (eg. if there are 2 stacked
exemptions we need to consider both tokens to pass it to ProcessRecord
according to logic in paragraph above). Because of this we don't remove
the callback anymore, instead we check on the callback the outstanding
possibly null tokens, if the callback is for the last token then we
execute the same logic as before (which means only the last callback
effectively does what it used to do before, keeping the old behavior),
but if it's not the last we simply update our originating token with
ProcessRecord. This way we correctly attribute the grant to the
originating token for each grace period.

Test: atest BackgroundActivityLaunchTest
Test: Post a service-trampoline notification, click on it and observe
      toast
Test: Start an app A service from foreground app B, then before 10s
      click on a service-trampoline notification for same service,
      observe no toast is shown, after the first 10s passed, try again
      and observe toast.
Bug: 167676448
Change-Id: Ibb32bb42200cca6eb77d52ad0022225a55393e00
parent faead856
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment