blob: baea2e87d397dee99b44fb9c55aa8729116654e6 [file] [log] [blame]
Steven Moreland02f75652018-09-18 14:08:30 -07001/*
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
22using ::android::IBinder;
23using ::android::ibinderForJavaObject;
24using ::android::javaObjectForIBinder;
25using ::android::sp;
26
27AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) {
28 sp<IBinder> ibinder = ibinderForJavaObject(env, binder);
29
30 sp<AIBinder> cbinder = ABpBinder::lookupOrCreateFromBinder(ibinder);
31 AIBinder_incStrong(cbinder.get());
32
33 return cbinder.get();
34}
35
36jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) {
37 if (binder == nullptr) {
38 return nullptr;
39 }
40
41 return javaObjectForIBinder(env, binder->getBinder());
42}