- Parts of this answer didn't work for OP, but nevertheless, they worked in all of my test cases with different ROMs, hence, the answer would certainly prove to be useful for some users.
- Device should have a custom recovery installed.
- adb should be setup in PC and USB debugging be enabled and authorized in the device.
- Anything mentioned next to
# anywhere in a line is a comment.
More or less, the changed DPI value would either be in
/system/build.prop or in memory only. I've covered instructions for all of these cases and they should prove to be helpful when the device gets stuck at boot animation.
If it is an Xposed module which changed the DPI and caused boot issue, then try disabling the module or the framework, or, remove the former or both. See my answer here for more info on that.
If you used command-line to change DPI (
wm), then when the device gets stuck at boot animation (past the OEM logo), execute
adb shell am display-density reset # For Android 4.2.x
adb shell wm density reset # For Android 4.3.x and above
In my Android 4.2.1, custom display density is saved as a value for the key
display_density_forced in the table
/data/data/com.android.providers.settings/databases/settings.db. If you've used command-line (am) or an app used this key, follow these steps:
When booted into recovery, mount data partition, pull the said file into PC and use an sqlite editor to either remove the key or change the value to a better or default DPI. After that, push the file back to its place.
adb pull /data/data/com.android.providers.settings/databases/settings.db LOCAL_PATH # to pull the file into PC
adb push LOCAL_PATH/settings.db /data/data/com.android.providers.settings/databases/ # to push the file into Android
LOCAL_PATH with the directory under which
settings.db is to be saved and is saved, respectively.
In Android 4.3 and above, custom display density can be found under
/data/property/persist.sys.lcd_density or by executing
adb shell "getprop | grep density". If you used command line (wm) or an app used that property to change DPI then follow these steps:
When booted into recovery, mount data partition and do
adb shell rm /data/property/persist.sys.lcd_density # this will cause Android to fall back to default DPI
adb shell busybox printf "DPI" > /data/property/persist.sys.lcd_density # change DPI with your custom DPI value
Finally, the easiest but a dangerous and extreme approach you or an app would take is to change the DPI for the key
/system/build.prop. The DPI in the said file is considered the stock DPI of that ROM.
When booted into recovery with data partition mounted,
You can choose to override the stock DPI by doing
# replace DPI with your custom DPI
adb shell am display-density DPI # For Android 4.2.x only
adb shell wm density DPI # For Android 4.3.x and above only
If that doesn't work for some reason, do
adb shell sed -i 's/.*ro.sf.lcd_density.*/ro.sf.lcd_density=DPI/g' /system/build.prop # sed is replacing the DPI with your custom DPI value
- If none of the solutions work then your only option is to replace
build.prop. If you've a clean backup of system partition or
build.prop then use it to replace original file, else flash the ROM as OP did.
Note: I personally did not test, but it has come to my notice to not edit any file of Android using any native text editor of Microsoft Windows OS. Instead, use Notepad++ or altogether do all the editing using command line in recovery.