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 #include "appfreeze_inner.h"
17 #include "appfreeze_state.h"
18 #include "hilog_tag_wrapper.h"
19 #include "xcollie/watchdog.h"
20
21 namespace OHOS {
22 namespace AbilityRuntime {
AppFreezeState()23 AppFreezeState::AppFreezeState()
24 {
25 appFreezeStateFlag_ = 0;
26 }
27
SetAppFreezeState(uint32_t flag)28 void AppFreezeState::SetAppFreezeState(uint32_t flag)
29 {
30 auto inner = AppExecFwk::AppfreezeInner::GetInstance();
31 if (inner == nullptr) {
32 TAG_LOGE(AAFwkTag::APPDFR, "null inner");
33 return;
34 }
35
36 appFreezeStateFlag_ |= flag;
37 if (appFreezeStateFlag_ > 0) {
38 inner->SetAppDebug(true);
39 OHOS::HiviewDFX::Watchdog::GetInstance().SetAppDebug(true);
40 }
41 TAG_LOGD(AAFwkTag::APPDFR, "App state flag: %{public}u, SetAppDebug true", appFreezeStateFlag_);
42 }
43
CancelAppFreezeState(uint32_t flag)44 void AppFreezeState::CancelAppFreezeState(uint32_t flag)
45 {
46 auto inner = AppExecFwk::AppfreezeInner::GetInstance();
47 if (inner == nullptr) {
48 TAG_LOGE(AAFwkTag::APPDFR, "null inner");
49 return;
50 }
51
52 appFreezeStateFlag_ &= ~flag;
53 if (appFreezeStateFlag_ == 0) {
54 inner->SetAppDebug(false);
55 OHOS::HiviewDFX::Watchdog::GetInstance().SetAppDebug(false);
56 }
57 TAG_LOGD(AAFwkTag::APPDFR, "App state flag: %{public}u, SetAppDebug false", appFreezeStateFlag_);
58 }
59 } // namespace AbilityRuntime
60 } // namespace OHOS