1*c2e18aaaSAndroid Build Coastguard Worker //! Tool to fingerprint the files on the device's filesystem.
2*c2e18aaaSAndroid Build Coastguard Worker // Run with:
3*c2e18aaaSAndroid Build Coastguard Worker // adb root
4*c2e18aaaSAndroid Build Coastguard Worker // m adevice_fingerprint
5*c2e18aaaSAndroid Build Coastguard Worker // adb push $ANDROID_PRODUCT_OUT/system/bin/adevice_fingerprint /system/bin/adevice_fingerprint
6*c2e18aaaSAndroid Build Coastguard Worker // adb shell /system/bin/adevice_fingerprint --partitions system
7*c2e18aaaSAndroid Build Coastguard Worker
8*c2e18aaaSAndroid Build Coastguard Worker use clap::Parser;
9*c2e18aaaSAndroid Build Coastguard Worker use std::io;
10*c2e18aaaSAndroid Build Coastguard Worker use std::path::PathBuf;
11*c2e18aaaSAndroid Build Coastguard Worker use std::process;
12*c2e18aaaSAndroid Build Coastguard Worker
13*c2e18aaaSAndroid Build Coastguard Worker mod fingerprint;
14*c2e18aaaSAndroid Build Coastguard Worker
main()15*c2e18aaaSAndroid Build Coastguard Worker fn main() {
16*c2e18aaaSAndroid Build Coastguard Worker let cli = HelperCli::parse();
17*c2e18aaaSAndroid Build Coastguard Worker let partitions: Vec<PathBuf> = cli.partitions.iter().map(PathBuf::from).collect();
18*c2e18aaaSAndroid Build Coastguard Worker let root = PathBuf::from("/");
19*c2e18aaaSAndroid Build Coastguard Worker
20*c2e18aaaSAndroid Build Coastguard Worker let infos = fingerprint::fingerprint_partitions(&root, &partitions).unwrap_or_else(|err| {
21*c2e18aaaSAndroid Build Coastguard Worker eprintln!("Error scanning directories: {}", err);
22*c2e18aaaSAndroid Build Coastguard Worker process::exit(1);
23*c2e18aaaSAndroid Build Coastguard Worker });
24*c2e18aaaSAndroid Build Coastguard Worker
25*c2e18aaaSAndroid Build Coastguard Worker serde_json::to_writer(io::stdout(), &infos).unwrap_or_else(|err| {
26*c2e18aaaSAndroid Build Coastguard Worker eprintln!("Error writing json: {}", err);
27*c2e18aaaSAndroid Build Coastguard Worker process::exit(1);
28*c2e18aaaSAndroid Build Coastguard Worker });
29*c2e18aaaSAndroid Build Coastguard Worker }
30*c2e18aaaSAndroid Build Coastguard Worker
31*c2e18aaaSAndroid Build Coastguard Worker #[derive(Parser, Debug)]
32*c2e18aaaSAndroid Build Coastguard Worker #[command(version = "0.4")]
33*c2e18aaaSAndroid Build Coastguard Worker struct HelperCli {
34*c2e18aaaSAndroid Build Coastguard Worker /// Partitions in the product tree to report. Repeat or comma-separate.
35*c2e18aaaSAndroid Build Coastguard Worker #[arg(long, short, global = true,
36*c2e18aaaSAndroid Build Coastguard Worker default_values_t = [String::from("system")], value_delimiter = ',')]
37*c2e18aaaSAndroid Build Coastguard Worker partitions: Vec<String>,
38*c2e18aaaSAndroid Build Coastguard Worker }
39*c2e18aaaSAndroid Build Coastguard Worker
40*c2e18aaaSAndroid Build Coastguard Worker #[cfg(test)]
41*c2e18aaaSAndroid Build Coastguard Worker #[allow(unused)]
42*c2e18aaaSAndroid Build Coastguard Worker mod tests {
43*c2e18aaaSAndroid Build Coastguard Worker use crate::fingerprint;
44*c2e18aaaSAndroid Build Coastguard Worker use std::path::PathBuf;
45*c2e18aaaSAndroid Build Coastguard Worker
46*c2e18aaaSAndroid Build Coastguard Worker // TODO(rbraunstein): Write better device tests.
47*c2e18aaaSAndroid Build Coastguard Worker #[test]
fingerprint_apex()48*c2e18aaaSAndroid Build Coastguard Worker fn fingerprint_apex() {
49*c2e18aaaSAndroid Build Coastguard Worker // Walking system fails on permssion denied because the test isn't run as root.
50*c2e18aaaSAndroid Build Coastguard Worker // TODO(rbraunstein): figure out how to run as root and deal better with filesystem errors.
51*c2e18aaaSAndroid Build Coastguard Worker /*
52*c2e18aaaSAndroid Build Coastguard Worker let partitions: Vec<PathBuf> = Vec::from([PathBuf::from("system")]);
53*c2e18aaaSAndroid Build Coastguard Worker let root = PathBuf::from("/");
54*c2e18aaaSAndroid Build Coastguard Worker
55*c2e18aaaSAndroid Build Coastguard Worker let infos = fingerprint::fingerprint_partitions(&root, &partitions).unwrap();
56*c2e18aaaSAndroid Build Coastguard Worker assert!(infos.len() > 2000);
57*c2e18aaaSAndroid Build Coastguard Worker */
58*c2e18aaaSAndroid Build Coastguard Worker }
59*c2e18aaaSAndroid Build Coastguard Worker }
60