@@ -121,7 +121,7 @@ protected void onCreate(Bundle savedInstanceState) {
121121 // a no-op and does not even contain the updater.
122122 UpdateHook .checkInBackground (this );
123123
124- apiKeyInput .setText (securePrefs . getString ( SecurePrefs . KEY_API_KEY , "" ));
124+ apiKeyInput .setText (savedApiKeyOrDefault ( ));
125125 tokenInput .setText (securePrefs .getString (SecurePrefs .KEY_TOKEN , "" ));
126126 serviceSwitch .setChecked (prefs .getBoolean ("service_enabled" , false ));
127127
@@ -169,7 +169,7 @@ protected void onCreate(Bundle savedInstanceState) {
169169 @ Override
170170 protected void onResume () {
171171 super .onResume ();
172- apiKeyInput .setText (securePrefs . getString ( SecurePrefs . KEY_API_KEY , "" ));
172+ apiKeyInput .setText (savedApiKeyOrDefault ( ));
173173 tokenInput .setText (securePrefs .getString (SecurePrefs .KEY_TOKEN , "" ));
174174 serviceSwitch .setChecked (prefs .getBoolean ("service_enabled" , false ));
175175 // Poll state and log only while the screen is up; onPause cancels it.
@@ -178,6 +178,17 @@ protected void onResume() {
178178
179179 // ---------- Credentials ----------
180180
181+ /**
182+ * The SAIC open-source gateway publishes this shared ABRP key for compatible clients.
183+ * A user-supplied key saved in encrypted preferences always takes precedence.
184+ */
185+ private String savedApiKeyOrDefault () {
186+ String savedApiKey = securePrefs .getString (SecurePrefs .KEY_API_KEY , "" );
187+ return savedApiKey == null || savedApiKey .trim ().isEmpty ()
188+ ? getString (R .string .default_abrp_api_key )
189+ : savedApiKey ;
190+ }
191+
181192 private void saveCredentials () {
182193 String apiKey = textOf (apiKeyInput );
183194 String token = textOf (tokenInput );
@@ -331,7 +342,7 @@ private void applyConfig(String text) {
331342 edit .apply ();
332343
333344 // Re-read every control from prefs so the screen shows what was imported.
334- apiKeyInput .setText (securePrefs . getString ( SecurePrefs . KEY_API_KEY , "" ));
345+ apiKeyInput .setText (savedApiKeyOrDefault ( ));
335346 tokenInput .setText (securePrefs .getString (SecurePrefs .KEY_TOKEN , "" ));
336347 apiKeyLayout .setError (null );
337348 tokenLayout .setError (null );
0 commit comments