| // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "libprotobinder/iservice_manager.h" |
| |
| #include "libprotobinder/binder_host.h" |
| #include "libprotobinder/binder_proxy.h" |
| #include "libprotobinder/parcel.h" |
| |
| namespace protobinder { |
| |
| IServiceManager* g_service_manager = nullptr; |
| |
| IServiceManager* GetServiceManager() { |
| if (g_service_manager) |
| return g_service_manager; |
| |
| g_service_manager = CreateInterface<IServiceManager>( |
| new BinderProxy(0)).release(); |
| return g_service_manager; |
| } |
| |
| class IServiceManagerProxy : public BinderProxyInterface<IServiceManager> { |
| public: |
| explicit IServiceManagerProxy(BinderProxy* proxy) |
| : BinderProxyInterface<IServiceManager>(proxy) {} |
| |
| virtual Status AddService(const char* name, BinderHost* binder) { |
| Parcel data, reply; |
| data.WriteInt32(0); |
| data.WriteString16("android.os.IServiceManager"); |
| data.WriteString16(name); |
| data.WriteStrongBinderFromIBinder(*binder); |
| return Remote()->Transact(ADD_SERVICE_TRANSACTION, &data, &reply, 0); |
| } |
| |
| virtual BinderProxy* GetService(const char* name) { |
| Parcel data, reply; |
| data.WriteInt32(0); |
| data.WriteString16("android.os.IServiceManager"); |
| data.WriteString16(name); |
| if (!Remote()->Transact(CHECK_SERVICE_TRANSACTION, &data, &reply, 0)) |
| return nullptr; |
| |
| IBinder* binder = nullptr; |
| return reply.ReadStrongBinderToIBinder(&binder) ? binder->GetBinderProxy() |
| : nullptr; |
| } |
| }; |
| |
| IMPLEMENT_META_INTERFACE(ServiceManager, "Test") |
| |
| } // namespace protobinder |