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 32 namespace OHOS::ArkCompiler { 33 enum class ServiceRunningState { 34 STATE_NOT_START, 35 STATE_RUNNING 36 }; 37 class AotCompilerService : public SystemAbility, public AotCompilerInterfaceStub { 38 DECLARE_SYSTEM_ABILITY(AotCompilerService) 39 DECLARE_DELAYED_SINGLETON(AotCompilerService) 40 public: 41 AotCompilerService(int32_t systemAbilityId, bool runOnCreate); 42 int32_t AotCompiler(const std::unordered_map<std::string, std::string> &argsMap, 43 std::vector<int16_t> &sigData) override; 44 int32_t StopAotCompiler() override; 45 int32_t GetAOTVersion(std::string& sigData) override; 46 int32_t NeedReCompile(const std::string& args, bool& sigData) override; 47 protected: 48 void OnStart() override; 49 void OnStop() override; 50 private: 51 bool Init(); 52 void RemoveUnloadTask(const std::string &taskId); 53 void DelayUnloadTask(const std::string &taskId, const int32_t delayTime); 54 void RegisterPowerDisconnectedListener(); 55 void RegisterScreenStatusSubscriber(); 56 void UnRegisterPowerDisconnectedListener(); 57 void UnRegisterScreenStatusSubscriber(); 58 59 std::shared_ptr<AppExecFwk::EventHandler> unLoadHandler_ { nullptr }; 60 ServiceRunningState state_; 61 std::shared_ptr<PowerDisconnectedListener> powerDisconnectedListener_ { nullptr }; 62 std::shared_ptr<ScreenStatusSubscriber> screenStatusSubscriber_ { nullptr }; 63 bool isPowerEventSubscribered_ { false }; 64 bool isScreenStatusSubscribered_ { false }; 65 }; 66 } // namespace OHOS::ArkCompiler 67 #endif // OHOS_ARKCOMPILER_AOTCOMPILER_SERVICE_H