• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <android/binder_ibinder.h>
20 #include <utils/RefBase.h>
21 
22 // warning: it is recommended to use AIDL output instead of this. binder_ibinder_utils.h and some of
23 // the other niceties make sure that, for instance, binder proxies are always the same. They also
24 // don't use internal Android APIs like refbase which are used here only for convenience.
25 
26 class IFoo : public virtual ::android::RefBase {
27    public:
28     static const char* kSomeInstanceName;
29     static const char* kInstanceNameToDieFor;
30     static const char* kInstanceNameToDieFor2;
31     static const char* kIFooDescriptor;
32 
33     static AIBinder_Class* kClass;
34     static AIBinder_Class* kClassDupe;
35 
36     // binder representing this interface with one reference count
37     // NOTE - this will create a new binder if it already exists. If you use
38     // getService for instance, you must pull outBinder. Don't use this without
39     // verifying isRemote or pointer equality. This is not a very good testing API - don't
40     // copy it - consider the AIDL-generated APIs instead.
41     AIBinder* getBinder();
42 
43     // Takes ownership of IFoo
44     binder_status_t addService(const char* instance);
45     static ::android::sp<IFoo> getService(const char* instance, AIBinder** outBinder = nullptr);
46 
47     enum Call {
48         DOFOO = FIRST_CALL_TRANSACTION + 0,
49         DIE = FIRST_CALL_TRANSACTION + 1,
50     };
51 
52     virtual ~IFoo();
53 
54     virtual binder_status_t doubleNumber(int32_t in, int32_t* out) = 0;
55     virtual binder_status_t die() = 0;
56 
57    private:
58     // this variable is only when IFoo is local (since this test combines 'IFoo' and 'BnFoo'), not
59     // for BpFoo.
60     AIBinder_Weak* mWeakBinder = nullptr;
61 };
62