From 69c9892c6d23ec046eb2dc57ec469e9d5fa21684 Mon Sep 17 00:00:00 2001 From: Bimmy Date: Thu, 18 Aug 2022 20:37:36 +0300 Subject: [PATCH] added some missed functions --- atf.inc.php | 87 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/atf.inc.php b/atf.inc.php index e420b20..e7b1c0e 100644 --- a/atf.inc.php +++ b/atf.inc.php @@ -64,6 +64,16 @@ class ATFApkInstaller } }); } + + function getSize() + { + list($status, $lines) = atf_host_exec("ls -sd -- ./{$this->apk_name}", DEPLOY_OPT_ERR_OK|DEPLOY_OPT_SILENT); + if($status != 0) + return 0; + $items = explode(' ', $lines[0]); + //ls -s returns size in blocks where each block is 512 bytes long + return $items[0]*512; + } } @@ -196,6 +206,8 @@ class ATFSession $install = new ATFApkInstaller($apk_name, $override_conf); + $this->trySendApkStatsEvent($install->getSize()); + foreach($this->plans as $plan) $this->_runPlan($install, $plan); @@ -250,32 +262,21 @@ class ATFSession }); } - function trySendApkStatsEvent() + function trySendApkStatsEvent($apk_size) { try { - $apk_sizeB = get_apk_size(); - $apk_sizeMb = round($apk_sizeB / 1024 / 1024,4); - $version = taskman_prop('GAME_VERSION'); - $rev_hash = taskman_prop('GAME_REVISION_HASH'); - $msg = "version $version($rev_hash) size: $apk_sizeMb Mb ($apk_sizeB B)"; + $msg = "version $this->version($this->rev_hash) size: $apk_size"; atf_slack_post($msg, array('channel' => _atf_slack_chan_qa())); - - $data['guid'] = $this->guid; - $data['time'] = time(); - $data['version'] = $version; - $data['revHash'] = $rev_hash; - $data['apk_size'] = $apk_sizeB; - atf_stats_send('apk_size', $data); - $data['guid'] = $this->guid; - $data['time'] = time(); + $data['time'] = time(); $data['version'] = $this->version; $data['revHash'] = $this->rev_hash; + $data['guid'] = $this->guid; $data['branch'] = $this->branch; $data['event'] = 'apk_size'; $data['value'] = $apk_size; - atf_stats_send('event_value', $data); + atf_stats_send('event_value', $data); } catch(Exception $e) { @@ -1232,6 +1233,23 @@ function atf_device_del_file_async($device, $device_path, $opts = 0) return atf_host_exec_async("%{adb}% -s $device shell rm -rf $device_path", $opts); } +function atf_device_blink($device, $times = 5) +{ + //disable auto brightness + atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness_mode 0"); + + for($i=0;$i<$times;++$i) + { + atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 255"); + sleep(1); + atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 5"); + } + + //enable auto brightness + atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness 100"); + atf_host_exec("%{adb}% -s $device shell settings put system screen_brightness_mode 1"); +} + function atf_device_pull_file_async($device, $device_path, $timeout = 10, $throw_error_on_timeout = false) { return Amp\call(function() use($device, $device_path, $throw_error_on_timeout, $timeout) { @@ -1317,6 +1335,43 @@ function atf_stats_send($table, array $data) $db->insert($table, array(array_values($data)), array_keys($data)); } +function atf_device_mem_async($device) +{ + return Amp\call(function() use($device) { + list($code, $lines) = yield atf_host_exec_async("%{adb}% -s $device shell dumpsys meminfo -s %{package_id}%", DEPLOY_OPT_ERR_OK, 20); + + $res = array( + 'total' => 0, + 'native' => 0, + 'java' => 0, + 'system' => 0, + 'graphics' => 0, + ); + + if($code !== 0) + return $res; + + foreach($lines as $idx => $line) + { + $items = preg_split('/\s+/', trim($line)); + if($items && $items[0] === "TOTAL:") + $res['total'] = 1*$items[1]; + else if($items && $items[0] === "TOTAL" && $items[1] === "PSS:") + $res['total'] = 1*$items[2]; + else if($items && $items[0] === "Native" && $items[1] === "Heap:") + $res['native'] = 1*$items[2]; + else if($items && $items[0] === "Java" && $items[1] === "Heap:") + $res['java'] = 1*$items[2]; + else if($items && $items[0] === "System:") + $res['system'] = 1*$items[1]; + else if($items && $items[0] === "Graphics:") + $res['graphics'] = 1*$items[1]; + } + + return $res; + }); +} + function atf_log($msg) { echo date("Y-m-d H:i:s") . " " . $msg . "\n";