• 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_table.h"
17 
18 #include "update_define.h"
19 
20 namespace OHOS {
21 namespace UpdateEngine {
GetTableName()22 std::string FirmwareTaskTable::GetTableName()
23 {
24     return FIRMWARE_TABLE_TASK;
25 }
26 
GetTableCreateSql()27 std::string FirmwareTaskTable::GetTableCreateSql()
28 {
29     return std::string("create table if not exists ")
30         .append(FIRMWARE_TABLE_TASK + " (")
31         .append(COLUMN_ID + " integer PRIMARY KEY autoincrement not null,")
32         .append(COLUMN_TASK_TASK_ID + " varchar(128),")
33         .append(COLUMN_TASK_STATUS + " integer,")
34         .append(COLUMN_TASK_PROGRESS + " integer,")
35         .append(COLUMN_TASK_DOWNLOAD_TASK_ID + " varchar(128),")
36         .append(COLUMN_TASK_ERROR_CODE + " integer,")
37         .append(COLUMN_TASK_ERROR_MSG + " varchar(512),")
38         .append(COLUMN_TASK_COMBINATION_TYPE + " integer,")
39         .append(COLUMN_TASK_DOWNLOAD_MODE + " integer,")
40         .append(COLUMN_TASK_DOWNLOAD_ALLOW_NETWORK + " integer,")
41         .append(COLUMN_TASK_DOWNLOAD_ORDER + " integer,")
42         .append(COLUMN_TASK_UPGRADE_MODE + " integer,")
43         .append(COLUMN_TASK_UPGRADE_ORDER + " integer,")
44         .append(COLUMN_TASK_AUTH_RESULT + " varchar(10240),")
45         .append(COLUMN_TASK_UPDATE_TOKEN + " varchar(256),")
46         .append(COLUMN_TASK_DEVICE_TOKEN + " varchar(256),")
47         .append(COLUMN_TASK_TOKEN_H_MAC + " varchar(256),")
48         .append(COLUMN_TASK_CURR_VERSION_LIST + " varchar(1024),")
49         .append(COLUMN_TASK_AUTH_TIME + " bigint,")
50         .append(COLUMN_TASK_EXTENDS1 + " varchar(256),")
51         .append(COLUMN_TASK_EXTENDS2 + " varchar(256),")
52         .append(COLUMN_TASK_EXTENDS3 + " varchar(256),")
53         .append(COLUMN_TASK_EXTENDS4 + " varchar(256),")
54         .append(COLUMN_TASK_EXTENDS5 + " varchar(256),")
55         .append(COLUMN_TASK_EXTENDS6 + " varchar(256)")
56         .append(")");
57 }
58 
ParseDbValue(ResultSet * resultSet,FirmwareTask & value)59 void FirmwareTaskTable::ParseDbValue(ResultSet *resultSet, FirmwareTask &value)
60 {
61     GetColumnValue(resultSet, COLUMN_TASK_TASK_ID, value.taskId);
62     int32_t status = CAST_INT(UpgradeStatus::INIT);
63     GetColumnValue(resultSet, COLUMN_TASK_STATUS, status);
64     value.status = static_cast<UpgradeStatus>(status);
65     GetColumnValue(resultSet, COLUMN_TASK_PROGRESS, value.progress);
66     GetColumnValue(resultSet, COLUMN_TASK_DOWNLOAD_TASK_ID, value.downloadTaskId);
67     GetColumnValue(resultSet, COLUMN_TASK_ERROR_CODE, value.errorCode);
68     GetColumnValue(resultSet, COLUMN_TASK_ERROR_MSG, value.errorMsg);
69     int32_t combinationType = CAST_INT(CombinationType::INVALLID_TYPE);
70     GetColumnValue(resultSet, COLUMN_TASK_COMBINATION_TYPE, combinationType);
71     value.combinationType = static_cast<CombinationType>(combinationType);
72     int32_t downloadMode = CAST_INT(DownloadMode::MANUAL);
73     GetColumnValue(resultSet, COLUMN_TASK_DOWNLOAD_MODE, downloadMode);
74     value.downloadMode = static_cast<DownloadMode>(downloadMode);
75     int32_t downloadAllowNetwork = CAST_INT(NetType::WIFI);
76     GetColumnValue(resultSet, COLUMN_TASK_DOWNLOAD_ALLOW_NETWORK, downloadAllowNetwork);
77     value.downloadAllowNetwork = static_cast<NetType>(downloadAllowNetwork);
78     int32_t downloadOrder = CAST_INT(NetType::WIFI);
79     GetColumnValue(resultSet, COLUMN_TASK_DOWNLOAD_ORDER, downloadOrder);
80     value.downloadOrder = static_cast<Order>(downloadOrder);
81     int32_t upgradeMode = CAST_INT(UpgradeMode::MANUAL);
82     GetColumnValue(resultSet, COLUMN_TASK_UPGRADE_MODE, upgradeMode);
83     value.upgradeMode = static_cast<UpgradeMode>(upgradeMode);
84     int32_t upgradeOrder = CAST_INT(Order::INSTALL_AND_APPLY);
85     GetColumnValue(resultSet, COLUMN_TASK_UPGRADE_ORDER, upgradeOrder);
86     value.upgradeOrder = static_cast<Order>(upgradeOrder);
87     GetColumnValue(resultSet, COLUMN_TASK_AUTH_RESULT, value.authResult);
88     GetColumnValue(resultSet, COLUMN_TASK_UPDATE_TOKEN, value.updateToken);
89     GetColumnValue(resultSet, COLUMN_TASK_DEVICE_TOKEN, value.deviceToken);
90     GetColumnValue(resultSet, COLUMN_TASK_TOKEN_H_MAC, value.tokenHMac);
91     GetColumnValue(resultSet, COLUMN_TASK_CURR_VERSION_LIST, value.currentVersionList);
92     GetColumnValue(resultSet, COLUMN_TASK_AUTH_TIME, value.authTime);
93 }
94 
BuildDbValue(const FirmwareTask & value,NativeRdb::ValuesBucket & dbValue)95 void FirmwareTaskTable::BuildDbValue(const FirmwareTask &value, NativeRdb::ValuesBucket &dbValue)
96 {
97     PutColumnValue(dbValue, COLUMN_TASK_TASK_ID, value.taskId);
98     PutColumnValue(dbValue, COLUMN_TASK_STATUS, CAST_INT(value.status));
99     PutColumnValue(dbValue, COLUMN_TASK_PROGRESS, value.progress);
100     PutColumnValue(dbValue, COLUMN_TASK_DOWNLOAD_TASK_ID, value.downloadTaskId);
101     PutColumnValue(dbValue, COLUMN_TASK_ERROR_CODE, value.errorCode);
102     PutColumnValue(dbValue, COLUMN_TASK_ERROR_MSG, value.errorMsg);
103     PutColumnValue(dbValue, COLUMN_TASK_COMBINATION_TYPE, CAST_INT(value.combinationType));
104     PutColumnValue(dbValue, COLUMN_TASK_DOWNLOAD_MODE, CAST_INT(value.downloadMode));
105     PutColumnValue(dbValue, COLUMN_TASK_DOWNLOAD_ALLOW_NETWORK, CAST_INT(value.downloadAllowNetwork));
106     PutColumnValue(dbValue, COLUMN_TASK_DOWNLOAD_ORDER, CAST_INT(value.downloadOrder));
107     PutColumnValue(dbValue, COLUMN_TASK_UPGRADE_MODE, CAST_INT(value.upgradeMode));
108     PutColumnValue(dbValue, COLUMN_TASK_UPGRADE_ORDER, CAST_INT(value.upgradeOrder));
109     PutColumnValue(dbValue, COLUMN_TASK_AUTH_RESULT, value.authResult);
110     PutColumnValue(dbValue, COLUMN_TASK_UPDATE_TOKEN, value.updateToken);
111     PutColumnValue(dbValue, COLUMN_TASK_DEVICE_TOKEN, value.deviceToken);
112     PutColumnValue(dbValue, COLUMN_TASK_TOKEN_H_MAC, value.tokenHMac);
113     PutColumnValue(dbValue, COLUMN_TASK_CURR_VERSION_LIST, value.currentVersionList);
114     PutColumnValue(dbValue, COLUMN_TASK_AUTH_TIME, value.authTime);
115 }
116 } // namespace UpdateEngine
117 } // namespace OHOS