adb.php
adb.php
php
/**
*
* Copyright (C) 2002-2022 MlgmXyysd All Rights Reserved.
* Copyright (C) 2013-2022 MeowCat Studio All Rights Reserved.
* Copyright (C) 2020-2022 Meow Mobile All Rights Reserved.
*
*/
/**
*
* PHP Android Debug Bridge Library
*
* https://github.com/MlgmXyysd/php-adb
*
* Simple wrapper of Android Debug Bridge for PHP.
*
* Environment requirement:
* - PHP
*
* @author MlgmXyysd
* @version 1.2
*
* All copyright in the software is not allowed to be deleted
* or changed without permission.
*
*/
declare(strict_types=1);
namespace MeowMobile;
/**
* MeowMobile/ADB
*/
class ADB {
public $bin;
private $devices;
self::runAdb("root");
self::refreshDeviceList();
}
/**
* Refresh device list and get it
*
* @access public
* @return array Device list
*/
public function refreshDeviceList() {
$this -> devices = array();
$result = self::runAdb("devices -l");
if (self::judgeOutput($result)) {
array_shift($result[0]); // List of devices attached
foreach ($result[0] as $key => $value) {
$value = preg_replace("/[ \t]+/is", " ", $value);
$device = explode(" ", $value);
$temp = array("serial" => "", "status" => "", "transport" => "");
switch ($device[1]) {
case self::CONNECT_TYPE_DEVICE:
case self::CONNECT_TYPE_RECOVERY:
$transport = str_replace("transport_id:", "", $device[5]);
$temp["manufacturer"] = self::runAdb("-t " . $transport . "
shell getprop ro.product.manufacturer")[0][0];
$temp["brand"] = self::runAdb("-t " . $transport . " shell
getprop ro.product.brand")[0][0];
$temp["board"] = self::runAdb("-t " . $transport . " shell
getprop ro.product.board")[0][0];
$temp["name"] = self::runAdb("-t " . $transport . " shell
getprop ro.product.name")[0][0];
case self::CONNECT_TYPE_SIDELOAD:
case self::CONNECT_TYPE_RESCUE:
$temp["serial"] = $device[0];
$temp["status"] = $device[1];
$temp["product"] = str_replace("product:", "", $device[2]);
$temp["model"] = str_replace("model:", "", $device[3]);
$temp["device"] = str_replace("device:", "", $device[4]);
$temp["transport"] = str_replace("transport_id:", "",
$device[5]);
break;
case self::CONNECT_TYPE_UNAUTHORIZED:
case self::CONNECT_TYPE_OFFLINE:
$temp["serial"] = $device[0];
$temp["status"] = $device[1];
$temp["transport"] = str_replace("transport_id:", "",
$device[2]);
break;
}
$this -> devices[] = $temp;
}
}
return $this -> devices;
}
/**
* Get device list
*
* @access public
* @return array Device list
*/
public function getDeviceList() {
return $this -> devices;
}
/* Utilities */