• 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* kIFooDescriptor;
31 
32     static AIBinder_Class* kClass;
33     static AIBinder_Class* kClassDupe;
34 
35     // binder representing this interface with one reference count
36     // NOTE - this will create a new binder if it already exists. If you use
37     // getService for instance, you must pull outBinder. Don't use this without
38     // verifying isRemote or pointer equality. This is not a very good testing API - don't
39     // copy it - consider the AIDL-generated APIs instead.
40     AIBinder* getBinder();
41 
42     // Takes ownership of IFoo
43     binder_status_t addService(const char* instance);
44     static ::android::sp<IFoo> getService(const char* instance, AIBinder** outBinder = nullptr);
45 
46     enum Call {
47         DOFOO = FIRST_CALL_TRANSACTION + 0,
48         DIE = FIRST_CALL_TRANSACTION + 1,
49     };
50 
51     virtual ~IFoo();
52 
53     virtual binder_status_t doubleNumber(int32_t in, int32_t* out) = 0;
54     virtual binder_status_t die() = 0;
55 
56    private:
57     // this variable is only when IFoo is local (since this test combines 'IFoo' and 'BnFoo'), not
58     // for BpFoo.
59     AIBinder_Weak* mWeakBinder = nullptr;
60 };
61