1 /* 2 * Copyright (C) 2016 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 #ifndef ANDROID_OS_HW_PARCEL_H 18 #define ANDROID_OS_HW_PARCEL_H 19 20 #include <android-base/macros.h> 21 #include <hwbinder/IBinder.h> 22 #include <hwbinder/Parcel.h> 23 #include <jni.h> 24 #include <utils/RefBase.h> 25 26 #include "android_os_HwBlob.h" 27 #include "hwbinder/EphemeralStorage.h" 28 29 namespace android { 30 31 struct JHwParcel : public RefBase { 32 static void InitClass(JNIEnv *env); 33 34 static sp<JHwParcel> SetNativeContext( 35 JNIEnv *env, jobject thiz, const sp<JHwParcel> &context); 36 37 static sp<JHwParcel> GetNativeContext(JNIEnv *env, jobject thiz); 38 39 static jobject NewObject(JNIEnv *env); 40 41 JHwParcel(JNIEnv *env, jobject thiz); 42 43 void setParcel(hardware::Parcel *parcel, bool assumeOwnership); 44 hardware::Parcel *getParcel(); 45 46 EphemeralStorage *getStorage(); 47 48 void addBlob(const sp<JHwBlob> &blob); 49 50 void setTransactCallback(::android::hardware::IBinder::TransactCallback cb); 51 52 void send(); 53 bool wasSent() const; 54 55 protected: 56 virtual ~JHwParcel(); 57 58 private: 59 hardware::Parcel *mParcel; 60 bool mOwnsParcel; 61 62 EphemeralStorage mStorage; 63 64 ::android::hardware::IBinder::TransactCallback mTransactCallback; 65 bool mWasSent; 66 std::vector<sp<JHwBlob>> mBlobs; 67 68 DISALLOW_COPY_AND_ASSIGN(JHwParcel); 69 }; 70 71 void signalExceptionForError(JNIEnv *env, status_t err, bool canThrowRemoteException = false); 72 int register_android_os_HwParcel(JNIEnv *env); 73 74 } // namespace android 75 76 #endif // ANDROID_OS_HW_PARCEL_H 77