[Sony Xperia 1 V] xdagoblin:
They seem to have added Xperia 1 V now.

I had this issue (couldn't set up a PIN/password/pattern lock after setting it and then unlocking the bootloader) and this helped, many thanks.

After re-unlocking the bootloader, I've set up a PIN of 1234 and a Fingerprint unlock with 3 Fingerprints.

Shortly after booting the device, PIN unlock and fingerprint unlock, as well as going to Settings to change the PIN/Fingerprints works fine.

However, it appears that after some time of using the phone (locking/unlocking the screen, installing/using some apps or ADB debugging via USB cable – not yet sure what causes this), the phone goes into a mode when the PIN unlock stops working – both from the screen unlock dialog and from Security settings (where I try to change the PIN or unlock method). I enter 1234 in both cases (can't get this wrong, really) and I get "Wrong PIN". Fingerprint unlock remains working (unless I enter the PIN "wrong" too many times and the device starts asking for the PIN again as a "routine security check").

Rebooting seems to help, so far I was always able to enter the PIN shortly after booting.

Can anyone shed some light on this? Is the partition with the unlock credentials getting unmounted or something?

EDIT 1:

I had installed the "AlwaysOn" app from F-Droid and I had initially thought that it was causing this, however the problem persists even after I uninstalled it.

EDIT 2:

I can now confirm that I pretty much didn't do anything to cause it to break. At one point the PIN works fine, then I keep the phone locked for a few minutes, and then out of a sudden it stops working until I reboot.

EDIT 3:

I've changed PIN to Pattern for a test and Pattern unlock breaks exactly the same way as PIN did (Fingerprint still works).

EDIT 4:

It wasn't happening for about an hour, but now it did it again. locksettings verify --old <mypattern> in adb shell is now saying Old password '<mypattern>' didn't match, whereas previously (or after a reboot) it was saying Lock credential verified successfully.

EDIT 5:

Running logcat in a Termux session (in order to get some more insight) seems to prevent the problem from occuring (it's been running for 18 hours without a fault so far). I've also determined that /proc/mounts doesn't change between before and after the problem is triggered. I'm guessing it's something related to the device sleeping, which a running logcat maybe prevents? Or perhaps my Trusted Platform Module is faulty? Still testing.

EDIT 6:

At 14:25, since the error wasn't triggering for 20 hours, I disabled adb (both remote and local) and unplugged the USB cable from the PC, and after a while I got the error to trigger again. I checked at 15:00 and the device was still unlocking with PIN fine. Then at 17:20 it stopped unlocking with PIN, so I quickly went to check the recent logcats and found this (grepped for keystore; also the same set of log lines was repeated once (it appeared exactly the same 2 seconds later)):

10-01 17:04:29.582 1176 1244 E keystore2: keystore2::remote_provisioning: In get_remote_provisioning_key_and_certs: Error occurred: In get_rem_prov_attest_key: Failed to get a key
10-01 17:04:29.582 1176 1244 E keystore2:
10-01 17:04:29.582 1176 1244 E keystore2: Caused by:
10-01 17:04:29.582 1176 1244 E keystore2: 0: In get_rem_prov_attest_key_helper: Failed to assign a key
10-01 17:04:29.582 1176 1244 E keystore2: 1: In assign_attestation_key:
10-01 17:04:29.582 1176 1244 E keystore2: 2: In with_transaction.
10-01 17:04:29.582 1176 1244 E keystore2: 3: Out of keys.
10-01 17:04:29.582 1176 1244 E keystore2: 4: Error::Rc(ResponseCode(22))
10-01 17:04:29.610 1176 1244 E keystore2: keystore2::error: In generate_key.
10-01 17:04:29.610 1176 1244 E keystore2:
10-01 17:04:29.610 1176 1244 E keystore2: Caused by:
10-01 17:04:29.610 1176 1244 E keystore2: 0: While generating Key without explicit attestation key.
10-01 17:04:29.610 1176 1244 E keystore2: 1: Error::Km(ErrorCode(-74))
10-01 17:04:29.615 1176 1244 E keystore2: keystore2::remote_provisioning: In get_remote_provisioning_key_and_certs: Error occurred: In get_rem_prov_attest_key: Failed to get a key
10-01 17:04:29.615 1176 1244 E keystore2:
10-01 17:04:29.615 1176 1244 E keystore2: Caused by:
10-01 17:04:29.615 1176 1244 E keystore2: 0: In get_rem_prov_attest_key_helper: Failed to assign a key
10-01 17:04:29.615 1176 1244 E keystore2: 1: In assign_attestation_key:
10-01 17:04:29.615 1176 1244 E keystore2: 2: In with_transaction.
10-01 17:04:29.615 1176 1244 E keystore2: 3: Out of keys.
10-01 17:04:29.615 1176 1244 E keystore2: 4: Error::Rc(ResponseCode(22))
10-01 17:04:29.639 1176 1244 E keystore2: keystore2::error: In generate_key.
10-01 17:04:29.639 1176 1244 E keystore2:
10-01 17:04:29.639 1176 1244 E keystore2: Caused by:
10-01 17:04:29.639 1176 1244 E keystore2: 0: While generating Key without explicit attestation key.
10-01 17:04:29.639 1176 1244 E keystore2: 1: Error::Km(ErrorCode(-74))

I have not allowed any Internet access to this device's OS since I got it brand new. I was planning on using AfWall+ to only allow access to a select few fully open-source apps.

Does Android really need Internet access to allow a user to unlock a screen with her PIN? Can I work around it somehow? I've read up a bit about Keystore, and I'd really prefer to have it mocked (i.e. have a special app that just stores the keys in a regular file, bypassing all "Trusted" hardware), so that I can extract all my keys when I move to a different phone in the future.

Any hints appreciated.

EDIT 7:

I've started a new thread in the Hacking Q&A forum to try to remedy this.

EDIT 8:

After many days of trying to debug this, I've flashed back the original firmware and re-locked the bootloader (remembering to remove the PIN while it was still unlocked, otherwise PIN setup doesn't work after re-locking). The problem didn't occur for a few days.

I then decided to only unlock the bootloader, without flashing anything or installing Magisk. The PIN unlock worked for 2 days, but then stopped again, with the same symptoms (fingerprint unlock works fine, PIN gets rejected until reboot).

Therefore I conclude that this is a bug with stock Sony firmware, not the rooting procedure or Magisk. The "can't set up PIN after (un)locking the bootloader and then changing the lock" might be a related issue. I wonder if there is any place I can report it and get Sony to fix it, given that unlocking the bootloader probably voids any support agreements.