mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 17:43:40 +08:00
Keep vehicle preferences during the upgrade
This commit is contained in:
@@ -23,12 +23,23 @@ RENAMED_BOOL_KEYS = {'AndroidAutoEnabled': 'StarPortEnabled'}
|
||||
MAX_VALUE_BYTES = 32 * 1024 * 1024
|
||||
MAX_SNAPSHOT_BYTES = 256 * 1024 * 1024
|
||||
MAX_KEYS = 4096
|
||||
VEHICLE_PREFERENCE_KEYS = frozenset({
|
||||
'RemoteStartBootsComma', 'HKGRemoteStartBootsComma', 'IgnoreIgnitionLine',
|
||||
'TeslaWakeOnCAN', 'DisableOpenpilotLongitudinal', 'LongPitch',
|
||||
'VoltSNG', 'SNGHack', 'GMAutoHold',
|
||||
'VoltOnePedalMode', 'TeslaCoopSteering', 'TeslaAOLScreenTap',
|
||||
'TeslaAOLDisengageOnBrake', 'SubaruAvhStartup', 'SubaruStopStartOff',
|
||||
'SubaruSNG', 'SubaruRedneckCruise', 'ToyotaAutoHold',
|
||||
'JeepBrakeHold', 'DriveModeProfiles', 'DriveModeAcceleration',
|
||||
'DriveModeDeceleration', 'NostalgiaMode', 'RemapCancelToDistance',
|
||||
'FordHandsFreeCluster',
|
||||
})
|
||||
OPERATIONAL_KEYS = frozenset({
|
||||
'DongleId', 'HardwareSerial', 'GithubSshKeys', 'GithubUsername', 'SshEnabled',
|
||||
'AlphaLongitudinalEnabled', 'HasAcceptedTerms', 'CompletedTrainingVersion',
|
||||
'CellularDisabled', 'GsmApn', 'GsmMetered', 'GsmRoaming', 'NetworkMetered', 'BluetoothEnabled',
|
||||
'ConnectProvider', 'PairingProvider', 'PairingEmail', 'PrimeType', 'AssistNowToken', 'SecOCKey', 'SecOCKeys',
|
||||
})
|
||||
}) | VEHICLE_PREFERENCE_KEYS
|
||||
|
||||
|
||||
class MigrationRequired(RuntimeError):
|
||||
|
||||
@@ -64,6 +64,36 @@ class TestFirstStartMigration(unittest.TestCase):
|
||||
self.start()
|
||||
self.assertEqual({str(path): path.read_bytes() for path in self.storage.rglob('*') if path.is_file()}, before)
|
||||
|
||||
def test_vehicle_preferences_keep_canonical_choices_and_new_settings_survive_restart(self):
|
||||
self.types.update(dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, 'BOOL'))
|
||||
original = {key: b'1' if index % 2 else b'0' for index, key in enumerate(sorted(migration.VEHICLE_PREFERENCE_KEYS))}
|
||||
original.update({'AlphaLongitudinalEnabled': b'1', 'CarParamsCache': b'old fingerprint',
|
||||
'CarParamsPersistent': b'old safety configuration', 'CarParamsPrevRoute': b'old route', 'SteerFriction': b'0.337'})
|
||||
self.write(original)
|
||||
self.start()
|
||||
expected = {key: raw for key, raw in original.items() if key in migration.OPERATIONAL_KEYS}
|
||||
self.assertEqual(self.values(), expected)
|
||||
self.assertEqual(migration.load_snapshot(next((self.storage / 'snapshots').iterdir())), original)
|
||||
for key in migration.VEHICLE_PREFERENCE_KEYS:
|
||||
(self.namespace / key).write_bytes(b'0' if expected[key] == b'1' else b'1')
|
||||
changed = self.values()
|
||||
self.start()
|
||||
self.assertEqual(self.values(), changed)
|
||||
|
||||
def test_invalid_vehicle_preferences_are_archived_without_enabling_them(self):
|
||||
self.types.update(dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, 'BOOL'))
|
||||
original = dict.fromkeys(migration.VEHICLE_PREFERENCE_KEYS, b'true')
|
||||
self.write(original)
|
||||
self.start()
|
||||
self.assertEqual(self.values(), {})
|
||||
self.assertEqual(migration.load_snapshot(next((self.storage / 'snapshots').iterdir())), original)
|
||||
|
||||
def test_vehicle_preference_keys_are_registered_booleans(self):
|
||||
from openpilot.common.params import Params
|
||||
params = Params(str(self.root / 'native-params'))
|
||||
for key in migration.VEHICLE_PREFERENCE_KEYS:
|
||||
self.assertEqual(params.get_type(key).name, 'BOOL', key)
|
||||
|
||||
def test_onboarding_keeps_only_previously_saved_acceptance(self):
|
||||
self.write({'HasAcceptedTerms': b'2', 'CompletedTrainingVersion': b'0.2.0', 'ForceStops': b'1'})
|
||||
self.start()
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "2757d3911f64e0e886f766807ed90f2b0af3149497d12b346dad955efcc698fc", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "aa8ef45fd68935ebf9b0f9885dcc6862763a00b0f3fa35f7f69ccfc6e515ce6a", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user