• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 #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     AddAcceptResTypes({
31         ResType::RES_TYPE_APP_INSTALL_UNINSTALL,
32     });
33 }
34 
~ContinuousAppInstallRecognizer()35 ContinuousAppInstallRecognizer::~ContinuousAppInstallRecognizer()
36 {
37     RESSCHED_LOGI("~ContinuousAppInstallRecognizer");
38 }
39 
OnDispatchResource(uint32_t resType,int64_t value,const nlohmann::json & payload)40 void ContinuousAppInstallRecognizer::OnDispatchResource(uint32_t resType, int64_t value, const nlohmann::json& payload)
41 {
42     if (resType != ResType::RES_TYPE_APP_INSTALL_UNINSTALL) {
43         return;
44     }
45     if (value == ResType::AppInstallStatus::APP_INSTALL_START) {
46         if (exitAppInstall_) {
47             ffrt::skip(exitAppInstall_);
48         }
49         if (!isInContinuousInstall_.load()) {
50             nlohmann::json payload;
51             ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_CONTINUOUS_INSTALL,
52                 ResType::ContinuousInstallStatus::START_CONTINUOUS_INSTALL, payload);
53             isInContinuousInstall_.store(true);
54         }
55     } else if (value == ResType::AppInstallStatus::APP_INSTALL_END) {
56         if (exitAppInstall_) {
57             ffrt::skip(exitAppInstall_);
58         }
59         exitAppInstall_ = ffrt::submit_h([recognizer = shared_from_this()]() {
60             nlohmann::json payload;
61             ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_CONTINUOUS_INSTALL,
62                 ResType::ContinuousInstallStatus::STOP_CONTINUOUS_INSTALL, payload);
63             recognizer->isInContinuousInstall_.store(false);
64         }, {}, {}, ffrt::task_attr().delay(EXIT_INSTALL_DELAY_TIME));
65     }
66 }
67 } // namespace ResourceSchedule
68 } // namespace OHOS