Skip to content

Commit c6ef9e8

Browse files
authored
Add files via upload
1 parent bf656ee commit c6ef9e8

File tree

5 files changed

+1972
-0
lines changed

5 files changed

+1972
-0
lines changed

src/adb_globals.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
3+
from asyncio.windows_events import NULL
4+
from concurrent.futures import thread
5+
from ppadb.client import Client as AdbClient
6+
from io import StringIO
7+
import TouchPortalAPI as TP
8+
from asyncio.windows_events import NULL
9+
from concurrent.futures import thread
10+
from argparse import ArgumentParser
11+
from logging import (getLogger, Formatter, NullHandler, FileHandler, StreamHandler, DEBUG, INFO, WARNING)
12+
13+
14+
### FROM MAIN IMPORTS
15+
from asyncio.windows_events import NULL
16+
from concurrent.futures import thread
17+
import TouchPortalAPI as TP
18+
import time
19+
import threading
20+
import re
21+
import sys
22+
from ctypes import windll
23+
import subprocess
24+
25+
### These were needed for Update check
26+
import requests
27+
import base64
28+
import json
29+
30+
31+
""" Moved other variables to device_states.py where they are used, device list is used globally"""
32+
battery_states = {}
33+
device_names = []
34+
device_list = {}
35+
36+
37+
sleep_states = {
38+
'mHoldingWakeLockSuspendBlocker': '',
39+
'mHoldingDisplaySuspendBlocker': ''}
40+
41+
42+
43+
def bat_state_conver(choice, num):
44+
45+
## This converts the numbers given by ADB into a string thats readable
46+
if choice == "status":
47+
statusDict = {1 : "UNKNOWN",
48+
2 : "CHARGING",
49+
3 : "DISCHARGING",
50+
4 : "NOT_CHARGING",
51+
5 : "FULL"}
52+
result = statusDict[int(num)]
53+
54+
if choice == "health":
55+
healthDict = {1 : "UNKNOWN",
56+
2 : "GOOD",
57+
3 : "OVERHEAT",
58+
4 : "DEAD",
59+
5 : "OVER VOLTAGE",
60+
6 : "unspecified failure",
61+
7: "COLD"}
62+
result = healthDict[int(num)]
63+
64+
return result
65+
66+
67+
def match_device(name):
68+
""" Returns the device ID associated with the device name"""
69+
return device_list[name]['ID']
70+
71+
72+
def kb2mb(num):
73+
return int(num) // 1024
74+
75+
76+
77+
78+
def out(command):
79+
"""Power Shell Func
80+
- Checking Devices Test
81+
"""
82+
systemencoding = windll.kernel32.GetConsoleOutputCP()
83+
systemencoding= f"cp{systemencoding}"
84+
output = subprocess.run(command, stdout=subprocess.PIPE, shell=True)
85+
result = str(output.stdout.decode(systemencoding))
86+
for device in result.splitlines():
87+
if device.endswith('\tdevice'):
88+
result= device.split('\t')[0]
89+
return result
90+

src/androidadb.ico

1.56 KB
Binary file not shown.

