• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         TRANS_ID_ACCESS_TOKENID_64 = 21,
53     };
54 public:
55     virtual int TestSyncTransaction(int data, int &reply, int delayTime = 0) = 0;
56     virtual int TestAsyncTransaction(int data, int timeout = 0) = 0;
57     virtual int TestAsyncCallbackTrans(int data, int &reply, int timeout = 0) = 0;
58     virtual int TestGetFileDescriptor() = 0;
59     virtual int TestPingService(const std::u16string &serviceName) = 0;
60     virtual int TestStringTransaction(const std::string &data) = 0;
61     virtual int TestZtraceTransaction(std::string &send, std::string &reply, int len) = 0;
62     virtual void TestDumpService() = 0;
63     virtual int TestRawDataTransaction(int length, int &reply) = 0;
64     virtual int TestRawDataReply(int length) = 0;
65     virtual sptr<IFoo> TestGetFooService() = 0;
66     virtual int TestCallingUidPid() = 0;
67     virtual int TestFlushAsyncCalls(int count, int length) = 0;
68     virtual int TestMultipleProcesses(int data, int &rep, int delayTime) = 0;
69     virtual std::u16string TestAshmem(sptr<Ashmem> ashmem, int32_t contentSize) = 0;
70     virtual void TestAsyncDumpService() = 0;
71     virtual int TestNestingSend(int sendCode, int &replyCode) = 0;
72     virtual int TestAccessTokenID(int32_t ftoken_expected) = 0;
73     virtual int TestAccessTokenID64(uint64_t token_expected, uint64_t ftoken_expected) = 0;
74     virtual int TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src) = 0;
75     virtual int TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src,
76         MessageParcel &reply, bool withObject) = 0;
77 public:
78     DECLARE_INTERFACE_DESCRIPTOR(u"test.ipc.ITestService");
79 };
80 
81 class TestServiceStub : public IRemoteStub<ITestService> {
82 public:
83     int OnRemoteRequest(uint32_t code,
84         MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
85 private:
86     static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestServiceStub" };
87     int TransferRawData(MessageParcel &data, MessageParcel &reply);
88     int ReplyRawData(MessageParcel &data, MessageParcel &reply);
89     void TransferToNextProcess(MessageParcel &data, MessageParcel &reply);
90     void ReadAshmem(MessageParcel &data, MessageParcel &reply);
91 };
92 
93 class TestServiceProxy : public IRemoteProxy<ITestService> {
94 public:
95     explicit TestServiceProxy(const sptr<IRemoteObject> &impl);
96     ~TestServiceProxy() = default;
97     int TestSyncTransaction(int data, int &reply, int delayTime = 0) override;
98     int TestAsyncTransaction(int data, int timeout = 0) override;
99     int TestAsyncCallbackTrans(int data, int &reply, int timeout = 0) override;
100     int TestPingService(const std::u16string &serviceName) override;
101     int TestGetFileDescriptor() override;
102     int TestStringTransaction(const std::string &data) override;
103     int TestZtraceTransaction(std::string &send, std::string &reply, int len) override;
104     void TestDumpService() override;
105     int TestRawDataTransaction(int length, int &reply) override;
106     int TestRawDataReply(int length) override;
107     sptr<IFoo> TestGetFooService() override;
108     int TestCallingUidPid() override;
109     int TestFlushAsyncCalls(int count, int length) override;
110     int TestMultipleProcesses(int data, int &rep, int delayTime) override;
111     std::u16string TestAshmem(sptr<Ashmem> ashmem, int32_t contentSize) override;
112     void TestAsyncDumpService() override;
113     int TestNestingSend(int sendCode, int &replyCode) override;
114     int TestAccessTokenID(int32_t ftoken_expected) override;
115     int TestAccessTokenID64(uint64_t token_expected, uint64_t ftoken_expected) override;
116     int TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src) override;
117     int TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src,
118         MessageParcel &reply, bool withObject) override;
119 private:
120     static inline BrokerDelegator<TestServiceProxy> delegator_;
121     static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestServiceProxy" };
122 };
123 
124 class TestDeathRecipient : public IRemoteObject::DeathRecipient {
125 public:
126     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
127     TestDeathRecipient();
128     virtual ~TestDeathRecipient();
129     static bool GotDeathRecipient();
130     static bool gotDeathRecipient_;
131 private:
132     static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestDeathRecipient" };
133 };
134 
135 } // namespace OHOS
136 #endif // OHOS_TEST_SERVICE_SKELETON_H
137