diff options
| author | 2024-03-11 14:04:18 -0700 | |
|---|---|---|
| committer | 2024-03-11 14:37:01 -0700 | |
| commit | c431def111f22952fe43aa04d48439c6432d50b6 (patch) | |
| tree | 1bb017ee2162ad4395d29625b05d7ac4b52464ca | |
| parent | 4faa2d19f61e4076d40cb21f4dec6d9013318c6c (diff) | |
Clear dns cache when restoring network access
Sometimes apps need to wait for network rules to be updated before some
of their lifecycle events can be dispatched. This happens specifically
before resuming activities today.
Because the process-level InetAddress library can cache dns failures,
we need to clear its cache so that the app can resume making valid dns
queries as soon as any of its activities resume.
Test: Manual
Bug: 237556596
Change-Id: Ia99a43731801078ec8d67cf17fbfee9c329b6e96
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 7 | ||||
| -rw-r--r-- | core/java/android/app/network-policy.aconfig | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 1d39186de183..8de0a8321696 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -4073,6 +4073,13 @@ public final class ActivityThread extends ClientTransactionHandler ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq); mNetworkBlockSeq = INVALID_PROC_STATE_SEQ; } catch (RemoteException ignored) {} + if (Flags.clearDnsCacheOnNetworkRulesUpdate()) { + // InetAddress will cache UnknownHostException failures. If the rules got + // updated and the app has network access now, we need to clear the negative + // cache to ensure valid dns queries can work immediately. + // TODO: b/329133769 - Clear only the negative cache once it is available. + InetAddress.clearDnsCache(); + } } } } diff --git a/core/java/android/app/network-policy.aconfig b/core/java/android/app/network-policy.aconfig new file mode 100644 index 000000000000..88f386f6025d --- /dev/null +++ b/core/java/android/app/network-policy.aconfig @@ -0,0 +1,11 @@ +package: "android.app" + +flag { + namespace: "backstage_power" + name: "clear_dns_cache_on_network_rules_update" + description: "Clears the DNS cache when the network rules update" + bug: "237556596" + metadata { + purpose: PURPOSE_BUGFIX + } +}
\ No newline at end of file |