From 4cb96ca45f3334f49ebe23359001b7a636a1973b Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 17 May 2016 13:55:29 -0700 Subject: [PATCH] Fix issue #28817455: [NYC] [BullHead] Fatal Exception in CNEService Deadlock between DeviceIdleController and NetworkPolicyManagerService because DeviceIdleController was calling out to ConnectivityService with its lock held. Change-Id: I21195c2dfd5f50d0264e5e32819f8fc1f35a23a9 --- .../android/server/DeviceIdleController.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/DeviceIdleController.java b/services/core/java/com/android/server/DeviceIdleController.java index b60f3e2f0bc3f..69960c7223d27 100644 --- a/services/core/java/com/android/server/DeviceIdleController.java +++ b/services/core/java/com/android/server/DeviceIdleController.java @@ -325,9 +325,7 @@ public class DeviceIdleController extends SystemService @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case ConnectivityManager.CONNECTIVITY_ACTION: { - synchronized (DeviceIdleController.this) { - updateConnectivityStateLocked(intent); - } + updateConnectivityState(intent); } break; case Intent.ACTION_BATTERY_CHANGED: { synchronized (DeviceIdleController.this) { @@ -1426,9 +1424,9 @@ public class DeviceIdleController extends SystemService mLocalPowerManager.setDeviceIdleWhitelist(mPowerSaveWhitelistAllAppIdArray); mLocalAlarmManager.setDeviceIdleUserWhitelist(mPowerSaveWhitelistUserAppIdArray); mDisplayManager.registerDisplayListener(mDisplayListener, null); - updateConnectivityStateLocked(null); updateDisplayLocked(); } + updateConnectivityState(null); } } @@ -1707,9 +1705,17 @@ public class DeviceIdleController extends SystemService } } - void updateConnectivityStateLocked(Intent connIntent) { - if (mConnectivityService != null) { - NetworkInfo ni = mConnectivityService.getActiveNetworkInfo(); + void updateConnectivityState(Intent connIntent) { + ConnectivityService cm; + synchronized (this) { + cm = mConnectivityService; + } + if (cm == null) { + return; + } + // Note: can't call out to ConnectivityService with our lock held. + NetworkInfo ni = cm.getActiveNetworkInfo(); + synchronized (this) { boolean conn; if (ni == null) { conn = false;