Fix linter / errorprone issues

Fix some issues with newly added parcelable objects: lint and a
parcelling issue.

Also update the associated tests to use existing infrastructure.

Bug: 236612872
Test: build / treehugger
Test: atest core/tests/coretests/src/android/app/time/
Change-Id: Ib7d3589ac8b4c022dc9fb20e0bdc6fa67a46c9b9
diff --git a/core/java/android/app/time/TimeState.java b/core/java/android/app/time/TimeState.java
index 15411e5..01c869d 100644
--- a/core/java/android/app/time/TimeState.java
+++ b/core/java/android/app/time/TimeState.java
@@ -63,6 +63,12 @@
         return new TimeState(unixEpochTime, userShouldConfirmId);
     }
 
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeParcelable(mUnixEpochTime, 0);
+        dest.writeBoolean(mUserShouldConfirmTime);
+    }
+
     /** @hide */
     @Nullable
     public static TimeState parseCommandLineArgs(@NonNull ShellCommand cmd) {
@@ -119,12 +125,6 @@
         return 0;
     }
 
-    @Override
-    public void writeToParcel(@NonNull Parcel dest, int flags) {
-        dest.writeParcelable(mUnixEpochTime, 0);
-        dest.writeBoolean(mUserShouldConfirmTime);
-    }
-
     @NonNull
     public UnixEpochTime getUnixEpochTime() {
         return mUnixEpochTime;
diff --git a/core/java/android/app/time/TimeZoneState.java b/core/java/android/app/time/TimeZoneState.java
index efdff81..8e87111 100644
--- a/core/java/android/app/time/TimeZoneState.java
+++ b/core/java/android/app/time/TimeZoneState.java
@@ -58,11 +58,17 @@
     }
 
     private static TimeZoneState createFromParcel(Parcel in) {
-        String zoneId = in.readString();
+        String zoneId = in.readString8();
         boolean userShouldConfirmId = in.readBoolean();
         return new TimeZoneState(zoneId, userShouldConfirmId);
     }
 
+    @Override
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        dest.writeString8(mId);
+        dest.writeBoolean(mUserShouldConfirmId);
+    }
+
     /** @hide */
     @Nullable
     public static TimeZoneState parseCommandLineArgs(@NonNull ShellCommand cmd) {
@@ -107,12 +113,6 @@
         return 0;
     }
 
-    @Override
-    public void writeToParcel(@NonNull Parcel dest, int flags) {
-        dest.writeString(mId);
-        dest.writeBoolean(mUserShouldConfirmId);
-    }
-
     @NonNull
     public String getId() {
         return mId;
diff --git a/core/java/android/app/time/UnixEpochTime.java b/core/java/android/app/time/UnixEpochTime.java
index f1a176e..576bf64 100644
--- a/core/java/android/app/time/UnixEpochTime.java
+++ b/core/java/android/app/time/UnixEpochTime.java
@@ -94,7 +94,6 @@
     }
 
     /** Returns the unix epoch time value. See {@link UnixEpochTime} for more information. */
-    @Nullable
     public long getUnixEpochTimeMillis() {
         return mUnixEpochTimeMillis;
     }
@@ -109,7 +108,7 @@
         }
         UnixEpochTime that = (UnixEpochTime) o;
         return mElapsedRealtimeMillis == that.mElapsedRealtimeMillis
-                && Objects.equals(mUnixEpochTimeMillis, that.mUnixEpochTimeMillis);
+                && mUnixEpochTimeMillis == that.mUnixEpochTimeMillis;
     }
 
     @Override
@@ -125,32 +124,19 @@
                 + '}';
     }
 
