blob: 3979945e45c8c2f5d1525092edd19d0dc5c04d85 [file] [log] [blame]
Steven Moreland2e87adc2018-08-20 19:47:00 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android/binder_manager.h>
18#include "AIBinder_internal.h"
19
20#include <binder/IServiceManager.h>
21
22using ::android::defaultServiceManager;
23using ::android::IBinder;
24using ::android::IServiceManager;
25using ::android::sp;
26using ::android::String16;
27
28binder_status_t AServiceManager_addService(AIBinder* binder, const char* instance) {
29 if (binder == nullptr || instance == nullptr) {
30 return EX_NULL_POINTER;
31 }
32
33 sp<IServiceManager> sm = defaultServiceManager();
34 return sm->addService(String16(instance), binder->getBinder());
35}
36AIBinder* AServiceManager_getService(const char* instance) {
37 if (instance == nullptr) {
38 return nullptr;
39 }
40
41 sp<IServiceManager> sm = defaultServiceManager();
42 sp<IBinder> binder = sm->getService(String16(instance));
43
Steven Moreland71cddc32018-08-30 23:39:22 -070044 sp<AIBinder> ret = ABpBinder::fromBinder(binder);
45 AIBinder_incStrong(ret.get());
46 return ret.get();
Steven Moreland2e87adc2018-08-20 19:47:00 -070047}