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 #include "platform_version.h" 45 #endif 46 47 #ifndef VSOC_PLATFORM_SDK_VERSION 48 #error VSOC_PLATFORM_SDK_VERSION is not set. Check your Android.mk 49 #endif 50 51 // Hide some C++ annotations that we'd like to use but need to avoid on older 52 // compilers. 53 #if __cplusplus <= 199711L 54 #define override 55 #endif 56 57 #define VSOC_PLATFORM_SDK_J 16 58 #define VSOC_PLATFORM_SDK_J_MR1 17 59 #define VSOC_PLATFORM_SDK_J_MR2 18 60 #define VSOC_PLATFORM_SDK_K 19 61 // Version 20 reserved for KitKat wearables only. See 62 // http://developer.android.com/guide/topics/manifest/uses-sdk-element.html 63 #define VSOC_PLATFORM_SDK_L 21 64 #define VSOC_PLATFORM_SDK_L_MR1 22 65 #define VSOC_PLATFORM_SDK_M 23 66 #define VSOC_PLATFORM_SDK_N 24 67 #define VSOC_PLATFORM_SDK_N_MR1 25 68 #define VSOC_PLATFORM_SDK_O 26 69 #define VSOC_PLATFORM_SDK_O_MR1 27 70 #define VSOC_PLATFORM_SDK_P 28 71 #define VSOC_PLATFORM_SDK_Q 29 72 #define VSOC_PLATFORM_SDK_LAST_SHIPPED 28 73 74 #define VSOC_PLATFORM_SDK_BEFORE(X) (VSOC_PLATFORM_SDK_VERSION < VSOC_PLATFORM_SDK_##X) 75 #define VSOC_PLATFORM_SDK_AFTER(X) (VSOC_PLATFORM_SDK_VERSION > VSOC_PLATFORM_SDK_##X) 76 77 #if VSOC_PLATFORM_SDK_BEFORE(J_MR2) 78 #define VSOC_STATIC_INITIALIZER(X) X: 79 #else 80 #define VSOC_STATIC_INITIALIZER(X) .X = 81 #endif 82 83 #if VSOC_PLATFORM_SDK_BEFORE(K) 84 // audio_input_flags_t was first defind in K. 85 // JBMR2 and K use the same audio HAL version, so define a work-around here. 86 typedef enum { 87 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes 88 } audio_input_flags_t; 89 #endif 90 91 // cstdint doesn't provide PRI... before C++11. On some branches (K) inttypes.h 92 // also doesn't behave as if it's C++. Just define the PRI... types here 93 // the kludgy way so our source is clean from a C++11 point-of-view. 94 #ifndef __STDC_FORMAT_MACROS 95 #define __STDC_FORMAT_MACROS 1 96 #endif 97 #include <inttypes.h> 98 99 #if VSOC_PLATFORM_SDK_BEFORE(L) 100 #define HAL_PIXEL_FORMAT_RAW16 HAL_PIXEL_FORMAT_RAW_SENSOR 101 #define VSOC_FDPRINTF fdprintf 102 103 #define KLOG_ERROR_LEVEL 3 104 #define KLOG_WARNING_LEVEL 4 105 #define KLOG_NOTICE_LEVEL 5 106 #define KLOG_INFO_LEVEL 6 107 #define KLOG_DEBUG_LEVEL 7 108 109 #else 110 #define VSOC_FDPRINTF dprintf 111 #endif 112 113 #if VSOC_PLATFORM_SDK_BEFORE(M) 114 __BEGIN_DECLS 115 extern int clock_nanosleep(clockid_t, int, const struct timespec*, 116 struct timespec*); 117 __END_DECLS 118 #endif 119