blob: 1ab6653208278e2dfe7b947ae988257c6fcf8ba5 [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 item->writeToParcel(&data);
59
Andy Hunga87e69c2019-10-18 10:07:40 -070060 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 Essick3938dc62016-11-01 08:56:56 -070065 }
Ray Essick3938dc62016-11-01 08:56:56 -070066};
67
68IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsService");
69
70// ----------------------------------------------------------------------
71
72status_t BnMediaAnalyticsService::onTransact(
73 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
74{
Andy Hunga87e69c2019-10-18 10:07:40 -070075 const int clientPid = IPCThreadState::self()->getCallingPid();
Ray Essick3938dc62016-11-01 08:56:56 -070076
77 switch (code) {
Andy Hunga87e69c2019-10-18 10:07:40 -070078 case SUBMIT_ITEM_ONEWAY: {
79 CHECK_INTERFACE(IMediaAnalyticsService, data, reply);
Ray Essick3938dc62016-11-01 08:56:56 -070080
Andy Hunga87e69c2019-10-18 10:07:40 -070081 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 Essick3938dc62016-11-01 08:56:56 -070089
Andy Hunga87e69c2019-10-18 10:07:40 -070090 default:
91 return BBinder::onTransact(code, data, reply, flags);
Ray Essick3938dc62016-11-01 08:56:56 -070092 }
93}
94
95// ----------------------------------------------------------------------------
96
97} // namespace android