通过查看您提到的 Binder 机制的 android 源代码,您应该查看方法“getMediaPlayerService()”并检查服务管理器如何处理媒体服务。如果您可以修补此方法并正确定义您的服务,那么您应该没问题。
IMediaDeathNotifier::getMediaPlayerService()
{
LOGV("getMediaPlayerService");
Mutex::Autolock _l(sServiceLock);
if (sMediaPlayerService.get() == 0) {
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
do {
binder = sm->getService(String16("media.player"));
if (binder != 0) {
break;
}
LOGW("Media player service not published, waiting...");
usleep(500000); // 0.5 s
} while(true);
if (sDeathNotifier == NULL) {
sDeathNotifier = new DeathNotifier();
}
binder->linkToDeath(sDeathNotifier);
sMediaPlayerService = interface_cast<IMediaPlayerService>(binder);
}
LOGE_IF(sMediaPlayerService == 0, "no media player service!?");
return sMediaPlayerService;
}
有问题的方法位于:
frameworks/base/media/libmedia/IMediaDeathNotifier.cpp
此外,通过调用设置服务:
void MediaPlayerService::instantiate() {
defaultServiceManager()->addService(
String16("media.player"), new MediaPlayerService());
}
可以在以下位置找到:/frameworks/base/media/libmediaplayerservice/MediaPlayerService.cpp