Don't call into phone process with lock held.
Bug: 77456094
Fixes: 77456094
Test: Manual test:
- Insert SIM card to device
- Set break point to setNetworkTemplateEnabledInner
- Change connectivity and make sure setNetworkTemplateEnabledInner()
is called with right arguments.
Change-Id: I6ff3c5639b48cb95419b431a85c498e214ee8e0d
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index 29d2e55..224d085 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -362,6 +362,7 @@
private static final int MSG_RESET_FIREWALL_RULES_BY_UID = 15;
private static final int MSG_SUBSCRIPTION_OVERRIDE = 16;
private static final int MSG_METERED_RESTRICTED_PACKAGES_CHANGED = 17;
+ private static final int MSG_SET_NETWORK_TEMPLATE_ENABLED = 18;
private static final int UID_MSG_STATE_CHANGED = 100;
private static final int UID_MSG_GONE = 101;
@@ -1566,6 +1567,13 @@
* {@link NetworkTemplate}.
*/
private void setNetworkTemplateEnabled(NetworkTemplate template, boolean enabled) {
+ // Don't call setNetworkTemplateEnabledInner() directly because we may have a lock
+ // held. Call it via the handler.
+ mHandler.obtainMessage(MSG_SET_NETWORK_TEMPLATE_ENABLED, enabled ? 1 : 0, 0, template)
+ .sendToTarget();
+ }
+
+ private void setNetworkTemplateEnabledInner(NetworkTemplate template, boolean enabled) {
// TODO: reach into ConnectivityManager to proactively disable bringing
// up this network, since we know that traffic will be blocked.
@@ -4182,6 +4190,12 @@
setMeteredRestrictedPackagesInternal(packageNames, userId);
return true;
}
+ case MSG_SET_NETWORK_TEMPLATE_ENABLED: {
+ final NetworkTemplate template = (NetworkTemplate) msg.obj;
+ final boolean enabled = msg.arg1 != 0;
+ setNetworkTemplateEnabledInner(template, enabled);
+ return true;
+ }
default: {
return false;
}