1 /* 2 * Copyright (C) 2018 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 /** 18 * @addtogroup NdkBinder 19 * @{ 20 */ 21 22 /** 23 * @file binder_ibinder_jni.h 24 * @brief Conversions between AIBinder and android.os.IBinder 25 */ 26 27 #pragma once 28 29 #include <android/binder_ibinder.h> 30 31 #include <jni.h> 32 33 __BEGIN_DECLS 34 35 /** 36 * Converts an android.os.IBinder object into an AIBinder* object. 37 * 38 * If the binder is null, null is returned. If this binder object was originally an 39 * AIBinder object, the original object is returned. The returned object has one refcount 40 * associated with it, and so this should be accompanied with an AIBinder_decStrong call. 41 * 42 * Available since API level 29. 43 * 44 * \param env Java environment. Must not be null. 45 * \param binder android.os.IBinder java object. 46 * 47 * \return an AIBinder object representing the Java binder object. If either parameter is null, or 48 * the Java object is of the wrong type, this will return null. 49 */ 50 __attribute__((warn_unused_result)) AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) 51 __INTRODUCED_IN(29); 52 53 /** 54 * Converts an AIBinder* object into an android.os.IBinder object. 55 * 56 * If the binder is null, null is returned. If this binder object was originally an IBinder object, 57 * the original java object will be returned. 58 * 59 * WARNING: this function returns global and local references. This can be 60 * figured out using GetObjectRefType. Though, when this function is called 61 * from within a Java context, the local ref will automatically be cleaned 62 * up. If this is called outside of a Java frame, 63 * PushObjectFrame/PopObjectFrame can simulate this automatic cleanup. 64 * 65 * Available since API level 29. 66 * 67 * \param env Java environment. Must not be null. 68 * \param binder the object to convert. 69 * 70 * \return an android.os.IBinder object or null if the parameters were null. 71 */ 72 __attribute__((warn_unused_result)) jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) 73 __INTRODUCED_IN(29); 74 75 __END_DECLS 76 77 /** @} */ 78