Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 1 | /* |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 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 | |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 17 | package com.android.camera.util; |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 18 | |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 19 | import android.os.Build; |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 20 | |
Angus Kong | 708bfce | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 21 | import java.lang.reflect.Field; |
| 22 | |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 23 | public class ApiHelper { |
Alan Newberger | fdefc72 | 2014-11-20 10:03:52 -0800 | [diff] [blame] | 24 | // Documented value of CPU_ABI on x86 architectures |
| 25 | private static final String X86ABI = "x86"; |
| 26 | |
Bobby Georgescu | 8f69397 | 2013-03-07 14:15:57 -0800 | [diff] [blame] | 27 | public static final boolean AT_LEAST_16 = Build.VERSION.SDK_INT >= 16; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 28 | |
Mangesh Ghiware | 5df64b0 | 2013-09-18 18:25:26 -0700 | [diff] [blame] | 29 | public static final boolean HAS_APP_GALLERY = |
| 30 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 31 | |
| 32 | public static final boolean HAS_ANNOUNCE_FOR_ACCESSIBILITY = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 33 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; |
Chih-Chung Chang | 9341cc2 | 2012-07-04 16:54:02 +0800 | [diff] [blame] | 34 | public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 35 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; |
Angus Kong | 708bfce | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 36 | public static final boolean HAS_MEDIA_ACTION_SOUND = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 37 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 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; |
Angus Kong | fbf6dba | 2012-08-07 17:15:14 +0800 | [diff] [blame] | 42 | public static final boolean HAS_SURFACE_TEXTURE_RECORDING = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 43 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; |
Doris Liu | 040e3c0 | 2014-02-10 14:42:08 -0800 | [diff] [blame] | 44 | public static final boolean HAS_ROBOTO_MEDIUM_FONT = |
Doris Liu | 53b3ddb | 2013-12-05 13:11:22 -0800 | [diff] [blame] | 45 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 46 | |
Sascha Haeberling | 9bf0fd6 | 2013-10-03 12:10:48 -0700 | [diff] [blame] | 47 | public static final boolean HAS_CAMERA_HDR_PLUS = isKitKatOrHigher(); |
Spike Sprague | d25eac4 | 2014-10-08 18:49:26 -0700 | [diff] [blame] | 48 | public static final boolean HDR_PLUS_CAN_USE_ARBITRARY_ASPECT_RATIOS = isKitKatMR2OrHigher(); |
Wu-cheng Li | ea1d1d2 | 2012-08-25 21:10:04 +0800 | [diff] [blame] | 49 | public static final boolean HAS_CAMERA_HDR = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 50 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 51 | public static final boolean HAS_DISPLAY_LISTENER = |
| 52 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; |
Michael Kolb | 6afdb17 | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 53 | |
Michael Kolb | d1e0a6e | 2013-04-15 11:35:52 -0700 | [diff] [blame] | 54 | public static final boolean HAS_ORIENTATION_LOCK = |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 55 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; |
Mangesh Ghiware | a5682ab | 2013-09-19 09:24:23 -0700 | [diff] [blame] | 56 | public static final boolean HAS_ROTATION_ANIMATION = |
| 57 | Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 58 | |
| 59 | public static final boolean HAS_HIDEYBARS = isKitKatOrHigher(); |
Doris Liu | f479c0d | 2013-05-03 10:26:01 -0700 | [diff] [blame] | 60 | |
Alan Newberger | fdefc72 | 2014-11-20 10:03:52 -0800 | [diff] [blame] | 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 | |
Alan Newberger | 2631a15 | 2014-09-24 14:23:30 -0700 | [diff] [blame] | 65 | public static final boolean IS_NEXUS_4 = "mako".equalsIgnoreCase(Build.DEVICE); |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 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); |
I-Jong Lin | 838095a | 2014-10-27 15:38:32 -0700 | [diff] [blame] | 70 | public static final boolean IS_NEXUS_9 = "htc".equalsIgnoreCase(Build.MANUFACTURER) |
| 71 | && ("flounder".equalsIgnoreCase(Build.DEVICE) |
| 72 | || "flounder_lte".equalsIgnoreCase(Build.DEVICE)); |
Alan Newberger | 2ebdbd5 | 2014-11-04 14:21:33 -0800 | [diff] [blame] | 73 | public static final boolean IS_HTC = "htc".equalsIgnoreCase(Build.MANUFACTURER); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 74 | |
Puneet Lall | 7c703ce | 2014-09-26 11:42:54 -0700 | [diff] [blame] | 75 | public static final boolean HAS_CAMERA_2_API = isLOrHigher(); |
| 76 | |
Wu-cheng Li | 36d16bc | 2012-08-21 15:05:17 +0800 | [diff] [blame] | 77 | public static int getIntFieldIfExists(Class<?> klass, String fieldName, |
| 78 | Class<?> obj, int defaultVal) { |
| 79 | try { |
| 80 | Field f = klass.getDeclaredField(fieldName); |
| 81 | return f.getInt(obj); |
| 82 | } catch (Exception e) { |
| 83 | return defaultVal; |
| 84 | } |
| 85 | } |
| 86 | |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 87 | public static boolean isKitKatOrHigher() { |
| 88 | // TODO: Remove CODENAME check as soon as VERSION_CODES.KITKAT is final. |
| 89 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT |
| 90 | || "KeyLimePie".equals(Build.VERSION.CODENAME); |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame] | 91 | } |
Alan Newberger | fb172ac | 2014-08-21 14:42:36 -0700 | [diff] [blame] | 92 | |
Spike Sprague | d25eac4 | 2014-10-08 18:49:26 -0700 | [diff] [blame] | 93 | public static boolean isKitKatMR2OrHigher() { |
| 94 | return isLOrHigher() |
| 95 | || (isKitKatOrHigher() && |
| 96 | ("4.4.4".equals(Build.VERSION.RELEASE) || "4.4.3".equals(Build.VERSION.RELEASE))); |
| 97 | } |
| 98 | |
Alan Newberger | fb172ac | 2014-08-21 14:42:36 -0700 | [diff] [blame] | 99 | public static boolean isLOrHigher() { |
Dianne Hackborn | 43d66a0 | 2014-10-08 09:37:44 -0700 | [diff] [blame] | 100 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP |
Alan Newberger | fb172ac | 2014-08-21 14:42:36 -0700 | [diff] [blame] | 101 | || "L".equals(Build.VERSION.CODENAME); |
| 102 | } |
Senpo Hu | 2272f8a | 2014-12-16 11:56:39 -0800 | [diff] [blame^] | 103 | |
| 104 | public static boolean shouldShowAspectRatioDialog() { |
| 105 | return IS_NEXUS_4 || IS_NEXUS_5 || IS_NEXUS_6; |
| 106 | } |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 107 | } |