Loading media/audioserver/Android.mk +5 −1 Original line number Diff line number Diff line Loading @@ -9,11 +9,14 @@ LOCAL_SHARED_LIBRARIES := \ libaudioflinger \ libaudiopolicyservice \ libbinder \ libcutils \ liblog \ libmedia \ libmedialogservice \ libnbaio \ libradioservice \ libsoundtriggerservice \ libutils \ libutils LOCAL_C_INCLUDES := \ frameworks/av/services/audioflinger \ Loading @@ -22,6 +25,7 @@ LOCAL_C_INCLUDES := \ frameworks/av/services/audiopolicy/common/include \ frameworks/av/services/audiopolicy/engine/interface \ frameworks/av/services/audiopolicy/service \ frameworks/av/services/medialog \ frameworks/av/services/radio \ frameworks/av/services/soundtrigger \ $(call include-path-for, audio-utils) \ Loading media/audioserver/main_audioserver.cpp +98 −12 Original line number Diff line number Diff line Loading @@ -17,6 +17,11 @@ #define LOG_TAG "audioserver" //#define LOG_NDEBUG 0 #include <fcntl.h> #include <sys/prctl.h> #include <sys/wait.h> #include <cutils/properties.h> #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <binder/IServiceManager.h> Loading @@ -25,19 +30,99 @@ // from LOCAL_C_INCLUDES #include "AudioFlinger.h" #include "AudioPolicyService.h" #include "MediaLogService.h" #include "RadioService.h" #include "SoundTriggerHwService.h" using namespace android; int main(int argc __unused, char **argv __unused) int main(int argc __unused, char **argv) { signal(SIGPIPE, SIG_IGN); // TODO: add logging b/24511453#3 bool doLog = (bool) property_get_bool("ro.test_harness", 0); pid_t childPid; // FIXME The advantage of making the process containing media.log service the parent process of // the process that contains the other audio services, is that it allows us to collect more // detailed information such as signal numbers, stop and continue, resource usage, etc. // But it is also more complex. Consider replacing this by independent processes, and using // binder on death notification instead. if (doLog && (childPid = fork()) != 0) { // media.log service //prctl(PR_SET_NAME, (unsigned long) "media.log", 0, 0, 0); // unfortunately ps ignores PR_SET_NAME for the main thread, so use this ugly hack strcpy(argv[0], "media.log"); sp<ProcessState> proc(ProcessState::self()); MediaLogService::instantiate(); ProcessState::self()->startThreadPool(); for (;;) { siginfo_t info; int ret = waitid(P_PID, childPid, &info, WEXITED | WSTOPPED | WCONTINUED); if (ret == EINTR) { continue; } if (ret < 0) { break; } char buffer[32]; const char *code; switch (info.si_code) { case CLD_EXITED: code = "CLD_EXITED"; break; case CLD_KILLED: code = "CLD_KILLED"; break; case CLD_DUMPED: code = "CLD_DUMPED"; break; case CLD_STOPPED: code = "CLD_STOPPED"; break; case CLD_TRAPPED: code = "CLD_TRAPPED"; break; case CLD_CONTINUED: code = "CLD_CONTINUED"; break; default: snprintf(buffer, sizeof(buffer), "unknown (%d)", info.si_code); code = buffer; break; } struct rusage usage; getrusage(RUSAGE_CHILDREN, &usage); ALOG(LOG_ERROR, "media.log", "pid %d status %d code %s user %ld.%03lds sys %ld.%03lds", info.si_pid, info.si_status, code, usage.ru_utime.tv_sec, usage.ru_utime.tv_usec / 1000, usage.ru_stime.tv_sec, usage.ru_stime.tv_usec / 1000); sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.log")); if (binder != 0) { Vector<String16> args; binder->dump(-1, args); } switch (info.si_code) { case CLD_EXITED: case CLD_KILLED: case CLD_DUMPED: { ALOG(LOG_INFO, "media.log", "exiting"); _exit(0); // not reached } default: break; } } } else { // all other services if (doLog) { prctl(PR_SET_PDEATHSIG, SIGKILL); // if parent media.log dies before me, kill me also setpgid(0, 0); // but if I die first, don't kill my parent } sp<ProcessState> proc(ProcessState::self()); sp<IServiceManager> sm(defaultServiceManager()); sp<IServiceManager> sm = defaultServiceManager(); ALOGI("ServiceManager: %p", sm.get()); AudioFlinger::instantiate(); AudioPolicyService::instantiate(); Loading @@ -46,3 +131,4 @@ int main(int argc __unused, char **argv __unused) ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); } } media/mediaserver/Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libcamera_metadata\ libcameraservice \ libmedialogservice \ libresourcemanagerservice \ libcutils \ libmedia \ Loading services/audioflinger/AudioFlinger.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -184,8 +184,7 @@ AudioFlinger::AudioFlinger() mSystemReady(false) { getpid_cached = getpid(); // disable media.log until the service is reenabled, see b/26306954 const bool doLog = false; // property_get_bool("ro.test_harness", false); const bool doLog = property_get_bool("ro.test_harness", false); if (doLog) { mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters", MemoryHeapBase::READ_ONLY); Loading services/medialog/MediaLogService.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ namespace android { void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, const char *name) { if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0 || if (IPCThreadState::self()->getCallingUid() != AID_AUDIOSERVER || shared == 0 || size < kMinSize || size > kMaxSize || name == NULL || shared->size() < NBLog::Timeline::sharedSize(size)) { return; Loading @@ -41,7 +41,7 @@ void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, con void MediaLogService::unregisterWriter(const sp<IMemory>& shared) { if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0) { if (IPCThreadState::self()->getCallingUid() != AID_AUDIOSERVER || shared == 0) { return; } Mutex::Autolock _l(mLock); Loading @@ -58,7 +58,7 @@ status_t MediaLogService::dump(int fd, const Vector<String16>& args __unused) { // FIXME merge with similar but not identical code at services/audioflinger/ServiceUtilities.cpp static const String16 sDump("android.permission.DUMP"); if (!(IPCThreadState::self()->getCallingUid() == AID_MEDIA || if (!(IPCThreadState::self()->getCallingUid() == AID_AUDIOSERVER || PermissionCache::checkCallingPermission(sDump))) { dprintf(fd, "Permission Denial: can't dump media.log from pid=%d, uid=%d\n", IPCThreadState::self()->getCallingPid(), Loading Loading
media/audioserver/Android.mk +5 −1 Original line number Diff line number Diff line Loading @@ -9,11 +9,14 @@ LOCAL_SHARED_LIBRARIES := \ libaudioflinger \ libaudiopolicyservice \ libbinder \ libcutils \ liblog \ libmedia \ libmedialogservice \ libnbaio \ libradioservice \ libsoundtriggerservice \ libutils \ libutils LOCAL_C_INCLUDES := \ frameworks/av/services/audioflinger \ Loading @@ -22,6 +25,7 @@ LOCAL_C_INCLUDES := \ frameworks/av/services/audiopolicy/common/include \ frameworks/av/services/audiopolicy/engine/interface \ frameworks/av/services/audiopolicy/service \ frameworks/av/services/medialog \ frameworks/av/services/radio \ frameworks/av/services/soundtrigger \ $(call include-path-for, audio-utils) \ Loading
media/audioserver/main_audioserver.cpp +98 −12 Original line number Diff line number Diff line Loading @@ -17,6 +17,11 @@ #define LOG_TAG "audioserver" //#define LOG_NDEBUG 0 #include <fcntl.h> #include <sys/prctl.h> #include <sys/wait.h> #include <cutils/properties.h> #include <binder/IPCThreadState.h> #include <binder/ProcessState.h> #include <binder/IServiceManager.h> Loading @@ -25,19 +30,99 @@ // from LOCAL_C_INCLUDES #include "AudioFlinger.h" #include "AudioPolicyService.h" #include "MediaLogService.h" #include "RadioService.h" #include "SoundTriggerHwService.h" using namespace android; int main(int argc __unused, char **argv __unused) int main(int argc __unused, char **argv) { signal(SIGPIPE, SIG_IGN); // TODO: add logging b/24511453#3 bool doLog = (bool) property_get_bool("ro.test_harness", 0); pid_t childPid; // FIXME The advantage of making the process containing media.log service the parent process of // the process that contains the other audio services, is that it allows us to collect more // detailed information such as signal numbers, stop and continue, resource usage, etc. // But it is also more complex. Consider replacing this by independent processes, and using // binder on death notification instead. if (doLog && (childPid = fork()) != 0) { // media.log service //prctl(PR_SET_NAME, (unsigned long) "media.log", 0, 0, 0); // unfortunately ps ignores PR_SET_NAME for the main thread, so use this ugly hack strcpy(argv[0], "media.log"); sp<ProcessState> proc(ProcessState::self()); MediaLogService::instantiate(); ProcessState::self()->startThreadPool(); for (;;) { siginfo_t info; int ret = waitid(P_PID, childPid, &info, WEXITED | WSTOPPED | WCONTINUED); if (ret == EINTR) { continue; } if (ret < 0) { break; } char buffer[32]; const char *code; switch (info.si_code) { case CLD_EXITED: code = "CLD_EXITED"; break; case CLD_KILLED: code = "CLD_KILLED"; break; case CLD_DUMPED: code = "CLD_DUMPED"; break; case CLD_STOPPED: code = "CLD_STOPPED"; break; case CLD_TRAPPED: code = "CLD_TRAPPED"; break; case CLD_CONTINUED: code = "CLD_CONTINUED"; break; default: snprintf(buffer, sizeof(buffer), "unknown (%d)", info.si_code); code = buffer; break; } struct rusage usage; getrusage(RUSAGE_CHILDREN, &usage); ALOG(LOG_ERROR, "media.log", "pid %d status %d code %s user %ld.%03lds sys %ld.%03lds", info.si_pid, info.si_status, code, usage.ru_utime.tv_sec, usage.ru_utime.tv_usec / 1000, usage.ru_stime.tv_sec, usage.ru_stime.tv_usec / 1000); sp<IServiceManager> sm = defaultServiceManager(); sp<IBinder> binder = sm->getService(String16("media.log")); if (binder != 0) { Vector<String16> args; binder->dump(-1, args); } switch (info.si_code) { case CLD_EXITED: case CLD_KILLED: case CLD_DUMPED: { ALOG(LOG_INFO, "media.log", "exiting"); _exit(0); // not reached } default: break; } } } else { // all other services if (doLog) { prctl(PR_SET_PDEATHSIG, SIGKILL); // if parent media.log dies before me, kill me also setpgid(0, 0); // but if I die first, don't kill my parent } sp<ProcessState> proc(ProcessState::self()); sp<IServiceManager> sm(defaultServiceManager()); sp<IServiceManager> sm = defaultServiceManager(); ALOGI("ServiceManager: %p", sm.get()); AudioFlinger::instantiate(); AudioPolicyService::instantiate(); Loading @@ -46,3 +131,4 @@ int main(int argc __unused, char **argv __unused) ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); } }
media/mediaserver/Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libcamera_metadata\ libcameraservice \ libmedialogservice \ libresourcemanagerservice \ libcutils \ libmedia \ Loading
services/audioflinger/AudioFlinger.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -184,8 +184,7 @@ AudioFlinger::AudioFlinger() mSystemReady(false) { getpid_cached = getpid(); // disable media.log until the service is reenabled, see b/26306954 const bool doLog = false; // property_get_bool("ro.test_harness", false); const bool doLog = property_get_bool("ro.test_harness", false); if (doLog) { mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters", MemoryHeapBase::READ_ONLY); Loading
services/medialog/MediaLogService.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ namespace android { void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, const char *name) { if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0 || if (IPCThreadState::self()->getCallingUid() != AID_AUDIOSERVER || shared == 0 || size < kMinSize || size > kMaxSize || name == NULL || shared->size() < NBLog::Timeline::sharedSize(size)) { return; Loading @@ -41,7 +41,7 @@ void MediaLogService::registerWriter(const sp<IMemory>& shared, size_t size, con void MediaLogService::unregisterWriter(const sp<IMemory>& shared) { if (IPCThreadState::self()->getCallingUid() != AID_MEDIA || shared == 0) { if (IPCThreadState::self()->getCallingUid() != AID_AUDIOSERVER || shared == 0) { return; } Mutex::Autolock _l(mLock); Loading @@ -58,7 +58,7 @@ status_t MediaLogService::dump(int fd, const Vector<String16>& args __unused) { // FIXME merge with similar but not identical code at services/audioflinger/ServiceUtilities.cpp static const String16 sDump("android.permission.DUMP"); if (!(IPCThreadState::self()->getCallingUid() == AID_MEDIA || if (!(IPCThreadState::self()->getCallingUid() == AID_AUDIOSERVER || PermissionCache::checkCallingPermission(sDump))) { dprintf(fd, "Permission Denial: can't dump media.log from pid=%d, uid=%d\n", IPCThreadState::self()->getCallingPid(), Loading