• 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_SKELETON_H
17 #define OHOS_IPC_IPC_SKELETON_H
18 
19 #include "accesstoken_kit.h"
20 #include "iremote_object.h"
21 
22 namespace OHOS {
23 class IPCSkeleton {
24 public:
25     IPCSkeleton() = default;
26     ~IPCSkeleton() = default;
27 
28     /**
29      * @brief Set the max number of work thread.
30      *          Default max is 4, only if you need a customize value.
31      *
32      * @param maxThreadNum Indicates the max number of work thread
33      * @return Indicates the result.
34      */
35     static bool SetMaxWorkThreadNum(int maxThreadNum);
36 
37     /**
38      * @brief Join current thread into work loop.
39      */
40     static void JoinWorkThread();
41 
42     /**
43      * @brief Remove current thread from work loop.
44      */
45     static void StopWorkThread();
46 
47     /**
48      * @brief Get calling pid.
49      *
50      * @return Indicates the calling pid.
51      */
52     static pid_t GetCallingPid();
53 
54     /**
55      * @brief Get calling uid.
56      *
57      * @return Indicates the calling uid.
58      */
59     static pid_t GetCallingUid();
60 
61     /**
62      * @brief Get the ID of local device.
63      *
64      * @return Indicates the ID of local device.
65      */
66     static std::string GetLocalDeviceID();
67 
68     static Security::AccessToken::AccessTokenID GetCallingTokenID();
69 
70     /**
71      * @brief Get the ID of calling device.
72      *
73      * @return Indicates the ID of calling device.
74      */
75     static std::string GetCallingDeviceID();
76 
77     /**
78      * @brief Whether it is locally calling.
79      *
80      * @return Return ture for calling from local, otherwise false.
81      */
82     static bool IsLocalCalling();
83 
84     /**
85      * @brief Get the instance.
86      *
87      * @return Indicates the instance.
88      */
89     static IPCSkeleton &GetInstance();
90 
91     /**
92      * @brief Get the object of context.
93      *
94      * @return Indicates the context cobject.
95      */
96     static sptr<IRemoteObject> GetContextObject();
97 
98     /**
99      * @brief Set the object of context.
100      *
101      * @param object Indicates the context cobject.
102      * @return Indicates the result.
103      */
104     static bool SetContextObject(sptr<IRemoteObject> &object);
105 
106     /**
107      * @brief Flush the commands.
108      *
109      * @param object Indicates the object.
110      * @return Indicates the result.
111      */
112     static int FlushCommands(IRemoteObject *object);
113 
114     /**
115      * @brief Reset calling identity.
116      *
117      * @return Indicates the result.
118      */
119     static std::string ResetCallingIdentity();
120 
121     /**
122      * @brief Set calling identity.
123      *
124      * @param identity Indicates the identity.
125      * @return Indicates the result.
126      */
127     static bool SetCallingIdentity(std::string &identity);
128 
129     /**
130      * @brief Set calling uid.
131      *
132      * @param uid Indicates the uid.
133      */
134     static void SetCallingUid(pid_t uid);
135 
136     static void SetCallingTokenID(Security::AccessToken::AccessTokenID callerToken);
137 };
138 }  // namespace OHOS
139 #endif  // OHOS_IPC_IPC_SKELETON_H
140