/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ABILITY_RUNTIME_CACHE_PROCESS_MANAGER_H #define OHOS_ABILITY_RUNTIME_CACHE_PROCESS_MANAGER_H #include #include #include #include #include #include "singleton.h" #include "app_running_record.h" #include "cpp/mutex.h" namespace OHOS { namespace AppExecFwk { class CacheProcessManager { DECLARE_DELAYED_SINGLETON(CacheProcessManager); public: bool QueryEnableProcessCache(); void SetAppMgr(const std::weak_ptr &appMgr); bool PenddingCacheProcess(const std::shared_ptr &appRecord); bool CheckAndCacheProcess(const std::shared_ptr &appRecord); bool IsCachedProcess(const std::shared_ptr &appRecord); void OnProcessKilled(const std::shared_ptr &appRecord); void ReuseCachedProcess(const std::shared_ptr &appRecord); bool IsAppSupportProcessCache(const std::shared_ptr &appRecord); bool IsAppShouldCache(const std::shared_ptr &appRecord); void RefreshCacheNum(); std::string PrintCacheQueue(); void PrepareActivateCache(const std::shared_ptr &appRecord); void OnAppProcessCacheBlocked(const std::shared_ptr &appRecord); void CheckAndSetProcessCacheEnable(const std::shared_ptr &appRecord); private: bool IsAppAbilitiesEmpty(const std::shared_ptr &appRecord); int GetCurrentCachedProcNum(); void RemoveCacheRecord(const std::shared_ptr &appRecord); void ShrinkAndKillCache(); bool KillProcessByRecord(const std::shared_ptr &appRecord); void AddToApplicationSet(const std::shared_ptr &appRecord); void RemoveFromApplicationSet(const std::shared_ptr &appRecord); bool CheckAndNotifyCachedState(const std::shared_ptr &appRecord); bool IsAppContainsSrvExt(const std::shared_ptr &appRecord); bool IsAppSupportProcessCacheInnerFirst(const std::shared_ptr &appRecord); bool IsProcessSupportHotStart(const std::shared_ptr &appRecord); bool warmStartProcesEnable_ = false; int32_t maxProcCacheNum_ = 0; int32_t allowedCacheNum_ = 0; std::deque> cachedAppRecordQueue_; ffrt::recursive_mutex cacheQueueMtx; std::weak_ptr appMgr_; bool shouldCheckApi = true; // whether the feature should check setSupportedProcessCache value or not bool shouldCheckSupport = true; // bundleName->uid->record std::map>>> sameAppSet; // stores records that are servcie extension std::set> srvExtRecords; // stores records that has been checked service extension std::unordered_set> srvExtCheckedFlag; }; } // namespace OHOS } // namespace AppExecFwk #endif