• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 com.android.camera.util;
18 
19 import android.os.Build;
20 
21 import java.lang.reflect.Field;
22 
23 public class ApiHelper {
24     public static final boolean AT_LEAST_16 = Build.VERSION.SDK_INT >= 16;
25 
26     public static final boolean HAS_APP_GALLERY =
27             Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
28 
29     public static final boolean HAS_ANNOUNCE_FOR_ACCESSIBILITY =
30             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
31     public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK =
32             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
33     public static final boolean HAS_MEDIA_ACTION_SOUND =
34             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
35     public static final boolean HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT =
36             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
37     public static final boolean HAS_SET_BEAM_PUSH_URIS =
38             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
39     public static final boolean HAS_SURFACE_TEXTURE_RECORDING =
40             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
41 
42     public static final boolean HAS_CAMERA_HDR_PLUS = isKitKatOrHigher();
43     public static final boolean HAS_CAMERA_HDR =
44             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
45     public static final boolean HAS_DISPLAY_LISTENER =
46             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
47 
48     public static final boolean HAS_ORIENTATION_LOCK =
49             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
50     public static final boolean HAS_ROTATION_ANIMATION =
51             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
52 
53     public static final boolean HAS_HIDEYBARS = isKitKatOrHigher();
54 
getIntFieldIfExists(Class<?> klass, String fieldName, Class<?> obj, int defaultVal)55     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
56             Class<?> obj, int defaultVal) {
57         try {
58             Field f = klass.getDeclaredField(fieldName);
59             return f.getInt(obj);
60         } catch (Exception e) {
61             return defaultVal;
62         }
63     }
64 
isKitKatOrHigher()65     public static boolean isKitKatOrHigher() {
66         // TODO: Remove CODENAME check as soon as VERSION_CODES.KITKAT is final.
67         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
68                 || "KeyLimePie".equals(Build.VERSION.CODENAME);
69     }
70 }
71