• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "continuous_app_install_recognizer.h"
17 #include "ffrt_inner.h"
18 #include "res_sched_log.h"
19 #include "res_sched_mgr.h"
20 #include "res_type.h"
21 
22 namespace OHOS {
23 namespace ResourceSchedule {
24 namespace {
25     constexpr int64_t EXIT_INSTALL_DELAY_TIME = 50 * 1000 * 1000;
26 }
27 
~ContinuousAppInstallRecognizer()28 ContinuousAppInstallRecognizer::~ContinuousAppInstallRecognizer()
29 {
30     RESSCHED_LOGI("~ContinuousAppInstallRecognizer");
31 }
32 
OnDispatchResource(uint32_t resType,int64_t value,const nlohmann::json & payload)33 void ContinuousAppInstallRecognizer::OnDispatchResource(uint32_t resType, int64_t value, const nlohmann::json& payload)
34 {
35     if (resType != ResType::RES_TYPE_APP_INSTALL_UNINSTALL) {
36         return;
37     }
38     if (value == ResType::AppInstallStatus::APP_INSTALL_START) {
39         if (exitAppInstall_) {
40             ffrt::skip(exitAppInstall_);
41         }
42         if (!isInContinuousInstall_.load()) {
43             nlohmann::json payload;
44             ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_CONTINUOUS_INSTALL,
45                 ResType::ContinuousInstallStatus::START_CONTINUOUS_INSTALL, payload);
46             isInContinuousInstall_.store(true);
47         }
48     } else if (value == ResType::AppInstallStatus::APP_INSTALL_END) {
49         if (exitAppInstall_) {
50             ffrt::skip(exitAppInstall_);
51         }
52         exitAppInstall_ = ffrt::submit_h([recognizer = shared_from_this()]() {
53             nlohmann::json payload;
54             ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_CONTINUOUS_INSTALL,
55                 ResType::ContinuousInstallStatus::STOP_CONTINUOUS_INSTALL, payload);
56             recognizer->isInContinuousInstall_.store(false);
57         }, {}, {}, ffrt::task_attr().delay(EXIT_INSTALL_DELAY_TIME));
58     }
59 }
60 } // namespace ResourceSchedule
61 } // namespace OHOS