-    public static final @NonNull Creator<UnixEpochTime> CREATOR =
-            new ClassLoaderCreator<UnixEpochTime>() {
+    public static final @NonNull Creator<UnixEpochTime> CREATOR = new Creator<>() {
+        @Override
+        public UnixEpochTime createFromParcel(@NonNull Parcel source) {
+            long elapsedRealtimeMillis = source.readLong();
+            long unixEpochTimeMillis = source.readLong();
+            return new UnixEpochTime(elapsedRealtimeMillis, unixEpochTimeMillis);
+        }
 
-                @Override
-                public UnixEpochTime createFromParcel(@NonNull Parcel source) {
-                    return createFromParcel(source, null);
-                }
-
-                @Override
-                public UnixEpochTime createFromParcel(
-                        @NonNull Parcel source, @Nullable ClassLoader classLoader) {
-                    long elapsedRealtimeMillis = source.readLong();
-                    long unixEpochTimeMillis = source.readLong();
-                    return new UnixEpochTime(elapsedRealtimeMillis, unixEpochTimeMillis);
-                }
-
-                @Override
-                public UnixEpochTime[] newArray(int size) {
-                    return new UnixEpochTime[size];
-                }
-            };
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
+        @Override
+        public UnixEpochTime[] newArray(int size) {
+            return new UnixEpochTime[size];
+        }
+    };
 
     @Override
     public void writeToParcel(@NonNull Parcel dest, int flags) {
@@ -158,6 +144,11 @@
         dest.writeLong(mUnixEpochTimeMillis);
     }
 
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
     /**
      * Creates a new Unix epoch time value at {@code elapsedRealtimeTimeMillis} by adjusting this
      * Unix epoch time by the difference between the elapsed realtime value supplied and the one
diff --git a/core/tests/coretests/src/android/app/time/TimeStateTest.java b/core/tests/coretests/src/android/app/time/TimeStateTest.java
index a032290..bce0909 100644
--- a/core/tests/coretests/src/android/app/time/TimeStateTest.java
+++ b/core/tests/coretests/src/android/app/time/TimeStateTest.java
@@ -16,12 +16,12 @@
 
 package android.app.time;
 
+import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable;
 import static android.app.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
-import android.os.Parcel;
 import android.os.ShellCommand;
 
 import androidx.test.runner.AndroidJUnit4;
@@ -60,19 +60,8 @@
     @Test
     public void testParceling() {
         UnixEpochTime time = new UnixEpochTime(1, 2);
-        TimeState value = new TimeState(time, true);
-        Parcel parcel = Parcel.obtain();
-        try {
-            parcel.writeParcelable(value, 0);
-
-            parcel.setDataPosition(0);
-
-            TimeState stringValueCopy =
-                    parcel.readParcelable(null /* classLoader */, TimeState.class);
-            assertEquals(value, stringValueCopy);
-        } finally {
-            parcel.recycle();
-        }
+        assertRoundTripParcelable(new TimeState(time, true));
+        assertRoundTripParcelable(new TimeState(time, false));
     }
 
     @Test(expected = IllegalArgumentException.class)
diff --git a/core/tests/coretests/src/android/app/time/TimeZoneStateTest.java b/core/tests/coretests/src/android/app/time/TimeZoneStateTest.java
index 9786bb0..35a9dbc 100644
--- a/core/tests/coretests/src/android/app/time/TimeZoneStateTest.java
+++ b/core/tests/coretests/src/android/app/time/TimeZoneStateTest.java
@@ -16,12 +16,12 @@
 
 package android.app.time;
 
+import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable;
 import static android.app.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
-import android.os.Parcel;
 import android.os.ShellCommand;
 
 import androidx.test.runner.AndroidJUnit4;
@@ -59,19 +59,8 @@
 
     @Test
     public void testParceling() {
-        TimeZoneState value = new TimeZoneState("Europe/London", true);
-        Parcel parcel = Parcel.obtain();
-        try {
-            parcel.writeParcelable(value, 0);
-
-            parcel.setDataPosition(0);
-
-            TimeZoneState stringValueCopy =
-                    parcel.readParcelable(null /* classLoader */, TimeZoneState.class);
-            assertEquals(value, stringValueCopy);
-        } finally {
-            parcel.recycle();
-        }
+        assertRoundTripParcelable(new TimeZoneState("Europe/London", true));
+        assertRoundTripParcelable(new TimeZoneState("Europe/London", false));
     }
 
     @Test(expected = IllegalArgumentException.class)
diff --git a/core/tests/coretests/src/android/app/time/UnixEpochTimeTest.java b/core/tests/coretests/src/android/app/time/UnixEpochTimeTest.java
index cd75348..3ab01f3 100644
--- a/core/tests/coretests/src/android/app/time/UnixEpochTimeTest.java
+++ b/core/tests/coretests/src/android/app/time/UnixEpochTimeTest.java
@@ -16,12 +16,12 @@
 
 package android.app.time;
 
+import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable;
 import static android.app.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
-import android.os.Parcel;
 import android.os.ShellCommand;
 
 import androidx.test.runner.AndroidJUnit4;
@@ -57,19 +57,7 @@
 
     @Test
     public void testParceling() {
-        UnixEpochTime value = new UnixEpochTime(1000, 1);
-        Parcel parcel = Parcel.obtain();
-        try {
-            parcel.writeParcelable(value, 0);
-
-            parcel.setDataPosition(0);
-
-            UnixEpochTime stringValueCopy =
-                    parcel.readParcelable(null /* classLoader */, UnixEpochTime.class);
-            assertEquals(value, stringValueCopy);
-        } finally {
-            parcel.recycle();
-        }
+        assertRoundTripParcelable(new UnixEpochTime(1000, 1));
     }
 
     @Test(expected = IllegalArgumentException.class)