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

Commit f0ef026a authored by Vladimir Komsiyski's avatar Vladimir Komsiyski Committed by Android (Google) Code Review
Browse files

Merge "Do not call into the app process with system identity" into main

parents 029bb2c8 09a651f1
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.companion.virtualdevice.flags.Flags;
import android.content.ComponentName;
import android.content.Context;
import android.hardware.display.VirtualDisplayConfig;
import android.os.Binder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SharedMemory;
@@ -844,25 +845,29 @@ public final class VirtualDeviceParams implements Parcelable {
                        Duration.ofNanos(MICROSECONDS.toNanos(samplingPeriodMicros));
                final Duration batchReportingLatency =
                        Duration.ofNanos(MICROSECONDS.toNanos(batchReportLatencyMicros));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onConfigurationChanged(
                        sensor, enabled, samplingPeriod, batchReportingLatency));
                                sensor, enabled, samplingPeriod, batchReportingLatency)));
            }

            @Override
            public void onDirectChannelCreated(int channelHandle,
                    @NonNull SharedMemory sharedMemory) {
                if (mDirectChannelCallback != null && mDirectChannelExecutor != null) {
                    mDirectChannelExecutor.execute(
                            () -> mDirectChannelCallback.onDirectChannelCreated(channelHandle,
                                    sharedMemory));
                    Binder.withCleanCallingIdentity(() ->
                            mDirectChannelExecutor.execute(() ->
                                        mDirectChannelCallback.onDirectChannelCreated(
                                                channelHandle, sharedMemory)));
                }
            }

            @Override
            public void onDirectChannelDestroyed(int channelHandle) {
                if (mDirectChannelCallback != null && mDirectChannelExecutor != null) {
                    mDirectChannelExecutor.execute(
                            () -> mDirectChannelCallback.onDirectChannelDestroyed(channelHandle));
                    Binder.withCleanCallingIdentity(() ->
                            mDirectChannelExecutor.execute(() ->
                                    mDirectChannelCallback.onDirectChannelDestroyed(
                                            channelHandle)));
                }
            }

@@ -870,9 +875,10 @@ public final class VirtualDeviceParams implements Parcelable {
            public void onDirectChannelConfigured(int channelHandle, @NonNull VirtualSensor sensor,
                    int rateLevel, int reportToken) {
                if (mDirectChannelCallback != null && mDirectChannelExecutor != null) {
                    mDirectChannelExecutor.execute(
                            () -> mDirectChannelCallback.onDirectChannelConfigured(
                                    channelHandle, sensor, rateLevel, reportToken));
                    Binder.withCleanCallingIdentity(() ->
                            mDirectChannelExecutor.execute(() ->
                                    mDirectChannelCallback.onDirectChannelConfigured(
                                            channelHandle, sensor, rateLevel, reportToken)));
                }
            }
        }
+5 −2
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.media.AudioTrack;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioMixingRule;
import android.media.audiopolicy.AudioPolicy;
import android.os.Binder;
import android.util.IntArray;
import android.util.Log;

@@ -90,14 +91,16 @@ public final class VirtualAudioSession extends IAudioRoutingCallback.Stub implem
        @Override
        public void onPlaybackConfigChanged(List<AudioPlaybackConfiguration> configs) {
            if (mCallback != null) {
                mExecutor.execute(() -> mCallback.onPlaybackConfigChanged(configs));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onPlaybackConfigChanged(configs)));
            }
        }

        @Override
        public void onRecordingConfigChanged(List<AudioRecordingConfiguration> configs) {
            if (mCallback != null) {
                mExecutor.execute(() -> mCallback.onRecordingConfigChanged(configs));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onRecordingConfigChanged(configs)));
            }
        }
    }
+17 −9
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.params.StreamConfiguration;
import android.hardware.camera2.params.StreamConfigurationDuration;
import android.os.Binder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
@@ -516,7 +517,7 @@ public final class VirtualCameraConfig implements Parcelable {
        @Override
        public void onOpenCamera() {
            if (Flags.virtualCameraOnOpen()) {
                mExecutor.execute(mCallback::onOpenCamera);
                Binder.withCleanCallingIdentity(() -> mExecutor.execute(mCallback::onOpenCamera));
            }
        }

@@ -527,32 +528,39 @@ public final class VirtualCameraConfig implements Parcelable {
                VirtualCameraSessionConfig virtualCameraSessionConfig =
                        new VirtualCameraSessionConfig(sessionParameters);

                mExecutor.execute(() -> mCallback.onConfigureSession(virtualCameraSessionConfig,
                        convertToFrameworkCaptureResultConsumer(captureResultConsumer)));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onConfigureSession(
                                virtualCameraSessionConfig,
                                convertToFrameworkCaptureResultConsumer(captureResultConsumer))));
            }
        }

        @Override
        public void onStreamConfigured(int streamId, Surface surface, int width, int height,
                int format) {
            mExecutor.execute(() -> mCallback.onStreamConfigured(streamId, surface, width, height,
                    format));
            Binder.withCleanCallingIdentity(() ->
                    mExecutor.execute(() -> mCallback.onStreamConfigured(
                            streamId, surface, width, height, format)));
        }

        @Override
        public void onProcessCaptureRequest(int streamId, long frameId,
                CaptureRequest captureRequest) {
            if (Flags.virtualCameraMetadata() && mPerFrameCameraMetadataEnabled) {
                mExecutor.execute(
                        () -> mCallback.onProcessCaptureRequest(streamId, frameId, captureRequest));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onProcessCaptureRequest(
                                streamId, frameId, captureRequest)));
            } else {
                mExecutor.execute(() -> mCallback.onProcessCaptureRequest(streamId, frameId));
                Binder.withCleanCallingIdentity(() ->
                        mExecutor.execute(() -> mCallback.onProcessCaptureRequest(
                                streamId, frameId)));
            }
        }

        @Override
        public void onStreamClosed(int streamId) {
            mExecutor.execute(() -> mCallback.onStreamClosed(streamId));
            Binder.withCleanCallingIdentity(() ->
                    mExecutor.execute(() -> mCallback.onStreamClosed(streamId)));
        }

        @Nullable