void Process::Stub::onTransact(int32_t what, int32_t arg1, int32_t arg2, const sp<Object>& obj, const sp<Bundle>& data, const sp<Object>& result) { switch (what) { case MSG_CREATE_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); sp<IBinder> binder = data->getBinder("binder"); createService(intent, RemoteCallback::Stub::asInterface(binder)); break; } case MSG_START_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); int32_t flags = arg1; int32_t startId = arg2; sp<IBinder> binder = data->getBinder("binder"); startService(intent, flags, startId, RemoteCallback::Stub::asInterface(binder)); break; } case MSG_STOP_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); sp<IBinder> binder = data->getBinder("binder"); if (binder == nullptr) { stopService(intent); } else { stopService(intent, RemoteCallback::Stub::asInterface(binder)); } break; } case MSG_BIND_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); sp<ServiceConnection> conn = object_cast<ServiceConnection>(data->getObject("conn")); int32_t flags = data->getInt("flags"); sp<IBinder> binder = data->getBinder("binder"); bindService(intent, conn, flags, RemoteCallback::Stub::asInterface(binder)); break; } case MSG_UNBIND_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); sp<IBinder> binder = data->getBinder("binder"); if (binder == nullptr) { unbindService(intent); } else { unbindService(intent, RemoteCallback::Stub::asInterface(binder)); } break; } default: Binder::onTransact(what, arg1, arg2, obj, data, result); break; } }
void onResult(const sp<Bundle>& data) { sp<ContextImpl> context = mContext.get(); if (context != nullptr) { bool result = data->getBoolean("result"); if (result) { sp<IBinder> binder = data->getBinder("binder"); mConn->onServiceConnected(mService->getComponent(), binder); } else { Log::e(ContextImpl::TAG, "Cannot bind to service %s", mService->getComponent()->toShortString()->c_str()); } context->mServiceConnectionCallbacks->remove(getCallback()); } }
void ServiceManager::Stub::onTransact(int32_t what, int32_t arg1, int32_t arg2, const sp<Object>& obj, const sp<Bundle>& data, const sp<Object>& result) { switch (what) { case MSG_START_SERVICE: { auto promise = object_cast<Promise<sp<ComponentName>>>(result); sp<Intent> service = object_cast<Intent>(obj); sp<ComponentName> component = startService(service); promise->set(component); break; } case MSG_STOP_SERVICE: { auto promise = object_cast<Promise<bool>>(result); sp<Intent> service = object_cast<Intent>(obj); promise->set(stopService(service)); break; } case MSG_BIND_SERVICE: { auto promise = object_cast<Promise<bool>>(result); sp<Intent> service = object_cast<Intent>(data->getObject("intent")); sp<ServiceConnection> conn = object_cast<ServiceConnection> (data->getObject("conn")); int32_t flags = data->getInt("flags"); sp<IBinder> binder = data->getBinder("binder"); promise->set(bindService(service, conn, flags, binder::RemoteCallback::Stub::asInterface(binder))); break; } case MSG_UNBIND_SERVICE: { sp<Intent> intent = object_cast<Intent>(data->getObject("intent")); sp<ServiceConnection> conn = object_cast<ServiceConnection> (data->getObject("conn")); sp<IBinder> binder = nullptr; if (binder == nullptr) { unbindService(intent, conn); } else { unbindService(intent, conn, binder::RemoteCallback::Stub::asInterface(binder)); } break; } case MSG_START_SYSTEM_SERVICE: { auto promise = object_cast<Promise<sp<ComponentName>>>(result); sp<Intent> service = object_cast<Intent>(obj); sp<ComponentName> component = startSystemService(service); promise->set(component); break; } case MSG_STOP_SYSTEM_SERVICE: { auto promise = object_cast<Promise<bool>>(result); sp<Intent> service = object_cast<Intent>(obj); promise->set(stopSystemService(service)); break; } default: Binder::onTransact(what, arg1, arg2, obj, data, result); } }