Skip to content

ignassew/AndroidSensorCollector

Repository files navigation

Sensor Collector Library for Android

Collect sensor data and system information to a websocket server

Usage

  1. Add Jitpack repository to your root build.gradle:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency:
dependencies {
    implementation 'com.github.ignassew:AndroidSensorCollector:v1.0.4'
}
  1. Add necessary permissions
  2. Initialize the Collector class when the app starts:
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    Collector(application, "<server address>")
    // ...
}

Permissions

Internet

This library doesn't state any permissions in its manifest, but it does require internet access. You will need to add android.permission.INTERNETto your AndroidManifest.xml

Cleartext traffic (optional)

If your WebSocket server is not behind TLS, you will have to add android:usesCleartextTraffic="true" attribute to application in AndroidManifest.xml.

What data is being collected

All data being collected is anonymous.

Device data

Sensor data

To prevent battery drain, this library will collect at least 1024 events of each type and then turn off. This takes around 4 minutes.

This library collects only following sensor events:

Server

My server is currently not open source.

If you want to build your own server, read the spec below:

Message types

This library uses WebSockets to communicate with the server. There are only 4 message types sent by the client. Messages are encoded in JSON. Server is not expected to ever send anything back.

Identity

This message has to be sent before any other message. Otherwise server shall close the connection.

{
  "messageType": "identity",
  "packageName": "com.ignassew.myapplication"
}
System Info
{
  "build": {
    "board": "string",
    "bootloader": "string",
    "brand": "string",
    "device": "string",
    "display": "string",
    "fingerprint": "string",
    "hardware": "string",
    "host": "string",
    "id": "string",
    "manufacturer": "string",
    "model": "string",
    "product": "string",
    "tags": "string",
    "type": "string",
    "user": "string",
    "version": {
      "codename": "string",
      "incremental": "string",
      "release": "string",
      "sdk_int": "int"
    }
  },
  "id": "string",
  "messageType": "systemInfo",
  "perfBench": "list<string>",
  "screen": {
    "density": "float",
    "heightPixels": "int",
    "widthPixels": "int"
  },
  "sensorList": "list<string>"
}
Sensor
{
  "accuracy": "int",
  "messageType": "sensor",
  "timestamp": "int (nanoseconds)",
  "type": "int",
  "x": "float",
  "y": "float",
  "z": "float"
}
Error
{
  "messageType": "error",
  "message": "string"
}

License

Copyright 2023 Ignacy Sewastianowicz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Collect sensor data and system information to a websocket server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages