@Nullable
    @SuppressWarnings("UnusedException")
    private static byte[] readKeysetFromPrefs(
        Context context, String keysetName, String prefFileName) throws IOException {
      if (keysetName == null) {
        throw new IllegalArgumentException("keysetName cannot be null");
      }
      Context appContext = context.getApplicationContext();
      SharedPreferences sharedPreferences;
      if (prefFileName == null) {
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
      } else {
        sharedPreferences = appContext.getSharedPreferences(prefFileName, Context.MODE_PRIVATE);
      }
      try {
        String keysetHex = sharedPreferences.getString(keysetName, /* defValue= */ null);
        if (keysetHex == null) {
          return null;
        }
        return Hex.decode(keysetHex);
      } catch (ClassCastException | IllegalArgumentException ex) {
        // The original exception is swallowed to prevent leaked key material.
        throw new CharConversionException(
            String.format(
                "can't read keyset; the pref value %s is not a valid hex string", keysetName));
      }
    }
Returns the serialized keyset if it exist or null.
java_src/src/main/java/com/google/crypto/tink/integration/android/AndroidKeysetManager.java