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 31 static AIBinder_Class* kClass; 32 33 // Takes ownership of IFoo 34 binder_status_t addService(const char* instance); 35 static ::android::sp<IFoo> getService(const char* instance, AIBinder** outBinder = nullptr); 36 37 enum Call { 38 DOFOO = FIRST_CALL_TRANSACTION + 0, 39 DIE = FIRST_CALL_TRANSACTION + 1, 40 }; 41 42 virtual ~IFoo(); 43 44 virtual binder_status_t doubleNumber(int32_t in, int32_t* out) = 0; 45 virtual binder_status_t die() = 0; 46 47 private: 48 // this variable is only when IFoo is local (since this test combines 'IFoo' and 'BnFoo'), not 49 // for BpFoo. 50 AIBinder_Weak* mWeakBinder = nullptr; 51 }; 52