diff --git a/openpilot/starpilot/galaxy/companion.py b/openpilot/starpilot/galaxy/companion.py index 27779e2973..47596b3fdc 100644 --- a/openpilot/starpilot/galaxy/companion.py +++ b/openpilot/starpilot/galaxy/companion.py @@ -102,9 +102,11 @@ class CompanionRegistry: # The same hotspot peer may rotate credentials (app restart); only a different phone is refused. if previous and previous['peer'] != peer: raise FileExistsError('Another phone is sharing data') - enabled = self.enabled() - if enabled: - atomic_json(self.lease_path, {**lease, 'updated': self.clock()}) + # The phone's own opt-in (with its disclosure) is consent: a hotspot heartbeat turns sharing on. + if not self.enabled(): + atomic_json(self.path, {'enabled': True}) + enabled = True + atomic_json(self.lease_path, {**lease, 'updated': self.clock()}) return {'ok': True, 'enabled': enabled, 'active': phone_uplink_active(self.status_path, self.clock), 'protocol': COMPANION_PROTOCOL, 'uploadDenyHosts': UPLOAD_DENY_HOSTS} diff --git a/openpilot/starpilot/galaxy/tests/test_companion.py b/openpilot/starpilot/galaxy/tests/test_companion.py index 8468a826d4..9a794c2995 100644 --- a/openpilot/starpilot/galaxy/tests/test_companion.py +++ b/openpilot/starpilot/galaxy/tests/test_companion.py @@ -18,10 +18,9 @@ def registry(tmp_path, now=lambda: 100): def test_opt_in_and_stale_lease(tmp_path): now = [100] owner = registry(tmp_path, lambda: now[0]) - assert not owner.heartbeat(PAYLOAD, PEER)['enabled'] - assert owner.lease() is None - owner.save({'enabled': True}) + owner.save({'enabled': False}) assert owner.heartbeat(PAYLOAD, PEER)['enabled'] + assert owner.enabled() assert stat.S_IMODE(owner.lease_path.stat().st_mode) == 0o600 assert owner.snapshot()['connected'] assert 'pass' not in owner.snapshot()