blob: f60749d1d6e4f7416a948c3e7870d24c29366ff4 [file] [log] [blame]
Glenn Kastenfdf4e4f2013-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>
Glenn Kasten4ee99622013-03-26 15:09:04 -070022#include <binder/PermissionCache.h>
Glenn Kastenfdf4e4f2013-01-18 15:31:41 -080023#include <media/nbaio/NBLog.h>
24#include <private/android_filesystem_config.h>
25#include "MediaLogService.h"
26
27namespace android {
28
29void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, const char *name)
30{
31 if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0 ||
32 size < kMinSize || size > kMaxSize || name == NULL ||
33 shared->size() < NBLog::Timeline::sharedSize(size)) {
34 return;
35 }
36 sp<NBLog::Reader> reader(new NBLog::Reader(size, shared));
37 NamedReader namedReader(reader, name);
38 Mutex::Autolock _l(mLock);
39 mNamedReaders.add(namedReader);
40}
41
42void MediaLogService::unregisterWriter(const sp<IMemory>& shared)
43{
44 if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0) {
45 return;
46 }
47 Mutex::Autolock _l(mLock);
48 for (size_t i = 0; i < mNamedReaders.size(); ) {
49 if (mNamedReaders[i].reader()->isIMemory(shared)) {
50 mNamedReaders.removeAt(i);
51 } else {
52 i++;
53 }
54 }
55}
56
57status_t MediaLogService::dump(int fd, const Vector<String16>& args)
58{
Glenn Kasten4ee99622013-03-26 15:09:04 -070059 // FIXME merge with similar but not identical code at services/audioflinger/ServiceUtilities.cpp
60 static const String16 sDump("android.permission.DUMP");
61 if (!(IPCThreadState::self()->getCallingUid() == AID_MEDIA ||
62 PermissionCache::checkCallingPermission(sDump))) {
63 fdprintf(fd, "Permission denied.\n");
64 return NO_ERROR;
65 }
66
Glenn Kastenfdf4e4f2013-01-18 15:31:41 -080067 Vector<NamedReader> namedReaders;
68 {
69 Mutex::Autolock _l(mLock);
70 namedReaders = mNamedReaders;
71 }
72 for (size_t i = 0; i < namedReaders.size(); i++) {
73 const NamedReader& namedReader = namedReaders[i];
74 if (fd >= 0) {
75 fdprintf(fd, "\n%s:\n", namedReader.name());
76 } else {
77 ALOGI("%s:", namedReader.name());
78 }
79 namedReader.reader()->dump(fd, 0 /*indent*/);
80 }
81 return NO_ERROR;
82}
83
84status_t MediaLogService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
85 uint32_t flags)
86{
87 return BnMediaLogService::onTransact(code, data, reply, flags);
88}
89
90} // namespace android