1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| void MediaPlayerService::instantiate() { defaultServiceManager()->addService( String16("media.player"), new MediaPlayerService()); }
virtual status_t addService(const String16& name, const sp<IBinder>& service, bool allowIsolated, int dumpsysPriority) { Parcel data, reply; data.writeInterfaceToken(IServiceManager::getInterfaceDescriptor()); data.writeString16(name); data.writeStrongBinder(service); data.writeInt32(allowIsolated ? 1 : 0); data.writeInt32(dumpsysPriority); status_t err = remote()->transact(ADD_SERVICE_TRANSACTION, data, &reply); return err == NO_ERROR ? reply.readExceptionCode() : err; }
status_t BpBinder::transact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags){ if (mAlive) { status_t status = IPCThreadState::self()->transact( mHandle, code, data, reply, flags); if (status == DEAD_OBJECT) mAlive = 0; return status; } return DEAD_OBJECT; }
status_t IPCThreadState::transact(...){ ......
err = writeTransactionData(BC_TRANSACTION, flags, handle, code, data,NULL); ......
err = waitForResponse(reply); ...... }
status_t IPCThreadState::waitForResponse(......){ while (1) { ...... if ((err=talkWithDriver()) < NO_ERROR) break; ...... } return err; }
status_t IPCThreadState::talkWithDriver(bool doReceive){ ...... binder_write_read bwr; ...... bwr.write_buffer = (uintptr_t)mOut.data(); ...... bwr.read_buffer = (uintptr_t)mIn.data(); ...... ioctl(mProcess->mDriverFD, BINDER_WRITE_READ, &bwr) }
1.sm进程内,循环监听bnder驱动有没有新消息 2.一旦有新消息,比如注册服务 3.根据 case SVC_MGR_ADD_SERVICE ,调用do_add_service() 4.服务名和handle值保存在svcinfo中,svcinfo保存到svclist列表中
|