Analysing the Android Demo Code – Pt 5

The following is a look at the code here on GitHub. If you’ve been following my progress so far you will know that I’ve so far managed to run this code, but I am let to take a proper look at the code and how it works.

The top level of the directory contains the following directories/files, typical to an Android project:

  1. directory called /res that contains the launcher icon, the xml file describing the layout, and two further xml files which hold the “values” associated with the application
  2. directory called /src that containing 4 java files LocalBinder.java, SigcommDemoAndroidActivity.java, SigcommDemoAndroidService.java and TestsSignpost.java and a collection of java files for different data views
  3. the AndroidManifest.xml file which highlights that the minimum SDK version is 10
  4. the lint.xml file which contains almost nothing
  5. the pom.xml file, I’m currently not sure what this does
  6. the project.properties file which just re-highlights that the SDK is version 10

I’m now going to take a closer look at the code:

SigcommDemoAndroidActivity.java

Public Methods

  • onCreate(Bundle savedInstanceState) – the method that is called when the application is first started
  • onDestroy() – the method that is called when the application is closed
  • onPause() – the method that is called when the application is paused
  • onClick(View v) – the method that is called when either of the two buttons on the application is pressed, v.getId() is then used to determine which button was pressed
  • updateTimestampArray (float [] array, float newval) – this method shifts all of the values in the array to the left by one position, disregarding the value at index 0 and inserting newval at the last place in the array. There are also minValBandwidth and maxValBandwidth which are updated according
  • updateHistoricValFloat (float [] array, float newval ) – this method shifts all the values in the array to the left by one position, disregarding the value at index 0 and inserting newval at the last place in the array. [Note: the difference between updateTimestampArray and updateHistoricValFloat is that only updateTimestampArray updates the minValBandwidth and maxValBandwidth ]
  • plotLatencyPairs (float [] timestampsDownstream, float [] arrayLatencyDownstream, float[] timestampsUpstream, float[] arrayLatencyUpstream) – this method plots latency pairs
  • plotBandwidthPairs (float [] timestampsDownstream, float [] arrayBandwidthDownstream, float[] timestampsUpstream, float[] arrayBandwidthUpstream) – this method plots bandwidth pairs
  • printVals(int [] array) – this method takes an array of integers, turns them into a string with the values separated by commas and sends them to the INFO log file [Note: API on the log output for android is available here and further information is here]
  • updateHistoricValInt (int [] array, int newval ) – this method shifts all the values in the array to the left by one position, disregarding the value at index 0 and inserting newval at the last place in the array.  [Note: the difference between updateHistoricValInt and updateHistoricValFloat is that updateHistoricValFloat takes a float array and updateHistoricValInt takes a int array]

SigcommDemoAndroidService.java


Public Methods

  • setMainActivity(SigcommDemoAndroidActivity activity, int [] server, int tcpPort) – this method is how SigcommDemoAndroidActivity.java calls this java file. SigcommDemoAndroidActivity.java calls this method when the user click on the start test button on the UI. This method using the data from SigcommDemoAndroidActivity to initialise some of the variables in SigcommDemoAndroidService such as server ip address and port number
  •  stopThread() – this method simply just re-sets the boolean flag testAlive
  •  onBind(Intent arg0) – this method calls the constructor of LocalBinder.java and passes the current instance of SigcommDemoAndroidService to LocalBinder.java
  • onUnbind(Intent intent) – this method seems to do nothing :S
  • onDestroy () – this method calls the onDestroy() on the class Service that SgcommDemoAndroidService inherits from
  • onCreate() – this method calls the onCreate() on the class Service that SgcommDemoAndroidService inherits from and creates a new thread called th
  • callFinalize() – this method calls System.exit(0)
  • notifyActivity (int value, int caseId) – this method refreshs values
  • run () – this method connects to the server and measures the time for packets to be transported between client and server

Leave a comment

Leave a Reply