I am using Encrypted shared preference to encrypted the preferences data. I am using it in the following way:
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
val sharedPreferences = EncryptedSharedPreferences.create(
context,
prefName,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
I accessing this securely shared preference instance from my application class. This is causing ANR issues in my production application.
at sun.misc.Unsafe.park (Native method)
at java.util.concurrent.locks.LockSupport.park (LockSupport.java:190)
at java.util.concurrent.CompletableFuture$Signaller.block (CompletableFuture.java:1723)
at java.util.concurrent.ForkJoinPool.managedBlock (ForkJoinPool.java:3446)
at java.util.concurrent.CompletableFuture.waitingGet (CompletableFuture.java:1752)
at java.util.concurrent.CompletableFuture.get (CompletableFuture.java:1923)
at android.security.KeyStore.begin (KeyStore.java:1104)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.ensureKeystoreOperationInitialized (AndroidKeyStoreCipherSpiBase.java:248)
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineInit (AndroidKeyStoreCipherSpiBase.java:109)
at javax.crypto.Cipher.tryTransformWithProvider (Cipher.java:2984)
at javax.crypto.Cipher.tryCombinations (Cipher.java:2891)
at javax.crypto.Cipher$SpiAndProviderUpdater.updateAndGetSpiAndProvider (Cipher.java:2796)
at javax.crypto.Cipher.chooseProvider (Cipher.java:773)
at javax.crypto.Cipher.init (Cipher.java:1143)
at javax.crypto.Cipher.init (Cipher.java:1084)
at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encryptInternal (AndroidKeystoreAesGcm.java:84)
at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.encrypt (AndroidKeystoreAesGcm.java:68)
at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.validateAead (AndroidKeystoreKmsClient.java:248)
at com.google.crypto.tink.integration.android.AndroidKeystoreKmsClient.getAead (AndroidKeystoreKmsClient.java:165)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewMasterKey (AndroidKeysetManager.java:267)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build (AndroidKeysetManager.java:236)
at androidx.security.crypto.EncryptedSharedPreferences.create (EncryptedSharedPreferences.java:160)
at androidx.security.crypto.EncryptedSharedPreferences.create (EncryptedSharedPreferences.java:120)
at my.application.example.sharedpref.PrefProvider.getSecuredSharedPref (PrefProvider.java:15)
This behaviour observer majorly on Android 9 and 10.
There is Andorid bug reported around cipher.init. Is there any way to solve this issue. It is causing bad behaviour for my application over playstore.