diff options
author | Eric Laurent <elaurent@google.com> | 2015-09-30 17:44:28 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2015-10-05 10:43:52 -0700 |
commit | e0ced4da1990583d6438cb3e99a8e16b5d1e8cc6 (patch) | |
tree | 51f6ae0e28e0ac62a812a4f4d1a18a3e2fce0f7a /services | |
parent | 24806db8f6f523542510097ce0af4a32beeda83b (diff) | |
download | frameworks_base-e0ced4da1990583d6438cb3e99a8e16b5d1e8cc6.zip frameworks_base-e0ced4da1990583d6438cb3e99a8e16b5d1e8cc6.tar.gz frameworks_base-e0ced4da1990583d6438cb3e99a8e16b5d1e8cc6.tar.bz2 |
ZenModeHelper: fix cross deadlock with AudioService
Processing ZenModeHelper.setConfig() synchronously in
ZenModeConditions.onConditionChanged() can cause a cross deadlock between
ConditionProviders.mMutex and AudioService.mSettingsLock.
Add a method to set Zen mode config asynchronously.
Bug: 24528290.
Change-Id: I9c1701ca6bef084527821175d84002b612241995
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/notification/ZenModeConditions.java | 4 | ||||
-rw-r--r-- | services/core/java/com/android/server/notification/ZenModeHelper.java | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/notification/ZenModeConditions.java b/services/core/java/com/android/server/notification/ZenModeConditions.java index b89a654..c2e4349 100644 --- a/services/core/java/com/android/server/notification/ZenModeConditions.java +++ b/services/core/java/com/android/server/notification/ZenModeConditions.java @@ -104,7 +104,7 @@ public class ZenModeConditions implements ConditionProviders.Callback { public void onServiceAdded(ComponentName component) { if (DEBUG) Log.d(TAG, "onServiceAdded " + component); if (isAutomaticActive(component)) { - mHelper.setConfig(mHelper.getConfig(), "zmc.onServiceAdded"); + mHelper.setConfigAsync(mHelper.getConfig(), "zmc.onServiceAdded"); } } @@ -120,7 +120,7 @@ public class ZenModeConditions implements ConditionProviders.Callback { updated |= updateSnoozing(automaticRule); } if (updated) { - mHelper.setConfig(config, "conditionChanged"); + mHelper.setConfigAsync(config, "conditionChanged"); } } diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java index 57d7758..461c3a2 100644 --- a/services/core/java/com/android/server/notification/ZenModeHelper.java +++ b/services/core/java/com/android/server/notification/ZenModeHelper.java @@ -315,6 +315,10 @@ public class ZenModeHelper { return setConfig(config, reason, true /*setRingerMode*/); } + public void setConfigAsync(ZenModeConfig config, String reason) { + mHandler.postSetConfig(config, reason); + } + private boolean setConfig(ZenModeConfig config, String reason, boolean setRingerMode) { if (config == null || !config.isValid()) { Log.w(TAG, "Invalid config in setConfig; " + config); @@ -743,6 +747,17 @@ public class ZenModeHelper { private final class H extends Handler { private static final int MSG_DISPATCH = 1; private static final int MSG_METRICS = 2; + private static final int MSG_SET_CONFIG = 3; + + private final class ConfigMessageData { + public final ZenModeConfig config; + public final String reason; + + ConfigMessageData(ZenModeConfig config, String reason) { + this.config = config; + this.reason = reason; + } + } private static final long METRICS_PERIOD_MS = 6 * 60 * 60 * 1000; @@ -760,6 +775,10 @@ public class ZenModeHelper { sendEmptyMessageDelayed(MSG_METRICS, METRICS_PERIOD_MS); } + private void postSetConfig(ZenModeConfig config, String reason) { + sendMessage(obtainMessage(MSG_SET_CONFIG, new ConfigMessageData(config, reason))); + } + @Override public void handleMessage(Message msg) { switch (msg.what) { @@ -769,6 +788,10 @@ public class ZenModeHelper { case MSG_METRICS: mMetrics.emit(); break; + case MSG_SET_CONFIG: + ConfigMessageData configData = (ConfigMessageData)msg.obj; + setConfig(configData.config, configData.reason); + break; } } } |