1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_TEST_SERVICE_SKELETON_H 17 #define OHOS_TEST_SERVICE_SKELETON_H 18 19 #include "ipc_debug.h" 20 #include "iremote_broker.h" 21 #include "iremote_stub.h" 22 #include "iremote_proxy.h" 23 #include "foo_service.h" 24 #include "ipc_file_descriptor.h" 25 #include "log_tags.h" 26 27 namespace OHOS { 28 29 class ITestService : public IRemoteBroker { 30 public: 31 enum { 32 TRANS_ID_SYNC_TRANSACTION = 1, 33 TRANS_ID_ASYNC_TRANSACTION = 2, 34 TRANS_ID_PING_SERVICE = 3, 35 TRANS_ID_GET_FOO_SERVICE = 4, 36 TRANS_ID_TRANSACT_FILE_DESC = 5, 37 TRANS_ID_STRING_TRANSACTION = 6, 38 TRANS_ID_ZTRACE_TRANSACTION = 7, 39 TRANS_ID_LOOP_TRANSACTION = 8, 40 TRANS_ID_DUMP_SERVICE = 9, 41 TRANS_ID_RAWDATA_TRANSACTION = 10, 42 TRANS_ID_RAWDATA_REPLY = 11, 43 TRANS_ID_CALLING_UID_PID = 12, 44 TRANS_ID_FLUSH_ASYNC_CALLS = 13, 45 TRANS_ID_MULTIPLE_PROCESSES = 14, 46 TRANS_ID_ASHMEM = 15, 47 TRANS_ID_ASYNC_DUMP_SERVICE = 16, 48 TRANS_ID_NESTING_SEND = 17, 49 TRANS_ID_ACCESS_TOKENID = 18, 50 TRANS_MESSAGE_PARCEL_ADDPED = 19, 51 TRANS_MESSAGE_PARCEL_ADDPED_WITH_OBJECT = 20, 52 }; 53 public: 54 virtual int TestSyncTransaction(int data, int &reply, int delayTime = 0) = 0; 55 virtual int TestAsyncTransaction(int data, int timeout = 0) = 0; 56 virtual int TestAsyncCallbackTrans(int data, int &reply, int timeout = 0) = 0; 57 virtual int TestGetFileDescriptor() = 0; 58 virtual int TestPingService(const std::u16string &serviceName) = 0; 59 virtual int TestStringTransaction(const std::string &data) = 0; 60 virtual int TestZtraceTransaction(std::string &send, std::string &reply, int len) = 0; 61 virtual void TestDumpService() = 0; 62 virtual int TestRawDataTransaction(int length, int &reply) = 0; 63 virtual int TestRawDataReply(int length) = 0; 64 virtual sptr<IFoo> TestGetFooService() = 0; 65 virtual int TestCallingUidPid() = 0; 66 virtual int TestFlushAsyncCalls(int count, int length) = 0; 67 virtual int TestMultipleProcesses(int data, int &rep, int delayTime) = 0; 68 virtual std::u16string TestAshmem(sptr<Ashmem> ashmem, int32_t contentSize) = 0; 69 virtual void TestAsyncDumpService() = 0; 70 virtual int TestNestingSend(int sendCode, int &replyCode) = 0; 71 virtual int TestAccessTokenID(int32_t ftoken_expected) = 0; 72 virtual int TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src) = 0; 73 virtual int TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src, 74 MessageParcel &reply, bool withObject) = 0; 75 public: 76 DECLARE_INTERFACE_DESCRIPTOR(u"test.ipc.ITestService"); 77 }; 78 79 class TestServiceStub : public IRemoteStub<ITestService> { 80 public: 81 int OnRemoteRequest(uint32_t code, 82 MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 83 private: 84 static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestServiceStub" }; 85 int TransferRawData(MessageParcel &data, MessageParcel &reply); 86 int ReplyRawData(MessageParcel &data, MessageParcel &reply); 87 void TransferToNextProcess(MessageParcel &data, MessageParcel &reply); 88 void ReadAshmem(MessageParcel &data, MessageParcel &reply); 89 }; 90 91 class TestServiceProxy : public IRemoteProxy<ITestService> { 92 public: 93 explicit TestServiceProxy(const sptr<IRemoteObject> &impl); 94 ~TestServiceProxy() = default; 95 int TestSyncTransaction(int data, int &reply, int delayTime = 0) override; 96 int TestAsyncTransaction(int data, int timeout = 0) override; 97 int TestAsyncCallbackTrans(int data, int &reply, int timeout = 0) override; 98 int TestPingService(const std::u16string &serviceName) override; 99 int TestGetFileDescriptor() override; 100 int TestStringTransaction(const std::string &data) override; 101 int TestZtraceTransaction(std::string &send, std::string &reply, int len) override; 102 void TestDumpService() override; 103 int TestRawDataTransaction(int length, int &reply) override; 104 int TestRawDataReply(int length) override; 105 sptr<IFoo> TestGetFooService() override; 106 int TestCallingUidPid() override; 107 int TestFlushAsyncCalls(int count, int length) override; 108 int TestMultipleProcesses(int data, int &rep, int delayTime) override; 109 std::u16string TestAshmem(sptr<Ashmem> ashmem, int32_t contentSize) override; 110 void TestAsyncDumpService() override; 111 int TestNestingSend(int sendCode, int &replyCode) override; 112 int TestAccessTokenID(int32_t ftoken_expected) override; 113 int TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src) override; 114 int TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src, 115 MessageParcel &reply, bool withObject) override; 116 private: 117 static inline BrokerDelegator<TestServiceProxy> delegator_; 118 static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestServiceProxy" }; 119 }; 120 121 class TestDeathRecipient : public IRemoteObject::DeathRecipient { 122 public: 123 virtual void OnRemoteDied(const wptr<IRemoteObject> &remote); 124 TestDeathRecipient(); 125 virtual ~TestDeathRecipient(); 126 static bool GotDeathRecipient(); 127 static bool gotDeathRecipient_; 128 private: 129 static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestDeathRecipient" }; 130 }; 131 132 } // namespace OHOS 133 #endif // OHOS_TEST_SERVICE_SKELETON_H 134