• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 pub(crate) use ffi::Reason;
15 
16 #[cxx::bridge(namespace = "OHOS::Request")]
17 mod ffi {
18     #[derive(Clone, Copy, PartialEq, Debug)]
19     #[repr(u8)]
20     pub(crate) enum Reason {
21         Default = 0,
22         TaskSurvivalOneMonth,
23         RunningTaskMeetLimits = 4,
24         UserOperation,
25         AppBackgroundOrTerminate,
26         NetworkOffline,
27         UnsupportedNetworkType,
28         BuildRequestFailed = 10,
29         GetFileSizeFailed,
30         ContinuousTaskTimeout = 12,
31         RequestError = 14,
32         UploadFileError,
33         RedirectError,
34         ProtocolError,
35         IoError,
36         UnsupportedRangeRequest,
37         OthersError,
38         AccountStopped,
39         Dns = 23,
40         Tcp,
41         Ssl,
42         InsufficientSpace,
43         NetworkApp = 27,
44         NetworkAccount = 28,
45         AppAccount = 29,
46         NetworkAppAccount = 30,
47         LowSpeed = 31,
48     }
49 }
50 
51 impl From<u8> for Reason {
from(value: u8) -> Self52     fn from(value: u8) -> Self {
53         match value {
54             0 => Reason::Default,
55             1 => Reason::TaskSurvivalOneMonth,
56             4 => Reason::RunningTaskMeetLimits,
57             5 => Reason::UserOperation,
58             6 => Reason::AppBackgroundOrTerminate,
59             7 => Reason::NetworkOffline,
60             8 => Reason::UnsupportedNetworkType,
61             10 => Reason::BuildRequestFailed,
62             11 => Reason::GetFileSizeFailed,
63             12 => Reason::ContinuousTaskTimeout,
64             14 => Reason::RequestError,
65             15 => Reason::UploadFileError,
66             16 => Reason::RedirectError,
67             17 => Reason::ProtocolError,
68             18 => Reason::IoError,
69             19 => Reason::UnsupportedRangeRequest,
70             21 => Reason::AccountStopped,
71             23 => Reason::Dns,
72             24 => Reason::Tcp,
73             25 => Reason::Ssl,
74             26 => Reason::InsufficientSpace,
75             27 => Reason::NetworkApp,
76             28 => Reason::NetworkAccount,
77             29 => Reason::AppAccount,
78             30 => Reason::NetworkAppAccount,
79             31 => Reason::LowSpeed,
80             _ => Reason::OthersError,
81         }
82     }
83 }
84 
85 impl Reason {
to_str(self) -> &'static str86     pub(crate) fn to_str(self) -> &'static str {
87         match self {
88             Reason::Default => "",
89             Reason::TaskSurvivalOneMonth => "The task has not been completed for a month yet",
90             Reason::RunningTaskMeetLimits => "Too many task in running state",
91             Reason::UserOperation => "User operation",
92             Reason::AppBackgroundOrTerminate => "The app is background or terminate",
93             Reason::NetworkOffline => "NetWork is offline",
94             Reason::UnsupportedNetworkType => "NetWork type not meet the task config",
95             Reason::BuildRequestFailed => "Build request error",
96             Reason::GetFileSizeFailed => "Failed because cannot get the file size from the server and the precise is setted true by user",
97             Reason::ContinuousTaskTimeout => "Continuous processing task time out",
98             Reason::RequestError => "Request error",
99             Reason::UploadFileError => "There are some files upload failed",
100             Reason::RedirectError => "Redirect error",
101             Reason::ProtocolError => "Http protocol error",
102             Reason::IoError => "Io Error",
103             Reason::UnsupportedRangeRequest => "The server is not support range request",
104             Reason::OthersError => "Some other error occured",
105             Reason::AccountStopped => "Account stopped",
106             Reason::Dns => "DNS error",
107             Reason::Tcp => "TCP error",
108             Reason::Ssl => "TSL/SSL error",
109             Reason::InsufficientSpace => "Insufficient space",
110             Reason::NetworkApp => "NetWork is offline and the app is background or terminate",
111             Reason::NetworkAccount => "NetWork is offline and the account is stopped",
112             Reason::AppAccount => "The app is background or terminate and the account is stopped",
113             Reason::NetworkAppAccount => "NetWork is offline and the app is background or terminate and the account is stopped",
114             Reason::LowSpeed => "Below low speed limit",
115             _ => "unknown error",
116         }
117     }
118 }
119 
120 #[cfg(test)]
121 mod ut_reason {
122     include!("../../tests/ut/task/ut_reason.rs");
123 }
124