mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-23 15:00:48 +00:00
!866 [Bug]: config 中 network 设置为 ANY,metered 设置为 false,设备仅用流量时,任务不应该运行
Merge pull request !866 from ZhangJianxin/metered
This commit is contained in:
commit
91d2306988
@ -48,16 +48,21 @@ impl Network {
|
||||
|
||||
pub(crate) fn satisfied_state(&self, config: &TaskConfig) -> bool {
|
||||
match &*self.state() {
|
||||
// Handles in `RequestTask::network_online`.
|
||||
NetworkState::Offline => true,
|
||||
NetworkState::Online(info) => match config.common_data.network_config {
|
||||
NetworkConfig::Any => true,
|
||||
NetworkConfig::Wifi if info.network_type == NetworkType::Cellular => false,
|
||||
NetworkConfig::Cellular if info.network_type == NetworkType::Wifi => false,
|
||||
_ => {
|
||||
(config.common_data.roaming || !info.is_roaming)
|
||||
&& (config.common_data.metered || !info.is_metered)
|
||||
NetworkState::Online(info) => {
|
||||
let cellular_satisfy = (config.common_data.roaming || !info.is_roaming)
|
||||
&& (config.common_data.metered || !info.is_metered);
|
||||
match config.common_data.network_config {
|
||||
NetworkConfig::Wifi => info.network_type == NetworkType::Wifi,
|
||||
NetworkConfig::Cellular => {
|
||||
info.network_type == NetworkType::Cellular && cellular_satisfy
|
||||
}
|
||||
NetworkConfig::Any => {
|
||||
info.network_type != NetworkType::Cellular || cellular_satisfy
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ impl TaskOperator {
|
||||
|
||||
let state = self.task.status.lock().unwrap().state;
|
||||
if (state != State::Running && state != State::Retrying)
|
||||
|| (self.task.conf.version == Version::API10 && !self.task.check_net_work_status())
|
||||
|| (self.task.conf.version == Version::API10 && !self.task.check_network_status())
|
||||
{
|
||||
info!("pause the task, tid: {}", self.task.task_id());
|
||||
return Poll::Ready(Err(HttpClientError::user_aborted()));
|
||||
|
@ -108,7 +108,7 @@ impl RequestTask {
|
||||
}
|
||||
|
||||
pub(crate) fn satisfied(&self) -> bool {
|
||||
if !self.net_work_online() || !self.check_net_work_status() {
|
||||
if !self.network_online() || !self.check_network_status() {
|
||||
error!("check network failed, tid: {}", self.task_id());
|
||||
false
|
||||
} else {
|
||||
@ -263,7 +263,7 @@ impl RequestTask {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn check_net_work_status(&self) -> bool {
|
||||
pub(crate) fn check_network_status(&self) -> bool {
|
||||
if !self.is_satisfied_configuration() {
|
||||
if !(self.conf.version == Version::API10
|
||||
&& self.conf.common_data.mode == Mode::BackGround
|
||||
@ -289,7 +289,7 @@ impl RequestTask {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn net_work_online(&self) -> bool {
|
||||
pub(crate) fn network_online(&self) -> bool {
|
||||
if !self.network.is_online() {
|
||||
if self.conf.version == Version::API10
|
||||
&& self.conf.common_data.mode == Mode::BackGround
|
||||
|
@ -354,7 +354,7 @@ impl Take<HashMap<String, String>> for &[u8] {
|
||||
|
||||
impl Take<String> for &[u8] {
|
||||
fn take_value(&mut self) -> String {
|
||||
let len = self.iter().position(|c| *c == b'\0' as u8).unwrap();
|
||||
let len = self.iter().position(|c| *c == b'\0').unwrap();
|
||||
let (left, right) = self.split_at(len + 1);
|
||||
*self = right;
|
||||
CString::from_vec_with_nul(left.to_vec())
|
||||
|
Loading…
Reference in New Issue
Block a user