• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 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, const SecCompClickEvent& clickInfo, sptr<IRemoteObject> callerToken) override;
48     bool VerifySavePermission(AccessToken::AccessTokenID tokenId) override;
49     sptr<IRemoteObject> GetEnhanceRemoteObject() override;
50     int32_t PreRegisterSecCompProcess() override;
51 
52     int Dump(int fd, const std::vector<std::u16string>& args) override;
53 
54 private:
55     int32_t ParseParams(const std::string& componentInfo, SecCompCallerInfo& caller, nlohmann::json& jsonRes);
56     bool Initialize() const;
57     bool RegisterAppStateObserver();
58     void UnregisterAppStateObserver();
59     bool GetCallerInfo(SecCompCallerInfo& caller);
60 
61     ServiceRunningState state_;
62     sptr<AppExecFwk::IAppMgr> iAppMgr_;
63     sptr<AppStateObserver> appStateObserver_;
64 };
65 }  // namespace SecurityComponent
66 }  // namespace Security
67 }  // namespace OHOS
68 #endif  // SECURITY_COMPONENT_SERVICE_H
69