1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +01:00

Add safeguard against invalid year of birth values

This commit is contained in:
José Rebelo 2024-08-31 21:29:47 +01:00
parent 72e8028ad6
commit e676f7c6b0

View File

@ -1728,9 +1728,18 @@ public class GBApplication extends Application {
if (oldVersion < 38) {
// Migrate year of birth to date of birth
final String yearOfBirth = sharedPrefs.getString("activity_user_year_of_birth", null);
if (StringUtils.isNotBlank(yearOfBirth)) {
editor.putString("activity_user_date_of_birth", String.format(Locale.ROOT, "%s-01-01", yearOfBirth.trim()));
try {
final String yearOfBirth = sharedPrefs.getString("activity_user_year_of_birth", null);
if (StringUtils.isNotBlank(yearOfBirth)) {
final int yearOfBirthValue = Integer.parseInt(yearOfBirth);
if (yearOfBirthValue > 1800 && yearOfBirthValue < 3000) {
editor.putString("activity_user_date_of_birth", String.format(Locale.ROOT, "%s-01-01", yearOfBirth.trim()));
} else {
Log.e(TAG, "Year of birth out of range, not migrating - " + yearOfBirth);
}
}
} catch (final Exception e) {
Log.e(TAG, "Failed to migrate year of birth to date of birth in version 38", e);
}
}