• 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_IPC_IPC_OBJECT_STUB_H
17 #define OHOS_IPC_IPC_OBJECT_STUB_H
18 
19 #include "iremote_object.h"
20 #include <list>
21 #include "ipc_object_proxy.h"
22 
23 namespace OHOS {
24 struct RefCountNode {
25     int remotePid;
26     std::string deviceId;
27 };
28 
29 class IPCObjectStub : public IRemoteObject {
30 public:
31     enum {
32         OBJECT_TYPE_NATIVE,
33         OBJECT_TYPE_JAVA,
34         OBJECT_TYPE_JAVASCRIPT,
35     };
36 
37     explicit IPCObjectStub(std::u16string descriptor = std::u16string());
38     ~IPCObjectStub();
39 
IsProxyObject()40     bool IsProxyObject() const override
41     {
42         return false;
43     };
44 
45     int32_t GetObjectRefCount() override;
46 
47     int Dump(int fd, const std::vector<std::u16string> &args) override;
48 
49     virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
50 
51     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
52 
53     void OnFirstStrongRef(const void *objectId) override;
54 
55     void OnLastStrongRef(const void *objectId) override;
56 
57     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override;
58 
59     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override;
60 
61     int GetCallingPid();
62 
63     int GetCallingUid();
64 
65     uint32_t GetCallingTokenID();
66 
67     uint32_t GetFirstTokenID();
68 
69     virtual int OnRemoteDump(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
70 
71     virtual int32_t ProcessProto(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
72 
73     virtual int GetObjectType() const;
74 
75 #ifndef CONFIG_IPC_SINGLE
76     int32_t InvokerThread(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
77     int32_t NoticeServiceDie(MessageParcel &data, MessageParcel &reply, MessageOption &option);
78     int32_t InvokerDataBusThread(MessageParcel &data, MessageParcel &reply);
79     int32_t IncStubRefs(MessageParcel &data, MessageParcel &reply);
80     int32_t DecStubRefs(MessageParcel &data, MessageParcel &reply);
81     int32_t AddAuthInfo(MessageParcel &data, MessageParcel &reply, uint32_t code);
82 
83 private:
84     int32_t GrantDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
85     int32_t TransDataBusName(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
86     std::string CreateDatabusName(int uid, int pid);
87     std::string GetDataBusName();
88 #endif
89 private:
90     bool IsDeviceIdIllegal(const std::string &deviceID);
91 };
92 } // namespace OHOS
93 #endif // OHOS_IPC_IPC_OBJECT_STUB_H
94