To modify the default setting settings, You need to analyze the setting source code, as well as data storage and reading.
Android applications are stored in the packages/apps directory.
The main directories and files are as follows:
Here, resouce is the resource file, SRC is the source code, and tests contains the test code. Android. mk and androidmanifest. XML are compilation and global data of the application respectively.
The source code layout also follows the Java package management method. We take settings-Sound & Display-orientation as a clue to understand how the entire settings application works. Because the target board I developed currently does not have a gsenser, my goal is to set this item to unchecked by default.
In Res/XML/setting. XML, specify the options included in settings, and find the items related to sound and display.
According to the definition of targetclass, we can find the corresponding soundanddisplaysettings class from the source code.
Sound & display options still have many sub-options. orientation is only one of the Sound & display options. Similarly, you can find the definition of the orientation option in RES/XML/sound_and_display_settings.xml.
How do you know that accelerometer is orientation? On the one hand, I guess from the literal meaning that 8 and 9 do not leave 10, on the other hand, from packages/apps/settings/RES/values/strings. XML (for example) can also be seen that accelerometer corresponds to orientation. (the default language string description. If you select a Chinese language, in packages/apps/settings/RES/Values-ZH-RCN/strings. XML to find the Chinese description)
In the source code, the constant string key_accelerometer defines the unique identifier of this option.
In oncreate () initialization, the system uses findpreference to find the acclerometer description in XML, and forcibly converts the obtained preference type to the checkboxpreference class.
When this checkbox is clicked, it comes to the code of the response button. If the checkbox is checked, write 1; otherwise, write 0.
Setting. system. putint is used to write the modified value of this option to the database. putstring function:
The database is stored in COM. Android. providers. Settings/databases/settings. DB. The android database is stored in SQLite. Copy settings. DB and use the SQLite management tool to open the database. You can see the value you just wrote:
The value of accelerometer_rotation is 0, indicating that the checkbox of orientation is not checked.
Now, we know that almost all the default settings will be written in settings. in dB, if you want to modify a large number of default options, you can use the SQLite database tool to manually modify settings. DB value. The system automatically loads the values written in settings. dB at the next startup. Before batch production, you only need to compress the modified settings. dB to data. IMG and then burn it into the system. You can also modify the default value from the source code.
Another question to be aware of is: how does the system set the orientation state at startup? The idea is to read the database value from settings. DB and set the corresponding status.
First, determine the policy of the platform during compilation. In build/target/product/CORE. mk, There is a description like this:
In the compilation option, product_policy is Android. policy_phone. Then the system uses the phone policy to start. Start to read the database value. One related class is phonewindowmanager (similarly, mid corresponds to midwindowmanager)
Find this class from frameworks/policies/base/phone/COM/Android/Internal/policy/impl/phonewindowmanager. Java,
Here we only focus on the functions related to the checkbox of orientation. Although there are multiple lines of code in phonewindowmanager. Java two thousand, Here we only look at the related lines in the update method:
These rows obtain the value of the orientation item from the settings. DB database. If the default value is 0 (that is, the value is 1), then updateorientationlistenerlp ();
The entire analysis route is
Full text