[SetUI] Change last commit date to build tag

Tests: fx run-host-tests settings_tests
Bug: SU-213
Change-Id: I62ef53f9a2f542f954580c23c3de643367bfafef
diff --git a/bin/device_settings/lib/src/model.dart b/bin/device_settings/lib/src/model.dart
index 5f65f0d..2f72fb0 100644
--- a/bin/device_settings/lib/src/model.dart
+++ b/bin/device_settings/lib/src/model.dart
@@ -32,8 +32,12 @@
   /// TODO: replace with better status info from update service
   DateTime _lastUpdate;
 
+  /// Holds the build tag if a release build, otherwise holds
+  /// the time the source code was updated.
+  String _buildTag;
+
   /// Holds the time the source code was updated.
-  DateTime _sourceDate;
+  String _sourceDate;
 
   /// Length of time since system bootup.
   Duration _uptime;
@@ -61,7 +65,9 @@
   /// be displayed.
   bool get showResetConfirmation => _showResetConfirmation;
 
-  DateTime get sourceDate => _sourceDate;
+  String get buildTag => _buildTag;
+
+  String get sourceDate => _sourceDate;
 
   Duration get uptime => _uptime;
 
@@ -102,7 +108,8 @@
   }
 
   Future<void> _onStart() async {
-    _sourceDate = DeviceInfo.getSourceDate();
+    _buildTag = DeviceInfo.buildTag;
+    _sourceDate = DeviceInfo.sourceDate;
 
     updateUptime();
     _uptimeRefreshTimer =
@@ -132,11 +139,12 @@
       }
 
       int status = System.connectToService(
-        '/svc/${devmgr.Administrator.$serviceName}',
-        channels.second.passHandle());
-      if (status != 0 ) {
+          '/svc/${devmgr.Administrator.$serviceName}',
+          channels.second.passHandle());
+      if (status != 0) {
         channels.first.close();
-        log.severe('Unable to connect to device administrator service: $status');
+        log.severe(
+            'Unable to connect to device administrator service: $status');
         return;
       }
 
diff --git a/bin/settings/lib/src/models/settings_model.dart b/bin/settings/lib/src/models/settings_model.dart
index a4af1dc..f8524ef 100644
--- a/bin/settings/lib/src/models/settings_model.dart
+++ b/bin/settings/lib/src/models/settings_model.dart
@@ -12,7 +12,6 @@
 import 'package:fuchsia_modular/module.dart';
 import 'package:fuchsia_scenic_flutter/child_view.dart' show ChildView;
 import 'package:fuchsia_scenic_flutter/child_view_connection.dart';
-import 'package:intl/intl.dart';
 import 'package:lib.settings/device_info.dart';
 import 'package:lib.widgets/model.dart';
 
@@ -32,7 +31,7 @@
 
   HashMap<String, _CachedModule> _cachedModules;
 
-  DateTime _testDeviceSourceDate;
+  String _testBuildTag;
 
   /// Constructor.
   SettingsModel() {
@@ -78,18 +77,11 @@
 
   /// Returns the build info, if build info file is found on the system image.
   String get buildInfo {
-    final DateTime buildTimeStamp = _testDeviceSourceDate != null
-        ? _testDeviceSourceDate
-        : DeviceInfo.getSourceDate();
+    final String buildTag =
+        _testBuildTag != null ? _testBuildTag : DeviceInfo.buildTag;
 
-    if (buildTimeStamp != null) {
-      final builtAt =
-          DateFormat('H:mm', 'en_US').format(buildTimeStamp).toLowerCase();
-      final builtOn =
-          DateFormat('MMM dd, yyyy', 'en_US').format(buildTimeStamp);
-      // The time zone is hardcoded because DateFormat and DateTime currently doesn't
-      // support time zones.
-      return 'Built at $builtAt UTC on $builtOn';
+    if (buildTag != null) {
+      return buildTag;
     } else {
       log.warning('Last built time doesn\'t exist!');
     }
@@ -102,8 +94,7 @@
   /// Returns the datetime status.
   String get datetimeStatus => _settingsStatus.timezoneStatus;
 
-  set testDeviceSourceDate(DateTime testDeviceSourceDate) =>
-      _testDeviceSourceDate = testDeviceSourceDate;
+  set testBuildTag(String testBuildTag) => _testBuildTag = testBuildTag;
 }
 
 /// A helper class which holds a reference to the [EmbeddedModule]
diff --git a/bin/settings/test/settings_model_test.dart b/bin/settings/test/settings_model_test.dart
index ea21b45..f30a8a9 100644
--- a/bin/settings/test/settings_model_test.dart
+++ b/bin/settings/test/settings_model_test.dart
@@ -13,10 +13,14 @@
 void main() {
   TestSettingsModel _settingsModel = TestSettingsModel();
 
-  test('test buildInfo', () {
+  test('test buildInfo - debug build', () {
     final DateTime testDate = DateTime.utc(2006, 10, 6, 13, 20, 0);
-    _settingsModel.testDeviceSourceDate = testDate;
-    expect(
-        _settingsModel.buildInfo, equals('Built at 13:20 UTC on Oct 06, 2006'));
+    _settingsModel.testBuildTag = testDate.toString();
+    expect(_settingsModel.buildInfo, equals('2006-10-06 13:20:00.000Z'));
+  });
+
+  test('test buildInfo - release build', () {
+    _settingsModel.testBuildTag = '20190422_00_RC01';
+    expect(_settingsModel.buildInfo, equals('20190422_00_RC01'));
   });
 }
diff --git a/lib/settings/lib/device_info.dart b/lib/settings/lib/device_info.dart
index f79f883..2c43c1f 100644
--- a/lib/settings/lib/device_info.dart
+++ b/lib/settings/lib/device_info.dart
@@ -5,6 +5,8 @@
 import 'package:fuchsia_services/services.dart';
 import 'package:meta/meta.dart';
 
+// If a release build, will show the build tag. Otherwise defaults to last built date.
+const String _buildTagFilePath = '/config/build-info/version';
 const String _lastUpdateFilePath = '/config/build-info/latest-commit-date';
 const String _factoryResetKey = 'FactoryReset';
 
@@ -13,22 +15,35 @@
   DateTime _sourceTimeStamp;
   DateTime get sourceTimeStamp => _sourceTimeStamp;
 
+  /// Returns the build tag if available, or the date the source code was last updated.
+  static String get buildTag {
+    final File updateFile = File(_buildTagFilePath);
+
+    if (updateFile.existsSync()) {
+      return updateFile.readAsStringSync();
+    }
+    log.warning('Update file not present');
+    return null;
+  }
+
   /// Returns the date the source code was last updated.
-  static DateTime getSourceDate() {
+  static String get sourceDate {
     final File updateFile = File(_lastUpdateFilePath);
 
     if (updateFile.existsSync()) {
-      final String lastUpdate = updateFile.readAsStringSync();
-
-      try {
-        return DateTime.parse(lastUpdate.trim());
-      } on FormatException {
-        log.warning('Could not parse build timestamp!');
-      }
-    } else {
-      log.warning('Update file not present');
+      return updateFile.readAsStringSync();
     }
+    log.warning('Update file not present');
+    return null;
+  }
 
+  /// Backwards compatibility, TODO: remove later [SU-246]
+  static DateTime getSourceDate() {
+    try {
+      return DateTime.parse(sourceDate.trim());
+    } on FormatException {
+      log.warning('Could not parse build timestamp!');
+    }
     return null;
   }