Logging improvements for time zone updates

Logging improvements for time zone updates:
1) Add EventLog entries time zone update service interactions.
2) Add more information to dumpsys logs to improve debugging.

Unit tests run with:

make -j30 FrameworksServicesTests
adb install -r -g \
  "out/target/product/angler/data/app/FrameworksServicesTests/FrameworksServicesTests.apk"
adb shell am instrument -e package com.android.server.timezone -w \
  com.android.frameworks.servicestests \
  "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner"

Bug: 31008728
Test: See above for unit testing.
Test: Internal xTS tests
Test: adb shell dumpsys timezone
Test: adb logcat -b events -v threadtime -v printable -v uid -d *:v
Change-Id: I9356f4694e60b49e4b06aadd632d1bad517b8a29
diff --git a/services/core/java/com/android/server/timezone/RulesManagerService.java b/services/core/java/com/android/server/timezone/RulesManagerService.java
index d97ba2d..1c5aa60 100644
--- a/services/core/java/com/android/server/timezone/RulesManagerService.java
+++ b/services/core/java/com/android/server/timezone/RulesManagerService.java
@@ -17,6 +17,7 @@
 package com.android.server.timezone;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.EventLogTags;
 import com.android.server.SystemService;
 import com.android.timezone.distro.DistroException;
 import com.android.timezone.distro.DistroVersion;
@@ -56,8 +57,6 @@
 import static android.app.timezone.RulesState.STAGED_OPERATION_UNINSTALL;
 import static android.app.timezone.RulesState.STAGED_OPERATION_UNKNOWN;
 
-// TODO(nfuller) Add EventLog calls where useful in the system server.
-// TODO(nfuller) Check logging best practices in the system server.
 // TODO(nfuller) Check error handling best practices in the system server.
 public final class RulesManagerService extends IRulesManager.Stub {
 
@@ -203,6 +202,7 @@
             if (checkTokenBytes != null) {
                 checkToken = createCheckTokenOrThrow(checkTokenBytes);
             }
+            EventLogTags.writeTimezoneRequestInstall(toStringOrNull(checkToken));
 
             synchronized (this) {
                 if (distroParcelFileDescriptor == null) {
@@ -254,6 +254,8 @@
 
         @Override
         public void run() {
+            EventLogTags.writeTimezoneInstallStarted(toStringOrNull(mCheckToken));
+
             boolean success = false;
             // Adopt the ParcelFileDescriptor into this try-with-resources so it is closed
             // when we are done.
@@ -266,6 +268,7 @@
                 TimeZoneDistro distro = new TimeZoneDistro(is);
                 int installerResult = mInstaller.stageInstallWithErrorCode(distro);
                 int resultCode = mapInstallerResultToApiCode(installerResult);
+                EventLogTags.writeTimezoneInstallComplete(toStringOrNull(mCheckToken), resultCode);
                 sendFinishedStatus(mCallback, resultCode);
 
                 // All the installer failure modes are currently non-recoverable and won't be
@@ -273,6 +276,8 @@
                 success = true;
             } catch (Exception e) {
                 Slog.w(TAG, "Failed to install distro.", e);
+                EventLogTags.writeTimezoneInstallComplete(
+                        toStringOrNull(mCheckToken), Callback.ERROR_UNKNOWN_FAILURE);
                 sendFinishedStatus(mCallback, Callback.ERROR_UNKNOWN_FAILURE);
             } finally {
                 // Notify the package tracker that the operation is now complete.
@@ -308,6 +313,7 @@
         if (checkTokenBytes != null) {
             checkToken = createCheckTokenOrThrow(checkTokenBytes);
         }
+        EventLogTags.writeTimezoneRequestUninstall(toStringOrNull(checkToken));
         synchronized(this) {
             if (callback == null) {
                 throw new NullPointerException("callback == null");
@@ -337,6 +343,7 @@
 
         @Override
         public void run() {
+            EventLogTags.writeTimezoneUninstallStarted(toStringOrNull(mCheckToken));
             boolean success = false;
             try {
                 success = mInstaller.stageUninstall();
@@ -344,8 +351,12 @@
                 // against SUCCESS. More granular failures may be added in future.
                 int resultCode = success ? Callback.SUCCESS
                         : Callback.ERROR_UNKNOWN_FAILURE;
+                EventLogTags.writeTimezoneUninstallComplete(
+                        toStringOrNull(mCheckToken), resultCode);
                 sendFinishedStatus(mCallback, resultCode);
             } catch (Exception e) {
+                EventLogTags.writeTimezoneUninstallComplete(
+                        toStringOrNull(mCheckToken), Callback.ERROR_UNKNOWN_FAILURE);
                 Slog.w(TAG, "Failed to uninstall distro.", e);
                 sendFinishedStatus(mCallback, Callback.ERROR_UNKNOWN_FAILURE);
             } finally {
@@ -372,7 +383,9 @@
         if (checkTokenBytes != null) {
             checkToken = createCheckTokenOrThrow(checkTokenBytes);
         }
+        EventLogTags.writeTimezoneRequestNothing(toStringOrNull(checkToken));
         mPackageTracker.recordCheckResult(checkToken, success);
+        EventLogTags.writeTimezoneNothingComplete(toStringOrNull(checkToken));
     }
 
     @Override
@@ -445,6 +458,7 @@
         pw.println("RulesManagerService state: " + toString());
         pw.println("Active rules version (ICU, libcore): " + ICU.getTZDataVersion() + ","
                 + ZoneInfoDB.getInstance().getVersion());
+        pw.println("Distro state: " + rulesState.toString());
         mPackageTracker.dump(pw);
     }
 
@@ -491,4 +505,8 @@
                 return "Unknown";
         }
     }
+
+    private static String toStringOrNull(Object obj) {
+        return obj == null ? null : obj.toString();
+    }
 }