6

Android saved settings in a database file which is /data/data/com.android.providers.settings/databases/settings.db.

Android use sqlite3 as the database. We can use adb to manage the database file. I want to know if there is a way to run all these commands in a perl/python script to automate the whole query process?

$adb shell 
$sqlite3 /data/data/com.android.providers.settings/databases/settings.db 

The above command will open the settings database. Then you will enter into sqlite3 command line.

First check how many tables existed in the database. Here lists the result.

sqlite> .tables

android_metadata   bookmarks          gservices        
bluetooth_devices  favorites          system  

The settings (such as volume_alarm) I want to get are in "system" table, a .dump command will list all items in the table.

sqlite> .dump system
BEGIN TRANSACTION;
CREATE TABLE system (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT);
INSERT INTO "system" VALUES(3,’volume_system’,’5′);
INSERT INTO "system" VALUES(4,’volume_voice’,’4′);
INSERT INTO "system" VALUES(5,’volume_alarm’,’6′);
.....
$ select value from system where name ='volume_alarm';
select value from system where name ='volume_alarm'
6
$.quit;
Raghu Srikanth Reddy
  • 2,703
  • 33
  • 29
  • 42
ericyoung
  • 621
  • 2
  • 15
  • 21
  • yes, you can. http://search.cpan.org/~msergeant/DBD-SQLite-0.31/lib/DBD/SQLite.pm – mpapec May 31 '13 at 07:23
  • @mpapec, he wants to use perl/python on PC to query database on the device. the sqlite perl module is not going to help unless he would pull the database file to PC. – Alex P. May 31 '13 at 07:30

3 Answers3

12

To query a specific value:

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select value from 'system' where name = 'volume_alarm';"

Or to pull all records from a table:

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select name, value from 'system';"
Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • 1
    @Alex I have the same question with you, and when I enter the command above, there is an error: `sqlite3: Error: too many options: "acct"`, Do you know how to resolve it ? And do you have any suggestion on this issue that use a script to query android sqlite3? hope your reply,thanks. – Ying.Zhao Jan 05 '16 at 08:03
  • @Ying.Zhao you ned to quote the query like this: adb shell sqlite3 /path/file.db '"select * form table;"' – pelotasplus May 06 '16 at 18:32
  • slightly modifying this worked for me, try my answer below – Veener Jun 07 '18 at 14:07
0

this one works.

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "\"select name, value from 'system';\""

jay fall
  • 184
  • 1
  • 4
0

Alex P's answer didn't quite work for me but this does:

To query a specific value

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "\"select value from 'system' where name = 'volume_alarm';\""

Or to pull all records from a table:

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "\"select name, value from 'system';\""
Veener
  • 4,771
  • 2
  • 29
  • 37