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