/*
 * Copyright 2021 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 androidx.camera.video.internal.compat.quirk;

import android.media.MediaCodec;
import android.os.Build;

import androidx.camera.core.impl.Quirk;
import androidx.camera.video.Recorder;
import androidx.camera.video.VideoCapture;
import androidx.camera.video.VideoOutput;

import java.util.Arrays;
import java.util.List;


/**
 * Quirk denotes that the encoder surface needs to be removed from repeating request before stop
 * the encoder.
 *
 * <p>As described in b/196039619, on devices with certain chipsets, the camera fails if
 * {@link MediaCodec} is stopped while frames are still being provided.
 *
 * <p>In {@link Recorder}, {@link Recorder#getStreamState()} has to returns
 * {@link VideoOutput.StreamState#INACTIVE} when the active recording is being stopped.
 * {@link VideoCapture} monitors {@link VideoOutput#getStreamState()} and
 * detach the surface from camera if it becomes {@link VideoOutput.StreamState#INACTIVE inactive}.
 * So making the {@link Recorder} inactive in stopping state will stop the camera from producing
 * frames to the {@link MediaCodec} before actually stopping it.
 */
public class DeactivateEncoderSurfaceBeforeStopEncoderQuirk implements Quirk {

    private static final List<String> BUILD_HARDWARE_SET = Arrays.asList("sc8830",
            "samsungexynos7580");

    static boolean load() {
        return "SAMSUNG".equalsIgnoreCase(Build.BRAND) && BUILD_HARDWARE_SET.contains(
                Build.HARDWARE.toLowerCase());
    }
}

@@ -892,58 +892,8 @@
 t;%0A%0A
-import java.util.Arrays;%0Aimport java.util.List;%0A%0A%0A
 /**%0A
@@ -1046,42 +1046,8 @@
 619,
- on devices with certain chipsets,
  the
@@ -1062,19 +1062,16 @@
 fails if
-%0A *
  %7B@link 
@@ -1105,16 +1105,19 @@
 e frames
+%0A *
  are sti
@@ -1729,282 +1729,74 @@
     
-private static final List%3CString%3E BUILD_HARDWARE_SET = Arrays.asList(%22sc8830%22,%0A            %22samsungexynos7580%22);%0A%0A    static boolean load() %7B%0A        return %22SAMSUNG%22.equalsIgnoreCase(Build.BRAND) && BUILD_HARDWARE_SET.contains(%0A                Build.HARDWARE.toLowerCase())
+static boolean load() %7B%0A        return Build.VERSION.SDK_INT %3C= 22
 ;%0A  

Change the condition of DeactivateEncoderSurfaceBeforeStopEncoderQuirk