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 #ifndef FIRMWARE_TASK_OPERATOR_H 17 #define FIRMWARE_TASK_OPERATOR_H 18 19 #include "singleton.h" 20 21 #include "firmware_common.h" 22 #include "firmware_database.h" 23 #include "firmware_task_table.h" 24 #include "firmware_task.h" 25 #include "network_type.h" 26 #include "order.h" 27 28 #ifdef RELATIONAL_STORE_NATIVE_RDB_ENABLE 29 #include "table_base_operator.h" 30 #endif 31 32 namespace OHOS { 33 namespace UpdateEngine { 34 #ifdef RELATIONAL_STORE_NATIVE_RDB_ENABLE 35 class FirmwareTaskOperator final : public TableBaseOperator<FirmwareTaskTable, FirmwareTask> { 36 #else 37 class FirmwareTaskOperator final { 38 #endif 39 public: 40 #ifdef RELATIONAL_STORE_NATIVE_RDB_ENABLE FirmwareTaskOperator()41 FirmwareTaskOperator() : TableBaseOperator(DelayedSingleton<FirmwareDatabase>::GetInstance()) {} 42 #else 43 FirmwareTaskOperator() = default; 44 bool Insert(const FirmwareTask &value); 45 bool DeleteAll(); 46 #endif 47 ~FirmwareTaskOperator() = default; 48 void QueryTask(FirmwareTask &task); 49 bool UpdateProgressByTaskId(const std::string &taskId, UpgradeStatus status, int32_t progress); 50 bool UpdateErrMsgByTaskId(const std::string &taskId, int errorCode, const std::string &errorMsg); 51 bool UpdateDownloadTaskIdByTaskId(const std::string &taskId, const std::string &downloadTaskId); 52 bool UpdateCombinationTypeByTaskId(const std::string &taskId, 53 const CombinationType &combinationType); 54 55 bool UpdateDownloadModeByTaskId(const std::string &taskId, DownloadMode downloadMode); 56 bool UpdateDownloadAllowNetworkByTaskId(const std::string &taskId, NetType downloadAllowNetwork); 57 bool UpdateDownloadOrderByTaskId(const std::string &taskId, Order downloadOrder); 58 bool UpdateDownloadOptionByTaskId(const std::string &taskId, 59 DownloadMode downloadMode, NetType downloadAllowNetwork, Order downloadOrder); 60 61 bool UpdateUpgradeModeByTaskId(const std::string &taskId, UpgradeMode upgradeMode); 62 bool UpdateUpgradeOrderByTaskId(const std::string &taskId, Order upgradeOrder); 63 64 private: 65 #ifdef RELATIONAL_STORE_NATIVE_RDB_ENABLE 66 bool UpdateByTaskId(const std::string &taskId, const NativeRdb::ValuesBucket &values); 67 #endif 68 }; 69 } // namespace UpdateEngine 70 } // namespace OHOS 71 #endif // FIRMWARE_TASK_OPERATOR_H