Monday, September 18, 2017

Storing collected data in Anomaly Detector app

Storing collected data in Anomaly Detector app


Since I am building an Android application which collects certain data about the Android system and the mobile device on which it is running, I am going to use this post to explain where that data is stored on the device, how it is transferred to PC for processing and what are some future goals for this part of the application.

Data Storage

In the earlier versions of the application, I used to store the data in the devices internal memory. The advantage of that approach was that no other application could have access to the data. In that way the collected data was secured from modification by some other app. The bad part in this approach was that the application was using a very limited amount of devices internal memory and because of that I decided to move the entire "data storage thing" to external memory.
There are two types of external memories on an Android device. One is the traditional SD card, while the other is the built-in storage in a device that is distinct from the protected internal storage. Since I do not have a SD card at the moment, I am using the built-in external storage of my device. To use the external storage you first must check whether the external storage is mounted and ready for writing. That can be done as shown in Code snippet 1.
public static boolean isExternalStorageWritable(){
   String state = Environment.getExternalStorageState();
   if(Environment.MEDIA_MOUNTED.equals(state)){
      return true;
   }
   return false;
 } 

Code snippet 1. Check whether the external storage is mounted

If the storage is mounted you can use Javas FileInputStream or FileOutputStream to read or write data from the external storage.

Data transfer and future goals 

At the time being the data is transferred to PC via USB cable. When you plug your Android device to a computer you simply navigate to the folder where the data is kept and you copy the data to the PC. The data is kept in a folder called ...Android/data/anomalyDetector.featureExtractor/. In the future versions of the application I will add the feature where users will be able to connect to a remote server and transfer the data securely over the Internet.
The entire project can be followed on Github, where you can also download the current version of the application and test it.


download file now