最近遇到音乐自动播放的问题,需要确定是哪个apk或者服务调用的,有两种方法。
通过命令行:
adb shell dumpsys media.audio_flinger
查看pid对应的process name:
adb shell cat /proc/551/cmdline
system_server
system_server 不需要关注
adb shell cat /proc/1401/cmdline
com.kugou.android.support
直接在代码中打印log:
kris@:~/rk3288/frameworks/av/services/audioflinger$ g df diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cppindex fab1ef5..4166545 100644--- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp@@ -462,8 +462,33 @@ status_t AudioFlinger::dump(int fd, const Vector<String16>& args) return NO_ERROR; } +static char audioCallProcess[30]; +char* AudioFlinger::getCallingProcess(pid_t pid) +{ + int fp = -1; + audioCallProcess[0] = 0x00; + sprintf(audioCallProcess,"/proc/%d/cmdline",pid); + + fp = open(audioCallProcess, O_RDONLY); + + if (fp < 0) { + memset(audioCallProcess,0x00,sizeof(audioCallProcess)); + ALOGE("Obtain calling process info failed"); + } else { + memset(audioCallProcess,0x00,sizeof(audioCallProcess)); + read(fp, audioCallProcess, 29); + close(fp); + fp = -1; + //ALOGD("Calling process is: %s",audioCallProcess); + } + return audioCallProcess; + +} + + sp<AudioFlinger::Client> AudioFlinger::registerPid(pid_t pid) { + ALOGI("registerPid:%d name:%s", pid, getCallingProcess(pid)); Mutex::Autolock _cl(mClientLock); // If pid is already in the mClients wp<> map, then use that entry // (for which promote() is always != 0), otherwise create a new entry and Client.@@ -1258,7 +1283,7 @@ void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client) sp<NotificationClient> notificationClient = new NotificationClient(this, client, pid); - ALOGV("registerClient() client %p, pid %d", notificationClient.get(), pid); + ALOGI("registerClient() client %p, pid %d", notificationClient.get(), pid); mNotificationClients.add(pid, notificationClient);
本文标题:[Android] 调试笔记 - 查看音乐播放对应的进程名
本文链接:http://zvvv.cn/post/591.html
版权声明:本文使用「署名-相同方式共享 4.0 国际」创作共享协议,转载或使用请遵守署名协议。