A debug data server for Android. Allow an Android application to publish data for diagnostic purpose and to consume this data via a simple rest API from client applications.
Create a service to host the debug data server. And override onBuildServer()
adding the required data sources.
@Override public void onBuildServer(DebugDataServer.Builder builder) {
SharedPreferences sharedPrefs
= PreferenceManager.getDefaultSharedPreferences(this);
builder.interfaceName(sharedPrefs.getString(PREF_INTERFACE_NAME, "lo"))
.port(sharedPrefs.getInt(PREF_PORT, 8080))
.addStaticClass(DebugData.class);
}
Then in your main activity start the server with the following code.
DebugDataServer.start(this, AddsService.class, this);
This will callback to onDebugDataServerStarted(DebugDataServer debugDataServer)
when the server is ready.
To run the sample project (adds-sample) install and run the APK.
gradle assembleDebug
adb install -r adds-sample/build/apk/adds-sample-debug-unaligned.apk
Be default it binds to localhost port 8080. Map this to a local port using adb.
adb forward tcp:8080 tcp:8080
Now the debug data can be queried/updated using simple curl commands.
curl http://localhost:8080/source
{
"dataSources": [
{
"name": "DebugData"
}
]
}
curl http://localhost:8080/source/DebugData
{
"BOOLEAN_VALUE": true,
"INT_VALUE": 1,
"POJO_VALUE": {
"d": "Test123",
"b": true,
"c": 1.2,
"a": 1
},
"STRING_VALUE": "Hello World!"
}
curl http://localhost:8080/source/DebugData/STRING_VALUE
{
"name": "STRING_VALUE",
"propertySourceType": "FieldPropertySource",
"value": "Hello World!"
}
curl -X PUT \
-H "Content-Type: application/json" \
-d '{"value": "Test 12345!!!"}' \
http://localhost:8080/source/DebugData/STRING_VALUE
Because the main activity has registered to track changes as you change properties you should see them reflected in the main activity on the application.