- Add patch 0040: cut panel VSP/VSN always-on rails, attach panel follower to Synaptics TCM touch, add Novatek NT36672A touch node, add BOE panel DTS, and extend DVFS up to 1.84/2.2 GHz. - Prevent Qualcomm ABL infinite reboot loop on poweroff while charger connected via standby detection in phone-poweroff.py. - Implement HTTP Basic Auth in camera web preview server with secure digest verification. - Add battery guard daemon and unit tests to maintain SoC between 50% and 65%. - Implement Option 2 for cellular data: disable ZRAM swap to prevent Hexagon DMA fragmentation crash, add modem modules to initfs, enable ModemManager/NetworkManager WWAN packages and services, and add phone-cellular-setup.py CLI utility with unit tests. - Update recipe checksums and verify 109 unit tests and public index boundaries.
124 lines
5.2 KiB
Python
124 lines
5.2 KiB
Python
"""Verify Platina cellular data setup, APN detection, and NetworkManager commands."""
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import subprocess
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
spec = importlib.util.spec_from_file_location('cellular_setup', ROOT / 'scripts/phone-cellular-setup.py')
|
|
cellular = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(cellular)
|
|
|
|
|
|
SAMPLE_MMCLI_OUTPUT = """
|
|
--------------------------------
|
|
General | path: /org/freedesktop/ModemManager1/Modem/0
|
|
| device id: d060cbb6f1837ac6
|
|
--------------------------------
|
|
Hardware | manufacturer: QUALCOMM INCORPORATED
|
|
| model: SDM660
|
|
| equipment id: 867530901234567
|
|
--------------------------------
|
|
Status | state: connected
|
|
| power state: on
|
|
| access tech: lte
|
|
| signal quality: 84% (recent)
|
|
--------------------------------
|
|
3GPP | imei: 867530901234567
|
|
| operator id: 46000
|
|
| operator name: CMCC
|
|
| registration: home
|
|
--------------------------------
|
|
Bearer | paths: /org/freedesktop/ModemManager1/Bearer/0
|
|
"""
|
|
|
|
|
|
class CellularSetupTests(unittest.TestCase):
|
|
def test_apn_detection_known_carriers(self):
|
|
# China Mobile
|
|
self.assertEqual(cellular.detect_apn_for_operator('46000'), 'cmnet')
|
|
self.assertEqual(cellular.detect_apn_for_operator('46002'), 'cmnet')
|
|
self.assertEqual(cellular.detect_apn_for_operator('46007'), 'cmnet')
|
|
# China Unicom
|
|
self.assertEqual(cellular.detect_apn_for_operator('46001'), '3gnet')
|
|
self.assertEqual(cellular.detect_apn_for_operator('46006'), '3gnet')
|
|
# China Telecom
|
|
self.assertEqual(cellular.detect_apn_for_operator('46003'), 'ctnet')
|
|
self.assertEqual(cellular.detect_apn_for_operator('46011'), 'ctnet')
|
|
# US carriers
|
|
self.assertEqual(cellular.detect_apn_for_operator('310260'), 'fast.t-mobile.com')
|
|
self.assertEqual(cellular.detect_apn_for_operator('310410'), 'nxtgenphone')
|
|
# Fallback
|
|
self.assertEqual(cellular.detect_apn_for_operator('99999', fallback='custom.apn'), 'custom.apn')
|
|
self.assertEqual(cellular.detect_apn_for_operator(None, fallback='internet'), 'internet')
|
|
|
|
def test_parse_mmcli_modem_info(self):
|
|
info = cellular.parse_mmcli_modem_info(SAMPLE_MMCLI_OUTPUT)
|
|
self.assertEqual(info['modem_path'], '/org/freedesktop/ModemManager1/Modem/0')
|
|
self.assertEqual(info['state'], 'connected')
|
|
self.assertEqual(info['operator_name'], 'CMCC')
|
|
self.assertEqual(info['operator_code'], '46000')
|
|
self.assertEqual(info['signal_percent'], 84)
|
|
self.assertEqual(info['access_tech'], 'lte')
|
|
self.assertEqual(info['equipment_id'], '867530901234567')
|
|
self.assertEqual(info['bearer_path'], '/org/freedesktop/ModemManager1/Bearer/0')
|
|
|
|
def test_build_nmcli_setup_commands_new(self):
|
|
cmds = cellular.build_nmcli_setup_commands(
|
|
con_name='platina-cellular',
|
|
apn='cmnet',
|
|
ifname='*',
|
|
existing_connections=['platina-usb', 'WLAN-Home']
|
|
)
|
|
self.assertEqual(len(cmds), 1)
|
|
self.assertIn('add', cmds[0])
|
|
self.assertIn('cmnet', cmds[0])
|
|
self.assertIn('platina-cellular', cmds[0])
|
|
|
|
def test_build_nmcli_setup_commands_existing(self):
|
|
cmds = cellular.build_nmcli_setup_commands(
|
|
con_name='platina-cellular',
|
|
apn='3gnet',
|
|
ifname='rmnet_data0',
|
|
existing_connections=['platina-cellular', 'platina-usb']
|
|
)
|
|
self.assertEqual(len(cmds), 1)
|
|
self.assertIn('modify', cmds[0])
|
|
self.assertIn('3gnet', cmds[0])
|
|
self.assertIn('platina-cellular', cmds[0])
|
|
|
|
def test_configure_cellular_invokes_executor(self):
|
|
recorded_calls = []
|
|
|
|
def mock_executor(cmd, **kwargs):
|
|
recorded_calls.append(cmd)
|
|
# If asking for connection list
|
|
if 'connection' in cmd and 'show' in cmd:
|
|
return subprocess.CompletedProcess(cmd, 0, stdout='platina-usb\n', stderr='')
|
|
return subprocess.CompletedProcess(cmd, 0, stdout='', stderr='')
|
|
|
|
res = cellular.configure_cellular(apn='ctnet', ifname='*', executor=mock_executor)
|
|
self.assertEqual(res['apn'], 'ctnet')
|
|
self.assertEqual(res['connection'], 'platina-cellular')
|
|
# Ensure nmcli add command was executed
|
|
add_calls = [c for c in recorded_calls if 'add' in c]
|
|
self.assertEqual(len(add_calls), 1)
|
|
self.assertIn('ctnet', add_calls[0])
|
|
|
|
def test_toggle_cellular(self):
|
|
recorded_calls = []
|
|
|
|
def mock_executor(cmd, **kwargs):
|
|
recorded_calls.append(cmd)
|
|
return subprocess.CompletedProcess(cmd, 0)
|
|
|
|
cellular.toggle_cellular(activate=True, executor=mock_executor)
|
|
self.assertEqual(recorded_calls[-1], ['nmcli', 'connection', 'up', 'platina-cellular'])
|
|
|
|
cellular.toggle_cellular(activate=False, executor=mock_executor)
|
|
self.assertEqual(recorded_calls[-1], ['nmcli', 'connection', 'down', 'platina-cellular'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|