Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f5f3e689 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioService: enable reusing an AudioPolicy

Enable registering/unregistering an AudioPolicy, and then
registering it again later.
Doing so was failing before as when a policy was re-registered,
its mix count didn't restart at 0 on the client side, causing
the mix to have an invalid registration string not in sync with
the policy configuration on the server side.

Bug: 161491896
Test: atest AudioHostTest#testAudioPolicyReuse
Change-Id: I51fc41c46817791de4ce3a4f9d36c38d9466602e
parent 0903756c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3801,7 +3801,7 @@ public class AudioManager {
        final IAudioService service = getService();
        try {
            service.unregisterAudioPolicyAsync(policy.cb());
            policy.setRegistration(null);
            policy.reset();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -3823,7 +3823,7 @@ public class AudioManager {
        try {
            policy.invalidateCaptorsAndInjectors();
            service.unregisterAudioPolicy(policy.cb());
            policy.setRegistration(null);
            policy.reset();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+5 −0
Original line number Diff line number Diff line
@@ -487,6 +487,11 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
        }
    }

    /** @hide */
    public AudioAttributes getAudioAttributes() {
        return mAudioAttributes;
    }

    /**
     * Builder class for {@link AudioRecord} objects.
     * Use this class to configure and create an <code>AudioRecord</code> instance. By setting the
+11 −0
Original line number Diff line number Diff line
@@ -553,6 +553,12 @@ public class AudioPolicy {
        }
    }

    /** @hide */
    public void reset() {
        setRegistration(null);
        mConfig.reset();
    }

    public void setRegistration(String regId) {
        synchronized (mLock) {
            mRegistrationId = regId;
@@ -566,6 +572,11 @@ public class AudioPolicy {
        sendMsg(MSG_POLICY_STATUS_CHANGE);
    }

    /**@hide*/
    public String getRegistration() {
        return mRegistrationId;
    }

    private boolean policyReadyToUse() {
        synchronized (mLock) {
            if (mStatus != POLICY_STATUS_REGISTERED) {
+5 −1
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ public class AudioPolicyConfig implements Parcelable {

    public String toLogFriendlyString () {
        String textDump = new String("android.media.audiopolicy.AudioPolicyConfig:\n");
        textDump += mMixes.size() + " AudioMix: "+ mRegistrationId + "\n";
        textDump += mMixes.size() + " AudioMix, reg:" + mRegistrationId + "\n";
        for(AudioMix mix : mMixes) {
            // write mix route flags
            textDump += "* route flags=0x" + Integer.toHexString(mix.getRouteFlags()) + "\n";
@@ -220,6 +220,10 @@ public class AudioPolicyConfig implements Parcelable {
        return textDump;
    }

    protected void reset() {
        mMixCounter = 0;
    }

    protected void setRegistration(String regId) {
        final boolean currentRegNull = (mRegistrationId == null) || mRegistrationId.isEmpty();
        final boolean newRegNull = (regId == null) || regId.isEmpty();