1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <android/binder_ibinder.h> 20 21 #if !defined(__ANDROID_APEX__) && !defined(__ANDROID_VNDK__) 22 #include <binder/IBinder.h> 23 #endif 24 25 __BEGIN_DECLS 26 27 /** 28 * Makes calls to AIBinder_getCallingSid work if the kernel supports it. This 29 * must be called on a local binder server before it is sent out to any othe 30 * process. If this is a remote binder, it will abort. If the kernel doesn't 31 * support this feature, you'll always get null from AIBinder_getCallingSid. 32 * 33 * \param binder local server binder to request security contexts on 34 */ 35 void AIBinder_setRequestingSid(AIBinder* binder, bool requestingSid) __INTRODUCED_IN(31); 36 37 /** 38 * Returns the selinux context of the callee. 39 * 40 * In order for this to work, the following conditions must be met: 41 * - The kernel must be new enough to support this feature. 42 * - The server must have called AIBinder_setRequestingSid. 43 * - The callee must be a remote process. 44 * 45 * \return security context or null if unavailable. The lifetime of this context 46 * is the lifetime of the transaction. 47 */ 48 __attribute__((warn_unused_result)) const char* AIBinder_getCallingSid() __INTRODUCED_IN(31); 49 50 __END_DECLS 51 52 #if !defined(__ANDROID_APEX__) && !defined(__ANDROID_VNDK__) 53 54 /** 55 * Get libbinder version of binder from AIBinder. 56 * 57 * WARNING: function calls to a local object on the other side of this function 58 * will parcel. When converting between binders, keep in mind it is not as 59 * efficient as a direct function call. 60 * 61 * \param binder binder with ownership retained by the client 62 * \return platform binder object 63 */ 64 android::sp<android::IBinder> AIBinder_toPlatformBinder(AIBinder* binder); 65 66 /** 67 * Get libbinder_ndk version of binder from platform binder. 68 * 69 * WARNING: function calls to a local object on the other side of this function 70 * will parcel. When converting between binders, keep in mind it is not as 71 * efficient as a direct function call. 72 * 73 * \param binder platform binder which may be from anywhere (doesn't have to be 74 * created with libbinder_ndK) 75 * \return binder with one reference count of ownership given to the client. See 76 * AIBinder_decStrong 77 */ 78 AIBinder* AIBinder_fromPlatformBinder(const android::sp<android::IBinder>& binder); 79 80 #endif 81