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

Commit 042d6f10 authored by Eric Laurent's avatar Eric Laurent Committed by android-build-merger
Browse files

Merge "AudioService: communicate audio HAL process pids to native audioserver" am: e16beef1

am: 917934e7

Change-Id: I2ccce2d261e42e3c33d974d30b71bcebd0493f1b
parents 4f475553 917934e7
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -2250,6 +2250,20 @@ android_media_AudioSystem_setRttEnabled(JNIEnv *env, jobject thiz, jboolean enab
    return (jint) check_AudioSystem_Command(AudioSystem::setRttEnabled(enabled));
}

static jint
android_media_AudioSystem_setAudioHalPids(JNIEnv *env, jobject clazz, jintArray jPids)
{
    if (jPids == NULL) {
        return (jint)AUDIO_JAVA_BAD_VALUE;
    }
    pid_t *nPidsArray = (pid_t *)env->GetIntArrayElements(jPids, NULL);
    std::vector<pid_t> nPids(nPidsArray, nPidsArray + env->GetArrayLength(jPids));
    status_t status = AudioSystem::setAudioHalPids(nPids);
    env->ReleaseIntArrayElements(jPids, nPidsArray, 0);
    jint jStatus = nativeToJavaStatus(status);
    return jStatus;
}

// ----------------------------------------------------------------------------

static const JNINativeMethod gMethods[] = {
@@ -2328,6 +2342,7 @@ static const JNINativeMethod gMethods[] = {
                    (void*)android_media_AudioSystem_getHwOffloadEncodingFormatsSupportedForA2DP},
    {"setAllowedCapturePolicy", "(II)I", (void *)android_media_AudioSystem_setAllowedCapturePolicy},
    {"setRttEnabled",       "(Z)I",     (void *)android_media_AudioSystem_setRttEnabled},
    {"setAudioHalPids",  "([I)I", (void *)android_media_AudioSystem_setAudioHalPids},
};

static const JNINativeMethod gEventHandlerMethods[] = {
+6 −0
Original line number Diff line number Diff line
@@ -1124,6 +1124,12 @@ public class AudioSystem
     */
    public static native boolean isHapticPlaybackSupported();

    /**
     * Send audio HAL server process pids to native audioserver process for use
     * when generating audio HAL servers tombstones
     */
    public static native int setAudioHalPids(int[] pids);

    // Items shared with audio service

    /**
+42 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.hardware.hdmi.HdmiPlaybackClient;
import android.hardware.hdmi.HdmiTvClient;
import android.hardware.input.InputManager;
import android.hardware.usb.UsbManager;
import android.hidl.manager.V1_0.IServiceManager;
import android.media.AudioAttributes;
import android.media.AudioFocusInfo;
import android.media.AudioFocusRequest;
@@ -148,10 +149,12 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

@@ -721,6 +724,8 @@ public class AudioService extends IAudioService.Stub

        AudioSystem.setErrorCallback(mAudioSystemCallback);

        updateAudioHalPids();

        boolean cameraSoundForced = readCameraSoundForced();
        mCameraSoundForced = new Boolean(cameraSoundForced);
        sendMsg(mAudioHandler,
@@ -949,6 +954,8 @@ public class AudioService extends IAudioService.Stub
        }
        Log.e(TAG, "Audioserver started.");

        updateAudioHalPids();

        // indicate to audio HAL that we start the reconfiguration phase after a media
        // server crash
        // Note that we only execute this when the media server
@@ -7290,6 +7297,41 @@ public class AudioService extends IAudioService.Stub
        return (AudioSystem.checkAudioFlinger() == AudioSystem.AUDIO_STATUS_OK);
    }

    //======================
    // Audio HAL process dump
    //======================

    private static final String AUDIO_HAL_SERVICE_PREFIX = "android.hardware.audio";

    private Set<Integer> getAudioHalPids() {
        try {
            IServiceManager serviceManager = IServiceManager.getService();
            ArrayList<IServiceManager.InstanceDebugInfo> dump =
                    serviceManager.debugDump();
            HashSet<Integer> pids = new HashSet<>();
            for (IServiceManager.InstanceDebugInfo info : dump) {
                if (info.pid != IServiceManager.PidConstant.NO_PID
                        && info.interfaceName != null
                        && info.interfaceName.startsWith(AUDIO_HAL_SERVICE_PREFIX)) {
                    pids.add(info.pid);
                }
            }
            return pids;
        } catch (RemoteException e) {
            return new HashSet<Integer>();
        }
    }

    private void updateAudioHalPids() {
        Set<Integer> pidsSet = getAudioHalPids();
        if (pidsSet.isEmpty()) {
            Slog.w(TAG, "Could not retrieve audio HAL service pids");
            return;
        }
        int[] pidsArray = pidsSet.stream().mapToInt(Integer::intValue).toArray();
        AudioSystem.setAudioHalPids(pidsArray);
    }

    //======================
    // misc
    //======================