Debugging the WSO2 IoTS Android System application
Most enterprises prefer having own custom firmware to achieve their very specific requirements. Recently most of android devices are in beyond the manufacturer specific flagship phones like Samsung Galaxy S4 or HTC One. and they are being performed as POS or Kiosk at different trades.
Since Android OS is declared as a fully open source, device vendors or any other enthusiasts can build their own version of android operating system with replacing its original skin.They tweak into use different launcher, customize theme and vendor specific apps with their mobile device. Manufacturers modify Android’s code to do this, and they make it impossible to use the default interface if you prefer it.
Since Custom firmware enables maintaining user specific functionalities by avoiding unnecessary bloatware, Almost all the companies are induced to maintain custom firmwares or get device vendors to build a custom device so that suit their requirements. So Apps and devices are signed with the vendor firmware signing key and install it on devices as a system app.
WSO2 IoTS provides system app which can be signed by firmware signing key and installed on your Android device as a system application at the side of Android agent application.It enables ultimate control over the device for its capabilities which are required to having certain system level settings.
When System app is installed on the Android device which is already enrolled against WSO2 IoTs, Android agent application communicates with system application to trigger the system level operations or policies like reboot device, system upgrade, whitelisting applications etc.
In here my main focus is to debug the system application with the Android agent application.
There are two ways to run the system app on Android device.
- Installed and run on rooted device.
- Installed and run on firmware signed device.
Here I have taken firmware signed device to depict the processes. But above both approaches are almost same in debugging process.
Build the source code
Download the source code from here and checkout the appropriate branch.
System app can not be build via android SDK as it requires to access developer restricted apis. You need to replace the android android.jar file which resides under
<SDK_LOCATION>/platforms/android-<COMPILE_SDK_VERSION> directory with the explicitly built android.jar file that has access to the restricted APIs. Download the Android Open Source Project (AOSP) and build the source code to get the jar file for the required SDK level.
Open the system service application via Android studio and clean build the project as usual.
Sign the system service application
Sign the system application via device firmware signing key. If you don’t have access to the firmware signing key, you have to sign it through the device vendor.
If you are going to debug the Application, You will need to add following entry to the build.gradle property file under Gradle script to sign the application otherwise if you run it as usual, you can put the same entry in release profile.
Note: There are two build profiles as release and build in build.gradle property file.
enable the debug mode under debug profile in the same build.gradle file.
Enable the communication between the Android agent and system application
Navigate to the Constants.java class, which is in the org.wso2.emm.agent.utils package and configure the SYSTEM_APP_ENABLED field as follows.
Install the system application service
You can install the app externally through an Android debug bridge command or otherwise you can simply copy the signed system service APK file to the /system/priv-apps directory of the device.It will automatically activate as a system application, once the device reboot or restart at first time.
Debug the system application
Enable the developer option on the device and connect your Android device via the USB to the computer.
set break points in the application.

To start debugging, click Debug icon in the toolbar and select the connected device.

System app will be installed on the device and when you just after successfully register the android agent application, device administrator will ask to activate the WSO2 IoT system service.
Now you can debug operations and policies which need to having certain system settings.