• 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 <file_ex.h>
17 
18 #include "system_upgrade_scene_recognizer.h"
19 #include "ffrt_inner.h"
20 #include "parameters.h"
21 #include "plugin_mgr.h"
22 #include "res_sched_log.h"
23 #include "res_sched_mgr.h"
24 #include "res_type.h"
25 #include "res_sched_event_reporter.h"
26 
27 
28 namespace OHOS {
29 namespace ResourceSchedule {
30 namespace {
31     static const char* OLD_SYSTEM_FINGERPRINT_PATH = "/data/service/el1/public/ressched/device_version";
32     static const char* SEPARATOR = "|";
33     static const std::vector<std::string> FINGERPRINTS = {
34         "const.product.software.version",
35         "const.product.build.type",
36         "const.product.brand",
37         "const.product.name",
38         "const.product.incremental.version",
39         "const.comp.hl.product_base_version.real"
40     };
41 }
42 
~SystemUpgradeSceneRecognizer()43 SystemUpgradeSceneRecognizer::~SystemUpgradeSceneRecognizer()
44 {
45     RESSCHED_LOGI("~UpdatingSceneRecognizer");
46 }
47 
SystemUpgradeSceneRecognizer()48 SystemUpgradeSceneRecognizer::SystemUpgradeSceneRecognizer()
49 {
50     Init();
51     AddAcceptResTypes({
52         ResType::RES_TYPE_BOOT_COMPLETED,
53     });
54 }
55 
Init()56 void SystemUpgradeSceneRecognizer::Init()
57 {
58     std::string oldSystemFingerprint;
59     OHOS::LoadStringFromFile(OLD_SYSTEM_FINGERPRINT_PATH, oldSystemFingerprint);
60     std::string curSystemFingerprint = GetCurSystemFingerprint();
61     isSystemUpgraded_ = oldSystemFingerprint.empty() || (oldSystemFingerprint != curSystemFingerprint);
62     if (isSystemUpgraded_) {
63         OHOS::SaveStringToFile(OLD_SYSTEM_FINGERPRINT_PATH, curSystemFingerprint, true);
64     }
65     ResschedEventReporter::GetInstance().ReportFileSizeEvent(OLD_SYSTEM_FINGERPRINT_PATH);
66 }
67 
GetCurSystemFingerprint()68 std::string SystemUpgradeSceneRecognizer::GetCurSystemFingerprint()
69 {
70     std::string curSystemFingerprint;
71     for (const auto &item : FINGERPRINTS) {
72         std::string itemFingerprint = OHOS::system::GetParameter(item, "");
73         if (itemFingerprint.empty()) {
74             continue;
75         }
76         if (!curSystemFingerprint.empty()) {
77             curSystemFingerprint.append(SEPARATOR);
78         }
79         curSystemFingerprint.append(itemFingerprint);
80     }
81     return curSystemFingerprint;
82 }
83 
OnDispatchResource(uint32_t resType,int64_t value,const nlohmann::json & payload)84 void SystemUpgradeSceneRecognizer::OnDispatchResource(uint32_t resType, int64_t value, const nlohmann::json& payload)
85 {
86     if (resType != ResType::RES_TYPE_BOOT_COMPLETED) {
87         return;
88     }
89     if (isSystemUpgraded_) {
90         RESSCHED_LOGI("enter updating scene");
91         nlohmann::json payload;
92         ResSchedMgr::GetInstance().ReportData(ResType::RES_TYPE_FIRST_BOOT_AFTER_SYSTEM_UPGRADE, 0, payload);
93     }
94 }
95 } // namespace ResourceSchedule
96 } // namespace OHOS