1 /* 2 * Copyright (C) 2015 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 #define LOG_TAG "ResultReceiver" 18 19 #include <binder/IResultReceiver.h> 20 21 #include <utils/Log.h> 22 #include <binder/Parcel.h> 23 #include <utils/String8.h> 24 25 namespace android { 26 27 // ---------------------------------------------------------------------- 28 29 class BpResultReceiver : public BpInterface<IResultReceiver> 30 { 31 public: BpResultReceiver(const sp<IBinder> & impl)32 explicit BpResultReceiver(const sp<IBinder>& impl) 33 : BpInterface<IResultReceiver>(impl) 34 { 35 } 36 send(int32_t resultCode)37 virtual void send(int32_t resultCode) { 38 Parcel data; 39 data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor()); 40 data.writeInt32(resultCode); 41 remote()->transact(OP_SEND, data, nullptr, IBinder::FLAG_ONEWAY); 42 } 43 }; 44 45 IMPLEMENT_META_INTERFACE(ResultReceiver, "com.android.internal.os.IResultReceiver") 46 47 // ---------------------------------------------------------------------- 48 49 // NOLINTNEXTLINE(google-default-arguments) 50 status_t BnResultReceiver::onTransact( 51 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 52 { 53 switch(code) { 54 case OP_SEND: { 55 CHECK_INTERFACE(IResultReceiver, data, reply); 56 int32_t resultCode = data.readInt32(); 57 send(resultCode); 58 if (reply != nullptr) { 59 reply->writeNoException(); 60 } 61 return NO_ERROR; 62 } break; 63 default: 64 return BBinder::onTransact(code, data, reply, flags); 65 } 66 } 67 68 } // namespace android 69