1 /* 2 * Copyright (C) 2021 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 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * The content of libsplitapp_number_provider_proxy.so 23 */ 24 #ifdef ANDROID_SPLIT_APP_NUMBER_PROXY_SO 25 #include <dlfcn.h> 26 27 const char* kFunctionName = "get_number"; 28 29 typedef int (*pFuncGetNumber)(); 30 get_number(const char * libraryFileName)31int get_number(const char* libraryFileName) { 32 void *handle; 33 char *error; 34 handle = dlopen (libraryFileName, RTLD_LAZY); 35 if (!handle) { 36 return -1; 37 } 38 pFuncGetNumber functionGetNumber = (pFuncGetNumber) dlsym(handle, kFunctionName); 39 if ((error = dlerror()) != NULL) { 40 dlclose(handle); 41 return -2; 42 } 43 int ret = functionGetNumber(); 44 dlclose(handle); 45 46 return ret; 47 } 48 get_number_a()49int get_number_a() { 50 return get_number("libsplitapp_number_provider_a.so"); 51 } 52 get_number_b()53int get_number_b() { 54 return get_number("libsplitapp_number_provider_b.so"); 55 } 56 57 #endif // ANDROID_SPLIT_APP_NUMBER_PROXY_SO 58 59 /** 60 * The content of libsplitapp_number_provider_a.so 61 */ 62 #ifdef ANDROID_SPLIT_APP_NUMBER_PROVIDER_A_SO get_number()63int get_number() { 64 return 7; 65 } 66 #endif // ANDROID_SPLIT_APP_NUMBER_PROVIDER_A_SO 67 68 69 /** 70 * The content of libsplitapp_number_provider_b.so 71 */ 72 #ifdef ANDROID_SPLIT_APP_NUMBER_PROVIDER_B_SO get_number()73int get_number() { 74 return 11; 75 } 76 #endif // ANDROID_SPLIT_APP_NUMBER_PROVIDER_B_SO 77 78 #ifdef __cplusplus 79 } 80 #endif 81