Steven Moreland | 02f7565 | 2018-09-18 14:08:30 -0700 | [diff] [blame] | 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 | |
Jooyung Han | 1f65e77 | 2019-03-07 16:55:04 +0900 | [diff] [blame] | 20 | #include <android_util_Binder.h> |
Steven Moreland | 02f7565 | 2018-09-18 14:08:30 -0700 | [diff] [blame] | 21 | |
| 22 | using ::android::IBinder; |
Jooyung Han | 1f65e77 | 2019-03-07 16:55:04 +0900 | [diff] [blame] | 23 | using ::android::ibinderForJavaObject; |
| 24 | using ::android::javaObjectForIBinder; |
Steven Moreland | 02f7565 | 2018-09-18 14:08:30 -0700 | [diff] [blame] | 25 | using ::android::sp; |
| 26 | |
| 27 | AIBinder* AIBinder_fromJavaBinder(JNIEnv* env, jobject binder) { |
Steven Moreland | 81311c0 | 2019-01-22 16:02:02 -0800 | [diff] [blame] | 28 | if (binder == nullptr) { |
| 29 | return nullptr; |
| 30 | } |
| 31 | |
Jooyung Han | 1f65e77 | 2019-03-07 16:55:04 +0900 | [diff] [blame] | 32 | sp<IBinder> ibinder = ibinderForJavaObject(env, binder); |
Steven Moreland | 02f7565 | 2018-09-18 14:08:30 -0700 | [diff] [blame] | 33 | sp<AIBinder> cbinder = ABpBinder::lookupOrCreateFromBinder(ibinder); |
| 34 | AIBinder_incStrong(cbinder.get()); |
| 35 | |
| 36 | return cbinder.get(); |
| 37 | } |
| 38 | |
| 39 | jobject AIBinder_toJavaBinder(JNIEnv* env, AIBinder* binder) { |
| 40 | if (binder == nullptr) { |
| 41 | return nullptr; |
| 42 | } |
| 43 | |
Jooyung Han | 1f65e77 | 2019-03-07 16:55:04 +0900 | [diff] [blame] | 44 | return javaObjectForIBinder(env, binder->getBinder()); |
Steven Moreland | 02f7565 | 2018-09-18 14:08:30 -0700 | [diff] [blame] | 45 | } |