1 /*
2  * Copyright (c) 2024 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 ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_VERIFY_HELPER_H
17 #define ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_VERIFY_HELPER_H
18 
19 #include <mutex>
20 #include <map>
21 #include <unordered_map>
22 
23 #include "transaction/rs_transaction_data.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 
28 class RSB_EXPORT RsCommandVerifyHelper {
29 public:
30     static RsCommandVerifyHelper &GetInstance();
31     void RegisterNonSystemPid(pid_t pid);
32     void AddSurfaceNodeCreateCnt(pid_t pid);
33     void SubSurfaceNodeCreateCnt(pid_t pid);
34     void RemoveCntWithPid(pid_t pid);
35     bool IsSurfaceNodeCreateCommandVaild(pid_t pid);
36 
37 private:
38     RsCommandVerifyHelper() = default;
39     ~RsCommandVerifyHelper() = default;
40     RsCommandVerifyHelper(const RsCommandVerifyHelper&) = delete;
41     RsCommandVerifyHelper(const RsCommandVerifyHelper&&) = delete;
42     RsCommandVerifyHelper& operator=(const RsCommandVerifyHelper&) = delete;
43     RsCommandVerifyHelper& operator=(const RsCommandVerifyHelper&&) = delete;
44     // the number of times a non-system app can call surfaceNode create
45     std::unordered_map<pid_t, uint32_t> nonSystemSurfaceNodeCreateCnt_;
46     std::mutex commandMutex_;
47 };
48 } // namespace Rosen
49 } // namespace OHOS
50 
51 #endif // ROSEN_RENDER_SERVICE_BASE_COMMAND_RS_COMMAND_VERIFY_HELPER_H
52