blob: 2332b3e45548939d4c0178f0aa9d9030c0a8a09f [file] [log] [blame]
Glenn Kasten6f1c1912013-01-18 15:31:41 -08001/*
2 * Copyright (C) 2013 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 "MediaLog"
18//#define LOG_NDEBUG 0
19
20#include <sys/mman.h>
21#include <utils/Log.h>
22#include <media/nbaio/NBLog.h>
23#include <private/android_filesystem_config.h>
24#include "MediaLogService.h"
25
26namespace android {
27
28void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, const char *name)
29{
30 if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0 ||
31 size < kMinSize || size > kMaxSize || name == NULL ||
32 shared->size() < NBLog::Timeline::sharedSize(size)) {
33 return;
34 }
35 sp<NBLog::Reader> reader(new NBLog::Reader(size, shared));
36 NamedReader namedReader(reader, name);
37 Mutex::Autolock _l(mLock);
38 mNamedReaders.add(namedReader);
39}
40
41void MediaLogService::unregisterWriter(const sp<IMemory>& shared)
42{
43 if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0) {
44 return;
45 }
46 Mutex::Autolock _l(mLock);
47 for (size_t i = 0; i < mNamedReaders.size(); ) {
48 if (mNamedReaders[i].reader()->isIMemory(shared)) {
49 mNamedReaders.removeAt(i);
50 } else {
51 i++;
52 }
53 }
54}
55
56status_t MediaLogService::dump(int fd, const Vector<String16>& args)
57{
58 Vector<NamedReader> namedReaders;
59 {
60 Mutex::Autolock _l(mLock);
61 namedReaders = mNamedReaders;
62 }
63 for (size_t i = 0; i < namedReaders.size(); i++) {
64 const NamedReader& namedReader = namedReaders[i];
65 if (fd >= 0) {
66 fdprintf(fd, "\n%s:\n", namedReader.name());
67 } else {
68 ALOGI("%s:", namedReader.name());
69 }
70 namedReader.reader()->dump(fd, 0 /*indent*/);
71 }
72 return NO_ERROR;
73}
74
75status_t MediaLogService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
76 uint32_t flags)
77{
78 return BnMediaLogService::onTransact(code, data, reply, flags);
79}
80
81} // namespace android