• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 
17 #include "critical_handler.h"
18 #include "mem_mgr_client.h"
19 #include "mem_mgr_proxy.h"
20 #include "hc_log.h"
21 #include <system_ability_definition.h>
22 
23 static int32_t g_count = 0;
24 static std::mutex g_criticalLock;
25 
NotifyProcessIsActive(void)26 void NotifyProcessIsActive(void)
27 {
28     LOGI("start to notify memmgr sa active.");
29     OHOS::Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 1, OHOS::DEVICE_AUTH_SERVICE_ID);
30 }
31 
NotifyProcessIsStop(void)32 void NotifyProcessIsStop(void)
33 {
34     LOGI("start to notify memmgr sa stop.");
35     OHOS::Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 0, OHOS::DEVICE_AUTH_SERVICE_ID);
36 }
37 
IncreaseCriticalCnt(int addCnt)38 void IncreaseCriticalCnt(int addCnt)
39 {
40     std::lock_guard<std::mutex> autoLock(g_criticalLock);
41     if (g_count == 0) {
42         LOGI("Try to set critical to true.");
43         OHOS::Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, OHOS::DEVICE_AUTH_SERVICE_ID);
44     }
45     g_count = g_count + addCnt;
46 }
47 
DecreaseCriticalCnt(void)48 void DecreaseCriticalCnt(void)
49 {
50     std::lock_guard<std::mutex> autoLock(g_criticalLock);
51     g_count = g_count - 1;
52     if (g_count == 0) {
53         LOGI("Try to set critical to false.");
54         OHOS::Memory::MemMgrClient::GetInstance().SetCritical(getpid(), false, OHOS::DEVICE_AUTH_SERVICE_ID);
55     }
56 }
57 
GetCriticalCnt(void)58 int32_t GetCriticalCnt(void)
59 {
60     std::lock_guard<std::mutex> autoLock(g_criticalLock);
61     return g_count;
62 }