Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions common/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import struct
import subprocess
import random

ANDROID = os.path.isfile('/EON')

Expand All @@ -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():
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def getSimInfo():
network_type = android.getprop("gsm.network.type").split(',')
mcc_mnc = android.getprop("gsm.sim.operator.numeric") or None

sim_id = android.parse_service_call_string(['iphonesubinfo', '11'])
cell_data_state = android.parse_service_call_unpack(['phone', '46'], ">q")
sim_id = android.parse_service_call_string(android.service_call(['iphonesubinfo', '11']))
cell_data_state = android.parse_service_call_unpack(android.service_call(['phone', '46']), ">q")
cell_data_connected = (cell_data_state == 2)

return {
Expand Down