blob: d931785cd4312c1bc42a9e7082d8cc8045125237 [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
Jooyung Han1f65e772019-03-07 16:55:04 +090020#include <android_util_Binder.h>
Steven Moreland02f75652018-09-18 14:08:30 -070021
22using ::android::IBinder;
Jooyung Han1f65e772019-03-07 16:55:04 +090023using ::android::ibinderForJavaObject;
24using ::android::javaObjectForIBinder;
Steven Moreland02f75652018-09-18 14:08:30 -070025using ::android::sp;
26
27AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) {
Steven Moreland81311c02019-01-22 16:02:02 -080028 if (binder == nullptr) {
29 return nullptr;
30 }
31
Jooyung Han1f65e772019-03-07 16:55:04 +090032 sp<IBinder> ibinder = ibinderForJavaObject(env, binder);
Steven Moreland02f75652018-09-18 14:08:30 -070033 sp<AIBinder> cbinder = ABpBinder::lookupOrCreateFromBinder(ibinder);
34 AIBinder_incStrong(cbinder.get());
35
36 return cbinder.get();
37}
38
39jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) {
40 if (binder == nullptr) {
41 return nullptr;
42 }
43
Jooyung Han1f65e772019-03-07 16:55:04 +090044 return javaObjectForIBinder(env, binder->getBinder());
Steven Moreland02f75652018-09-18 14:08:30 -070045}