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 #include <android/binder_ibinder_jni.h>
18 #include "ibinder_internal.h"
19
20 #include <android_util_Binder.h>
21
22 using ::android::IBinder;
23 using ::android::ibinderForJavaObject;
24 using ::android::javaObjectForIBinder;
25 using ::android::sp;
26
AIBinder_fromJavaBinder(JNIEnv * env,jobject binder)27 AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) {
28 if (binder == nullptr) {
29 return nullptr;
30 }
31
32 sp<IBinder> ibinder = ibinderForJavaObject(env, binder);
33 sp<AIBinder> cbinder = ABpBinder::lookupOrCreateFromBinder(ibinder);
34 AIBinder_incStrong(cbinder.get());
35
36 return cbinder.get();
37 }
38
AIBinder_toJavaBinder(JNIEnv * env,AIBinder * binder)39 jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) {
40 if (binder == nullptr) {
41 return nullptr;
42 }
43
44 return javaObjectForIBinder(env, binder->getBinder());
45 }
46