1 /* 2 * Copyright (c) 2022-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 CM_SA_H 17 #define CM_SA_H 18 19 #include "event_handler.h" 20 #include "event_runner.h" 21 #include "iremote_broker.h" 22 #include "iremote_stub.h" 23 #include "nocopyable.h" 24 #include "system_ability.h" 25 26 #include "cert_manager_service_ipc_interface_code.h" 27 28 namespace OHOS { 29 namespace Security { 30 namespace CertManager { 31 enum ServiceRunningState { 32 STATE_NOT_START, 33 STATE_RUNNING 34 }; 35 enum ResponseCode { 36 CM_SYSTEM_ERROR = -1, 37 }; 38 39 constexpr int SA_ID_KEYSTORE_SERVICE = 3512; 40 41 class ICertManagerService : public IRemoteBroker { 42 public: 43 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.cm.service"); 44 }; 45 46 class CertManagerService : public SystemAbility, public IRemoteStub<ICertManagerService> { 47 DECLEAR_SYSTEM_ABILITY(CertManagerService) 48 49 public: 50 DISALLOW_COPY_AND_MOVE(CertManagerService); 51 CertManagerService(); 52 virtual ~CertManagerService(); 53 54 void OnStart(const SystemAbilityOnDemandReason& startReason) override; 55 void OnStop() override; 56 int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 57 58 void DelayUnload(); 59 static CertManagerService& GetInstance(); 60 61 protected: 62 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 63 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 64 65 private: 66 bool Init(); 67 68 bool registerToService_; 69 ServiceRunningState runningState_; 70 std::shared_ptr<AppExecFwk::EventHandler> unloadHandler; 71 }; 72 } // namespace CertManager 73 } // namespace Security 74 } // namespace OHOS 75 76 #endif // CM_SA_H 77