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

Commit 77c5fef8 authored by Ján Sebechlebský's avatar Ján Sebechlebský Committed by Android (Google) Code Review
Browse files

Merge "Override equals & hash for VirtualCameraStreamConfig" into main

parents 28a69b96 cc326873
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.graphics.ImageFormat;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * The configuration of a single virtual camera stream.
 *
@@ -98,6 +100,19 @@ public final class VirtualCameraStreamConfig implements Parcelable {
        return mHeight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        VirtualCameraStreamConfig that = (VirtualCameraStreamConfig) o;
        return mWidth == that.mWidth && mHeight == that.mHeight && mFormat == that.mFormat;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mWidth, mHeight, mFormat);
    }

    /** Returns the {@link ImageFormat} of this stream. */
    @ImageFormat.Format
    public int getFormat() {
+71 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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 com.android.server.companion.virtual.camera;

import android.companion.virtual.camera.VirtualCameraStreamConfig;
import android.graphics.ImageFormat;
import android.graphics.PixelFormat;
import android.os.Parcel;
import android.platform.test.annotations.Presubmit;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.google.common.testing.EqualsTester;

import org.junit.Test;
import org.junit.runner.RunWith;

@Presubmit
@RunWith(AndroidJUnit4.class)
public class VirtualCameraStreamConfigTest {

    private static final int VGA_WIDTH = 640;
    private static final int VGA_HEIGHT = 480;

    private static final int QVGA_WIDTH = 320;
    private static final int QVGA_HEIGHT = 240;

    @Test
    public void testEquals() {
        VirtualCameraStreamConfig vgaYuvStreamConfig = new VirtualCameraStreamConfig(VGA_WIDTH,
                VGA_HEIGHT,
                ImageFormat.YUV_420_888);
        VirtualCameraStreamConfig qvgaYuvStreamConfig = new VirtualCameraStreamConfig(QVGA_WIDTH,
                QVGA_HEIGHT, ImageFormat.YUV_420_888);
        VirtualCameraStreamConfig vgaRgbaStreamConfig = new VirtualCameraStreamConfig(VGA_WIDTH,
                VGA_HEIGHT, PixelFormat.RGBA_8888);

        new EqualsTester()
                .addEqualityGroup(vgaYuvStreamConfig, reparcel(vgaYuvStreamConfig))
                .addEqualityGroup(qvgaYuvStreamConfig, reparcel(qvgaYuvStreamConfig))
                .addEqualityGroup(vgaRgbaStreamConfig, reparcel(vgaRgbaStreamConfig))
                .testEquals();
    }

    private static VirtualCameraStreamConfig reparcel(VirtualCameraStreamConfig config) {
        Parcel parcel = Parcel.obtain();
        try {
            config.writeToParcel(parcel, /* flags= */ 0);
            parcel.setDataPosition(0);
            return VirtualCameraStreamConfig.CREATOR.createFromParcel(parcel);
        } finally {
            parcel.recycle();
        }
    }


}