| Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 22 | using ::android::defaultServiceManager; | 
|  | 23 | using ::android::IBinder; | 
|  | 24 | using ::android::IServiceManager; | 
|  | 25 | using ::android::sp; | 
|  | 26 | using ::android::String16; | 
|  | 27 |  | 
|  | 28 | binder_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 | } | 
|  | 36 | AIBinder* 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 Moreland | 71cddc3 | 2018-08-30 23:39:22 -0700 | [diff] [blame] | 44 | sp<AIBinder> ret = ABpBinder::fromBinder(binder); | 
|  | 45 | AIBinder_incStrong(ret.get()); | 
|  | 46 | return ret.get(); | 
| Steven Moreland | 2e87adc | 2018-08-20 19:47:00 -0700 | [diff] [blame] | 47 | } |