update common/android.py
parent
460a8e3189
commit
67ab1c5b2e
|
@ -4,6 +4,7 @@ import itertools
|
|||
import re
|
||||
import struct
|
||||
import subprocess
|
||||
import random
|
||||
|
||||
ANDROID = os.path.isfile('/EON')
|
||||
|
||||
|
@ -17,9 +18,10 @@ def get_imei(slot):
|
|||
if slot not in ("0", "1"):
|
||||
raise ValueError("SIM slot must be 0 or 1")
|
||||
|
||||
ret = parse_service_call_string(["iphonesubinfo", "3" ,"i32", str(slot)])
|
||||
ret = parse_service_call_string(service_call(["iphonesubinfo", "3" ,"i32", str(slot)]))
|
||||
if not ret:
|
||||
ret = "000000000000000"
|
||||
# allow non android to be identified differently
|
||||
ret = "%015d" % random.randint(0, 1<<32)
|
||||
return ret
|
||||
|
||||
def get_serial():
|
||||
|
@ -29,7 +31,7 @@ def get_serial():
|
|||
return ret
|
||||
|
||||
def get_subscriber_info():
|
||||
ret = parse_service_call_string(["iphonesubinfo", "7"])
|
||||
ret = parse_service_call_string(service_call(["iphonesubinfo", "7"]))
|
||||
if ret is None or len(ret) < 8:
|
||||
return ""
|
||||
return ret
|
||||
|
@ -47,15 +49,23 @@ def reboot(reason=None):
|
|||
"i32", "1" # wait
|
||||
])
|
||||
|
||||
def parse_service_call_unpack(call, fmt):
|
||||
r = parse_service_call_bytes(call)
|
||||
def service_call(call):
|
||||
if not ANDROID:
|
||||
return None
|
||||
|
||||
ret = subprocess.check_output(["service", "call", *call], encoding='utf8').strip()
|
||||
if 'Parcel' not in ret:
|
||||
return None
|
||||
|
||||
return parse_service_call_bytes(ret)
|
||||
|
||||
def parse_service_call_unpack(r, fmt):
|
||||
try:
|
||||
return struct.unpack(fmt, r)[0]
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
def parse_service_call_string(call):
|
||||
r = parse_service_call_bytes(call)
|
||||
def parse_service_call_string(r):
|
||||
try:
|
||||
r = r[8:] # Cut off length field
|
||||
r = r.decode('utf_16_be')
|
||||
|
@ -71,13 +81,7 @@ def parse_service_call_string(call):
|
|||
except Exception:
|
||||
return None
|
||||
|
||||
def parse_service_call_bytes(call):
|
||||
if not ANDROID:
|
||||
return None
|
||||
ret = subprocess.check_output(["service", "call", *call], encoding='utf8').strip()
|
||||
if 'Parcel' not in ret:
|
||||
return None
|
||||
|
||||
def parse_service_call_bytes(ret):
|
||||
try:
|
||||
r = b""
|
||||
for hex_part in re.findall(r'[ (]([0-9a-f]{8})', ret):
|
||||
|
|
Loading…
Reference in New Issue