blob: 8b973019eec066fec66dd5f41eab44ba8f602996 [file] [log] [blame]
Dianne Hackborn1941a402016-08-29 12:30:43 -07001/*
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#define LOG_TAG "ShellCallback"
18
19#include <binder/IShellCallback.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
27namespace android {
28
29// ----------------------------------------------------------------------
30
31class BpShellCallback : public BpInterface<IShellCallback>
32{
33public:
34 explicit BpShellCallback(const sp<IBinder>& impl)
35 : BpInterface<IShellCallback>(impl)
36 {
37 }
38
39 virtual int openOutputFile(const String16& path, const String16& seLinuxContext) {
40 Parcel data, reply;
41 data.writeInterfaceToken(IShellCallback::getInterfaceDescriptor());
42 data.writeString16(path);
43 data.writeString16(seLinuxContext);
44 remote()->transact(OP_OPEN_OUTPUT_FILE, data, &reply, 0);
45 reply.readExceptionCode();
46 int fd = reply.readParcelFileDescriptor();
47 return fd >= 0 ? dup(fd) : fd;
48
49 }
50};
51
52IMPLEMENT_META_INTERFACE(ShellCallback, "com.android.internal.os.IShellCallback");
53
54// ----------------------------------------------------------------------
55
56status_t BnShellCallback::onTransact(
57 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
58{
59 switch(code) {
60 case OP_OPEN_OUTPUT_FILE: {
61 CHECK_INTERFACE(IShellCallback, data, reply);
62 String16 path(data.readString16());
63 String16 seLinuxContext(data.readString16());
64 int fd = openOutputFile(path, seLinuxContext);
65 if (reply != NULL) {
66 reply->writeNoException();
67 if (fd >= 0) {
68 reply->writeInt32(1);
69 reply->writeParcelFileDescriptor(fd, true);
70 } else {
71 reply->writeInt32(0);
72 }
73 } else if (fd >= 0) {
74 close(fd);
75 }
76 return NO_ERROR;
77 } break;
78 default:
79 return BBinder::onTransact(code, data, reply, flags);
80 }
81}
82
83}; // namespace android