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(SecCompInfo& secCompInfo, 37 sptr<IRemoteObject> callerToken, sptr<IRemoteObject> dialogCallback, std::string& message); 38 bool VerifySavePermission(AccessToken::AccessTokenID tokenId); 39 sptr<IRemoteObject> GetEnhanceRemoteObject(bool doLoadSa); 40 int32_t PreRegisterSecCompProcess(); 41 bool IsServiceExist(); 42 bool LoadService(); 43 bool IsSystemAppCalling(); 44 45 void FinishStartSASuccess(const sptr<IRemoteObject>& remoteObject); 46 void FinishStartSAFail(); 47 void OnRemoteDiedHandle(); 48 49 private: 50 SecCompClient(); 51 virtual ~SecCompClient(); 52 DISALLOW_COPY_AND_MOVE(SecCompClient); 53 54 bool TryToGetSecCompSa(); 55 bool StartLoadSecCompSa(); 56 void WaitForSecCompSa(); 57 void GetSecCompSa(); 58 void LoadSecCompSa(); 59 sptr<ISecCompService> GetProxy(bool doLoadSa); 60 void GetProxyFromRemoteObject(const sptr<IRemoteObject>& remoteObject); 61 62 std::mutex cvLock_; 63 bool readyFlag_ = false; 64 std::condition_variable secComCon_; 65 std::mutex proxyMutex_; 66 sptr<ISecCompService> proxy_ = nullptr; 67 sptr<SecCompDeathRecipient> serviceDeathObserver_ = nullptr; 68 }; 69 } // namespace SecurityComponent 70 } // namespace Security 71 } // namespace OHOS 72 #endif // SECURITY_COMPONENT_CLIENT_H 73