[go: nahoru, domu]

blob: 277cc6151a29dd0ad259062ba4b1f653727a6c8c [file] [log] [blame]
leo huang54cf8ea2020-01-17 22:12:17 +08001/*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package androidx.camera.extensions.impl;
18
19import android.hardware.camera2.CameraCharacteristics;
20import android.util.Log;
21
22import androidx.annotation.NonNull;
Trevor McGuiree0327b22021-09-22 22:59:57 -070023import androidx.annotation.RequiresApi;
leo huang54cf8ea2020-01-17 22:12:17 +080024
25import java.util.Arrays;
26
27/**
28 * A utility class to check the availabilities of camera characteristics.
29 */
Trevor McGuiree0327b22021-09-22 22:59:57 -070030@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
leo huang54cf8ea2020-01-17 22:12:17 +080031final class CameraCharacteristicAvailability {
32 private static final String TAG = "CharacteristicAbility";
33
34 private CameraCharacteristicAvailability() {
35 }
36
37 /**
38 * Check if the given effect id is available in the camera characteristics.
39 *
40 * @param cameraCharacteristics the camera characteristics.
41 * @param effect the effect id.
42 * @return {@code true} if the given effect id is available in the camera characteristics.
43 * {@code false} otherwise.
44 */
45 static boolean isEffectAvailable(@NonNull CameraCharacteristics cameraCharacteristics,
46 int effect) {
47 int[] availableEffects = cameraCharacteristics.get(
48 CameraCharacteristics.CONTROL_AVAILABLE_EFFECTS);
49 if (availableEffects == null) {
50 Log.d(TAG, "No CONTROL_AVAILABLE_EFFECTS info");
51 return false;
52 }
53
54 for (int availableEffect : availableEffects) {
55 if (availableEffect == effect) {
56 return true;
57 }
58 }
59 Log.d(TAG, "effect: " + effect + " is not in available list "
60 + Arrays.toString(availableEffects));
61 return false;
62 }
63}