Class AndroidDeviceUtil

java.lang.Object
com.pnfsoftware.jeb.core.units.code.android.adb.AndroidDeviceUtil

public class AndroidDeviceUtil extends Object
Useful routines when debugging Android devices.
  • Method Details

    • uploadFileToDeviceTemp

      public static String uploadFileToDeviceTemp(AdbWrapper adb, String name, AndroidPlatformABI platformAbi) throws IOException
      Upload a JEB Android asset file to an Android device.
      Parameters:
      adb - ADB wrapper
      name - asset name
      platformAbi - optional ABI
      Returns:
      device path of the uploaded file
      Throws:
      IOException - on upload error
    • uploadFileToDeviceTemp

      public static String uploadFileToDeviceTemp(AdbWrapper adb, String name, AndroidPlatformABI platformAbi, String version, String extension) throws IOException
      Upload a JEB Android asset file to an Android device.
      Parameters:
      adb - mandatory ADB wrapper
      name - mandatory asset name
      platformAbi - optional
      version - optional
      extension - optional
      Returns:
      the path of the copied file on the target device, NOT containing platform/version/extension information
      Throws:
      IOException - on upload error
    • isRootDevice

      public static boolean isRootDevice(AdbWrapper adb)
      Heuristic to determine if the device appears to be rooted - and has a copy of su installed.
      Parameters:
      adb - ADB wrapper
      Returns:
      true if the device appears to be rooted
    • executeCommandAsRoot

      public static boolean executeCommandAsRoot(AdbWrapper adb, String command) throws AdbException
      Attempt to execute a single ADB command as root, with a prior root verification.
      Parameters:
      adb - ADB wrapper
      command - shell command
      Returns:
      true on success
      Throws:
      AdbException - on root or execution error
    • executeCommandAsRoot

      public static boolean executeCommandAsRoot(AdbWrapper adb, boolean rootVerification, String command) throws AdbException
      Attempt to execute a single ADB command as root.
      Parameters:
      adb - ADB wrapper
      rootVerification - true to verify root availability before execution
      command - shell command
      Returns:
      true on success
      Throws:
      AdbException - on root or execution error
    • executeCommandsAsRoot

      public static boolean executeCommandsAsRoot(AdbWrapper adb, String[] commands) throws AdbException
      Attempt to execute a sequence of ADB commands as root, with a prior root verification.
      Parameters:
      adb - ADB wrapper
      commands - shell commands
      Returns:
      true on success
      Throws:
      AdbException - on root or execution error
    • executeCommandsAsRoot

      public static boolean executeCommandsAsRoot(AdbWrapper adb, boolean rootVerification, String[] commands) throws AdbException
      Attempt to execute a sequence of ADB commands as root.
      Parameters:
      adb - ADB wrapper
      rootVerification - true to verify root availability before execution
      commands - shell commands
      Returns:
      true on success
      Throws:
      AdbException - on root or execution error
    • pullFile

      public static boolean pullFile(AdbWrapper adb, String remotePath, String localPath)
      Attempt to pull a file from a device using a variety of methods. Ultimately, if the device is rooted, this method may resort to using super-user capabilities to download the file.
      Parameters:
      adb - ADB wrapper
      remotePath - file path on device
      localPath - local destination path
      Returns:
      true on success
    • getSupportedABIs

      public static List<AndroidPlatformABI> getSupportedABIs(AdbWrapper adb)
      Get the ABIs supported by a device.
      Parameters:
      adb - ADB wrapper
      Returns:
      a list of ABIs, never null, but empty on error
    • getPreferredABI

      public static AndroidPlatformABI getPreferredABI(AdbWrapper adb)
      Get the preferred ABI supported by a device.
      Parameters:
      adb - ADB wrapper
      Returns:
      an ABI, null on error
    • getBestABIForApp

      public static AndroidPlatformABI getBestABIForApp(AdbWrapper adb, IApkUnit apk)
      Get the best ABI to run a given Android app on a given device. This method is a heuristic and may fail.
      Parameters:
      adb - ADB wrapper
      apk - APK unit
      Returns:
      the ABI that should be selected when running the app; null on error if if no compatible ABI was found
    • getProcessesByName

      public static List<Integer> getProcessesByName(AdbWrapper adb, String processName)
      Get a list of PIDs by process name
      Parameters:
      adb - ADB wrapper
      processName - process name
      Returns:
      matching process ids
    • getAndroidApiLevel

      public static int getAndroidApiLevel(AdbWrapper adb)
      Retrieve the numerical API level (eg, 29 on Android Q) of the target.
      Parameters:
      adb - ADB wrapper
      Returns:
      0 on error
    • isDebuggableApp

      public static boolean isDebuggableApp(AdbWrapper adb, String pname)
      Determine whether an installed app is debuggable. An app is debuggable if its manifest has the 'debuggable' attribute explicitly set to true.
      Parameters:
      adb - ADB wrapper
      pname - application package name
      Returns:
      true if the app is debuggable