1 /* 2 * Copyright (C) 2017 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 #pragma once 17 18 // Fixes for various things that go wrong between Android versions. 19 // By convention this should be the very first include: it tweaks some 20 // flags that affect the processing of the system headers. 21 // 22 // Code that needs to cope with platform changes should use the 23 // VSOC_PLATFORM_SDK_BEFORE and VSOC_PLATFORM_SDK_AFTER macros below. 24 // It's fine to provide declarations for broadly used things in this file 25 // if that's easier. 26 // 27 // To use this header add $(VSOC_VERSION_CFLAGS) to the LOCAL_CFLAGS 28 // in the corresponding Android.mk. There is an error check to catch 29 // cases where this wasn't done. 30 // 31 // Code should not examine the SDK_PLATFORM_VERSION, and generally shouldn't 32 // look at the VSOC_PLATFORM_SDK_* values. While these currently track 33 // PLATFORM_SDK_VERSION, that's an implementation detail that will probably 34 // change: Android will eventually break things without bumping 35 // PLATFORM_SDK_VERSION. 36 // 37 // This is also why there is no SDK_PLATFORM_VERSION_IS(). Convert these 38 // statements into BEFORE and/or AFTER. 39 // 40 // To check for master/AOSP use VSOC_PLATFORM_VERSION_AFTER(LAST_SHIPPED) 41 #include <time.h> 42 43 #ifndef VSOC_PLATFORM_SDK_VERSION 44 #error VSOC_PLATFORM_SDK_VERSION is not set. Check your Android.mk 45 #endif 46 47 // Hide some C++ annotations that we'd like to use but need to avoid on older 48 // compilers. 49 #if __cplusplus <= 199711L 50 #define override 51 #endif 52 53 #define VSOC_PLATFORM_SDK_J 16 54 #define VSOC_PLATFORM_SDK_J_MR1 17 55 #define VSOC_PLATFORM_SDK_J_MR2 18 56 #define VSOC_PLATFORM_SDK_K 19 57 // Version 20 reserved for KitKat wearables only. See 58 // http://developer.android.com/guide/topics/manifest/uses-sdk-element.html 59 #define VSOC_PLATFORM_SDK_L 21 60 #define VSOC_PLATFORM_SDK_L_MR1 22 61 #define VSOC_PLATFORM_SDK_M 23 62 #define VSOC_PLATFORM_SDK_N 24 63 #define VSOC_PLATFORM_SDK_N_MR1 25 64 #define VSOC_PLATFORM_SDK_O 26 65 #define VSOC_PLATFORM_SDK_O_MR1 27 66 #define VSOC_PLATFORM_SDK_P 28 67 #define VSOC_PLATFORM_SDK_LAST_SHIPPED 27 68 69 #define VSOC_PLATFORM_SDK_BEFORE(X) (VSOC_PLATFORM_SDK_VERSION < VSOC_PLATFORM_SDK_##X) 70 #define VSOC_PLATFORM_SDK_AFTER(X) (VSOC_PLATFORM_SDK_VERSION > VSOC_PLATFORM_SDK_##X) 71 72 #if VSOC_PLATFORM_SDK_BEFORE(J_MR2) 73 #define VSOC_STATIC_INITIALIZER(X) X: 74 #else 75 #define VSOC_STATIC_INITIALIZER(X) .X = 76 #endif 77 78 #if VSOC_PLATFORM_SDK_BEFORE(K) 79 // audio_input_flags_t was first defind in K. 80 // JBMR2 and K use the same audio HAL version, so define a work-around here. 81 typedef enum { 82 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes 83 } audio_input_flags_t; 84 #endif 85 86 // cstdint doesn't provide PRI... before C++11. On some branches (K) inttypes.h 87 // also doesn't behave as if it's C++. Just define the PRI... types here 88 // the kludgy way so our source is clean from a C++11 point-of-view. 89 #ifndef __STDC_FORMAT_MACROS 90 #define __STDC_FORMAT_MACROS 1 91 #endif 92 #include <inttypes.h> 93 94 #if VSOC_PLATFORM_SDK_BEFORE(L) 95 #define HAL_PIXEL_FORMAT_RAW16 HAL_PIXEL_FORMAT_RAW_SENSOR 96 #define VSOC_FDPRINTF fdprintf 97 98 #define KLOG_ERROR_LEVEL 3 99 #define KLOG_WARNING_LEVEL 4 100 #define KLOG_NOTICE_LEVEL 5 101 #define KLOG_INFO_LEVEL 6 102 #define KLOG_DEBUG_LEVEL 7 103 104 #else 105 #define VSOC_FDPRINTF dprintf 106 #endif 107 108 #if VSOC_PLATFORM_SDK_BEFORE(M) 109 __BEGIN_DECLS 110 extern int clock_nanosleep(clockid_t, int, const struct timespec*, 111 struct timespec*); 112 __END_DECLS 113 #endif 114