1 /* 2 * Copyright (C) 2024, 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 #include "utils.h" 18 19 #include <android/binder_manager.h> 20 #include <com_android_os_statsd_flags.h> 21 22 namespace flags = com::android::os::statsd::flags; 23 getStatsdBinder()24ndk::SpAIBinder getStatsdBinder() { 25 ndk::SpAIBinder binder; 26 // below ifs cannot be combined into single statement due to the way how 27 // macro __builtin_available is handler by compiler: 28 // - it should be used explicitly & independently to guard the corresponding API call 29 // once use_wait_for_service_api flag will be finalized, external if/else pair will be 30 // removed 31 #ifdef __ANDROID__ 32 if (flags::use_wait_for_service_api()) { 33 if (__builtin_available(android __ANDROID_API_S__, *)) { 34 binder.set(AServiceManager_waitForService("stats")); 35 } else { 36 binder.set(AServiceManager_getService("stats")); 37 } 38 } else { 39 binder.set(AServiceManager_getService("stats")); 40 } 41 #endif // __ANDROID__ 42 return binder; 43 }