Do not report boot timings on first boot or runtime restart

During first boot after OTA, additional dexopting has to be done
during PM initialization. Timings for OTA are reported separately,
so we should ignore first boot to avoid skewing the metrics.

The following metrics were updated:
 - boot_system_server_init - check added for consistency with other
   metrics in SystemServer. The metric is actually unaffected by first boot,
   because dexopt will start later
 - boot_package_manager_init_ready
 - boot_system_server_init
 - framework_locked_boot_completed
 - framework_boot_completed

Test: manual + UserControllerTest pass
Bug: 32807863
Change-Id: Iff13697b7d4f9ff8439e1e932d7e276f48cd5c37
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 283de42..68cb0c5 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -278,7 +278,7 @@
             Slog.i(TAG, "Entered the Android system server!");
             int uptimeMillis = (int) SystemClock.elapsedRealtime();
             EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, uptimeMillis);
-            if (!mRuntimeRestart) {
+            if (!mRuntimeRestart && !mFirstBoot) {
                 MetricsLogger.histogram(null, "boot_system_server_init", uptimeMillis);
                 // Also report when first stage of init has started
                 long initStartNs = SystemProperties.getLong("ro.boottime.init", -1);
@@ -352,6 +352,8 @@
 
             // Create the system service manager.
             mSystemServiceManager = new SystemServiceManager(mSystemContext);
+            mSystemServiceManager.setRuntimeRestarted(mRuntimeRestart);
+            mSystemServiceManager.setFirstBoot(mFirstBoot);
             LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
             // Prepare the thread pool for init tasks that can be parallelized
             SystemServerInitThreadPool.get();
@@ -378,7 +380,7 @@
         if (StrictMode.conditionallyEnableDebugLogging()) {
             Slog.i(TAG, "Enabled StrictMode for system server main thread.");
         }
-        if (!mRuntimeRestart) {
+        if (!mRuntimeRestart && !mFirstBoot) {
             MetricsLogger.histogram(null, "boot_system_server_ready",
                     (int) SystemClock.elapsedRealtime());
         }
@@ -520,7 +522,7 @@
         mFirstBoot = mPackageManagerService.isFirstBoot();
         mPackageManager = mSystemContext.getPackageManager();
         traceEnd();
-        if (!mRuntimeRestart) {
+        if (!mRuntimeRestart && !mFirstBoot) {
             MetricsLogger.histogram(null, "boot_package_manager_init_ready",
                     (int) SystemClock.elapsedRealtime());
         }