Fix flaky failures when re-registering AudioPolicy.
The failures were caused by mix address being out of sync with registered mix address because the mix ids were advanced during unregistration of the mix and access to the mix config config was not properly synchronized. This cl: * Moves resetting the mix ids (mConfig.reset call) to synchronized section. * Changes mix counter behavior so it's incremented only during registration (and not unregistration) and fixes the comment. * Makes mStatusListener, mIsFocusPolicy and mIsTestFocusPolicy final since they never change since construction. * Removes unnecessary synchronization when accessing mStatusListener callback. Bug: 247788804 Test: atest AudioHostTest --iterations 15 Change-Id: I1544329654cec5c13ec5e20a983d8d318ab3549d
This commit is contained in:
@@ -75,11 +75,13 @@ public class AudioPolicy {
|
||||
*/
|
||||
public static final int POLICY_STATUS_REGISTERED = 2;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private int mStatus;
|
||||
@GuardedBy("mLock")
|
||||
private String mRegistrationId;
|
||||
private AudioPolicyStatusListener mStatusListener;
|
||||
private boolean mIsFocusPolicy;
|
||||
private boolean mIsTestFocusPolicy;
|
||||
private final AudioPolicyStatusListener mStatusListener;
|
||||
private final boolean mIsFocusPolicy;
|
||||
private final boolean mIsTestFocusPolicy;
|
||||
|
||||
/**
|
||||
* The list of AudioTrack instances created to inject audio into the associated mixes
|
||||
@@ -115,6 +117,7 @@ public class AudioPolicy {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private AudioPolicyConfig mConfig;
|
||||
|
||||
private final MediaProjection mProjection;
|
||||
@@ -552,7 +555,6 @@ public class AudioPolicy {
|
||||
/** @hide */
|
||||
public void reset() {
|
||||
setRegistration(null);
|
||||
mConfig.reset();
|
||||
}
|
||||
|
||||
public void setRegistration(String regId) {
|
||||
@@ -563,6 +565,7 @@ public class AudioPolicy {
|
||||
mStatus = POLICY_STATUS_REGISTERED;
|
||||
} else {
|
||||
mStatus = POLICY_STATUS_UNREGISTERED;
|
||||
mConfig.reset();
|
||||
}
|
||||
}
|
||||
sendMsg(MSG_POLICY_STATUS_CHANGE);
|
||||
@@ -940,14 +943,9 @@ public class AudioPolicy {
|
||||
}
|
||||
|
||||
private void onPolicyStatusChange() {
|
||||
AudioPolicyStatusListener l;
|
||||
synchronized (mLock) {
|
||||
if (mStatusListener == null) {
|
||||
return;
|
||||
}
|
||||
l = mStatusListener;
|
||||
if (mStatusListener != null) {
|
||||
mStatusListener.onStatusChange();
|
||||
}
|
||||
l.onStatusChange();
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
@@ -42,9 +42,7 @@ public class AudioPolicyConfig implements Parcelable {
|
||||
|
||||
private String mRegistrationId = null;
|
||||
|
||||
/** counter for the mixes that are / have been in the list of AudioMix
|
||||
* e.g. register 4 mixes (counter is 3), remove 1 (counter is 3), add 1 (counter is 4)
|
||||
*/
|
||||
// Corresponds to id of next mix to be registered.
|
||||
private int mMixCounter = 0;
|
||||
|
||||
protected AudioPolicyConfig(AudioPolicyConfig conf) {
|
||||
@@ -286,7 +284,7 @@ public class AudioPolicyConfig implements Parcelable {
|
||||
if ((mix.getRouteFlags() & AudioMix.ROUTE_FLAG_LOOP_BACK) ==
|
||||
AudioMix.ROUTE_FLAG_LOOP_BACK) {
|
||||
mix.setRegistration(mRegistrationId + "mix" + mixTypeId(mix.getMixType()) + ":"
|
||||
+ mMixCounter);
|
||||
+ mMixCounter++);
|
||||
} else if ((mix.getRouteFlags() & AudioMix.ROUTE_FLAG_RENDER) ==
|
||||
AudioMix.ROUTE_FLAG_RENDER) {
|
||||
mix.setRegistration(mix.mDeviceAddress);
|
||||
@@ -294,7 +292,6 @@ public class AudioPolicyConfig implements Parcelable {
|
||||
} else {
|
||||
mix.setRegistration("");
|
||||
}
|
||||
mMixCounter++;
|
||||
}
|
||||
|
||||
@GuardedBy("mMixes")
|
||||
|
||||
Reference in New Issue
Block a user