1818import static com .google .firebase .remoteconfig .FirebaseRemoteConfig .LAST_FETCH_STATUS_NO_FETCH_YET ;
1919import static com .google .firebase .remoteconfig .FirebaseRemoteConfig .LAST_FETCH_STATUS_SUCCESS ;
2020import static com .google .firebase .remoteconfig .FirebaseRemoteConfig .LAST_FETCH_STATUS_THROTTLED ;
21+ import static com .google .firebase .remoteconfig .FirebaseRemoteConfig .TAG ;
2122import static com .google .firebase .remoteconfig .RemoteConfigComponent .CONNECTION_TIMEOUT_IN_SECONDS ;
2223import static com .google .firebase .remoteconfig .RemoteConfigConstants .RequestFieldKey .CUSTOM_SIGNALS ;
2324import static com .google .firebase .remoteconfig .internal .ConfigFetchHandler .DEFAULT_MINIMUM_FETCH_INTERVAL_IN_SECONDS ;
2425import static java .lang .annotation .RetentionPolicy .SOURCE ;
2526
2627import android .content .SharedPreferences ;
28+ import android .util .Log ;
2729import androidx .annotation .IntDef ;
2830import androidx .annotation .Nullable ;
2931import androidx .annotation .VisibleForTesting ;
@@ -81,6 +83,12 @@ public class ConfigMetadataClient {
8183 private static final String REALTIME_BACKOFF_END_TIME_IN_MILLIS_KEY =
8284 "realtime_backoff_end_time_in_millis" ;
8385
86+ /** Constants for custom signal limits. */
87+ private static final int CUSTOM_SIGNALS_MAX_KEY_LENGTH = 250 ;
88+
89+ private static final int CUSTOM_SIGNALS_MAX_STRING_VALUE_LENGTH = 500 ;
90+ private static final int CUSTOM_SIGNALS_MAX_COUNT = 100 ;
91+
8492 private final SharedPreferences frcMetadata ;
8593
8694 private final Object frcInfoLock ;
@@ -268,11 +276,18 @@ public void setCustomSignals(Map<String, Object> newCustomSignals) {
268276
269277 // Validate value type, and key and value length
270278 if (value != null && !(value instanceof String || value instanceof Long )) {
271- throw new IllegalArgumentException ("Custom signal values must be of type String or Long" );
279+ Log .w (TAG , "Invalid custom signal: Custom signal values must be of type String or Long." );
280+ return ;
272281 }
273- if (key .length () > 250 || (value instanceof String && ((String ) value ).length () > 500 )) {
274- throw new IllegalArgumentException (
275- "Custom signal keys must be 250 characters or less, and string values must be 500 characters or less." );
282+ if (key .length () > CUSTOM_SIGNALS_MAX_KEY_LENGTH
283+ || (value instanceof String
284+ && ((String ) value ).length () > CUSTOM_SIGNALS_MAX_STRING_VALUE_LENGTH )) {
285+ Log .w (
286+ TAG ,
287+ String .format (
288+ "Invalid custom signal: Custom signal keys must be %d characters or less, and string values must be %d characters or less." ,
289+ CUSTOM_SIGNALS_MAX_KEY_LENGTH , CUSTOM_SIGNALS_MAX_STRING_VALUE_LENGTH ));
290+ return ;
276291 }
277292
278293 // Merge new signals with existing ones, overwriting existing keys.
@@ -288,9 +303,13 @@ public void setCustomSignals(Map<String, Object> newCustomSignals) {
288303 if (existingCustomSignals .equals (getCustomSignals ())) {
289304 return ;
290305 }
291- if (existingCustomSignals .size () > 100 ) {
292- throw new IllegalArgumentException (
293- "Too many custom signals provided. The maximum allowed is 100." );
306+ if (existingCustomSignals .size () > CUSTOM_SIGNALS_MAX_COUNT ) {
307+ Log .w (
308+ TAG ,
309+ String .format (
310+ "Invalid custom signal: Too many custom signals provided. The maximum allowed is %d." ,
311+ CUSTOM_SIGNALS_MAX_COUNT ));
312+ return ;
294313 }
295314
296315 frcMetadata
0 commit comments