Saturday 18 March 2017

Customizing Android application settings and application startup behaviour using overlays

When developing an Android custom device for a particular market you would need to customize the system application settings and behaviour such as enabling NFC after boot up or disabling the lock screen for testing etc.

For the above use case it is a bad practice to modify the settings or the code in the source tree of the application. The recommended way to change the settings is in something called the overlay. Overlay concept is similar to the ".rc" files present in Linux.

For example to change the default settings in the SettingsProvider  we have to change the settings in the defaults.xml. In the source tree of Android this package is present in frameworks/base/packages/SettingsProvider/res/values/defaults.xml

In this file you can find a lot of default settings under the resources tag such as def_dim_screen or def_accelerometer_rotation which enables the rotation of the screen by default etc.

To change a particular setting we have to create the similar folder structure in the overlays directory.
To do this we navigate to device/<vendor>/<product>/overlay. If there is no overlay directory create the directory.

Next we create the folder tree structure similar to the package folder structure mentioned above. So the final structure will be
device/<vendor>/<product>/overlay/frameworks/base/packages/SettingsProvider/res/value/

Next we create the defaults.xml file and copy only the needed settings inside the resources tag.

What the above does is overrides the settings present in the defaults.xml file in the application directory with the settings present in the defaults.xml file in the overlays directory.

Similarly we can create overlays for other applications or the frameworks. We can put the config.xml or the values.xml or even the wallpapers customized for the product.

Friday 17 March 2017

Adding an apt repository from behind a proxy

Generally adding an apt repository from behind a proxy does not go well i.e. it ends with a "end of file". The reason being that the http_proxy and the https_proxy environment variables are not preserved in the sudo's environment.

To fix this we need to edit the sudoers file to have the following lines:


1
2
Defaults env_keep+="http_proxy"
Defaults env_keep+="https_proxy"

Please remember to separate the "Defaults" and "env_keep" with a tab.

In this way the http_proxy and https_proxy will be preserved for the add-apt-repository to fetch the keys and the repo info.