Home | History | Annotate | Download | only in helpers
      1 /*
      2  * Copyright 2014 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 
     17 package android.hardware.cts.helpers;
     18 
     19 import android.content.Context;
     20 import android.hardware.Camera;
     21 import android.hardware.camera2.CameraCharacteristics;
     22 import android.hardware.camera2.CameraManager;
     23 
     24 import java.util.Comparator;
     25 
     26 /**
     27  * Utility class containing helper functions for the Camera CTS tests.
     28  */
     29 public class CameraUtils {
     30 
     31     /**
     32      * Returns {@code true} if this device only supports {@code LEGACY} mode operation in the
     33      * Camera2 API for the given camera ID.
     34      *
     35      * @param context {@link Context} to access the {@link CameraManager} in.
     36      * @param cameraId the ID of the camera device to check.
     37      * @return {@code true} if this device only supports {@code LEGACY} mode.
     38      */
     39     public static boolean isLegacyHAL(Context context, int cameraId) throws Exception {
     40         CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
     41         CameraCharacteristics characteristics =
     42                 manager.getCameraCharacteristics(Integer.toString(cameraId));
     43 
     44         return characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) ==
     45                 CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
     46     }
     47 
     48     /**
     49      * Shared size comparison method used by size comparators.
     50      *
     51      * <p>Compares the number of pixels it covers.If two the areas of two sizes are same, compare
     52      * the widths.</p>
     53      */
     54      public static int compareSizes(int widthA, int heightA, int widthB, int heightB) {
     55         long left = widthA * (long) heightA;
     56         long right = widthB * (long) heightB;
     57         if (left == right) {
     58             left = widthA;
     59             right = widthB;
     60         }
     61         return (left < right) ? -1 : (left > right ? 1 : 0);
     62     }
     63 
     64     /**
     65      * Size comparator that compares the number of pixels it covers.
     66      *
     67      * <p>If two the areas of two sizes are same, compare the widths.</p>
     68      */
     69     public static class LegacySizeComparator implements Comparator<Camera.Size> {
     70         @Override
     71         public int compare(Camera.Size lhs, Camera.Size rhs) {
     72             return compareSizes(lhs.width, lhs.height, rhs.width, rhs.height);
     73         }
     74     }
     75 
     76 }
     77