Merge "Keystore 2.0 SPI: Fix engineDoFinal with null input."
diff --git a/keystore/java/android/security/keystore2/AndroidKeyStoreCipherSpiBase.java b/keystore/java/android/security/keystore2/AndroidKeyStoreCipherSpiBase.java
index 9d8a5ef..e808c5c 100644
--- a/keystore/java/android/security/keystore2/AndroidKeyStoreCipherSpiBase.java
+++ b/keystore/java/android/security/keystore2/AndroidKeyStoreCipherSpiBase.java
@@ -579,7 +579,11 @@
     protected final byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
             throws IllegalBlockSizeException, BadPaddingException {
         if (mCipher != null) {
-            return mCipher.doFinal(input, inputOffset, inputLen);
+            if (input == null && inputLen == 0) {
+                return mCipher.doFinal();
+            } else {
+                return mCipher.doFinal(input, inputOffset, inputLen);
+            }
         }
 
         if (mCachedException != null) {