1 /* 2 * Copyright (c) 2023-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 #ifndef SECURITY_COMPONENT_SERVICE_H 16 #define SECURITY_COMPONENT_SERVICE_H 17 18 #include <string> 19 #include <vector> 20 #include "app_state_observer.h" 21 #include "iremote_object.h" 22 #include "nlohmann/json.hpp" 23 #include "nocopyable.h" 24 #include "sec_comp_manager.h" 25 #include "sec_comp_stub.h" 26 #include "singleton.h" 27 #include "system_ability.h" 28 29 namespace OHOS { 30 namespace Security { 31 namespace SecurityComponent { 32 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 33 class __attribute__((visibility("default"))) SecCompService final : public SystemAbility, public SecCompStub { 34 DECLARE_DELAYED_SINGLETON(SecCompService); 35 DECLEAR_SYSTEM_ABILITY(SecCompService); 36 37 public: 38 SecCompService(int32_t saId, bool runOnCreate); 39 40 void OnStart() override; 41 void OnStop() override; 42 43 int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; 44 int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; 45 int32_t UnregisterSecurityComponent(int32_t scId) override; 46 int32_t ReportSecurityComponentClickEvent(int32_t scId, 47 const std::string& componentInfo, SecCompClickEvent& clickInfo, 48 sptr<IRemoteObject> callerToken, sptr<IRemoteObject> dialogCallback) override; 49 bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override; 50 sptr<IRemoteObject> GetEnhanceRemoteObject() override; 51 int32_t PreRegisterSecCompProcess() override; 52 53 int Dump(int fd, const std::vector<std::u16string>& args) override; 54 55 private: 56 int32_t ParseParams(const std::string& componentInfo, SecCompCallerInfo& caller, nlohmann::json& jsonRes); 57 bool Initialize() const; 58 bool RegisterAppStateObserver(); 59 void UnregisterAppStateObserver(); 60 bool GetCallerInfo(SecCompCallerInfo& caller); 61 62 ServiceRunningState state_; 63 sptr<AppExecFwk::IAppMgr> iAppMgr_; 64 sptr<AppStateObserver> appStateObserver_; 65 }; 66 } // namespace SecurityComponent 67 } // namespace Security 68 } // namespace OHOS 69 #endif // SECURITY_COMPONENT_SERVICE_H 70