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

Commit 338b9d9c authored by Yuanjia Hsu's avatar Yuanjia Hsu Committed by Automerger Merge Worker
Browse files

Merge "Don't register playback/recording change if caller doesn't care it"...

Merge "Don't register playback/recording change if caller doesn't care it" into tm-dev am: 9270d9fd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17321718



Change-Id: I4e6a63e452e22889bac57fefb1d261c9efddb3dc
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a0ceced4 9270d9fd
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -17,7 +17,8 @@
package android.companion.virtual;

import android.app.PendingIntent;
import android.companion.virtual.audio.IAudioSessionCallback;
import android.companion.virtual.audio.IAudioConfigChangedCallback;
import android.companion.virtual.audio.IAudioRoutingCallback;
import android.graphics.Point;
import android.graphics.PointF;
import android.hardware.input.VirtualKeyEvent;
@@ -51,7 +52,8 @@ interface IVirtualDevice {
     */
    void onAudioSessionStarting(
            int displayId,
            IAudioSessionCallback callback);
            IAudioRoutingCallback routingCallback,
            IAudioConfigChangedCallback configChangedCallback);

    void onAudioSessionEnded();

+3 −7
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -20,15 +20,11 @@ import android.media.AudioPlaybackConfiguration;
import android.media.AudioRecordingConfiguration;

/**
 * Callback to control audio rerouting, notify playback and recording state of applications running
 * on virtual device.
 * Callback to notify playback and recording state of applications running on virtual device.
 *
 * @hide
 */
oneway interface IAudioSessionCallback {

    /** Updates the set of applications that need to have their audio rerouted. */
    void onAppsNeedingAudioRoutingChanged(in int[] appUids);
oneway interface IAudioConfigChangedCallback {

    /**
     * Called whenever the playback configuration of applications running on virtual device has
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.companion.virtual.audio;

/**
 * Callback to control audio rerouting for applications running on virtual device.
 *
 * @hide
 */
oneway interface IAudioRoutingCallback {

    /** Updates the set of applications that need to have their audio rerouted. */
    void onAppsNeedingAudioRoutingChanged(in int[] appUids);
}
+6 −4
Original line number Diff line number Diff line
@@ -76,8 +76,8 @@ public final class VirtualAudioDevice implements Closeable {
     * @hide
     */
    public VirtualAudioDevice(Context context, IVirtualDevice virtualDevice,
            VirtualDisplay virtualDisplay, Executor executor,
            AudioConfigurationChangeCallback callback) {
            @NonNull VirtualDisplay virtualDisplay, @Nullable Executor executor,
            @Nullable AudioConfigurationChangeCallback callback) {
        mContext = context;
        mVirtualDevice = virtualDevice;
        mVirtualDisplay = virtualDisplay;
@@ -105,7 +105,8 @@ public final class VirtualAudioDevice implements Closeable {

        try {
            mVirtualDevice.onAudioSessionStarting(mVirtualDisplay.getDisplay().getDisplayId(),
                    /* callback= */ mOngoingSession);
                    /* routingCallback= */ mOngoingSession,
                    /* configChangedCallback= */  mOngoingSession.getAudioConfigChangedListener());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -135,7 +136,8 @@ public final class VirtualAudioDevice implements Closeable {

        try {
            mVirtualDevice.onAudioSessionStarting(mVirtualDisplay.getDisplay().getDisplayId(),
                    /* callback= */ mOngoingSession);
                    /* routingCallback= */ mOngoingSession,
                    /* configChangedCallback= */ mOngoingSession.getAudioConfigChangedListener());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+42 −20
Original line number Diff line number Diff line
@@ -50,16 +50,14 @@ import java.util.concurrent.Executor;
 * @hide
 */
@VisibleForTesting
public final class VirtualAudioSession extends IAudioSessionCallback.Stub implements
public final class VirtualAudioSession extends IAudioRoutingCallback.Stub implements
        UserRestrictionsCallback, Closeable {
    private static final String TAG = "VirtualAudioSession";

    private final Context mContext;
    private final UserRestrictionsDetector mUserRestrictionsDetector;
    /** The {@link Executor} for sending {@link AudioConfigurationChangeCallback} to the caller */
    private final Executor mExecutor;
    @Nullable
    private final AudioConfigurationChangeCallback mCallback;
    private final AudioConfigChangedCallback mAudioConfigChangedCallback;
    private final Object mLock = new Object();
    @GuardedBy("mLock")
    private final IntArray mReroutedAppUids = new IntArray();
@@ -73,13 +71,44 @@ public final class VirtualAudioSession extends IAudioSessionCallback.Stub implem
    @GuardedBy("mLock")
    private AudioInjection mAudioInjection;

    /**
     * Class to receive {@link IAudioConfigChangedCallback} callbacks from service.
     *
     * @hide
     */
    @VisibleForTesting
    public static final class AudioConfigChangedCallback extends IAudioConfigChangedCallback.Stub {
        private final Executor mExecutor;
        private final AudioConfigurationChangeCallback mCallback;

        AudioConfigChangedCallback(Context context, Executor executor,
                AudioConfigurationChangeCallback callback) {
            mExecutor = executor != null ? executor : context.getMainExecutor();
            mCallback = callback;
        }

        @Override
        public void onPlaybackConfigChanged(List<AudioPlaybackConfiguration> configs) {
            if (mCallback != null) {
                mExecutor.execute(() -> mCallback.onPlaybackConfigChanged(configs));
            }
        }

        @Override
        public void onRecordingConfigChanged(List<AudioRecordingConfiguration> configs) {
            if (mCallback != null) {
                mExecutor.execute(() -> mCallback.onRecordingConfigChanged(configs));
            }
        }
    }

    @VisibleForTesting
    public VirtualAudioSession(Context context,
            @Nullable AudioConfigurationChangeCallback callback, @Nullable Executor executor) {
        mContext = context;
        mUserRestrictionsDetector = new UserRestrictionsDetector(context);
        mCallback = callback;
        mExecutor = executor != null ? executor : context.getMainExecutor();
        mAudioConfigChangedCallback = callback == null ? null : new AudioConfigChangedCallback(
                context, executor, callback);
    }

    /**
@@ -129,6 +158,13 @@ public final class VirtualAudioSession extends IAudioSessionCallback.Stub implem
        }
    }

    /** @hide */
    @VisibleForTesting
    @Nullable
    public AudioConfigChangedCallback getAudioConfigChangedListener() {
        return mAudioConfigChangedCallback;
    }

    /** @hide */
    @VisibleForTesting
    @Nullable
@@ -263,20 +299,6 @@ public final class VirtualAudioSession extends IAudioSessionCallback.Stub implem
        }
    }

    @Override
    public void onPlaybackConfigChanged(List<AudioPlaybackConfiguration> configs) {
        if (mCallback != null) {
            mExecutor.execute(() -> mCallback.onPlaybackConfigChanged(configs));
        }
    }

    @Override
    public void onRecordingConfigChanged(List<AudioRecordingConfiguration> configs) {
        if (mCallback != null) {
            mExecutor.execute(() -> mCallback.onRecordingConfigChanged(configs));
        }
    }

    /** @hide */
    @VisibleForTesting
    public IntArray getReroutedAppUids() {
Loading