@@ -34,7 +34,20 @@ var emulatorSerial string
3434// so cleanup only kills it if we own it.
3535var emulatorStartedByTest bool
3636
37+ // onDevice reports whether the test binary is running directly on an
38+ // Android device (i.e. /dev/binder is accessible). When true, the
39+ // emulator/adb setup is skipped — on-device tests open /dev/binder
40+ // directly, and aidlcli tests are skipped.
41+ var onDevice bool
42+
3743func TestMain (m * testing.M ) {
44+ if _ , err := os .Stat ("/dev/binder" ); err == nil {
45+ // Running on the device itself — skip emulator setup.
46+ onDevice = true
47+ os .Exit (m .Run ())
48+ }
49+
50+ // Running on the host — need emulator for aidlcli tests.
3851 serial := findEmulator ()
3952 if serial == "" {
4053 startEmulator ()
@@ -217,9 +230,13 @@ func shellQuote(s string) string {
217230 return "'" + strings .ReplaceAll (s , "'" , "'\\ ''" ) + "'"
218231}
219232
220- // runBindercliOrSkip runs bindercli; skips the test when the service is unavailable.
233+ // runBindercliOrSkip runs bindercli; skips the test when the service is unavailable
234+ // or when running directly on the device (aidlcli tests require adb from the host).
221235func runBindercliOrSkip (t * testing.T , args ... string ) string {
222236 t .Helper ()
237+ if onDevice {
238+ t .Skip ("bindercli tests require adb from host; skipping on-device" )
239+ }
223240 stdout , stderr , err := runBindercli (args ... )
224241 if err != nil {
225242 combined := stderr + stdout
@@ -685,6 +702,9 @@ func runBindercliHALOrSkip(
685702 args ... string ,
686703) string {
687704 t .Helper ()
705+ if onDevice {
706+ t .Skip ("bindercli tests require adb from host; skipping on-device" )
707+ }
688708 fullArgs := append ([]string {serviceName }, args ... )
689709 stdout , stderr , err := runBindercli (fullArgs ... )
690710 if err != nil {
0 commit comments