• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 <iostream>
18 
19 #define LOG_TAG "VtsFuzzerBinderClient"
20 #include <log/log.h>
21 #include <utils/RefBase.h>
22 
23 #include <binder/IBinder.h>
24 #include <binder/IInterface.h>
25 #include <binder/IServiceManager.h>
26 #include <binder/ProcessState.h>
27 
28 #include "BinderClientToDriver.h"
29 #include "binder/VtsFuzzerBinderService.h"
30 
31 using namespace std;
32 
33 namespace android {
34 namespace vts {
35 
36 // Returns a VtsFuzzer binder service's client.
GetBinderClient(const string & service_name)37 sp<IVtsFuzzer> GetBinderClient(const string& service_name) {
38   android::sp<IServiceManager> manager = defaultServiceManager();
39   if (!manager.get()) {
40     cerr << "can't get the default service manager." << std::endl;
41     return NULL;
42   }
43 
44   sp<IBinder> binder = manager->getService(String16(service_name.c_str()));
45   if (!binder.get()) {
46     cerr << "can't find the " << service_name << " binder service."
47          << std::endl;
48     return NULL;
49   }
50 
51   sp<IVtsFuzzer> fuzzer = interface_cast<IVtsFuzzer>(binder);
52   if (!fuzzer.get()) {
53     cerr << "can't cast the obtained " << service_name << " binder instance"
54          << std::endl;
55     return NULL;
56   }
57 
58   return fuzzer;
59 }
60 
61 }  // namespace vts
62 }  // namespace android
63