Android stores the lock‑screen PIN in a protected system database that is only accessible to privileged processes. When USB debugging is enabled, the adb daemon runs with the same privileges as the system UI, allowing it to invoke the locksettings service. The command adb shell locksettings clear --old <old‑pin> tells the service to forget the stored PIN, effectively resetting the lock screen.
This works only if the device already trusts the computer (the RSA key is authorized) and the user has previously enabled developer options. If those conditions are not met, the method cannot be used – the device will remain locked and a factory reset may be the only option.
When you run adb devices you should see the device listed as device. If it shows unauthorized, the phone is not trusting this computer – you cannot continue.
adb devices
Expected output:
List of devices attached
1234567890abcdef device
If the list is empty or shows offline, try a different cable, enable USB‑debugging again (if you can access Settings), or restart the adb server with adb kill-server && adb start-server.
Run the following command, replacing <old‑pin> with the PIN you think you set. If you are unsure, you can try common PINs (1234, 0000) – the command will simply fail without locking the device further.
adb shell locksettings clear --old <old‑pin>
When successful, you will see no output (just a new prompt). The device’s lock‑screen database is now cleared.
Although a reboot is not strictly required, it guarantees the UI picks up the change.
adb reboot
The phone will restart. After it powers on, the lock‑screen will no longer ask for a PIN.
Re‑enabling a PIN restores the protection you had before.
If USB debugging was never turned on, the ADB method cannot be used. In that case you can try the fastboot erase userdata command, but be aware it will erase all user data on the device.
Power + Volume Down).fastboot erase userdata.fastboot reboot.This method is a last resort when the device is completely inaccessible.
locksettings service was hardened in later releases).adb shell locksettings clear --old <old‑pin> --user 0.The ADB PIN‑clear relies on two conditions:
If either condition is missing, Android treats the device as a security‑critical environment and refuses the locksettings call. Newer Android versions (10+ on many OEMs) also add a "device‑policy‑manager" check that blocks the command when the device is managed by a corporate profile.
By following the steps above you can safely clear a forgotten Android PIN using ADB, provided the device already trusts your computer and has USB debugging enabled. This approach avoids a full factory reset, preserving your apps and data while restoring access to the device. Always keep a backup of your PIN or enable alternative unlock methods to prevent future lock‑outs.









