• 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     // 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 for x86 K, L is OK. See b/18435492
62     public static final boolean HAS_RENDERSCRIPT =
63             !(Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT && X86ABI.equals(Build.CPU_ABI));
64 
65     public static final boolean IS_NEXUS_4 = "mako".equalsIgnoreCase(Build.DEVICE);
66     public static final boolean IS_NEXUS_5 = "LGE".equalsIgnoreCase(Build.MANUFACTURER)
67             && "hammerhead".equalsIgnoreCase(Build.DEVICE);
68     public static final boolean IS_NEXUS_6 = "motorola".equalsIgnoreCase(Build.MANUFACTURER)
69             && "shamu".equalsIgnoreCase(Build.DEVICE);
70     public static final boolean IS_NEXUS_9 = "htc".equalsIgnoreCase(Build.MANUFACTURER)
71             && ("flounder".equalsIgnoreCase(Build.DEVICE)
72                  || "flounder_lte".equalsIgnoreCase(Build.DEVICE));
73 
74     public static final boolean HAS_CAMERA_2_API = isLOrHigher();
75 
getIntFieldIfExists(Class<?> klass, String fieldName, Class<?> obj, int defaultVal)76     public static int getIntFieldIfExists(Class<?> klass, String fieldName,
77             Class<?> obj, int defaultVal) {
78         try {
79             Field f = klass.getDeclaredField(fieldName);
80             return f.getInt(obj);
81         } catch (Exception e) {
82             return defaultVal;
83         }
84     }
85 
isKitKatOrHigher()86     public static boolean isKitKatOrHigher() {
87         // TODO: Remove CODENAME check as soon as VERSION_CODES.KITKAT is final.
88         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
89                 || "KeyLimePie".equals(Build.VERSION.CODENAME);
90     }
91 
isKitKatMR2OrHigher()92     public static boolean isKitKatMR2OrHigher() {
93         return isLOrHigher()
94                 || (isKitKatOrHigher() &&
95                        ("4.4.4".equals(Build.VERSION.RELEASE) || "4.4.3".equals(Build.VERSION.RELEASE)));
96     }
97 
isLollipop()98     public static boolean isLollipop() {
99         return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP;
100     }
101 
isLOrHigher()102     public static boolean isLOrHigher() {
103         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
104                 || "L".equals(Build.VERSION.CODENAME) || "LOLLIPOP".equals(Build.VERSION.CODENAME);
105     }
106 
isLMr1OrHigher()107     public static boolean isLMr1OrHigher() {
108         return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP;
109     }
110 
isLorLMr1()111     public static boolean isLorLMr1() {
112         return Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP
113                 || Build.VERSION.SDK_INT == 22; // Lollipop MR1
114     }
115 
isMOrHigher()116     public static boolean isMOrHigher() {
117         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
118                 || "MNC".equals(Build.VERSION.CODENAME);
119     }
120 }
121