src/device_states.py

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
from adb_globals import *
2+
3+
4+
5+
6+
"""
7+
-------------------------------------------------
8+
----------------- BATTERY USAGE -----------------
9+
-------------------------------------------------
10+
"""
11+
12+
battery_states_final={}
13+
def battery_state_update(device, format = "Celcius"):
14+
""" Returns Dictionary with Full Battery Details """
15+
battery_states = {"temperature": "", "level": "", "voltage":"", "status":"", "health": "",
16+
"AC powered": "", "USB powered": "", "Wireless powered":"", "present": ""}
17+
18+
ok=(device.shell('dumpsys battery'))
19+
buf = StringIO(ok)
20+
changes = 0
21+
for line2 in buf.readlines():
22+
line = line2.strip()
23+
if "Max charging voltage" in line:
24+
pass
25+
else:
26+
for state, value in battery_states.items():
27+
m = re.search(r'{}:(.*)'.format(state), line)
28+
if m:
29+
if value != m.group(1):
30+
changes += 1
31+
# print("changed: state={} old={} new={}".format(state, value, m.group(1)))
32+
33+
battery_states[state] = m.group(1).lstrip()
34+
35+
# Taking Battery Health/Status and Turning into "result"""
36+
if "vendor.samsung.hardware" in battery_states['health']:
37+
extract_health= (battery_states['health'].split("::")[0].replace("vendor.samsung.hardware.health@",""))
38+
battery_states['health'] = str(round(float(extract_health)))
39+
40+
# Converting Battery Status Number to String
41+
try:
42+
battery_states['status'] = bat_state_conver(choice='status',num=int(battery_states['status']))
43+
except:
44+
print("Unable to Convert Status, Check Results")
45+
46+
if changes > 0:
47+
print("---- {} changes".format(changes))
48+
# print(battery_states)
49+
pass
50+
51+
return battery_states
52+
53+
54+
55+
56+
57+
58+
59+
"""
60+
-------------------------------------------------
61+
------------------ SCREEN INFO ------------------
62+
-------------------------------------------------
63+
"""
64+
65+
dupe_device_count=1
66+
def get_screen_info(device_choice):
67+
"""Get Device Screen Info
68+
- This is where the device details are started
69+
"""
70+
global dupe_device_count
71+
density = device_choice.shell('wm density').split(":")[-1].split("\n")[0]
72+
size = device_choice.shell('wm size').split(":")[-1].split("\n")[0]
73+
model = device_choice.shell('getprop ro.product.model').split("\n")[0]
74+
manufac = device_choice.shell('getprop ro.product.manufacturer').split("\n")[0]
75+
board = device_choice.shell('getprop ro.product.board').split("\n")[0]
76+
hardware = device_choice.shell('getprop ro.hardware').split("\n")[0]
77+
android_version = device_choice.shell('getprop ro.build.version.release').split("\n")[0]
78+
79+
80+
### Incase of duplicate devices lets add 1 number...
81+
if model in device_names:
82+
model = f"{model}({dupe_device_count})"
83+
dupe_device_count = dupe_device_count +1
84+
device_names.append(model)
85+
return {"Version": android_version, "Hardware": hardware, "Board": board, "Manufacturer": manufac.capitalize(), "Model": model, "Screen Size": size, "Screen Density":density}
86+
87+
88+
89+
90+
91+
92+
93+
94+
"""
95+
-------------------------------------------------
96+
------------------- MEM USAGE -------------------
97+
-------------------------------------------------
98+
"""
99+
100+
def get_mem_info(device):
101+
""" Returns Dictionary with Memory Details"""
102+
memavail = 0
103+
memfree = 0
104+
memtotal = 0
105+
106+
try:
107+
mem_check = device.shell("cat /proc/meminfo")
108+
split = mem_check.splitlines(-1)
109+
memdict ={}
110+
for line in split:
111+
if 'MemTotal:' in line:
112+
size = kb2mb(int(line.split(" ")[-2]))
113+
memdict['MemTotal'] = f"{size}"
114+
memtotal = memdict['MemTotal']
115+
116+
if 'MemFree:' in line:
117+
size = kb2mb(line.split(" ")[-2])
118+
memdict['MemFree'] = f"{size}"
119+
memfree = memdict['MemFree']
120+
121+
if 'MemAvailable:' in line:
122+
size = kb2mb(line.split(" ")[-2])
123+
memdict['MemAvailable'] = f"{size}"
124+
memavail = memdict['MemAvailable']
125+
126+
127+
# print(memdict)
128+
"""Had to do this to get it to round?"""
129+
perce= int(memavail) / int(memtotal) * 100
130+
memdict['Percentage']= round(perce)
131+
132+
for x in device_list:
133+
if device_list[x]['ID'] == device:
134+
device_list[x].update({'MemAvailable':memavail})
135+
device_list[x].update({'MemFree':memfree})
136+
device_list[x].update({'Percentage':perce})
137+
# print(f"{x} Dictionary Updated with Memory Usage")
138+
139+
return memdict
140+
141+
except Exception as e:
142+
print(f"Error Getting Memory Info: {e}")
143+
return None
144+
145+
146+
147+
148+
149+
"""
150+
-------------------------------------------------
151+
------------------- CPU USAGE -------------------
152+
-------------------------------------------------
153+
"""
154+
155+
def get_cpu_usge(device):
156+
"""
157+
Get the CPU Usage of the Device(s)
158+
"""
159+
160+
build = {}
161+
thelist = {"cpu", "user", "nice", "sys", "idle"}
162+
ok = device.shell("top -n1")
163+
split = ok.splitlines(-1)
164+
complete = False
165+
for line in split:
166+
if not complete:
167+
if "cpu" in line:
168+
newline = line.split(" ")
169+
complete = True
170+
for x in newline:
171+
if x:
172+
final_split = x.split("%")
173+
if final_split[-1] in thelist:
174+
build[final_split[-1]] = final_split[0]
175+
176+
result= int(build['user']) + int(build['sys'])
177+
result = result / int(build['cpu'])
178+
result=result*100
179+
result = str(result)[0:2]
180+
181+
if "." in result:
182+
result = result.replace(".", "")
183+
184+
""" Updating CPU Usage for Devices"""
185+
for x in device_list:
186+
if device_list[x]['ID'] == device:
187+
device_list[x].update({'CPU USAGE':result})
188+
# print(f"{x} Dictionary Updated with CPU Usage")
189+
190+
return result

0 commit comments

Comments
 (0)