1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! An utility for testing the behavior of `android_logger` crate.
//!
//! ## Build
//!
//! 1. Setup [`cargo-ndk`](https://github.com/bbqsrc/cargo-ndk)
//!
//! ```
//! cargo install cargo-ndk
//! rustup target add x86_64-linux-android
//! ```
//!
//! 2. Build with `cargo ndk`:
//!
//! ```
//! ANDROID_NDK_HOME=/usr/lib/android-sdk/ndk/27.1.12297006 \
//! cargo ndk -t x86_64 build --release --features android-api-30 \
//! --example system_log_level_overrides
//! ```
//!
//! ## Run on emulator
//!
//! 1. Grab a [Cuttlefish](https://source.android.com/docs/devices/cuttlefish)
//! virtual device + Android build from [Android
//! CI](https://ci.android.com/builds/branches/aosp-main/grid?legacy=1). Select
//! the last green `aosp_cf_x86_64_phone` `trunk_staging-userdebug` build and
//! open "Artifacts" link, download:
//!
//! - `aosp_cf_x86_64_phone-img-BUILDNUMBER.zip`
//! - `cvd-host_package.tar.gz`
//!
//! 2. Unpack both archives & start the emulator.
//!
//! ```
//! cd $(mktemp -d)
//! unzip ~/Downloads/aosp_cf_x86_64_phone-img-*.zip
//! tar xf ~/Downloads/cvd-host_package.tar.gz
//! HOME=$PWD bin/launch_cvd
//! ```
//!
//! Once emulator launches, `adb` should detect it on `0.0.0.0:6520`
//! automatically. Shut down the `launch_cvd` command to exit the emulator.
//!
//! 3. Upload & run:
//!
//! ```
//! adb push ./target/x86_64-linux-android/release/examples/system_log_level_overrides /data/local/tmp/
//! adb shell /data/local/tmp/system_log_level_overrides
//! ```
//!
//! ## Test interaction with Android system properties
//!
//! See [`logd`
//! README](https://cs.android.com/android/platform/superproject/main/+/main:system/logging/logd/README.property)
//! in AOSP for details.
//!
//! ```
//! # default: should print info+ logs in `adb logcat -s log_test`
//! # hint: use `adb logcat -v color` is awesome too
//! adb shell /data/local/tmp/system_log_level_overrides
//!
//! # should print trace+ logs in `adb logcat -s log_test`
//! adb shell setprop log.tag V
//! adb shell /data/local/tmp/system_log_level_overrides
//!
//! # should print warn+ logs in `adb logcat -s log_test`
//! adb shell setprop log.tag.log_test W
//! adb shell /data/local/tmp/system_log_level_overrides
//! ```