IdleSmart's to dos - Tuong-Nguyen/Android GitHub Wiki

Purpose

Run application without connection to the board successfully.

Suggestion

Check dependencies of MainActivity class, stub all depending methods with "happy" returned value. For example, method open() of AccessoryControl class was called in MainActivity, it's used to open UsbAccessory, therefore we need find "happy" value and return it.

Add javadoc to methods to document what the method done and what is "happy" value.

Dependency classes

  • AccessoryControl
  • httpClient
  • ...

Refactoring Items:

Main layout (main.xml)

Problem: Many small screen are defined in this layout which are named as fragment ex: powerOnFragment, passwordFragment, ... This makes a large file and it is hard to focus or find the correct part.
Suggestion: move them into separated files.

MainActivity.java

Problem: There are many methods defined for sending data to the PBC (ex: sendVin - sendFleet - sendFeature - ...).
Suggestion: Move them in their own class.

Problem: UIHandler class is defined in MainActivity class. It makes MainActivity class big.
Suggestion: Move it to its own class.

Problem: ScreenReceiver class is defined in MainActivity class. It makes MainActivity class big.
Suggestion: Move it to its own class

Problem: There are methods in AccessoryControl for managing Log files (Log - CAN - Datum). They are very similar.
Suggestion: Create a class for those methods and use that class as association.

httpClient class

Problem: This class extends Activity class which does not use.
Suggestion: Remove this inheritance

Problem: Some variables are not used.
Suggestion: Remove them.

Problem: This class contains the code for calling http requests along with other processing code. Suggestion: Separate code for reading & writing to Server into a class for testing.

Problem: The application depends on server API. For testing the application, we need the server. Suggestion: Use swagger for defined the API and generate code for client and server stub. We can use server stub for testing.

AccessoryControl

Problem: contants are not declared in order
Suggestion: Re-order them

Problem: There are many commands which can be sent to PCB using write method of this class. It is hard to remember the parameters for each command.
Suggestion: Add a method for each command sent to PCB.

Problem: There are many commands which can be read from PCB (in UsbReader class). Suggestion: Add a method for parsing each command read from PCB. This help us to understand the code easier.

IdleSmart Architecture

Considerations

  • Use AppContext for keeping shared data
  • Add a bootstrap method for creating appropriate objects and connection between them
  • Synchronization between threads.
  • MainActivity class is really big. Separate it into multiple classes each has single responsibility.
  • Upgrad application.

Ideas

Learn Robolectric for testing fragment?

Done

httpClient.java

What done on this class are:

  • Get APK and CSC recent version
  • Check and update application (APK file)
  • Check and update gateway (firmware, CSC file - assumption)
  • Calling API to get data from server
  • Upload logs file to server
  • Update IdleSmart parameters (cabin temperature, battery, cold weather guard, ...) to server
  • Send activation request to server
  • Update installation state

AccessoryControl

  • USBReader: A thread for reading data from the PCB and send to MainActivity
    • Use Handler to send information to MainActivity
    • Set to MainActivity static public properties
    • Write to log files
  • Manage 3 log files:
    • Log.bin
    • Datum.bin
    • CANlog.bin
  • Having methods for writing data to PCB.
  • Complete unit tests for all methods: open, read, write, delete

httpClient.java

  • Rewrite uncompiled methods and unit tests for them
    • convertLogToJsonArray
    • convertDatumToJsonArray
  • Move above methods to a util class

UpdateGateway.java

  • Rewrite uncompiled methods and unit tests for them
    • sendCscHeaderToGateway
    • sendCscDataBlockToGateway

MainActivity.java

  • Refactor:
    • sendCmdString, sendFeatures, sendFleet, sendVIN, sendMaintInfo, (refactor and move to other class, they are depended on AccessoryControl class only)
    • Time2MinsSecsStr, isInteger, toInteger, move to util class
  • Move all param's methods, functionalities to Params class, add current param value list to this.
    • Move MainActivity's aParam variable to Params class as a property (ex: currentValues). MainActivity can use this property through get, set methods
    • incrParam, decrParam, incrValue, decrValue, initializeRunningParams
  • Move all dialogs in MainActivity to Dialog fragments: serialDialog, maintDialog, commDialog, passwordDialog, alertDialog