fix(platina): resolve touchscreen, dual panel, charging reboot, battery guard, camera auth, and internal SIM cellular data

- 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.
This commit is contained in:
shen
2026-11-07 23:27:43 -08:00
parent 655d0f5b49
commit 810a467ad3
15 changed files with 775 additions and 11 deletions
+63
View File
@@ -0,0 +1,63 @@
"""Verify battery charging guard policy and sysfs integration."""
import importlib.util
from pathlib import Path
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location('battery_guard', ROOT / 'scripts/phone-battery-guard.py')
guard = importlib.util.module_from_spec(spec)
spec.loader.exec_module(guard)
class BatteryGuardTests(unittest.TestCase):
def test_policy_thresholds(self):
policy = guard.BatteryPolicy(low=50, high=65)
# Low capacity: should charge
self.assertTrue(policy.evaluate(45))
self.assertTrue(policy.evaluate(50))
# Between 50 and 65: maintains previous state (charging)
self.assertTrue(policy.evaluate(58))
# High capacity reached (>= 65): should pause charging
self.assertFalse(policy.evaluate(65))
self.assertFalse(policy.evaluate(75))
# Dropping between 50 and 65: maintains previous state (paused)
self.assertFalse(policy.evaluate(55))
# Drops to or below low (<= 50): should resume charging
self.assertTrue(policy.evaluate(49))
def test_invalid_thresholds_rejected(self):
with self.assertRaises(ValueError):
guard.BatteryPolicy(low=70, high=50)
with self.assertRaises(ValueError):
guard.BatteryPolicy(low=5, high=60)
with self.assertRaises(ValueError):
guard.BatteryPolicy(low=50, high=99)
def test_set_charging_sysfs(self):
with tempfile.TemporaryDirectory() as temp:
battery = Path(temp) / 'battery'
charger = Path(temp) / 'charger'
battery.mkdir()
charger.mkdir()
(battery / 'charging_enabled').write_text('1\n')
(charger / 'charging_enabled').write_text('1\n')
(charger / 'current_max').write_text('1500000\n')
# Disable charging
applied = guard.set_charging(battery, charger, False)
self.assertTrue(applied)
self.assertEqual((battery / 'charging_enabled').read_text().strip(), '0')
self.assertEqual((charger / 'charging_enabled').read_text().strip(), '0')
self.assertEqual((charger / 'current_max').read_text().strip(), '0')
# Enable charging
applied = guard.set_charging(battery, charger, True)
self.assertTrue(applied)
self.assertEqual((battery / 'charging_enabled').read_text().strip(), '1')
self.assertEqual((charger / 'charging_enabled').read_text().strip(), '1')
self.assertEqual((charger / 'current_max').read_text().strip(), '1500000')
if __name__ == '__main__':
unittest.main()
+27
View File
@@ -69,6 +69,33 @@ class ControlTests(unittest.TestCase):
with self.assertRaises(HTTPError) as error:
self.get(endpoint)
self.assertEqual(error.exception.code, 503)
def test_authentication_enforced_when_configured(self):
auth = {'username': 'testuser', 'password': 'secretpassword'}
stop = threading.Event()
server = ThreadingHTTPServer(('127.0.0.1', 0), serve.make_handler(self.camera, stop, self.audio, auth=auth))
server.daemon_threads = True
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
base = 'http://127.0.0.1:' + str(server.server_port)
try:
with self.assertRaises(HTTPError) as err:
urlopen(base + '/status', timeout=3)
self.assertEqual(err.exception.code, 401)
self.assertIn('Basic', err.exception.headers.get('WWW-Authenticate', ''))
import base64
token = base64.b64encode(b'testuser:secretpassword').decode()
req = Request(base + '/status', headers={'Authorization': 'Basic ' + token})
with urlopen(req, timeout=3) as resp:
self.assertEqual(resp.status, 200)
data = json.load(resp)
self.assertEqual(data['state'], 'off')
finally:
stop.set()
server.shutdown()
server.server_close()
thread.join()
self.assertIsNone(self.camera.capture)
def test_settings_off_persist_but_capture_does_not(self):
+123
View File
@@ -0,0 +1,123 @@
"""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()