blob: 683fdf3fe1725becac304d4ff627301a44fbbca1 [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>
Glenn Kastenbc512072013-03-26 15:09:04 -070022#include <binder/PermissionCache.h>
Glenn Kasten6f1c1912013-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 Kastenbc512072013-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))) {
Glenn Kasten5ea77ae2013-04-18 15:26:47 -070063 fdprintf(fd, "Permission Denial: can't dump media.log from pid=%d, uid=%d\n",
64 IPCThreadState::self()->getCallingPid(),
65 IPCThreadState::self()->getCallingUid());
Glenn Kastenbc512072013-03-26 15:09:04 -070066 return NO_ERROR;
67 }
68
Glenn Kasten6f1c1912013-01-18 15:31:41 -080069 Vector<NamedReader> namedReaders;
70 {
71 Mutex::Autolock _l(mLock);
72 namedReaders = mNamedReaders;
73 }
74 for (size_t i = 0; i < namedReaders.size(); i++) {
75 const NamedReader& namedReader = namedReaders[i];
76 if (fd >= 0) {
77 fdprintf(fd, "\n%s:\n", namedReader.name());
78 } else {
79 ALOGI("%s:", namedReader.name());
80 }
81 namedReader.reader()->dump(fd, 0 /*indent*/);
82 }
83 return NO_ERROR;
84}
85
86status_t MediaLogService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
87 uint32_t flags)
88{
89 return BnMediaLogService::onTransact(code, data, reply, flags);
90}
91
92} // namespace android