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:
parent
72e8028ad6
commit
e676f7c6b0
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user