1
1
// https://android.googlesource.com/platform/packages/modules/adb/+/refs/heads/main/docs/user/adb.1.md
2
2
3
3
use crate :: parse:: { self , Device , ForwardedPorts } ;
4
- use alvr_filesystem:: Layout ;
4
+ use alvr_filesystem as afs ;
5
5
use anyhow:: { anyhow, Context , Result } ;
6
6
use std:: {
7
7
collections:: HashSet ,
8
8
io:: { Cursor , Read } ,
9
- path:: PathBuf ,
10
9
process:: Command ,
11
10
time:: Duration ,
12
11
} ;
@@ -137,7 +136,7 @@ pub fn is_activity_resumed(
137
136
// ADB Installation
138
137
139
138
pub fn require_adb (
140
- layout : & Layout ,
139
+ layout : & afs :: Layout ,
141
140
progress_callback : impl Fn ( usize , Option < usize > ) ,
142
141
) -> Result < String > {
143
142
match get_adb_path ( layout) {
@@ -150,11 +149,12 @@ pub fn require_adb(
150
149
}
151
150
}
152
151
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 ( ) ) ?;
158
158
159
159
Ok ( ( ) )
160
160
}
@@ -261,36 +261,24 @@ pub fn list_installed_packages(adb_path: &str, device_serial: &str) -> Result<Ha
261
261
// Paths
262
262
263
263
/// 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 > {
265
265
get_os_adb_path ( ) . or ( get_local_adb_path ( layout) )
266
266
}
267
267
268
268
fn get_os_adb_path ( ) -> Option < String > {
269
- let name = get_executable_name ( ) . to_owned ( ) ;
269
+ let name = afs :: exec_fname ( "adb" ) . to_owned ( ) ;
270
270
271
271
get_command ( & name, & [ ] ) . output ( ) . is_ok ( ) . then_some ( name)
272
272
}
273
273
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 ( ) ;
276
276
277
277
path. try_exists ( )
278
- . is_ok_and ( |e| e )
278
+ . unwrap_or ( false )
279
279
. then ( || path. to_string_lossy ( ) . to_string ( ) )
280
280
}
281
281
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
-
294
282
//////////////////
295
283
// Port forwarding
296
284
0 commit comments