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     // Documented value of CPU_ABI on x86 architectures
25     private static final String X86ABI = "x86";
26 
27     public static final boolean AT_LEAST_16 = Build.VERSION.SDK_INT >= 16;
28 
29     public static final boolean HAS_APP_GALLERY =
30             Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
31 
32     public static final boolean HAS_ANNOUNCE_FOR_ACCESSIBILITY =
33             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
34     public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK =
35             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
36     public static final boolean HAS_MEDIA_ACTION_SOUND =
37             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
38     public static final boolean HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT =
39             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
40     public static final boolean HAS_SET_BEAM_PUSH_URIS =
41             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
42     public static final boolean HAS_SURFACE_TEXTURE_RECORDING =
43             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
44     public static final boolean HAS_ROBOTO_MEDIUM_FONT =
45             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
46 
47     public static final boolean HAS_CAMERA_HDR_PLUS = isKitKatOrHigher();
48     public static final boolean HDR_PLUS_CAN_USE_ARBITRARY_ASPECT_RATIOS = isKitKatMR2OrHigher();
49     public static final boolean HAS_CAMERA_HDR =
50             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
51     public static final boolean HAS_DISPLAY_LISTENER =
52             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
53 
54     public static final boolean HAS_ORIENTATION_LOCK =
55             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
56     public static final boolean HAS_ROTATION_ANIMATION =
57             Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
58 
59     public static final boolean HAS_HIDEYBARS = isKitKatOrHigher();
60 
61     // Don't use renderscript. See b/18435492.
62     public static final boolean HAS_RENDERSCRIPT = false;
63 
64     public static final boolean IS_NEXUS_4 = "mako".equalsIgnoreCase(Build.DEVICE);
65     public static final boolean IS_NEXUS_5 = "LGE".equalsIgnoreCase(Build.MANUFACTURER)
66             && "hammerhead".equalsIgnoreCase(Build.DEVICE);
67     public static final boolean IS_NEXUS_6 = "motorola".equalsIgnoreCase(Build.MANUFACTURER)
68             && "shamu".equalsIgnoreCase(Build.DEVICE);
69     public static final boolean IS_NEXUS_9 = "htc".equalsIgnoreCase(Build.MANUFACTURER)
70             && ("flounder".equalsIgnoreCase(Build.DEVICE)
71                  || "flounder_lte".equalsIgnoreCase(Build.DEVICE));
72 
73     public static final boolean HAS_CAMERA_2_API = isLOrHigher();
74 
getIntFieldIfExists(Class<?> klass, String fieldName, Class<?> obj, int defaultVal)75     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
76             Class<?> obj, int defaultVal) {
77         try {
78             Field f = klass.getDeclaredField(fieldName);
79             return f.getInt(obj);
80         } catch (Exception e) {
81             return defaultVal;
82         }
83     }
84 
isKitKatOrHigher()85     public static boolean isKitKatOrHigher() {
86         // TODO: Remove CODENAME check as soon as VERSION_CODES.KITKAT is final.
87         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
88                 || "KeyLimePie".equals(Build.VERSION.CODENAME);
89     }
90 
isKitKatMR2OrHigher()91     public static boolean isKitKatMR2OrHigher() {
92         return isLOrHigher()
93                 || (isKitKatOrHigher() &&
94                        ("4.4.4".equals(Build.VERSION.RELEASE) || "4.4.3".equals(Build.VERSION.RELEASE)));
95     }
96 
isLollipop()97     public static boolean isLollipop() {
98         return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP;
99     }
100 
isLOrHigher()101     public static boolean isLOrHigher() {
102         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
103                 || "L".equals(Build.VERSION.CODENAME) || "LOLLIPOP".equals(Build.VERSION.CODENAME);
104     }
105 
isLMr1OrHigher()106     public static boolean isLMr1OrHigher() {
107         return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP;
108     }
109 
isLorLMr1()110     public static boolean isLorLMr1() {
111         return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP
112                 || Build.VERSION.SDK_INT == 22; // Lollipop MR1
113     }
114 
isMOrHigher()115     public static boolean isMOrHigher() {
116         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
117                 || "MNC".equals(Build.VERSION.CODENAME);
118     }
119 }
120