• 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 #[derive(Clone, Copy, PartialEq, Debug)]
17 #[repr(u8)]
18 pub enum Action {
19     DOWNLOAD = 0,
20     UPLOAD,
21     ANY,
22 }
23 
24 impl From<u8> for Action {
from(value: u8) -> Self25     fn from(value: u8) -> Self {
26         match value {
27             0 => Action::DOWNLOAD,
28             1 => Action::UPLOAD,
29             _ => Action::ANY,
30         }
31     }
32 }
33 
34 #[derive(Clone, Copy, PartialEq, Debug)]
35 #[repr(u8)]
36 pub enum Mode {
37     BACKGROUND = 0,
38     FRONTEND,
39     ANY,
40 }
41 
42 impl From<u8> for Mode {
from(value: u8) -> Self43     fn from(value: u8) -> Self {
44         match value {
45             0 => Mode::BACKGROUND,
46             1 => Mode::FRONTEND,
47             _ => Mode::ANY,
48         }
49     }
50 }
51 
52 #[derive(Clone, Copy, PartialEq, Debug)]
53 #[repr(u8, C)]
54 pub enum Network {
55     ANY = 0,
56     WIFI,
57     CELLULAR,
58 }
59 
60 #[derive(Debug)]
61 #[repr(C)]
62 pub struct NetworkInfo {
63     pub networkType: Network,
64     pub isMetered: bool,
65     pub isRoaming: bool,
66 }
67 
68 impl From<u8> for Network {
from(value: u8) -> Self69     fn from(value: u8) -> Self {
70         match value {
71             0 => Network::ANY,
72             2 => Network::CELLULAR,
73             _ => Network::WIFI,
74         }
75     }
76 }
77 
78 #[derive(Clone, Copy, PartialEq, Debug)]
79 #[repr(u8)]
80 pub enum State {
81     INITIALIZED = 0x00,
82     WAITING = 0x10,
83     RUNNING = 0x20,
84     RETRYING = 0x21,
85     PAUSED = 0x30,
86     STOPPED = 0x31,
87     COMPLETED = 0x40,
88     FAILED = 0x41,
89     REMOVED = 0x50,
90     CREATED = 0x60,
91     ANY = 0x61,
92 }
93 
94 #[derive(Clone, Copy, PartialEq, Debug)]
95 #[repr(i32)]
96 pub enum ApplicationState {
97     AppStateBegin = 0,
98     AppStateReady,
99     AppStateForeground,
100     AppStateFocus,
101     AppStateBackground,
102     AppStateTerminated,
103     AppStateEnd,
104 }
105 
106 #[derive(Clone, Copy, PartialEq, Debug)]
107 #[repr(i32)]
108 pub enum ErrorCode {
109     ErrOk = 0,
110     UnloadingSA = 1,
111     Ipc_size_too_large = 2,
112     MimeType_not_found = 3,
113     Task_index_too_large = 4,
114     Permission = 201,
115     SystemApi = 202,
116     Parameter_check = 401,
117     FileOperationErr = 13400001,
118     ServiceAbilityErr = 13400003,
119     Other = 13499999,
120     TaskEnqueueErr = 21900004,
121     TaskModeErr,
122     TaskNotFound,
123     TaskStateErr,
124 }
125 
126 #[derive(Clone, Copy, PartialEq, Debug)]
127 #[repr(u8)]
128 pub enum Version {
129     API9 = 1,
130     API10,
131 }
132 
133 impl From<u8> for Version {
from(value: u8) -> Self134     fn from(value: u8) -> Self {
135         match value {
136             2 => Version::API10,
137             _ => Version::API9,
138         }
139     }
140 }
141 
142 #[derive(Clone, Copy, PartialEq, Debug)]
143 #[repr(u8)]
144 pub enum Reason {
145     Default = 0,
146     TaskSurvivalOneMonth,
147     WaittingNetWorkOneday,
148     StoppedByNewFrontTask,
149     RunningTaskMeetLimits,
150     UserOperation,
151     AppBackgroundOrTerminate,
152     NetWorkOffline,
153     UnSupportedNetWorkType,
154     BuildClientFailed,
155     BuildRequestFailed,
156     GetFileSizeFailed,
157     ContinuousTaskTimeOut,
158     ConnectError,
159     RequestError,
160     UploadFileError,
161     RedirectError,
162     ProtocolError,
163     IoError,
164     UnSupportRangeRequest,
165     OthersError,
166 }
167 
168 impl From<u8> for Reason {
from(value: u8) -> Self169     fn from(value: u8) -> Self {
170         match value {
171             0 => Reason::Default,
172             1 => Reason::TaskSurvivalOneMonth,
173             2 => Reason::WaittingNetWorkOneday,
174             3 => Reason::StoppedByNewFrontTask,
175             4 => Reason::RunningTaskMeetLimits,
176             5 => Reason::UserOperation,
177             6 => Reason::AppBackgroundOrTerminate,
178             7 => Reason::NetWorkOffline,
179             8 => Reason::UnSupportedNetWorkType,
180             9 => Reason::BuildClientFailed,
181             10 => Reason::BuildRequestFailed,
182             11 => Reason::GetFileSizeFailed,
183             12 => Reason::ContinuousTaskTimeOut,
184             13 => Reason::ConnectError,
185             14 => Reason::RequestError,
186             15 => Reason::UploadFileError,
187             16 => Reason::RedirectError,
188             17 => Reason::ProtocolError,
189             18 => Reason::IoError,
190             19 => Reason::UnSupportRangeRequest,
191             _ => Reason::OthersError,
192         }
193     }
194 }
195 
196 impl Reason {
to_str(&self) -> &'static str197     pub fn to_str(&self) -> &'static str {
198         match self {
199             Reason::Default => "".into(),
200             Reason::TaskSurvivalOneMonth => "The task has not been completed for a month yet",
201             Reason::WaittingNetWorkOneday => "The task waiting for network recovery has not been completed for a day yet",
202             Reason::StoppedByNewFrontTask => "Stopped by a new front task",
203             Reason::RunningTaskMeetLimits => "Too many task in running state",
204             Reason::UserOperation => "User operation",
205             Reason::AppBackgroundOrTerminate => "The app is background or terminate",
206             Reason::NetWorkOffline => "NetWork is offline",
207             Reason::UnSupportedNetWorkType => "NetWork type not meet the task config",
208             Reason::BuildClientFailed => "Build client error",
209             Reason::BuildRequestFailed => "Build request error",
210             Reason::GetFileSizeFailed => "Failed because cannot get the file size from the server and the precise is setted true by user",
211             Reason::ContinuousTaskTimeOut => "Continuous processing task time out",
212             Reason::ConnectError => "Connect error",
213             Reason::RequestError => "Request error",
214             Reason::UploadFileError => "There are some files upload failed",
215             Reason::RedirectError => "Redirect error",
216             Reason::ProtocolError => "Http protocol error",
217             Reason::IoError => "Io Error",
218             Reason::UnSupportRangeRequest => "The server is not support range request",
219             Reason::OthersError => "Some other error occured",
220         }
221     }
222 }
223 
224 #[derive(PartialEq)]
225 #[repr(u8, C)]
226 pub enum QueryPermission {
227     NoPermisson = 0,
228     QueryDownLoad,
229     QueryUpload,
230     QueryAll,
231 }