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 ON_DEMAND_START_STOP_SA_H 17 #define ON_DEMAND_START_STOP_SA_H 18 19 #include <condition_variable> 20 21 #include "singleton.h" 22 #include "system_ability_load_callback_stub.h" 23 24 namespace OHOS { 25 namespace MiscServices { 26 class OnDemandStartStopSa : public std::enable_shared_from_this<OnDemandStartStopSa> { 27 public: 28 OnDemandStartStopSa() = default; 29 ~OnDemandStartStopSa() = default; 30 void UnloadInputMethodSystemAbility(); 31 static sptr<IRemoteObject> GetInputMethodSystemAbility(bool ifRetry = true); 32 static void IncreaseProcessingIpcCnt(); 33 static void DecreaseProcessingIpcCnt(); 34 static bool IsSaBusy(); 35 36 private: 37 sptr<IRemoteObject> LoadInputMethodSystemAbility(); 38 class SaLoadCallback : public SystemAbilityLoadCallbackStub { 39 public: SaLoadCallback(std::shared_ptr<OnDemandStartStopSa> onDemandObj)40 SaLoadCallback(std::shared_ptr<OnDemandStartStopSa> onDemandObj) : onDemandObj_(onDemandObj) {}; 41 void OnLoadSystemAbilitySuccess(int32_t said, const sptr<IRemoteObject> &object) override; 42 void OnLoadSystemAbilityFail(int32_t said) override; 43 44 std::shared_ptr<OnDemandStartStopSa> onDemandObj_ = nullptr; 45 }; 46 47 sptr<IRemoteObject> remoteObj_; 48 std::condition_variable loadSaCv_; 49 std::mutex loadSaMtx_; 50 static constexpr int32_t LOAD_SA_MAX_WAIT_TIME = 5; // 5s 51 static std::atomic<uint32_t> processingIpcCount_; 52 }; 53 } // namespace MiscServices 54 } // namespace OHOS 55 #endif // ON_DEMAND_START_STOP_SA_H