1 // Copyright 2023, The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <stdint.h> 18 #include <sys/cdefs.h> 19 20 __BEGIN_DECLS 21 22 /** 23 * AApexInfo represents an information object for an APEX including name 24 * and version. 25 */ 26 struct AApexInfo; 27 typedef struct AApexInfo AApexInfo; 28 29 /** 30 * AApexInfoError tells the error when AApexInfo_create() fails. 31 */ 32 typedef enum AApexInfoError : int32_t { 33 /* No error */ 34 AAPEXINFO_OK, 35 /* The calling process is not from an APEX. */ 36 AAPEXINFO_NO_APEX, 37 /* Failed to get the executable path of the calling process. 38 * See the log for details. 39 */ 40 AAPEXINFO_ERROR_EXECUTABLE_PATH, 41 /* The current APEX is ill-formed. eg) No/invalid apex_manifest.pb. 42 * See the log for details. 43 */ 44 AAPEXINFO_INVALID_APEX, 45 } AApexInfoError; 46 47 // Defining #llndk symbols 48 #if defined(__ANDROID_VNDK__) || !defined(__ANDROID_APEX__) 49 50 /** 51 * Creates an AApexInfo object from the current calling executable. For example, 52 * when called by a binary from /apex/com.android.foo/bin/foo, this will set an 53 * out parameter with an AApexInfo object corresponding the APEX 54 * "com.android.foo". The allocated AApexInfo object has to be deallocated using 55 * AApexInfo_destroy(). 56 * 57 * \param info out parameter for an AApexInfo object for the current APEX. Null 58 * when called from a non-APEX executable. 59 * 60 * \returns AApexInfoError 61 */ 62 __attribute__((warn_unused_result)) AApexInfoError AApexInfo_create( 63 AApexInfo *_Nullable *_Nonnull info) __INTRODUCED_IN(__ANDROID_API_V__); 64 65 /** 66 * Destroys an AApexInfo object created by AApexInfo_create(). 67 * 68 * \param info pointer to the AApexInfo object created by AApexInfo_create() 69 */ 70 void AApexInfo_destroy(AApexInfo *_Nonnull info) 71 __INTRODUCED_IN(__ANDROID_API_V__); 72 73 /** 74 * Returns a C-string for the APEX name. 75 * 76 * NOTE: The lifetime of the returned C-string is bound to the AApexInfo object. 77 * So, it has to be copied if it needs to be alive even after AApexInfo_destroy 78 * is called. 79 * 80 * \param info pointer to the AApexInfo object created by AApexInfo_create() 81 * 82 * \return the APEX name. 83 */ 84 __attribute__((warn_unused_result)) 85 const char *_Nonnull AApexInfo_getName(const AApexInfo *_Nonnull info) 86 __INTRODUCED_IN(__ANDROID_API_V__); 87 88 /** 89 * Returns the APEX version. 90 * 91 * \param info pointer to the AApexInfo object created by AApexInfo_create() 92 * 93 * \return the APEX version. 94 */ 95 int64_t AApexInfo_getVersion(const AApexInfo *_Nonnull info) 96 __INTRODUCED_IN(__ANDROID_API_V__); 97 98 #endif 99 100 // AApexSupport_loadLibrary is private to platform yet. 101 #if !defined(__ANDROID_VNDK__) && !defined(__ANDROID_APEX__) 102 /** 103 * Opens a library from a given apex and returns its handle. 104 * 105 * \param name the name of the library to open 106 * 107 * \param apexName the name of the APEX which to load the library from. Note 108 * that the apex should be visible in linker configuration. You might need to 109 * set `"visible": true` in its etc/linker.config.pb. 110 * 111 * \param flag the same as dlopen() flag. 112 * 113 * \return nonnull handle for the loaded object on success. null otherwise. 114 */ 115 __attribute__((warn_unused_result)) void *_Nullable AApexSupport_loadLibrary( 116 const char *_Nonnull name, const char *_Nonnull apexName, int flag); 117 #endif 118 119 __END_DECLS 120