Android 7.0 이상에서 분명 Locale 을 영어나 글로벌 언어로 해놓았는데, WebView 를 거치거나 chrome tab 을 이용하는 library 를 사용하게 되면 Locale 이 변경 되는 이슈가 있다.
해당 library 에서 변경하는 내부코드 부분을 찾아보려 했으나 찾지 못하였다.
DateTimeFormatter
public static DateTimeFormatter ofPattern(String pattern) {
return new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter();
}
public DateTimeFormatter toFormatter() {
return toFormatter(Locale.getDefault(Locale.Category.FORMAT));
}
DateTimeFormatter 내부에서는 Locale의 getDefault 를 호출하기 때문에 바뀐 locale 대로 출력되어 한글로 날짜가 표시된다.
로그인 성공 여부 상관없이 library 를 통해 웹 페이지가 표시 되면 Locale 이 변경되는 것을 확인.
Android 7.0 Nuga 부터 webView 에서 Locale 이 변경된다는 stackOverFlow 글이 있다.
Android - WebView language changes abruptly on Android 7.0 and above
실제로 android 7.0부터 발생(6.0 에서 발생되지 않는다.)
잠시 위의 이슈를 접어두고 provider 를 호출하였을 때 Locale.default 가 변경되는 것을 보면 Android 6.0 에서는 Locale.getDefault 가 그대로 유지되는데, Android 7.0 이상에서만 기기 설정의 첫번째 locale 로 변경된다.
그 이유를 알기 위해 Locale class 의 setDefault 를 비교해 보았다.
android 6.0 Locale.setDefault()
public synchronized static void setDefault(Locale locale) {
if (locale == null) {
throw new NullPointerException("locale == null");
}
String languageTag = locale.toLanguageTag();
NoImagePreloadHolder.defaultLocale = locale;
ICU.setDefaultLocale(languageTag);
}
android 7.0 Locale.setDefault()
public static synchronized void setDefault(Locale newLocale) {
setDefault(Category.DISPLAY, newLocale);
setDefault(Category.FORMAT, newLocale);
defaultLocale = newLocale;
ICU.setDefaultLocale(newLocale.toLanguageTag());
}
setDefault(Locale.Category category, Locale newLocale) 메서드는 android api 24(7.0) 부터 추가된 api 이다.
정리 :
SNS 인증 시 해당 library 에서 Locale.setDefault 를 호출하는 것으로 추정
android 7.0 부터 Locale.setDefault 시에 내부에서 setDefault(Category.FORMAT, newLocale); 를 호출하는데,
DateTimeFormatter 의 toFormatter 메서드에서 Locale.getDefault(Locale.Category.FORMAT)); 를 호출하기 때문에 android 7.0 부터 위의 현상이 나오는 것으로 보인다.
해결 방안 :
library 호출이 끝난 뒤에 Locale.setDefault(원하는 Locale) 로 변경을 해준다.