1 /* 2 * Copyright (C) 2024 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 //! shell 16 17 #[allow(unused_imports)] 18 use crate::daemon_lib::daemon_app; 19 use crate::daemon_lib::shell; 20 use crate::daemon_lib::auth; 21 #[allow(unused_imports)] 22 use crate::common::forward; 23 #[allow(unused_imports)] 24 use crate::common::jdwp; 25 #[allow(unused_imports)] 26 use crate::common::hdcfile; 27 #[allow(unused_imports)] 28 use crate::utils::hdc_log::*; 29 use crate::config::ConnectType; 30 use crate::transfer::buffer; 31 use crate::transfer::TcpMap; 32 use crate::transfer::UsbMap; 33 use crate::transfer::ConnectTypeMap; 34 35 pub async fn free_all_sessiones() { 36 let sessiones = ConnectTypeMap::get_all_session().await; 37 for session_id in sessiones { 38 free_session(session_id).await; 39 } 40 } 41 42 pub async fn free_session(session_id: u32) { 43 auth::AuthStatusMap::remove(session_id).await; 44 stop_task(session_id).await; 45 match ConnectTypeMap::get(session_id).await { 46 Some(ConnectType::Bt) => {} 47 Some(ConnectType::Tcp) => { 48 TcpMap::end(session_id).await; 49 } 50 Some(ConnectType::Uart) => {} 51 Some(ConnectType::Usb(_)) => { 52 UsbMap::end(session_id).await; 53 } 54 55 Some(ConnectType::HostUsb(_)) => { 56 // add to avoid warning 57 } 58 59 Some(ConnectType::Bridge) => {} 60 61 None => { 62 crate::warn!("free_session cannot find connect type for session_id:{session_id}"); 63 } 64 } 65 } 66 67 pub async fn stop_task(session_id: u32) { 68 hdcfile::stop_task(session_id).await; 69 shell::stop_task(session_id).await; 70 daemon_app::stop_task(session_id).await; 71 forward::stop_task(session_id).await; 72 jdwp::stop_session_task(session_id).await; 73 } 74 75 pub async fn dump_running_task_info() -> String { 76 let mut result = "\n".to_string(); 77 result.push_str(&format!("{:#}", buffer::dump_session().await)); 78 result.push_str(&format!("{:#}", hdcfile::dump_task().await)); 79 result.push_str(&format!("{:#}", shell::dump_task().await)); 80 result.push_str(&format!("{:#}", daemon_app::dump_task().await)); 81 result.push_str(&format!("{:#}", forward::dump_task().await)); 82 result.push_str("# "); 83 result.to_string() 84 } 85