Merge "Don't call into audiomanager holding a zen lock." into nyc-dev

This commit is contained in:
Julia Reynolds
2016-04-21 15:04:05 +00:00
committed by Android (Google) Code Review

View File

@@ -643,18 +643,22 @@ public class ZenModeHelper {
dispatchOnPolicyChanged(); dispatchOnPolicyChanged();
} }
mConfig = config; mConfig = config;
final String val = Integer.toString(config.hashCode()); mHandler.postApplyConfig(config, reason, setRingerMode);
Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
if (!evaluateZenMode(reason, setRingerMode)) {
applyRestrictions(); // evaluateZenMode will also apply restrictions if changed
}
mConditions.evaluateConfig(config, true /*processSubscriptions*/);
return true; return true;
} finally { } finally {
Binder.restoreCallingIdentity(identity); Binder.restoreCallingIdentity(identity);
} }
} }
private void applyConfig(ZenModeConfig config, String reason, boolean setRingerMode) {
final String val = Integer.toString(config.hashCode());
Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
if (!evaluateZenMode(reason, setRingerMode)) {
applyRestrictions(); // evaluateZenMode will also apply restrictions if changed
}
mConditions.evaluateConfig(config, true /*processSubscriptions*/);
}
private int getZenModeSetting() { private int getZenModeSetting() {
return Global.getInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF); return Global.getInt(mContext.getContentResolver(), Global.ZEN_MODE, Global.ZEN_MODE_OFF);
} }
@@ -1071,14 +1075,23 @@ public class ZenModeHelper {
private static final int MSG_DISPATCH = 1; private static final int MSG_DISPATCH = 1;
private static final int MSG_METRICS = 2; private static final int MSG_METRICS = 2;
private static final int MSG_SET_CONFIG = 3; private static final int MSG_SET_CONFIG = 3;
private static final int MSG_APPLY_CONFIG = 4;
private final class ConfigMessageData { private final class ConfigMessageData {
public final ZenModeConfig config; public final ZenModeConfig config;
public final String reason; public final String reason;
public final boolean setRingerMode;
ConfigMessageData(ZenModeConfig config, String reason) { ConfigMessageData(ZenModeConfig config, String reason) {
this.config = config; this.config = config;
this.reason = reason; this.reason = reason;
this.setRingerMode = false;
}
ConfigMessageData(ZenModeConfig config, String reason, boolean setRingerMode) {
this.config = config;
this.reason = reason;
this.setRingerMode = setRingerMode;
} }
} }
@@ -1102,6 +1115,11 @@ public class ZenModeHelper {
sendMessage(obtainMessage(MSG_SET_CONFIG, new ConfigMessageData(config, reason))); sendMessage(obtainMessage(MSG_SET_CONFIG, new ConfigMessageData(config, reason)));
} }
private void postApplyConfig(ZenModeConfig config, String reason, boolean setRingerMode) {
sendMessage(obtainMessage(MSG_APPLY_CONFIG,
new ConfigMessageData(config, reason, setRingerMode)));
}
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
@@ -1112,11 +1130,15 @@ public class ZenModeHelper {
mMetrics.emit(); mMetrics.emit();
break; break;
case MSG_SET_CONFIG: case MSG_SET_CONFIG:
ConfigMessageData configData = (ConfigMessageData)msg.obj; ConfigMessageData configData = (ConfigMessageData) msg.obj;
synchronized (mConfig) { synchronized (mConfig) {
setConfigLocked(configData.config, configData.reason); setConfigLocked(configData.config, configData.reason);
} }
break; break;
case MSG_APPLY_CONFIG:
ConfigMessageData applyConfigData = (ConfigMessageData) msg.obj;
applyConfig(applyConfigData.config, applyConfigData.reason,
applyConfigData.setRingerMode);
} }
} }
} }