Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0fa9120b authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

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
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c431def111f22952fe43aa04d48439c6432d50b6)
Merged-In: Ia99a43731801078ec8d67cf17fbfee9c329b6e96
Change-Id: Ia99a43731801078ec8d67cf17fbfee9c329b6e96
parent 557303d3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -4022,6 +4022,13 @@ public final class ActivityThread extends ClientTransactionHandler
                    ActivityManager.getService().waitForNetworkStateUpdate(mNetworkBlockSeq);
                    mNetworkBlockSeq = INVALID_PROC_STATE_SEQ;
                } catch (RemoteException ignored) {}
                if (android.app.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();
                }
            }
        }
    }
+11 −0
Original line number Diff line number Diff line
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