|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <fcntl.h> |
| 4 | +#include <sys/system_properties.h> |
| 5 | + |
| 6 | +#include <string_view> |
| 7 | + |
| 8 | +#include <shared/cpp-util.hh> |
| 9 | + |
| 10 | +namespace xamarin::android { |
| 11 | + class Constants |
| 12 | + { |
| 13 | +#if INTPTR_MAX == INT64_MAX |
| 14 | + static inline constexpr std::string_view BITNESS { "64bit" }; |
| 15 | +#else |
| 16 | + static inline constexpr std::string_view BITNESS { "32bit" }; |
| 17 | +#endif |
| 18 | + |
| 19 | + public: |
| 20 | +#if INTPTR_MAX == INT64_MAX |
| 21 | + static inline constexpr bool is_64_bit_target = true; |
| 22 | +#else |
| 23 | + static inline constexpr bool is_64_bit_target = false; |
| 24 | +#endif |
| 25 | + |
| 26 | +#if defined(RELEASE) |
| 27 | + static constexpr bool is_release_build = true; |
| 28 | + static constexpr bool is_debug_build = false; |
| 29 | +#else |
| 30 | + static constexpr bool is_release_build = false; |
| 31 | + static constexpr bool is_debug_build = true; |
| 32 | +#endif |
| 33 | + static constexpr std::string_view MANGLED_ASSEMBLY_NAME_EXT { ".so" }; |
| 34 | + |
| 35 | + private: |
| 36 | + static constexpr std::string_view RUNTIME_CONFIG_BLOB_BASE_NAME { "libarc.bin" }; |
| 37 | + static constexpr size_t runtime_config_blob_name_size = calc_size (RUNTIME_CONFIG_BLOB_BASE_NAME, MANGLED_ASSEMBLY_NAME_EXT); |
| 38 | + static constexpr auto RUNTIME_CONFIG_BLOB_NAME_ARRAY = concat_string_views<runtime_config_blob_name_size> (RUNTIME_CONFIG_BLOB_BASE_NAME, MANGLED_ASSEMBLY_NAME_EXT); |
| 39 | + |
| 40 | + public: |
| 41 | + // .data() must be used otherwise string_view length will include the trailing \0 in the array |
| 42 | + static constexpr std::string_view RUNTIME_CONFIG_BLOB_NAME { RUNTIME_CONFIG_BLOB_NAME_ARRAY.data () }; |
| 43 | + static constexpr std::string_view OVERRIDE_DIRECTORY_NAME { ".__override__" }; |
| 44 | + |
| 45 | + /* Android property containing connection information, set by XS */ |
| 46 | + static inline constexpr std::string_view DEBUG_MONO_CONNECT_PROPERTY { "debug.mono.connect" }; |
| 47 | + static inline constexpr std::string_view DEBUG_MONO_DEBUG_PROPERTY { "debug.mono.debug" }; |
| 48 | + static inline constexpr std::string_view DEBUG_MONO_ENV_PROPERTY { "debug.mono.env" }; |
| 49 | + static inline constexpr std::string_view DEBUG_MONO_EXTRA_PROPERTY { "debug.mono.extra" }; |
| 50 | + static inline constexpr std::string_view DEBUG_MONO_GC_PROPERTY { "debug.mono.gc" }; |
| 51 | + static inline constexpr std::string_view DEBUG_MONO_GDB_PROPERTY { "debug.mono.gdb" }; |
| 52 | + static inline constexpr std::string_view DEBUG_MONO_LOG_PROPERTY { "debug.mono.log" }; |
| 53 | + static inline constexpr std::string_view DEBUG_MONO_MAX_GREFC { "debug.mono.max_grefc" }; |
| 54 | + static inline constexpr std::string_view DEBUG_MONO_PROFILE_PROPERTY { "debug.mono.profile" }; |
| 55 | + static inline constexpr std::string_view DEBUG_MONO_RUNTIME_ARGS_PROPERTY { "debug.mono.runtime_args" }; |
| 56 | + static inline constexpr std::string_view DEBUG_MONO_SOFT_BREAKPOINTS { "debug.mono.soft_breakpoints" }; |
| 57 | + static inline constexpr std::string_view DEBUG_MONO_TRACE_PROPERTY { "debug.mono.trace" }; |
| 58 | + static inline constexpr std::string_view DEBUG_MONO_WREF_PROPERTY { "debug.mono.wref" }; |
| 59 | + |
| 60 | + static constexpr std::string_view LOG_CATEGORY_NAME_NONE { "*none*" }; |
| 61 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID { "monodroid" }; |
| 62 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_ASSEMBLY { "monodroid-assembly" }; |
| 63 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_DEBUG { "monodroid-debug" }; |
| 64 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_GC { "monodroid-gc" }; |
| 65 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_GREF { "monodroid-gref" }; |
| 66 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_LREF { "monodroid-lref" }; |
| 67 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_TIMING { "monodroid-timing" }; |
| 68 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_BUNDLE { "monodroid-bundle" }; |
| 69 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_NETWORK { "monodroid-network" }; |
| 70 | + static constexpr std::string_view LOG_CATEGORY_NAME_MONODROID_NETLINK { "monodroid-netlink" }; |
| 71 | + static constexpr std::string_view LOG_CATEGORY_NAME_ERROR { "*error*" }; |
| 72 | + |
| 73 | +#if defined(__arm__) |
| 74 | + static constexpr std::string_view android_abi { "armeabi_v7a" }; |
| 75 | + static constexpr std::string_view android_lib_abi { "armeabi-v7a" }; |
| 76 | + static constexpr std::string_view runtime_identifier { "android-arm" }; |
| 77 | +#elif defined(__aarch64__) |
| 78 | + static constexpr std::string_view android_abi { "arm64_v8a" }; |
| 79 | + static constexpr std::string_view android_lib_abi { "arm64-v8a" }; |
| 80 | + static constexpr std::string_view runtime_identifier { "android-arm64" }; |
| 81 | +#elif defined(__x86_64__) |
| 82 | + static constexpr std::string_view android_abi { "x86_64" }; |
| 83 | + static constexpr std::string_view android_lib_abi { "x86_64" }; |
| 84 | + static constexpr std::string_view runtime_identifier { "android-x64" }; |
| 85 | +#elif defined(__i386__) |
| 86 | + static constexpr std::string_view android_abi { "x86" }; |
| 87 | + static constexpr std::string_view android_lib_abi { "x86" }; |
| 88 | + static constexpr std::string_view runtime_identifier { "android-x86" }; |
| 89 | +#endif |
| 90 | + |
| 91 | + static constexpr std::string_view split_config_prefix { "/split_config." }; |
| 92 | + static constexpr std::string_view split_config_extension { ".apk" }; |
| 93 | + |
| 94 | + private: |
| 95 | + static constexpr size_t split_config_abi_apk_name_size = calc_size (split_config_prefix, android_abi, split_config_extension); |
| 96 | + |
| 97 | + public: |
| 98 | + static constexpr auto split_config_abi_apk_name = concat_string_views<split_config_abi_apk_name_size> (split_config_prefix, android_abi, split_config_extension); |
| 99 | + |
| 100 | + // |
| 101 | + // Indexes must match these of trhe `appDirs` array in src/java-runtime/mono/android/MonoPackageManager.java |
| 102 | + // |
| 103 | + static constexpr size_t APP_DIRS_FILES_DIR_INDEX = 0uz; |
| 104 | + static constexpr size_t APP_DIRS_CACHE_DIR_INDEX = 1uz; |
| 105 | + static constexpr size_t APP_DIRS_DATA_DIR_INDEX = 2uz; |
| 106 | + |
| 107 | + static inline constexpr size_t PROPERTY_VALUE_BUFFER_LEN = PROP_VALUE_MAX + 1uz; |
| 108 | + |
| 109 | + // 64-bit unsigned or 64-bit signed with sign |
| 110 | + static constexpr size_t MAX_INTEGER_DIGIT_COUNT_BASE10 = 21uz; |
| 111 | + static constexpr size_t INTEGER_BASE10_BUFFER_SIZE = MAX_INTEGER_DIGIT_COUNT_BASE10 + 1uz; |
| 112 | + |
| 113 | + // Documented in NDK's <android/log.h> comments |
| 114 | + static constexpr size_t MAX_LOGCAT_MESSAGE_LENGTH = 1023uz; |
| 115 | + |
| 116 | + // PATH_MAX is always 4096 on Linux, but for our purposes it's most likely too much and since |
| 117 | + // we use this value to allocate stack variables mostly, let's downsize it a bit to what the |
| 118 | + // _XOPEN_PATH_MAX is set to |
| 119 | + static constexpr size_t SENSIBLE_PATH_MAX = 1024uz; |
| 120 | + |
| 121 | + static constexpr int DEFAULT_DIRECTORY_MODE = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
| 122 | + |
| 123 | +#if defined (DEBUG) |
| 124 | + static constexpr std::string_view OVERRIDE_ENVIRONMENT_FILE_NAME { "environment" }; |
| 125 | + static constexpr uint32_t OVERRIDE_ENVIRONMENT_FILE_HEADER_SIZE = 22; |
| 126 | +#endif |
| 127 | + |
| 128 | + static constexpr std::string_view MONO_ANDROID_ASSEMBLY_NAME { "Mono.Android" }; |
| 129 | + static constexpr std::string_view ANDROID_RUNTIME_NS_NAME { "Android.Runtime" }; |
| 130 | + static constexpr std::string_view JNIENVINIT_CLASS_NAME { "JNIEnvInit" }; |
| 131 | + static constexpr std::string_view JNIENV_CLASS_NAME { "JNIEnv" }; |
| 132 | + |
| 133 | + private: |
| 134 | + static constexpr size_t JNIENVINIT_FULL_TYPE_NAME_SIZE = calc_size (ANDROID_RUNTIME_NS_NAME, "."sv, JNIENVINIT_CLASS_NAME); |
| 135 | + static constexpr auto JNIENVINIT_FULL_TYPE_NAME_ARRAY = concat_string_views<JNIENVINIT_FULL_TYPE_NAME_SIZE> (ANDROID_RUNTIME_NS_NAME, "."sv, JNIENVINIT_CLASS_NAME); |
| 136 | + |
| 137 | + public: |
| 138 | + static constexpr std::string_view JNIENVINIT_FULL_TYPE_NAME { JNIENVINIT_FULL_TYPE_NAME_ARRAY.data () }; |
| 139 | + |
| 140 | + static constexpr std::string_view ANDROID_ENVIRONMENT_CLASS_NAME { "AndroidEnvironment" }; |
| 141 | + static constexpr std::string_view ANDROID_RUNTIME_INTERNAL_CLASS_NAME { "AndroidRuntimeInternal" }; |
| 142 | + }; |
| 143 | +} |
0 commit comments