| Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 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 | #include <private/binder/Static.h> | 
 | 26 |  | 
 | 27 | namespace android { | 
 | 28 |  | 
 | 29 | // ---------------------------------------------------------------------- | 
 | 30 |  | 
 | 31 | class BpResultReceiver : public BpInterface<IResultReceiver> | 
 | 32 | { | 
 | 33 | public: | 
| Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 34 |     explicit BpResultReceiver(const sp<IBinder>& impl) | 
| Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 35 |         : BpInterface<IResultReceiver>(impl) | 
 | 36 |     { | 
 | 37 |     } | 
 | 38 |  | 
 | 39 |     virtual void send(int32_t resultCode) { | 
 | 40 |         Parcel data; | 
 | 41 |         data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor()); | 
 | 42 |         data.writeInt32(resultCode); | 
| Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 43 |         remote()->transact(OP_SEND, data, nullptr, IBinder::FLAG_ONEWAY); | 
| Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 44 |     } | 
 | 45 | }; | 
 | 46 |  | 
 | 47 | IMPLEMENT_META_INTERFACE(ResultReceiver, "com.android.internal.os.IResultReceiver"); | 
 | 48 |  | 
 | 49 | // ---------------------------------------------------------------------- | 
 | 50 |  | 
| Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 51 | // NOLINTNEXTLINE(google-default-arguments) | 
| Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 52 | status_t BnResultReceiver::onTransact( | 
 | 53 |     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
 | 54 | { | 
 | 55 |     switch(code) { | 
 | 56 |         case OP_SEND: { | 
 | 57 |             CHECK_INTERFACE(IResultReceiver, data, reply); | 
 | 58 |             int32_t resultCode = data.readInt32(); | 
 | 59 |             send(resultCode); | 
| Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 60 |             if (reply != nullptr) { | 
| Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 61 |                 reply->writeNoException(); | 
 | 62 |             } | 
 | 63 |             return NO_ERROR; | 
 | 64 |         } break; | 
 | 65 |         default: | 
 | 66 |             return BBinder::onTransact(code, data, reply, flags); | 
 | 67 |     } | 
 | 68 | } | 
 | 69 |  | 
 | 70 | }; // namespace android |