Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [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 | #define LOG_TAG "MediaAnalytics" |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <inttypes.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <binder/Parcel.h> |
| 24 | #include <binder/IMemory.h> |
| 25 | #include <binder/IPCThreadState.h> |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 26 | |
| 27 | #include <utils/Errors.h> // for status_t |
| 28 | #include <utils/List.h> |
| 29 | #include <utils/Log.h> |
| 30 | #include <utils/String8.h> |
| 31 | |
| 32 | #include <media/MediaAnalyticsItem.h> |
| 33 | #include <media/IMediaAnalyticsService.h> |
| 34 | |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 35 | namespace android { |
| 36 | |
| 37 | enum { |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 38 | SUBMIT_ITEM_ONEWAY = IBinder::FIRST_CALL_TRANSACTION, |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpMediaAnalyticsService: public BpInterface<IMediaAnalyticsService> |
| 42 | { |
| 43 | public: |
| 44 | explicit BpMediaAnalyticsService(const sp<IBinder>& impl) |
| 45 | : BpInterface<IMediaAnalyticsService>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 49 | status_t submit(MediaAnalyticsItem *item) override |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 50 | { |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 51 | if (item == nullptr) { |
| 52 | return BAD_VALUE; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 53 | } |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 54 | ALOGV("%s: (ONEWAY) item=%s", __func__, item->toString().c_str()); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 55 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 56 | Parcel data; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 57 | data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor()); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 58 | item->writeToParcel(&data); |
| 59 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 60 | status_t err = remote()->transact( |
| 61 | SUBMIT_ITEM_ONEWAY, data, nullptr /* reply */, IBinder::FLAG_ONEWAY); |
| 62 | ALOGW_IF(err != NO_ERROR, "%s: bad response from service for submit, err=%d", |
| 63 | __func__, err); |
| 64 | return err; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 65 | } |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsService"); |
| 69 | |
| 70 | // ---------------------------------------------------------------------- |
| 71 | |
| 72 | status_t BnMediaAnalyticsService::onTransact( |
| 73 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 74 | { |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 75 | const int clientPid = IPCThreadState::self()->getCallingPid(); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 76 | |
| 77 | switch (code) { |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 78 | case SUBMIT_ITEM_ONEWAY: { |
| 79 | CHECK_INTERFACE(IMediaAnalyticsService, data, reply); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 80 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 81 | MediaAnalyticsItem * const item = MediaAnalyticsItem::create(); |
| 82 | if (item->readFromParcel(data) < 0) { |
| 83 | return BAD_VALUE; |
| 84 | } |
| 85 | item->setPid(clientPid); |
| 86 | const status_t status __unused = submitInternal(item, true /* release */); |
| 87 | return NO_ERROR; |
| 88 | } break; |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 89 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame] | 90 | default: |
| 91 | return BBinder::onTransact(code, data, reply, flags); |
Ray Essick | 3938dc6 | 2016-11-01 08:56:56 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
| 95 | // ---------------------------------------------------------------------------- |
| 96 | |
| 97 | } // namespace android |