1 /* 2 * Copyright (c) 2023 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 SECURITY_COMPONENT_CLIENT_H 17 #define SECURITY_COMPONENT_CLIENT_H 18 19 #include <condition_variable> 20 #include <mutex> 21 #include <string> 22 #include "i_sec_comp_service.h" 23 #include "sec_comp_death_recipient.h" 24 #include "sec_comp_err.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace SecurityComponent { 29 class SecCompClient final { 30 public: 31 static SecCompClient& GetInstance(); 32 33 int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId); 34 int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo); 35 int32_t UnregisterSecurityComponent(int32_t scId); 36 int32_t ReportSecurityComponentClickEvent(int32_t scId, 37 const std::string& componentInfo, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken); 38 bool VerifySavePermission(AccessToken::AccessTokenID tokenId); 39 sptr<IRemoteObject> GetEnhanceRemoteObject(bool doLoadSa); 40 int32_t PreRegisterSecCompProcess(); 41 42 void FinishStartSASuccess(const sptr<IRemoteObject>& remoteObject); 43 void FinishStartSAFail(); 44 void OnRemoteDiedHandle(); 45 46 private: 47 SecCompClient(); 48 virtual ~SecCompClient(); 49 DISALLOW_COPY_AND_MOVE(SecCompClient); 50 51 bool TryToGetSecCompSa(); 52 bool StartLoadSecCompSa(); 53 void WaitForSecCompSa(); 54 void GetSecCompSa(); 55 void LoadSecCompSa(); 56 sptr<ISecCompService> GetProxy(bool doLoadSa); 57 void GetProxyFromRemoteObject(const sptr<IRemoteObject>& remoteObject); 58 59 std::mutex cvLock_; 60 bool readyFlag_ = false; 61 std::condition_variable secComCon_; 62 std::mutex proxyMutex_; 63 sptr<ISecCompService> proxy_ = nullptr; 64 sptr<SecCompDeathRecipient> serviceDeathObserver_ = nullptr; 65 }; 66 } // namespace SecurityComponent 67 } // namespace Security 68 } // namespace OHOS 69 #endif // SECURITY_COMPONENT_CLIENT_H 70