• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "firmware_task_operator.h"
17 
18 #include <memory>
19 
20 #include "network_type.h"
21 #include "order.h"
22 #include "time_utils.h"
23 #include "update_define.h"
24 #include "upgrade_status.h"
25 
26 namespace OHOS {
27 namespace UpdateService {
QueryTask(FirmwareTask & task)28 void FirmwareTaskOperator::QueryTask(FirmwareTask &task)
29 {
30     std::vector<FirmwareTask> taskList;
31     QueryAll(taskList);
32     if (taskList.empty()) {
33         FIRMWARE_LOGI("FirmwareTaskOperator QueryTask no task");
34         task.isExistTask = false;
35         return;
36     }
37     task = taskList[0];
38     task.isExistTask = true;
39 }
40 
UpdateProgressByTaskId(const std::string & taskId,UpgradeStatus status,int32_t progress)41 bool FirmwareTaskOperator::UpdateProgressByTaskId(const std::string &taskId, UpgradeStatus status, int32_t progress)
42 {
43     NativeRdb::ValuesBucket values;
44     values.PutInt(COLUMN_TASK_STATUS, CAST_INT(status));
45     values.PutInt(COLUMN_TASK_PROGRESS, progress);
46     return UpdateByTaskId(taskId, values);
47 }
48 
UpdateStatusByTaskId(const std::string & taskId,UpgradeStatus status)49 bool FirmwareTaskOperator::UpdateStatusByTaskId(const std::string &taskId, UpgradeStatus status)
50 {
51     NativeRdb::ValuesBucket values;
52     values.PutInt(COLUMN_TASK_STATUS, CAST_INT(status));
53     return UpdateByTaskId(taskId, values);
54 }
55 
UpdateErrMsgByTaskId(const std::string & taskId,int errorCode,const std::string & errorMsg)56 bool FirmwareTaskOperator::UpdateErrMsgByTaskId(const std::string &taskId, int errorCode, const std::string &errorMsg)
57 {
58     NativeRdb::ValuesBucket values;
59     values.PutInt(COLUMN_TASK_ERROR_CODE, errorCode);
60     values.PutString(COLUMN_TASK_ERROR_MSG, errorMsg);
61     return UpdateByTaskId(taskId, values);
62 }
63 
UpdateDownloadTaskIdByTaskId(const std::string & taskId,const std::string & downloadTaskId)64 bool FirmwareTaskOperator::UpdateDownloadTaskIdByTaskId(const std::string &taskId, const std::string &downloadTaskId)
65 {
66     NativeRdb::ValuesBucket values;
67     values.PutString(COLUMN_TASK_DOWNLOAD_TASK_ID, downloadTaskId);
68     return UpdateByTaskId(taskId, values);
69 }
70 
UpdateCombinationTypeByTaskId(const std::string & taskId,const CombinationType & combinationType)71 bool FirmwareTaskOperator::UpdateCombinationTypeByTaskId(const std::string &taskId,
72     const CombinationType &combinationType)
73 {
74     NativeRdb::ValuesBucket values;
75     values.PutInt(COLUMN_TASK_COMBINATION_TYPE, CAST_INT(combinationType));
76     return UpdateByTaskId(taskId, values);
77 }
78 
UpdateDownloadModeByTaskId(const std::string & taskId,DownloadMode downloadMode)79 bool FirmwareTaskOperator::UpdateDownloadModeByTaskId(const std::string &taskId, DownloadMode downloadMode)
80 {
81     NativeRdb::ValuesBucket values;
82     values.PutInt(COLUMN_TASK_DOWNLOAD_MODE, CAST_INT(downloadMode));
83     return UpdateByTaskId(taskId, values);
84 }
85 
UpdateDownloadAllowNetworkByTaskId(const std::string & taskId,NetType downloadAllowNetwork)86 bool FirmwareTaskOperator::UpdateDownloadAllowNetworkByTaskId(const std::string &taskId, NetType downloadAllowNetwork)
87 {
88     NativeRdb::ValuesBucket values;
89     values.PutInt(COLUMN_TASK_DOWNLOAD_ALLOW_NETWORK, CAST_INT(downloadAllowNetwork));
90     return UpdateByTaskId(taskId, values);
91 }
92 
UpdateDownloadOrderByTaskId(const std::string & taskId,Order downloadOrder)93 bool FirmwareTaskOperator::UpdateDownloadOrderByTaskId(const std::string &taskId, Order downloadOrder)
94 {
95     NativeRdb::ValuesBucket values;
96     values.PutInt(COLUMN_TASK_DOWNLOAD_ORDER, CAST_INT(downloadOrder));
97     return UpdateByTaskId(taskId, values);
98 }
99 
UpdateDownloadOptionByTaskId(const std::string & taskId,DownloadMode downloadMode,NetType downloadAllowNetwork,Order downloadOrder)100 bool FirmwareTaskOperator::UpdateDownloadOptionByTaskId(
101     const std::string &taskId, DownloadMode downloadMode, NetType downloadAllowNetwork, Order downloadOrder)
102 {
103     NativeRdb::ValuesBucket values;
104     values.PutInt(COLUMN_TASK_DOWNLOAD_MODE, CAST_INT(downloadMode));
105     values.PutInt(COLUMN_TASK_DOWNLOAD_ALLOW_NETWORK, CAST_INT(downloadAllowNetwork));
106     values.PutInt(COLUMN_TASK_DOWNLOAD_ORDER, CAST_INT(downloadOrder));
107     return UpdateByTaskId(taskId, values);
108 }
109 
UpdateUpgradeModeByTaskId(const std::string & taskId,UpgradeMode upgradeMode)110 bool FirmwareTaskOperator::UpdateUpgradeModeByTaskId(const std::string &taskId, UpgradeMode upgradeMode)
111 {
112     NativeRdb::ValuesBucket values;
113     values.PutInt(COLUMN_TASK_UPGRADE_MODE, CAST_INT(upgradeMode));
114     return UpdateByTaskId(taskId, values);
115 }
116 
UpdateUpgradeOrderByTaskId(const std::string & taskId,Order upgradeOrder)117 bool FirmwareTaskOperator::UpdateUpgradeOrderByTaskId(const std::string &taskId, Order upgradeOrder)
118 {
119     NativeRdb::ValuesBucket values;
120     values.PutInt(COLUMN_TASK_UPGRADE_ORDER, CAST_INT(upgradeOrder));
121     return UpdateByTaskId(taskId, values);
122 }
123 
UpdateByTaskId(const std::string & taskId,const NativeRdb::ValuesBucket & values)124 bool FirmwareTaskOperator::UpdateByTaskId(const std::string &taskId, const NativeRdb::ValuesBucket &values)
125 {
126     OHOS::NativeRdb::RdbPredicates predicates(GetTableName());
127     predicates.EqualTo(COLUMN_TASK_TASK_ID, taskId);
128     return TableBaseOperator::Update(values, predicates);
129 }
130 } // namespace UpdateService
131 } // namespace OHOS
132