Skip to content

Add SilentAuthReceiver for Doze network-block reproduction, Fixes AB#3612535#2516

Open
rpdome wants to merge 7 commits into
devfrom
rapong/doze-silent-auth-receiver
Open

Add SilentAuthReceiver for Doze network-block reproduction, Fixes AB#3612535#2516
rpdome wants to merge 7 commits into
devfrom
rapong/doze-silent-auth-receiver

Conversation

@rpdome
Copy link
Copy Markdown
Member

@rpdome rpdome commented May 20, 2026

AB#3612535

Summary

Add a BroadcastReceiver to MsalTestApp that triggers acquireTokenSilent from a background process context (PROCESS_STATE_RECEIVER). This enables reliable reproduction of the Doze network-block issue that affects background broker auth triggered by FCM notifications.

Root Cause (from investigation)

When a foreground app binds to Broker via IPC, Android's NetworkPolicyManagerService adds a \dozable-allow\ firewall rule for the Broker's UID — masking the Doze network block during UI testing.

When the caller is in a background context (BroadcastReceiver/Service handling FCM), the IPC binding does NOT elevate the Broker enough for \dozable-allow. The Broker's network call to eSTS fails with \UnknownHostException.

Evidence

  • Confirmed via \dumpsys netpolicy\ firewall rule logs (UID 11697 dozable-allow toggling)
  • Confirmed via AOSP \DeviceIdleController.java\ and \NetworkPolicyManagerService\ source
  • Successfully reproduced: \io_error: Unable to resolve host login.microsoftonline.com\

Files

  • SilentAuthReceiver.java — BroadcastReceiver that calls acquireTokenSilent with forceRefresh + powerOptCheckEnabled=false
  • AndroidManifest.xml — Receiver registration with exported=true

Usage

\\�ash

Prerequisites: broker + MsalTestApp installed, account signed in

adb shell dumpsys battery unplug
adb shell dumpsys deviceidle force-idle
adb shell am broadcast -a com.microsoft.identity.client.testapp.SILENT_AUTH -n com.msft.identity.client.sample.local/com.microsoft.identity.client.testapp.SilentAuthReceiver
adb logcat -s SilentAuthReceiver:*

Cleanup:

adb shell dumpsys deviceidle unforce && adb shell dumpsys battery reset
\\

Test script

A companion script \scripts/doze-repro-test.sh\ in android-complete automates the full sequence.

Add a BroadcastReceiver to MsalTestApp that triggers acquireTokenSilent
from a background process context (PROCESS_STATE_RECEIVER). This enables
reliable reproduction of the Doze network-block issue that affects
background broker auth triggered by FCM notifications.

Key findings from investigation:
- When a foreground app binds to Broker via IPC, Android's
  NetworkPolicyManagerService adds a dozable-allow firewall rule for the
  Broker's UID. This masks the Doze network block during UI testing.
- When the caller is in a background context (BroadcastReceiver/Service),
  the IPC binding does NOT elevate the Broker enough for dozable-allow.
  The Broker's network call fails with UnknownHostException.
- This matches the production scenario: Outlook receives FCM push in
  background -> calls OneAuth -> OneAuth calls Broker -> Broker's network
  to eSTS is blocked by Doze firewall.

Usage:
  adb shell dumpsys battery unplug
  adb shell dumpsys deviceidle force-idle
  adb shell am broadcast \
    -a com.microsoft.identity.client.testapp.SILENT_AUTH \
    -n com.msft.identity.client.sample.local/com.microsoft.identity.client.testapp.SilentAuthReceiver
  adb logcat -s SilentAuthReceiver:*
@rpdome rpdome requested a review from a team as a code owner May 20, 2026 20:44
Copilot AI review requested due to automatic review settings May 20, 2026 20:44
@github-actions
Copy link
Copy Markdown

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new testing hook in MsalTestApp to reproduce the Doze network-block scenario by triggering acquireTokenSilent from a BroadcastReceiver (background/receiver process state), along with manifest registration to invoke it via adb.

Changes:

  • Introduces SilentAuthReceiver to create a PCA instance and run acquireTokenSilentAsync(forceRefresh=true) from a receiver context.
  • Registers the receiver in AndroidManifest.xml with an intent-filter action for adb triggering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
testapps/testapp/src/main/java/com/microsoft/identity/client/testapp/SilentAuthReceiver.java Adds a BroadcastReceiver to run silent token acquisition from a background receiver context for Doze repro.
testapps/testapp/src/main/AndroidManifest.xml Registers the new receiver/action used to trigger the Doze repro flow.

Comment thread testapps/testapp/src/main/AndroidManifest.xml
@rpdome rpdome added the No-Changelog This change does not update the changelog. label May 20, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@rpdome rpdome force-pushed the rapong/doze-silent-auth-receiver branch 3 times, most recently from 8cf2f3c to bca228f Compare May 20, 2026 21:03
@github-actions
Copy link
Copy Markdown

❌ Invalid work item number: AB#3612535

##. Work item number must be a valid integer.

Click here to learn more.

@github-actions
Copy link
Copy Markdown

✅ Work item link check complete. Description contains link AB#3612535 to an Azure Boards work item.

@github-actions github-actions Bot changed the title Add SilentAuthReceiver for Doze network-block reproduction Add SilentAuthReceiver for Doze network-block reproduction, Fixes AB#3612535 May 20, 2026
@rpdome rpdome force-pushed the rapong/doze-silent-auth-receiver branch 2 times, most recently from 9a67d3b to a6d2373 Compare May 20, 2026 22:18
@Prvnkmr337
Copy link
Copy Markdown

Overall LGTM, just minor comments.

Copy link
Copy Markdown

@Prvnkmr337 Prvnkmr337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with minor comments. Kindly address the comments before merging :)

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -XX:&#43;HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant (dns block)
  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/working/files-to-index17473777082895257656.list --sourceArchiveDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/src --outputDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/trap/java (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/working/files-to-index16743005309963048569.list --sourceArchiveDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/src --outputDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of rpdome May 20, 2026 23:11
Copilot finished work on behalf of rpdome May 20, 2026 23:14
Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -XX:&#43;HeapDumpOnOutOfMemoryError -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant (dns block)
  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/working/files-to-index11018229262861532142.list --sourceArchiveDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/src --outputDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/trap/java (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.4/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/working/files-to-index8606033338045743479.list --sourceArchiveDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/src --outputDir=/tmp/codeql-scratch-38ad52fff39af1e6/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of rpdome May 20, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No-Changelog This change does not update the changelog. testapps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants