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