11package com .beautycoder .pflockscreen .security ;
22
33import android .content .Context ;
4+ import android .content .res .Configuration ;
5+ import android .content .res .Resources ;
46import android .security .KeyPairGeneratorSpec ;
57import android .security .keystore .KeyProperties ;
68import androidx .annotation .NonNull ;
1921import java .security .cert .CertificateException ;
2022import java .util .ArrayList ;
2123import java .util .Calendar ;
24+ import java .util .Locale ;
2225
2326import javax .crypto .Cipher ;
2427import javax .crypto .CipherInputStream ;
@@ -172,6 +175,12 @@ private boolean generateKeyOld(
172175 boolean isAuthenticationRequired
173176 ) {
174177 try {
178+ // Set English locale as default (workaround for rtl parsing date exception)
179+ // From https://stackoverflow.com/a/46602170
180+ // FIXME: A temporary fixture for issue described at https://issuetracker.google.com/issues/37095309
181+ Locale initialLocale = Locale .getDefault ();
182+ setLocale (context , Locale .ENGLISH );
183+
175184 final Calendar start = Calendar .getInstance ();
176185 final Calendar end = Calendar .getInstance ();
177186 end .add (Calendar .YEAR , 25 );
@@ -193,6 +202,8 @@ private boolean generateKeyOld(
193202
194203 keyGen .initialize (spec );
195204 keyGen .generateKeyPair ();
205+ // Reset default locale
206+ setLocale (context , initialLocale );
196207 return true ;
197208
198209 } catch ( NoSuchAlgorithmException
@@ -203,6 +214,14 @@ private boolean generateKeyOld(
203214 }
204215 }
205216
217+ private void setLocale (Context context , Locale locale ) {
218+ Locale .setDefault (locale );
219+ Resources resources = context .getResources ();
220+ Configuration config = resources .getConfiguration ();
221+ config .locale = locale ;
222+ resources .updateConfiguration (config , resources .getDisplayMetrics ());
223+ }
224+
206225 @ Override
207226 public boolean isKeystoreContainAlias (String alias ) throws PFSecurityException {
208227 final KeyStore keyStore = loadKeyStore ();
0 commit comments