blob: 60ece7269cd25477a4b6b41dcddc1aab39397820 [file] [log] [blame]
Dianne Hackborn23eb1e22015-10-07 17:35:27 -07001/*
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
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070021#include <binder/Parcel.h>
22#include <utils/String8.h>
23
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070024namespace android {
25
26// ----------------------------------------------------------------------
27
28class BpResultReceiver : public BpInterface<IResultReceiver>
29{
30public:
Chih-Hung Hsiehc4067912016-05-03 14:03:27 -070031 explicit BpResultReceiver(const sp<IBinder>& impl)
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070032 : BpInterface<IResultReceiver>(impl)
33 {
34 }
35
36 virtual void send(int32_t resultCode) {
37 Parcel data;
38 data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor());
39 data.writeInt32(resultCode);
Yi Kongfdd8da92018-06-07 17:52:27 -070040 remote()->transact(OP_SEND, data, nullptr, IBinder::FLAG_ONEWAY);
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070041 }
42};
43
Jooyung Hanc91e3cb2020-11-25 06:38:17 +090044IMPLEMENT_META_INTERFACE(ResultReceiver, "com.android.internal.os.IResultReceiver")
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070045
46// ----------------------------------------------------------------------
47
Jiyong Parkb86c8662018-10-29 23:01:57 +090048// NOLINTNEXTLINE(google-default-arguments)
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070049status_t BnResultReceiver::onTransact(
50 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
51{
52 switch(code) {
53 case OP_SEND: {
54 CHECK_INTERFACE(IResultReceiver, data, reply);
55 int32_t resultCode = data.readInt32();
56 send(resultCode);
Yi Kongfdd8da92018-06-07 17:52:27 -070057 if (reply != nullptr) {
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070058 reply->writeNoException();
59 }
60 return NO_ERROR;
61 } break;
62 default:
63 return BBinder::onTransact(code, data, reply, flags);
64 }
65}
66
Steven Moreland61ff8492019-09-26 16:05:45 -070067} // namespace android