Thursday, January 3, 2013

Android Settings Reset Using ADB

I'm going to try updating my blog with all the random hacks I seem to end up doing.

I run CM10.1 nightly (Android 4.2.1) on my Galaxy SII and decided to mess with some of the developer options. After enabling "Simulate secondary displays" my phone locked up. So I reboot and it locks up again during boot... sigh...

Now there are lots of ways to recover from this in a brute force manner (reinstall the ROM, do a factory reset, etc), but I decided to try reverting the specific option using ADB.

First I installed the Android SDK to get access to ADB, then rebooted my phone into CWM recovery (hold volume-up, home and power). After CWM recovery booted I mounted the "/system" and "/data" filesystems from the menu. After this I tried running ADB on my PC, which gave:

C:\adt-bundle-windows-x86_64\sdk\platform-tools>adb shell
error: device not found


Crap! It can't find my phone. A few minutes of sanity checking revealed that I didn't have the proper Samsung USB Drivers installed (SAMSUNG_USB_Driver_for_Mobile_Phones.exe). After installing them I could finally get access to the ADB shell of my phone:

C:\adt-bundle-windows-x86_64\sdk\platform-tools>adb shell
shell@android:/ $


Now to figure out what I need to change, and how to change it. Luckily Android and Cyanogenmod are both open source, and a quick search of the code for "Simulate secondary displays" located this:

https://github.com/CyanogenMod/android_packages_apps_Settings/blob/6a1d840ba025516a097063a4f309b0b6b440b6a2/res/values/strings.xml#L4007
<string name="overlay_display_devices_title">Simulate secondary displays</string>



https://github.com/CyanogenMod/android_packages_apps_Settings/blob/6a1d840ba025516a097063a4f309b0b6b440b6a2/src/com/android/settings/DevelopmentSettings.java#L947
private static final String OVERLAY_DISPLAY_DEVICES_KEY = "overlay_display_devices";
String value = Settings.Global.getString(getActivity().getContentResolver(), Settings.Global.OVERLAY_DISPLAY_DEVICES);


So the "overlay_display_devices" global setting is the culprit! After a bit of searching I found that android simply stores all settings in the "com.android.providers.settings/databases/settings.db" sqlite database. So resetting it should be pretty trivial. First I confirmed that I can actually see the value, and that it makes sense..

C:\adt-bundle-windows-x86_64\sdk\platform-tools>adb shell
shell@android:/ $ sqlite3 /data/data/com.android.providers.settings/databases/settings.db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from global where name="overlay_display_devices";
112|overlay_display_devices|1280x720/213


Okay, that looks sane! So hopefully just deleting that row and rebooting should work..

sqlite> delete from global where name="overlay_display_devices";
sqlite> select * from global where name="overlay_display_devices";
sqlite>


And... The setting is gone! And my phone boots into android again! Success!

17 comments:

  1. http://forum.xda-developers.com/showthread.php?t=2076180

    ReplyDelete
  2. Thanks, this helped me out!

    ReplyDelete
  3. This is EXACTLY what i needed thanks i did the same thing with my S2 but i was using AOKP Cheers:)

    ReplyDelete
  4. Hey!!! THANK YOU VERY MUCH!!! I've solved this situation following your instructions, but on a Motorola Xoom Wifi!

    Having problems with the sqlite3 part, cause the shell is returning that there is no sqlite3. I've pulled to my PC the settings.db, edited there with the sqlite3.exe from the SDK.

    When trying to push settings.db to the Xoom, again problems (push command not responding, no errors, nor success messages). Tried to mount/unmount several times, with read/write permissions... no success.

    Finally, I've got the IDEA! Put the SD card to the PC, copy the settings.db file, and then, with the SD card on the Xoom, moved the file throug ADB shell to the /data path.

    SUCCESS!!!!

    THANKS a LOT! From Catalonia! :D

    ReplyDelete
  5. This overlay setting is really troublesome, i have to re-flush my whole board to enter android before i get here.
    Thanks!

    ReplyDelete
  6. After a few hours of "try-to-connect" attempts (I'm using Win7 on a macbook white), your solution is working. Thank you...you save me from reinstall CM...without an update backup! :D
    Great guide, and greater solution.

    ReplyDelete
  7. This happened to me too... at the time, I didn't have access to a computer, but I had twrp that provided a file manager, so I just deleted the settings.db... I've to set everything again but at least I don't need to reflash!

    ReplyDelete
  8. you can also boot into safe mode by pressing volume buttons up + down, and power button, then, when the boot image comes out, release power button, and keep pressing volume keys, it should load the rom on safe mode, then simply change the Simulate secondary displays option to none, and then reboot, that's it, it should work like a charm!!

    ;-)

    ReplyDelete
  9. Thanks mate, you saved me lots of work ;)

    ReplyDelete
  10. Great post. Many thanks for your help.

    ReplyDelete
  11. Downloading and introducing an against spyware and a hostile to infection project will keep your PC secure and anticipate blunder messages, changes to your framework, and framework crashes. Upgrades ought to likewise be downloaded much of the time to guarantee that your definitions stay current.ABD Setup

    ReplyDelete