dragon: Exclude invalid/non-updatable firmwares from keyboard update service

This CL adds the logic to catch the version number parsing exception caused by
previous distribution of dev-signed keyboard firmware. This CL also adds the
minimum updatable firmware version(0.151020) to exclude the non-updatable
Pixel C keyboard.

Bug: 25831957
TEST=build and run Pixel C Keyboard Firmware Updater service

Change-Id: I34671b8d14e6bc7d3b266d00e907440caae28a03
diff --git a/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/res/values/strings.xml b/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/res/values/strings.xml
index 58a4533..7589952 100644
--- a/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/res/values/strings.xml
+++ b/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/res/values/strings.xml
@@ -26,6 +26,7 @@
     <string name="target_manufacturer" translatable="false">Google</string>
     <string name="target_battery_level" translatable="false">20</string>
     <string name="target_firmware_version" translatable="false">0.151104</string>
+    <string name="target_min_updatable_firmware_version" translatable="false">0.151020</string>
 
     <!-- File names of the firmware images in raw resource (for service use)-->
     <string name="target_firmware_init_file_name" translatable="false">init_151104_mp_signed</string>
diff --git a/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/src/com/android/dragonkeyboardfirmwareupdater/KeyboardFirmwareUpdateService.java b/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/src/com/android/dragonkeyboardfirmwareupdater/KeyboardFirmwareUpdateService.java
index 325abc4..72d2351 100644
--- a/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/src/com/android/dragonkeyboardfirmwareupdater/KeyboardFirmwareUpdateService.java
+++ b/DragonKeyboardFirmwareUpdater/keyboard_firmware_updater/src/com/android/dragonkeyboardfirmwareupdater/KeyboardFirmwareUpdateService.java
@@ -282,11 +282,29 @@
                 Log.d(TAG, "onCharacteristicRead DEVICE_INFORMATION_FIRMWARE_VERSION_CHARACTERISTIC: current: "
                         + mKeyboardFirmwareVersion + " new: " + getString(R.string.target_firmware_version));
 
-                // TODO(mcchou): update target_fimware_version
-                if (Float.parseFloat(mKeyboardFirmwareVersion) >= Float.parseFloat(getString(R.string.target_firmware_version))) {
+                Float versionNumber = 0.0f;
+                // Parse the firmware version into Float number for the following checks.
+                try {
+                    versionNumber = Float.parseFloat(mKeyboardFirmwareVersion);
+                } catch(NumberFormatException e) {
+                    Log.w(TAG, "onCharacteristicRead DEVICE_INFORMATION_FIRMWARE_VERSION_CHARACTERISTIC: " +
+                          "firmware version parsing error");
+                    changeDfuStatus(DFU_STATE_INFO_NOT_SUITABLE);
+                    return;
+                }
+
+                // Check if the current firmware is updatable.
+                if (versionNumber < Float.parseFloat(getString(R.string.target_min_updatable_firmware_version))) {
                     Log.d(TAG, "onCharacteristicRead DEVICE_INFORMATION_FIRMWARE_VERSION_CHARACTERISTIC: " +
-                            getKeyboardString() + " firmware(" + mKeyboardFirmwareVersion +
-                            ") is up to date");
+                          "current firmware(" + mKeyboardFirmwareVersion + ") is not updatable");
+                    changeDfuStatus(DFU_STATE_INFO_NOT_SUITABLE);
+                    return;
+                }
+
+                // Check if the current firmware is up to date.
+                if (versionNumber >= Float.parseFloat(getString(R.string.target_firmware_version))) {
+                    Log.d(TAG, "onCharacteristicRead DEVICE_INFORMATION_FIRMWARE_VERSION_CHARACTERISTIC: " +
+                            getKeyboardString() + " firmware(" + mKeyboardFirmwareVersion + ") is up to date");
                     changeDfuStatus(DFU_STATE_INFO_NOT_SUITABLE);
                     return;
                 }