Skip to content

Commit 3ea68c4

Browse files
committedMar 15, 2025
fix(dashboard): 🐛 Fix SteamVR fail to launch for dangling ADB process
1 parent deaff3d commit 3ea68c4

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed
 

‎alvr/adb/src/commands.rs

+13-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/docs/user/adb.1.md
22

33
use crate::parse::{self, Device, ForwardedPorts};
4-
use alvr_filesystem::Layout;
4+
use alvr_filesystem as afs;
55
use anyhow::{anyhow, Context, Result};
66
use std::{
77
collections::HashSet,
88
io::{Cursor, Read},
9-
path::PathBuf,
109
process::Command,
1110
time::Duration,
1211
};
@@ -137,7 +136,7 @@ pub fn is_activity_resumed(
137136
// ADB Installation
138137

139138
pub fn require_adb(
140-
layout: &Layout,
139+
layout: &afs::Layout,
141140
progress_callback: impl Fn(usize, Option<usize>),
142141
) -> Result<String> {
143142
match get_adb_path(layout) {
@@ -150,11 +149,12 @@ pub fn require_adb(
150149
}
151150
}
152151

153-
fn install_adb(layout: &Layout, progress_callback: impl Fn(usize, Option<usize>)) -> Result<()> {
154-
let buffer = download_adb(progress_callback)?;
155-
let mut reader = Cursor::new(buffer);
156-
let path = get_installation_path(layout);
157-
ZipArchive::new(&mut reader)?.extract(path)?;
152+
fn install_adb(
153+
layout: &afs::Layout,
154+
progress_callback: impl Fn(usize, Option<usize>),
155+
) -> Result<()> {
156+
let mut reader = Cursor::new(download_adb(progress_callback)?);
157+
ZipArchive::new(&mut reader)?.extract(layout.executables_dir.clone())?;
158158

159159
Ok(())
160160
}
@@ -261,36 +261,24 @@ pub fn list_installed_packages(adb_path: &str, device_serial: &str) -> Result<Ha
261261
// Paths
262262

263263
/// Returns the path of a local (i.e. installed by ALVR) or OS version of `adb` if found, `None` otherwise.
264-
fn get_adb_path(layout: &Layout) -> Option<String> {
264+
fn get_adb_path(layout: &afs::Layout) -> Option<String> {
265265
get_os_adb_path().or(get_local_adb_path(layout))
266266
}
267267

268268
fn get_os_adb_path() -> Option<String> {
269-
let name = get_executable_name().to_owned();
269+
let name = afs::exec_fname("adb").to_owned();
270270

271271
get_command(&name, &[]).output().is_ok().then_some(name)
272272
}
273273

274-
fn get_local_adb_path(layout: &Layout) -> Option<String> {
275-
let path = get_platform_tools_path(layout).join(get_executable_name());
274+
fn get_local_adb_path(layout: &afs::Layout) -> Option<String> {
275+
let path = layout.local_adb_exe();
276276

277277
path.try_exists()
278-
.is_ok_and(|e| e)
278+
.unwrap_or(false)
279279
.then(|| path.to_string_lossy().to_string())
280280
}
281281

282-
fn get_installation_path(layout: &Layout) -> PathBuf {
283-
layout.executables_dir.to_owned()
284-
}
285-
286-
fn get_platform_tools_path(layout: &Layout) -> PathBuf {
287-
get_installation_path(layout).join("platform-tools")
288-
}
289-
290-
fn get_executable_name() -> String {
291-
alvr_filesystem::exec_fname("adb")
292-
}
293-
294282
//////////////////
295283
// Port forwarding
296284

‎alvr/dashboard/src/data_sources.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use alvr_packets::ServerRequest;
44
use alvr_server_io::ServerSessionManager;
55
use eframe::egui;
66
use std::{
7-
env,
87
io::ErrorKind,
98
net::{SocketAddr, TcpStream},
109
str::FromStr,
@@ -25,9 +24,7 @@ enum SessionSource {
2524
}
2625

2726
pub fn get_local_session_source() -> ServerSessionManager {
28-
let session_file_path =
29-
alvr_filesystem::filesystem_layout_from_dashboard_exe(&env::current_exe().unwrap())
30-
.session();
27+
let session_file_path = crate::get_filesystem_layout().session();
3128

3229
ServerSessionManager::new(Some(session_file_path))
3330
}
@@ -150,10 +147,7 @@ impl DataSources {
150147
}
151148
ServerRequest::RegisterAlvrDriver => {
152149
let alvr_driver_dir =
153-
alvr_filesystem::filesystem_layout_from_dashboard_exe(
154-
&env::current_exe().unwrap(),
155-
)
156-
.openvr_driver_root_dir;
150+
crate::get_filesystem_layout().openvr_driver_root_dir;
157151

158152
alvr_server_io::driver_registration(&[alvr_driver_dir], true)
159153
.ok();

‎alvr/dashboard/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ use data_sources::DataSources;
1717
#[cfg(target_arch = "wasm32")]
1818
use data_sources_wasm::DataSources;
1919

20+
use alvr_filesystem as afs;
2021
use dashboard::Dashboard;
2122

23+
fn get_filesystem_layout() -> afs::Layout {
24+
afs::filesystem_layout_from_dashboard_exe(&std::env::current_exe().unwrap())
25+
}
26+
2227
#[cfg(not(target_arch = "wasm32"))]
2328
fn main() {
2429
use alvr_common::ALVR_VERSION;

‎alvr/dashboard/src/steamvr_launcher/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ pub struct Launcher {
115115

116116
impl Launcher {
117117
pub fn launch_steamvr(&self) {
118+
// The ADB server might be left running because of a unclean termination of SteamVR
119+
let local_adb_path = crate::get_filesystem_layout().local_adb_exe();
120+
for proc in
121+
sysinfo::System::new_all().processes_by_name(OsStr::new(&afs::exec_fname("adb")))
122+
{
123+
if let Some(proc_path) = proc.exe() {
124+
if proc_path == local_adb_path {
125+
proc.kill();
126+
}
127+
}
128+
}
129+
118130
#[cfg(target_os = "linux")]
119131
linux_steamvr::linux_hardware_checks();
120132

‎alvr/filesystem/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ impl Layout {
199199
self.executables_dir.join(dashboard_fname())
200200
}
201201

202+
pub fn local_adb_dir(&self) -> PathBuf {
203+
self.executables_dir.join("platform-tools")
204+
}
205+
206+
pub fn local_adb_exe(&self) -> PathBuf {
207+
self.local_adb_dir().join(exec_fname("adb"))
208+
}
209+
202210
pub fn resources_dir(&self) -> PathBuf {
203211
self.openvr_driver_root_dir.join("resources")
204212
}

0 commit comments

Comments
 (0)