1 /*
2 * Copyright (c) 2022 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 "slot_info/slot_info.h"
17
18 #include "log/log.h"
19 #include "partitionslot_manager.h"
20
21 namespace Updater {
22 #ifndef UPDATER_AB_SUPPORT
GetPartitionSuffix(std::string & suffix)23 void GetPartitionSuffix(std::string &suffix)
24 {
25 suffix = "";
26 }
SetActiveSlot()27 void SetActiveSlot()
28 {
29 }
30 #else
31 void GetPartitionSuffix(std::string &suffix)
32 {
33 OHOS::HDI::Partitionslot::V1_0::PartitionSlotManager psMgr;
34 int32_t curSlot = -1;
35 int32_t numOfSlots = 0;
36 int32_t ret = psMgr.GetCurrentSlot(curSlot, numOfSlots);
37 LOG(INFO) << "Get slot info, curSlot: " << curSlot << "numOfSlots :" << numOfSlots;
38 if (ret != 0 || curSlot <= 0 || curSlot > 2 || numOfSlots != 2) { // 2: max slot num
39 suffix = "";
40 return;
41 }
42
43 int32_t updateSlot = curSlot == 1 ? 2 : 1;
44 ret = psMgr.GetSlotSuffix(updateSlot, suffix);
45 if (ret != 0) {
46 LOG(ERROR) << "Get slot suffix error, partitionPath: " << suffix;
47 suffix = "";
48 }
49 }
50
51 void SetActiveSlot()
52 {
53 OHOS::HDI::Partitionslot::V1_0::PartitionSlotManager psMgr;
54 int32_t curSlot = -1;
55 int32_t numOfSlots = 0;
56 int32_t ret = psMgr.GetCurrentSlot(curSlot, numOfSlots);
57 LOG(INFO) << "Get slot info, curSlot: " << curSlot << "numOfSlots :" << numOfSlots;
58 if (ret != 0 || curSlot <= 0 || curSlot > 2 || numOfSlots != 2) { // 2: max slot num
59 return;
60 }
61
62 int32_t activeSlot = curSlot == 1 ? 2 : 1;
63 ret = psMgr.SetActiveSlot(activeSlot);
64 if (ret != 0) {
65 LOG(ERROR) << "Set active slot error, slot: " << activeSlot;
66 }
67 }
68 #endif
69 } // Updater
70