1 /* 2 * Copyright (c) 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 16 #ifndef OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H 17 #define OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include "aot_compiler_interface_stub.h" 23 #include "event_handler.h" 24 #include "event_runner.h" 25 #include "refbase.h" 26 #include "singleton.h" 27 #include "system_ability.h" 28 29 #include "power_disconnected_listener.h" 30 #include "screen_status_listener.h" 31 #include "thermal_mgr_listener.h" 32 33 namespace OHOS::ArkCompiler { 34 enum class ServiceRunningState { 35 STATE_NOT_START, 36 STATE_RUNNING 37 }; 38 class AotCompilerService : public SystemAbility, public AotCompilerInterfaceStub { 39 DECLARE_SYSTEM_ABILITY(AotCompilerService) 40 DECLARE_DELAYED_SINGLETON(AotCompilerService) 41 public: 42 AotCompilerService(int32_t systemAbilityId, bool runOnCreate); 43 int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap, 44 std::vector<int16_t> &sigData) override; 45 int32_t StopAotCompiler() override; 46 int32_t GetAOTVersion(std::string& sigData) override; 47 int32_t NeedReCompile(const std::string& args, bool& sigData) override; 48 protected: 49 void OnStart() override; 50 void OnStop() override; 51 private: 52 bool Init(); 53 void RemoveUnloadTask(const std::string &taskId); 54 void DelayUnloadTask(const std::string &taskId, const int32_t delayTime); 55 void RegisterPowerDisconnectedListener(); 56 void RegisterScreenStatusSubscriber(); 57 void RegisterThermalMgrListener(); 58 void UnRegisterPowerDisconnectedListener(); 59 void UnRegisterScreenStatusSubscriber(); 60 void UnRegisterThermalMgrListener(); 61 62 std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_ { nullptr }; 63 ServiceRunningState state_; 64 std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_ { nullptr }; 65 std::shared_ptr<ScreenStatusSubscriber> screenStatusSubscriber_ { nullptr }; 66 std::shared_ptr<ThermalMgrListener> thermalMgrListener_ { nullptr }; 67 bool isPowerEventSubscribered_ { false }; 68 bool isScreenStatusSubscribered_ { false }; 69 bool isThermalLevelEventSubscribered_ { false }; 70 }; 71 } // namespace OHOS::ArkCompiler 72 #endif // OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H