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_ABILITY_RUNTIME_EXIT_RESIDENT_PROCESS_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_EXIT_RESIDENT_PROCESS_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "app_mem_info.h" 23 #include "bundle_info.h" 24 #include "cpp/mutex.h" 25 #include "nocopyable.h" 26 #include "refbase.h" 27 28 29 namespace OHOS { 30 namespace AppExecFwk { 31 struct ExitResidentProcessInfo { 32 ExitResidentProcessInfo() = default; ExitResidentProcessInfoExitResidentProcessInfo33 ExitResidentProcessInfo(const std::string &bundleName, int32_t uid) 34 : bundleName(bundleName), uid(uid) {} 35 std::string bundleName; 36 int32_t uid = 0; 37 }; 38 39 class ExitResidentProcessManager { 40 public: 41 static ExitResidentProcessManager &GetInstance(); 42 ~ExitResidentProcessManager(); 43 bool IsMemorySizeSufficient() const; 44 bool IsNoRequireBigMemory() const; 45 bool RecordExitResidentBundleName(const std::string &bundleName, int32_t uid); 46 bool RecordExitResidentBundleNameOnRequireBigMemory(const std::string &bundleName, int32_t uid); 47 void RecordExitResidentBundleDependedOnWeb(const std::string &bundleName, int32_t uid); 48 int32_t HandleMemorySizeInSufficent(); 49 int32_t HandleRequireBigMemoryOptimization(); 50 int32_t HandleMemorySizeSufficient(std::vector<ExitResidentProcessInfo>& bundleNames); 51 int32_t HandleNoRequireBigMemoryOptimization(std::vector<ExitResidentProcessInfo>& bundleNames); 52 void HandleExitResidentBundleDependedOnWeb(std::vector<ExitResidentProcessInfo>& bundleNames); 53 void QueryExitBundleInfos(const std::vector<ExitResidentProcessInfo>& exitBundleNames, 54 std::vector<AppExecFwk::BundleInfo>& exitBundleInfos); 55 bool IsKilledForUpgradeWeb(const std::string &bundleName) const; 56 57 private: 58 ExitResidentProcessManager(); 59 MemoryState currentMemorySizeState_ = MemoryState::MEMORY_RECOVERY; 60 MemoryState currentBigMemoryState_ = MemoryState::NO_REQUIRE_BIG_MEMORY; 61 std::vector<ExitResidentProcessInfo> exitResidentInfos_; 62 std::vector<ExitResidentProcessInfo> exitResidentBigMemoryInfos_; 63 std::vector<ExitResidentProcessInfo> exitResidentBundlesDependedOnWeb_; 64 mutable ffrt::mutex mutexLock_; 65 mutable ffrt::mutex webMutexLock_; 66 mutable ffrt::mutex mutexLockBigMemory_; 67 DISALLOW_COPY_AND_MOVE(ExitResidentProcessManager); 68 }; 69 } // namespace AppExecFwk 70 } // namespace OHOS 71 #endif // OHOS_ABILITY_RUNTIME_EXIT_RESIDENT_PROCESS_MANAGER_H 72