blob: 4324f6d4c0b21398778d115e2bac7fd305b53d1a [file] [log] [blame]
Ray Essick3938dc62016-11-01 08:56:56 -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 "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 Essick3938dc62016-11-01 08:56:56 -070026
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 Essick3938dc62016-11-01 08:56:56 -070035namespace android {
36
37enum {
Andy Hunga87e69c2019-10-18 10:07:40 -070038 SUBMIT_ITEM_ONEWAY = IBinder::FIRST_CALL_TRANSACTION,
Ray Essick3938dc62016-11-01 08:56:56 -070039};
40
41class BpMediaAnalyticsService: public BpInterface<IMediaAnalyticsService>
42{
43public:
44 explicit BpMediaAnalyticsService(const sp<IBinder>& impl)
45 : BpInterface<IMediaAnalyticsService>(impl)
46 {
47 }
48
Andy Hunga87e69c2019-10-18 10:07:40 -070049 status_t submit(MediaAnalyticsItem *item) override
Ray Essick3938dc62016-11-01 08:56:56 -070050 {
Andy Hunga87e69c2019-10-18 10:07:40 -070051 if (item == nullptr) {
52 return BAD_VALUE;
Ray Essick3938dc62016-11-01 08:56:56 -070053 }
Andy Hunga87e69c2019-10-18 10:07:40 -070054 ALOGV("%s: (ONEWAY) item=%s", __func__, item->toString().c_str());
Ray Essick3938dc62016-11-01 08:56:56 -070055
Andy Hunga87e69c2019-10-18 10:07:40 -070056 Parcel data;
Ray Essick3938dc62016-11-01 08:56:56 -070057 data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor());
Ray Essick3938dc62016-11-01 08:56:56 -070058
Andy Hung3253f2d2019-10-21 14:50:07 -070059 status_t status = item->writeToParcel(&data);
60 if (status != NO_ERROR) { // assume failure logged in item
61 return status;
62 }
63
64 status = remote()->transact(
Andy Hunga87e69c2019-10-18 10:07:40 -070065 SUBMIT_ITEM_ONEWAY, data, nullptr /* reply */, IBinder::FLAG_ONEWAY);
Andy Hung3253f2d2019-10-21 14:50:07 -070066 ALOGW_IF(status != NO_ERROR, "%s: bad response from service for submit, status=%d",
67 __func__, status);
68 return status;
Ray Essick3938dc62016-11-01 08:56:56 -070069 }
Ray Essick3938dc62016-11-01 08:56:56 -070070};
71
72IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsService");
73
74// ----------------------------------------------------------------------
75
76status_t BnMediaAnalyticsService::onTransact(
77 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
78{
Andy Hunga87e69c2019-10-18 10:07:40 -070079 const int clientPid = IPCThreadState::self()->getCallingPid();
Ray Essick3938dc62016-11-01 08:56:56 -070080
81 switch (code) {
Andy Hunga87e69c2019-10-18 10:07:40 -070082 case SUBMIT_ITEM_ONEWAY: {
83 CHECK_INTERFACE(IMediaAnalyticsService, data, reply);
Ray Essick3938dc62016-11-01 08:56:56 -070084
Andy Hunga87e69c2019-10-18 10:07:40 -070085 MediaAnalyticsItem * const item = MediaAnalyticsItem::create();
Andy Hung3253f2d2019-10-21 14:50:07 -070086 status_t status = item->readFromParcel(data);
87 if (status != NO_ERROR) { // assume failure logged in item
88 return status;
Andy Hunga87e69c2019-10-18 10:07:40 -070089 }
Andy Hung3253f2d2019-10-21 14:50:07 -070090 // TODO: remove this setPid.
Andy Hunga87e69c2019-10-18 10:07:40 -070091 item->setPid(clientPid);
Andy Hung3253f2d2019-10-21 14:50:07 -070092 status = submitInternal(item, true /* release */);
93 // assume failure logged by submitInternal
Andy Hunga87e69c2019-10-18 10:07:40 -070094 return NO_ERROR;
95 } break;
Ray Essick3938dc62016-11-01 08:56:56 -070096
Andy Hunga87e69c2019-10-18 10:07:40 -070097 default:
98 return BBinder::onTransact(code, data, reply, flags);
Ray Essick3938dc62016-11-01 08:56:56 -070099 }
100}
101
102// ----------------------------------------------------------------------------
103
104} // namespace android