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

Commit cfe4c262 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

AudioService: implement de-registration (release) of recorders

Clients must unregister themselves when client-side AudioRecord
goes away. This allows removing the tracking record sooner than
the client app goes away.

"DEATH" event has been renamed to "RELEASE". Client death is handled
the same way as regular release.

Bug: 123312504
Test: start and stop audio recording, check "dumpsys audio"
Change-Id: I6a9578b29ab3c41bac2bf4c823224276efbe1beb
parent fbfb36f5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3774,7 +3774,7 @@ public class AudioManager {
    /** @hide */
    public static final int RECORD_CONFIG_EVENT_UPDATE = 2;
    /** @hide */
    public static final int RECORD_CONFIG_EVENT_DEATH = 3;
    public static final int RECORD_CONFIG_EVENT_RELEASE = 3;
    /**
     * keep in sync with frameworks/native/include/audiomanager/AudioManager.h
     */
+2 −0
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ interface IAudioService {

    oneway void recorderEvent(in int riid, in int event);

    oneway void releaseRecorder(in int riid);

    // Java-only methods below.

    oneway void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
+7 −0
Original line number Diff line number Diff line
@@ -7071,6 +7071,13 @@ public class AudioService extends IAudioService.Stub
        mRecordMonitor.recorderEvent(riid, event);
    }

    /**
     * Stop tracking the recorder
     */
    public void releaseRecorder(int riid) {
        mRecordMonitor.releaseRecorder(riid);
    }

    public void disableRingtoneSync(final int userId) {
        final int callingUserId = UserHandle.getCallingUserId();
        if (callingUserId != userId) {
+11 −8
Original line number Diff line number Diff line
@@ -176,8 +176,11 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
        dispatchCallbacks(updateSnapshot(configEvent, riid, null));
    }

    void unregisterRecorder(int riid) {
        dispatchCallbacks(updateSnapshot(AudioManager.RECORD_CONFIG_EVENT_DEATH, riid, null));
    /**
     * Stop tracking the recorder
     */
    public void releaseRecorder(int riid) {
        dispatchCallbacks(updateSnapshot(AudioManager.RECORD_CONFIG_EVENT_RELEASE, riid, null));
    }

    private void dispatchCallbacks(List<AudioRecordingConfiguration> configs) {
@@ -246,7 +249,7 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
                    if (state.isActiveConfiguration()) {
                        configChanged = true;
                        sEventLogger.log(new RecordingEvent(
                                        AudioManager.RECORD_CONFIG_EVENT_DEATH,
                                        AudioManager.RECORD_CONFIG_EVENT_RELEASE,
                                        state.getRiid(), state.getConfig()));
                    }
                    it.remove();
@@ -396,7 +399,7 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
            switch (event) {
                case AudioManager.RECORD_CONFIG_EVENT_START:
                    configChanged = state.setActive(true);
                    if (config != null) { // ??? Can remove ???
                    if (config != null) {
                        configChanged = state.setConfig(config) || configChanged;
                    }
                    break;
@@ -412,7 +415,7 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
                        mRecordStates.remove(stateIndex);
                    }
                    break;
                case AudioManager.RECORD_CONFIG_EVENT_DEATH:
                case AudioManager.RECORD_CONFIG_EVENT_RELEASE:
                    configChanged = state.isActiveConfiguration();
                    mRecordStates.remove(stateIndex);
                    break;
@@ -504,7 +507,7 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
        }

        public void binderDied() {
            sMonitor.unregisterRecorder(mRiid);
            sMonitor.releaseRecorder(mRiid);
        }

        boolean init() {
@@ -553,8 +556,8 @@ public final class RecordingActivityMonitor implements AudioSystem.AudioRecordin
                    return "update";
                case AudioManager.RECORD_CONFIG_EVENT_STOP:
                    return "stop";
                case AudioManager.RECORD_CONFIG_EVENT_DEATH:
                    return "death";
                case AudioManager.RECORD_CONFIG_EVENT_RELEASE:
                    return "release";
                default:
                    return "unknown (" + recEvent + ")";
            }