blob: 87b295a41538bee7acc31aad127c4b190a47fcb4 [file] [log] [blame]
Sudheer Shanka6ef26f12016-11-23 15:52:26 -08001/*
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
Nick Kralevichec9ec7d2016-12-17 19:47:27 -080017#include <unistd.h>
18#include <fcntl.h>
19
Sudheer Shanka6ef26f12016-11-23 15:52:26 -080020#include <binder/IActivityManager.h>
21
22#include <binder/Parcel.h>
23
24namespace android {
25
26// ------------------------------------------------------------------------------------
27
28class BpActivityManager : public BpInterface<IActivityManager>
29{
30public:
31 explicit BpActivityManager(const sp<IBinder>& impl)
32 : BpInterface<IActivityManager>(impl)
33 {
34 }
35
36 virtual int openContentUri(const String16& stringUri)
37 {
38 Parcel data, reply;
39 data.writeString16(stringUri);
40 status_t ret = remote()->transact(OPEN_CONTENT_URI_TRANSACTION, data, & reply);
41 int fd = -1;
42 if (ret == NO_ERROR) {
43 int32_t exceptionCode = reply.readExceptionCode();
44 if (!exceptionCode) {
45 // Success is indicated here by a nonzero int followed by the fd;
46 // failure by a zero int with no data following.
47 if (reply.readInt32() != 0) {
Nick Kralevichec9ec7d2016-12-17 19:47:27 -080048 fd = fcntl(reply.readParcelFileDescriptor(), F_DUPFD_CLOEXEC, 0);
Sudheer Shanka6ef26f12016-11-23 15:52:26 -080049 }
50 } else {
51 // An exception was thrown back; fall through to return failure
52 ALOGD("openContentUri(%s) caught exception %d\n",
53 String8(stringUri).string(), exceptionCode);
54 }
55 }
56 return fd;
57 }
58};
59
60// ------------------------------------------------------------------------------------
61
62IMPLEMENT_META_INTERFACE(ActivityManager, "android.app.IActivityManager");
63
64}; // namespace android