| // Copyright 2026 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package androidtools |
| |
| import ( |
| "strings" |
| |
| "go.chromium.org/infra/cros/recovery/internal/env" |
| "go.chromium.org/infra/cros/recovery/internal/localtlw/localproxy" |
| "go.chromium.org/infra/cros/recovery/tlw" |
| ) |
| |
| // servoMauiSerialPrefix is the prefix for Maui v1 servo serial numbers. |
| // Maui devices are direct-connection devices where the servo serial number |
| // starts with this prefix. |
| const servoMauiSerialPrefix = "MAUIV10" |
| |
| // ADBSerial generates ADB serial based on the DUT name and the defined ADB connection port. |
| // This serial is used to target commands to a specific device when multiple devices are connected. |
| // For network devices, this will be in the format "hostname:port". |
| func ADBSerial(dut *tlw.Dut) string { |
| // Maui cable is direct connection device to the execution host. |
| if sn := MauiSerial(dut); sn != "" { |
| return sn |
| } |
| // TCP based connection. |
| return localproxy.BuildAddrPort(dut.Name, env.ADBPort()) |
| } |
| |
| // MauiSerial extracts the Maui serial number from the DUT if it exists. |
| // |
| // Maui devices (specifically Maui v1 cables) are direct-connection devices where |
| // the servo serial number starts with the prefix 'MAUIV10' (defined by servoMauiSerialPrefix). |
| // This function checks if the DUT has a servo with a serial number matching this prefix. |
| // If it does, it returns the serial number, which is used as the ADB serial for the device. |
| // If the DUT is nil, doesn't have a servo, or the servo serial does not match the prefix, |
| // it returns an empty string. |
| func MauiSerial(dut *tlw.Dut) string { |
| if dut == nil { |
| return "" |
| } |
| sn := dut.GetChromeos().GetServo().GetSerialNumber() |
| |
| if strings.HasPrefix(sn, servoMauiSerialPrefix) { |
| return sn |
| } |
| return "" |
| } |