Merge "Add dplotnikov to OWNERS"
diff --git a/apex/blobstore/OWNERS b/apex/blobstore/OWNERS
index 8e04399..a53bbea 100644
--- a/apex/blobstore/OWNERS
+++ b/apex/blobstore/OWNERS
@@ -1,4 +1,2 @@
-set noparent
-
 sudheersai@google.com
 yamasani@google.com
diff --git a/config/preloaded-classes b/config/preloaded-classes
index d56fc77..29f6055 100644
--- a/config/preloaded-classes
+++ b/config/preloaded-classes
@@ -11759,7 +11759,6 @@
 libcore.util.ZoneInfo$CheckedArithmeticException
 libcore.util.ZoneInfo$WallTime
 libcore.util.ZoneInfo
-org.apache.harmony.dalvik.NativeTestTarget
 org.apache.harmony.dalvik.ddmc.Chunk
 org.apache.harmony.dalvik.ddmc.ChunkHandler
 org.apache.harmony.dalvik.ddmc.DdmServer
diff --git a/core/api/current.txt b/core/api/current.txt
index 1ef98be..7628ab3 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -40506,7 +40506,8 @@
   public final class CellSignalStrengthLte extends android.telephony.CellSignalStrength implements android.os.Parcelable {
     method public int describeContents();
     method public int getAsuLevel();
-    method public int getCqi();
+    method @IntRange(from=0, to=15) public int getCqi();
+    method @IntRange(from=1, to=6) public int getCqiTableIndex();
     method public int getDbm();
     method @IntRange(from=android.telephony.CellSignalStrength.SIGNAL_STRENGTH_NONE_OR_UNKNOWN, to=android.telephony.CellSignalStrength.SIGNAL_STRENGTH_GREAT) public int getLevel();
     method public int getRsrp();
@@ -40521,6 +40522,8 @@
   public final class CellSignalStrengthNr extends android.telephony.CellSignalStrength implements android.os.Parcelable {
     method public int describeContents();
     method public int getAsuLevel();
+    method @IntRange(from=0, to=15) @NonNull public java.util.List<java.lang.Integer> getCsiCqiReport();
+    method @IntRange(from=1, to=3) public int getCsiCqiTableIndex();
     method public int getCsiRsrp();
     method public int getCsiRsrq();
     method public int getCsiSinr();
@@ -57317,6 +57320,7 @@
     method public int getModifiers();
     method @NonNull public String getName();
     method @Nullable public Package getPackage();
+    method @NonNull public String getPackageName();
     method @Nullable public java.security.ProtectionDomain getProtectionDomain();
     method @Nullable public java.net.URL getResource(@NonNull String);
     method @Nullable public java.io.InputStream getResourceAsStream(@NonNull String);
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index b982dd7..3b3170f 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -1577,6 +1577,7 @@
     field @NonNull public static final android.os.ParcelUuid HOGP;
     field @NonNull public static final android.os.ParcelUuid HSP;
     field @NonNull public static final android.os.ParcelUuid HSP_AG;
+    field @NonNull public static final android.os.ParcelUuid LE_AUDIO;
     field @NonNull public static final android.os.ParcelUuid MAP;
     field @NonNull public static final android.os.ParcelUuid MAS;
     field @NonNull public static final android.os.ParcelUuid MNS;
diff --git a/core/java/android/bluetooth/BluetoothUuid.java b/core/java/android/bluetooth/BluetoothUuid.java
index e274af1..56c4824 100644
--- a/core/java/android/bluetooth/BluetoothUuid.java
+++ b/core/java/android/bluetooth/BluetoothUuid.java
@@ -153,7 +153,12 @@
     @SystemApi
     public static final ParcelUuid HEARING_AID =
             ParcelUuid.fromString("0000FDF0-0000-1000-8000-00805f9b34fb");
-
+   /** Placeholder until specification is released
+     * @hide */
+    @NonNull
+    @SystemApi
+    public static final ParcelUuid LE_AUDIO =
+            ParcelUuid.fromString("EEEEEEEE-EEEE-EEEE-EEEE-EEEEEEEEEEEE");
     /** @hide */
     @NonNull
     @SystemApi
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java
index df1f1b2..e77b163 100644
--- a/core/java/android/os/GraphicsEnvironment.java
+++ b/core/java/android/os/GraphicsEnvironment.java
@@ -249,6 +249,7 @@
         }
         if (appInfo == null) {
             Log.w(TAG, "Debug layer app '" + packageName + "' not installed");
+            return "";
         }
 
         final String abi = chooseAbi(appInfo);
diff --git a/core/java/android/uwb/AngleMeasurement.java b/core/java/android/uwb/AngleMeasurement.java
index 33bc121..93b5fd4 100644
--- a/core/java/android/uwb/AngleMeasurement.java
+++ b/core/java/android/uwb/AngleMeasurement.java
@@ -17,6 +17,7 @@
 package android.uwb;
 
 import android.annotation.FloatRange;
+import android.annotation.NonNull;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -109,7 +110,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeDouble(mRadians);
         dest.writeDouble(mErrorRadians);
         dest.writeDouble(mConfidenceLevel);
@@ -146,6 +147,7 @@
          * @param radians angle in radians
          * @throws IllegalArgumentException if angle exceeds allowed limits of [-Math.PI, +Math.PI]
          */
+        @NonNull
         public Builder setRadians(double radians) {
             if (radians < -Math.PI || radians > Math.PI) {
                 throw new IllegalArgumentException("Invalid radians: " + radians);
@@ -160,6 +162,7 @@
          * @param errorRadians error of the angle in radians
          * @throws IllegalArgumentException if the error exceeds the allowed limits of [0, +Math.PI]
          */
+        @NonNull
         public Builder setErrorRadians(double errorRadians) {
             if (errorRadians < 0.0 || errorRadians > Math.PI) {
                 throw new IllegalArgumentException(
@@ -175,6 +178,7 @@
          * @param confidenceLevel level of confidence of the angle measurement
          * @throws IllegalArgumentException if the error exceeds the allowed limits of [0.0, 1.0]
          */
+        @NonNull
         public Builder setConfidenceLevel(double confidenceLevel) {
             if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
                 throw new IllegalArgumentException(
@@ -189,6 +193,7 @@
          *
          * @throws IllegalStateException if angle, error, or confidence values are missing
          */
+        @NonNull
         public AngleMeasurement build() {
             if (Double.isNaN(mRadians)) {
                 throw new IllegalStateException("Angle is not set");
diff --git a/core/java/android/uwb/AngleOfArrivalMeasurement.java b/core/java/android/uwb/AngleOfArrivalMeasurement.java
index cd5af69..20a1c7a 100644
--- a/core/java/android/uwb/AngleOfArrivalMeasurement.java
+++ b/core/java/android/uwb/AngleOfArrivalMeasurement.java
@@ -53,7 +53,7 @@
      * @return the azimuth {@link AngleMeasurement}
      */
     @NonNull
-    public AngleMeasurement getAzimuth() {
+    public AngleMeasurement getAzimuthAngleMeasurement() {
         return mAzimuthAngleMeasurement;
     }
 
@@ -70,7 +70,7 @@
      * @return altitude {@link AngleMeasurement} or null when this is not available
      */
     @Nullable
-    public AngleMeasurement getAltitude() {
+    public AngleMeasurement getAltitudeAngleMeasurement() {
         return mAltitudeAngleMeasurement;
     }
 
@@ -85,8 +85,8 @@
 
         if (obj instanceof AngleOfArrivalMeasurement) {
             AngleOfArrivalMeasurement other = (AngleOfArrivalMeasurement) obj;
-            return mAzimuthAngleMeasurement.equals(other.getAzimuth())
-                    && mAltitudeAngleMeasurement.equals(other.getAltitude());
+            return mAzimuthAngleMeasurement.equals(other.getAzimuthAngleMeasurement())
+                    && mAltitudeAngleMeasurement.equals(other.getAltitudeAngleMeasurement());
         }
         return false;
     }
@@ -105,7 +105,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeParcelable(mAzimuthAngleMeasurement, flags);
         dest.writeParcelable(mAltitudeAngleMeasurement, flags);
     }
@@ -143,6 +143,7 @@
          *
          * @param azimuthAngle azimuth angle
          */
+        @NonNull
         public Builder setAzimuthAngleMeasurement(@NonNull AngleMeasurement azimuthAngle) {
             mAzimuthAngleMeasurement = azimuthAngle;
             return this;
@@ -153,6 +154,7 @@
          *
          * @param altitudeAngle altitude angle
          */
+        @NonNull
         public Builder setAltitudeAngleMeasurement(@NonNull AngleMeasurement altitudeAngle) {
             mAltitudeAngleMeasurement = altitudeAngle;
             return this;
@@ -163,6 +165,7 @@
          *
          * @throws IllegalStateException if the required azimuth angle is not provided
          */
+        @NonNull
         public AngleOfArrivalMeasurement build() {
             if (mAzimuthAngleMeasurement == null) {
                 throw new IllegalStateException("Azimuth angle measurement is not set");
diff --git a/core/java/android/uwb/DistanceMeasurement.java b/core/java/android/uwb/DistanceMeasurement.java
index c959840..10c2172 100644
--- a/core/java/android/uwb/DistanceMeasurement.java
+++ b/core/java/android/uwb/DistanceMeasurement.java
@@ -17,6 +17,7 @@
 package android.uwb;
 
 import android.annotation.FloatRange;
+import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -106,7 +107,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeDouble(mMeters);
         dest.writeDouble(mErrorMeters);
         dest.writeDouble(mConfidenceLevel);
@@ -143,6 +144,7 @@
          * @param meters distance in meters
          * @throws IllegalArgumentException if meters is NaN
          */
+        @NonNull
         public Builder setMeters(double meters) {
             if (Double.isNaN(meters)) {
                 throw new IllegalArgumentException("meters cannot be NaN");
@@ -157,6 +159,7 @@
          * @param errorMeters distance error in meters
          * @throws IllegalArgumentException if error is negative or NaN
          */
+        @NonNull
         public Builder setErrorMeters(double errorMeters) {
             if (Double.isNaN(errorMeters) || errorMeters < 0.0) {
                 throw new IllegalArgumentException(
@@ -172,6 +175,7 @@
          * @param confidenceLevel the confidence level in the distance measurement
          * @throws IllegalArgumentException if confidence level is not in the range of [0.0, 1.0]
          */
+        @NonNull
         public Builder setConfidenceLevel(double confidenceLevel) {
             if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
                 throw new IllegalArgumentException(
@@ -186,6 +190,7 @@
          *
          * @throws IllegalStateException if meters, error, or confidence are not set
          */
+        @NonNull
         public DistanceMeasurement build() {
             if (Double.isNaN(mMeters)) {
                 throw new IllegalStateException("Meters cannot be NaN");
diff --git a/core/java/android/uwb/OWNERS b/core/java/android/uwb/OWNERS
new file mode 100644
index 0000000..ea41c39
--- /dev/null
+++ b/core/java/android/uwb/OWNERS
@@ -0,0 +1,5 @@
+bstack@google.com
+eliptus@google.com
+jsolnit@google.com
+siyuanh@google.com
+zachoverflow@google.com
diff --git a/core/java/android/uwb/RangingManager.java b/core/java/android/uwb/RangingManager.java
new file mode 100644
index 0000000..a9bf4ab
--- /dev/null
+++ b/core/java/android/uwb/RangingManager.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.uwb;
+
+import android.annotation.NonNull;
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+import android.util.Log;
+
+import java.util.Hashtable;
+import java.util.concurrent.Executor;
+
+/**
+ * @hide
+ */
+public class RangingManager extends android.uwb.IUwbRangingCallbacks.Stub {
+    private static final String TAG = "Uwb.RangingManager";
+
+    private final IUwbAdapter mAdapter;
+    private final Hashtable<SessionHandle, RangingSession> mRangingSessionTable = new Hashtable<>();
+
+    public RangingManager(IUwbAdapter adapter) {
+        mAdapter = adapter;
+    }
+
+    /**
+     * Open a new ranging session
+     *
+     * @param params the parameters that define the ranging session
+     * @param executor {@link Executor} to run callbacks
+     * @param callbacks {@link RangingSession.Callback} to associate with the {@link RangingSession}
+     *                  that is being opened.
+     * @return a new {@link RangingSession}
+     */
+    public RangingSession openSession(@NonNull PersistableBundle params, @NonNull Executor executor,
+            @NonNull RangingSession.Callback callbacks) {
+        SessionHandle sessionHandle;
+        try {
+            sessionHandle = mAdapter.startRanging(this, params);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+
+        synchronized (this) {
+            if (hasSession(sessionHandle)) {
+                Log.w(TAG, "Newly created session unexpectedly reuses an active SessionHandle");
+                executor.execute(() -> callbacks.onClosed(
+                        RangingSession.Callback.CLOSE_REASON_LOCAL_GENERIC_ERROR,
+                        new PersistableBundle()));
+            }
+
+            RangingSession session =
+                    new RangingSession(executor, callbacks, mAdapter, sessionHandle);
+            mRangingSessionTable.put(sessionHandle, session);
+            return session;
+        }
+    }
+
+    private boolean hasSession(SessionHandle sessionHandle) {
+        return mRangingSessionTable.containsKey(sessionHandle);
+    }
+
+    @Override
+    public void onRangingStarted(SessionHandle sessionHandle, PersistableBundle parameters) {
+        synchronized (this) {
+            if (!hasSession(sessionHandle)) {
+                Log.w(TAG,
+                        "onRangingStarted - received unexpected SessionHandle: " + sessionHandle);
+                return;
+            }
+
+            RangingSession session = mRangingSessionTable.get(sessionHandle);
+            session.onRangingStarted(parameters);
+        }
+    }
+
+    @Override
+    public void onRangingStartFailed(SessionHandle sessionHandle, int reason,
+            PersistableBundle params) {
+        synchronized (this) {
+            if (!hasSession(sessionHandle)) {
+                Log.w(TAG, "onRangingStartFailed - received unexpected SessionHandle: "
+                        + sessionHandle);
+                return;
+            }
+
+            RangingSession session = mRangingSessionTable.get(sessionHandle);
+            session.onRangingClosed(convertStartFailureToCloseReason(reason), params);
+            mRangingSessionTable.remove(sessionHandle);
+        }
+    }
+
+    @Override
+    public void onRangingClosed(SessionHandle sessionHandle, int reason, PersistableBundle params) {
+        synchronized (this) {
+            if (!hasSession(sessionHandle)) {
+                Log.w(TAG, "onRangingClosed - received unexpected SessionHandle: " + sessionHandle);
+                return;
+            }
+
+            RangingSession session = mRangingSessionTable.get(sessionHandle);
+            session.onRangingClosed(convertToCloseReason(reason), params);
+            mRangingSessionTable.remove(sessionHandle);
+        }
+    }
+
+    @Override
+    public void onRangingResult(SessionHandle sessionHandle, RangingReport result) {
+        synchronized (this) {
+            if (!hasSession(sessionHandle)) {
+                Log.w(TAG, "onRangingResult - received unexpected SessionHandle: " + sessionHandle);
+                return;
+            }
+
+            RangingSession session = mRangingSessionTable.get(sessionHandle);
+            session.onRangingResult(result);
+        }
+    }
+
+    @RangingSession.Callback.CloseReason
+    private static int convertToCloseReason(@CloseReason int reason) {
+        switch (reason) {
+            case CloseReason.LOCAL_API:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_CLOSE_API;
+
+            case CloseReason.MAX_SESSIONS_REACHED:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED;
+
+            case CloseReason.SYSTEM_POLICY:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY;
+
+            case CloseReason.REMOTE_REQUEST:
+                return RangingSession.Callback.CLOSE_REASON_REMOTE_REQUEST;
+
+            case CloseReason.PROTOCOL_SPECIFIC:
+                return RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC;
+
+            case CloseReason.UNKNOWN:
+            default:
+                return RangingSession.Callback.CLOSE_REASON_UNKNOWN;
+        }
+    }
+
+    @RangingSession.Callback.CloseReason
+    private static int convertStartFailureToCloseReason(@StartFailureReason int reason) {
+        switch (reason) {
+            case StartFailureReason.BAD_PARAMETERS:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_BAD_PARAMETERS;
+
+            case StartFailureReason.MAX_SESSIONS_REACHED:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED;
+
+            case StartFailureReason.SYSTEM_POLICY:
+                return RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY;
+
+            case StartFailureReason.PROTOCOL_SPECIFIC:
+                return RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC;
+
+            case StartFailureReason.UNKNOWN:
+            default:
+                return RangingSession.Callback.CLOSE_REASON_UNKNOWN;
+        }
+    }
+}
diff --git a/core/java/android/uwb/RangingMeasurement.java b/core/java/android/uwb/RangingMeasurement.java
index f1c3162..50e5f0d 100644
--- a/core/java/android/uwb/RangingMeasurement.java
+++ b/core/java/android/uwb/RangingMeasurement.java
@@ -60,6 +60,9 @@
         return mRemoteDeviceAddress;
     }
 
+    /**
+     * @hide
+     */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef(value = {
             RANGING_STATUS_SUCCESS,
@@ -115,7 +118,7 @@
      *         {@link #RANGING_STATUS_SUCCESS}
      */
     @Nullable
-    public DistanceMeasurement getDistance() {
+    public DistanceMeasurement getDistanceMeasurement() {
         return mDistanceMeasurement;
     }
 
@@ -126,7 +129,7 @@
      *         {@link #RANGING_STATUS_SUCCESS}
      */
     @Nullable
-    public AngleOfArrivalMeasurement getAngleOfArrival() {
+    public AngleOfArrivalMeasurement getAngleOfArrivalMeasurement() {
         return mAngleOfArrivalMeasurement;
     }
 
@@ -144,8 +147,8 @@
             return mRemoteDeviceAddress.equals(other.getRemoteDeviceAddress())
                     && mStatus == other.getStatus()
                     && mElapsedRealtimeNanos == other.getElapsedRealtimeNanos()
-                    && mDistanceMeasurement.equals(other.getDistance())
-                    && mAngleOfArrivalMeasurement.equals(other.getAngleOfArrival());
+                    && mDistanceMeasurement.equals(other.getDistanceMeasurement())
+                    && mAngleOfArrivalMeasurement.equals(other.getAngleOfArrivalMeasurement());
         }
         return false;
     }
@@ -165,7 +168,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeParcelable(mRemoteDeviceAddress, flags);
         dest.writeInt(mStatus);
         dest.writeLong(mElapsedRealtimeNanos);
@@ -210,6 +213,7 @@
          *
          * @param remoteDeviceAddress remote device's address
          */
+        @NonNull
         public Builder setRemoteDeviceAddress(@NonNull UwbAddress remoteDeviceAddress) {
             mRemoteDeviceAddress = remoteDeviceAddress;
             return this;
@@ -220,6 +224,7 @@
          *
          * @param status the status of the ranging measurement
          */
+        @NonNull
         public Builder setStatus(@Status int status) {
             mStatus = status;
             return this;
@@ -230,6 +235,7 @@
          *
          * @param elapsedRealtimeNanos time the ranging measurement occurred
          */
+        @NonNull
         public Builder setElapsedRealtimeNanos(long elapsedRealtimeNanos) {
             if (elapsedRealtimeNanos < 0) {
                 throw new IllegalArgumentException("elapsedRealtimeNanos must be >= 0");
@@ -243,6 +249,7 @@
          *
          * @param distanceMeasurement the distance measurement for this ranging measurement
          */
+        @NonNull
         public Builder setDistanceMeasurement(@NonNull DistanceMeasurement distanceMeasurement) {
             mDistanceMeasurement = distanceMeasurement;
             return this;
@@ -254,6 +261,7 @@
          * @param angleOfArrivalMeasurement the angle of arrival measurement for this ranging
          *                                  measurement
          */
+        @NonNull
         public Builder setAngleOfArrivalMeasurement(
                 @NonNull AngleOfArrivalMeasurement angleOfArrivalMeasurement) {
             mAngleOfArrivalMeasurement = angleOfArrivalMeasurement;
@@ -268,6 +276,7 @@
          *                               elapsedRealtimeNanos of the measurement is invalid, or
          *                               if no remote device address is set
          */
+        @NonNull
         public RangingMeasurement build() {
             if (mStatus != RANGING_STATUS_SUCCESS) {
                 if (mDistanceMeasurement != null) {
diff --git a/core/java/android/uwb/RangingReport.java b/core/java/android/uwb/RangingReport.java
index 45180bf..5b5f084 100644
--- a/core/java/android/uwb/RangingReport.java
+++ b/core/java/android/uwb/RangingReport.java
@@ -83,7 +83,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeTypedList(mRangingMeasurements);
     }
 
@@ -113,6 +113,7 @@
          *
          * @param rangingMeasurement a ranging measurement
          */
+        @NonNull
         public Builder addMeasurement(@NonNull RangingMeasurement rangingMeasurement) {
             mMeasurements.add(rangingMeasurement);
             return this;
@@ -123,6 +124,7 @@
          *
          * @param rangingMeasurements {@link List} of {@link RangingMeasurement}s to add
          */
+        @NonNull
         public Builder addMeasurements(@NonNull List<RangingMeasurement> rangingMeasurements) {
             mMeasurements.addAll(rangingMeasurements);
             return this;
@@ -133,6 +135,7 @@
          *
          * @throws IllegalStateException if measurements are not in monotonically increasing order
          */
+        @NonNull
         public RangingReport build() {
             // Verify that all measurement timestamps are monotonically increasing
             RangingMeasurement prevMeasurement = null;
diff --git a/core/java/android/uwb/RangingSession.java b/core/java/android/uwb/RangingSession.java
index 8639269..b0dbd85 100644
--- a/core/java/android/uwb/RangingSession.java
+++ b/core/java/android/uwb/RangingSession.java
@@ -17,7 +17,11 @@
 package android.uwb;
 
 import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.os.Binder;
 import android.os.PersistableBundle;
+import android.os.RemoteException;
+import android.util.Log;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -33,12 +37,26 @@
  * {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)} to request to open a
  * session. Once the session is opened, a {@link RangingSession} object is provided through
  * {@link RangingSession.Callback#onOpenSuccess(RangingSession, PersistableBundle)}. If opening a
- * session fails, the failure is reported through {@link RangingSession.Callback#onClosed(int)} with
- * the failure reason.
+ * session fails, the failure is reported through
+ * {@link RangingSession.Callback#onClosed(int, PersistableBundle)} with the failure reason.
  *
  * @hide
  */
 public final class RangingSession implements AutoCloseable {
+    private static final String TAG = "Uwb.RangingSession";
+    private final SessionHandle mSessionHandle;
+    private final IUwbAdapter mAdapter;
+    private final Executor mExecutor;
+    private final Callback mCallback;
+
+    private enum State {
+        INIT,
+        OPEN,
+        CLOSED,
+    }
+
+    private State mState;
+
     /**
      * Interface for receiving {@link RangingSession} events
      */
@@ -50,8 +68,11 @@
          * @param session the newly opened {@link RangingSession}
          * @param sessionInfo session specific parameters from lower layers
          */
-        void onOpenSuccess(RangingSession session, PersistableBundle sessionInfo);
+        void onOpenSuccess(@NonNull RangingSession session, @NonNull PersistableBundle sessionInfo);
 
+        /**
+         * @hide
+         */
         @Retention(RetentionPolicy.SOURCE)
         @IntDef(value = {
                 CLOSE_REASON_UNKNOWN,
@@ -112,20 +133,46 @@
         int CLOSE_REASON_REMOTE_REQUEST = 7;
 
         /**
+         * Indicates that the session was closed for a protocol specific reason. The associated
+         * {@link PersistableBundle} should be consulted for additional information.
+         */
+        int CLOSE_REASON_PROTOCOL_SPECIFIC = 8;
+
+        /**
          * Invoked when session is either closed spontaneously, or per user request via
          * {@link RangingSession#close()} or {@link AutoCloseable#close()}, or when session failed
          * to open.
          *
          * @param reason reason for the session closure
+         * @param parameters protocol specific parameters related to the close reason
          */
-        void onClosed(@CloseReason int reason);
+        void onClosed(@CloseReason int reason, @NonNull PersistableBundle parameters);
 
         /**
          * Called once per ranging interval even when a ranging measurement fails
          *
          * @param rangingReport ranging report for this interval's measurements
          */
-        void onReportReceived(RangingReport rangingReport);
+        void onReportReceived(@NonNull RangingReport rangingReport);
+    }
+
+    /**
+     * @hide
+     */
+    public RangingSession(Executor executor, Callback callback, IUwbAdapter adapter,
+            SessionHandle sessionHandle) {
+        mState = State.INIT;
+        mExecutor = executor;
+        mCallback = callback;
+        mAdapter = adapter;
+        mSessionHandle = sessionHandle;
+    }
+
+    /**
+     * @hide
+     */
+    public boolean isOpen() {
+        return mState == State.OPEN;
     }
 
     /**
@@ -133,16 +180,74 @@
      * <p>If this session is currently open, it will close and stop the session.
      * <p>If the session is in the process of being opened, it will attempt to stop the session from
      * being opened.
-     * <p>If the session is already closed, the registered {@link Callback#onClosed(int)} callback
-     * will still be invoked.
+     * <p>If the session is already closed, the registered
+     * {@link Callback#onClosed(int, PersistableBundle)} callback will still be invoked.
      *
-     * <p>{@link Callback#onClosed(int)} will be invoked using the same callback
+     * <p>{@link Callback#onClosed(int, PersistableBundle)} will be invoked using the same callback
      * object given to {@link UwbManager#openRangingSession(PersistableBundle, Executor, Callback)}
      * when the {@link RangingSession} was opened. The callback will be invoked after each call to
      * {@link #close()}, even if the {@link RangingSession} is already closed.
      */
     @Override
     public void close() {
-        throw new UnsupportedOperationException();
+        if (mState == State.CLOSED) {
+            mExecutor.execute(() -> mCallback.onClosed(
+                    Callback.CLOSE_REASON_LOCAL_CLOSE_API, new PersistableBundle()));
+            return;
+        }
+
+        try {
+            mAdapter.closeRanging(mSessionHandle);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * @hide
+     */
+    public void onRangingStarted(@NonNull PersistableBundle parameters) {
+        if (mState == State.CLOSED) {
+            Log.w(TAG, "onRangingStarted invoked for a closed session");
+            return;
+        }
+
+        mState = State.OPEN;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mExecutor.execute(() -> mCallback.onOpenSuccess(this, parameters));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    /**
+     * @hide
+     */
+    public void onRangingClosed(@Callback.CloseReason int reason, PersistableBundle parameters) {
+        mState = State.CLOSED;
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mExecutor.execute(() -> mCallback.onClosed(reason, parameters));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    /**
+     * @hide
+     */
+    public void onRangingResult(@NonNull RangingReport report) {
+        if (!isOpen()) {
+            Log.w(TAG, "onRangingResult invoked for non-open session");
+            return;
+        }
+
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            mExecutor.execute(() -> mCallback.onReportReceived(report));
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 }
diff --git a/core/java/android/uwb/UwbAddress.java b/core/java/android/uwb/UwbAddress.java
index 828324c..b9523a3 100644
--- a/core/java/android/uwb/UwbAddress.java
+++ b/core/java/android/uwb/UwbAddress.java
@@ -51,7 +51,7 @@
      *       {@link #SHORT_ADDRESS_BYTE_LENGTH} or {@link #EXTENDED_ADDRESS_BYTE_LENGTH} bytes
      */
     @NonNull
-    public static UwbAddress fromBytes(@NonNull byte[] address) throws IllegalArgumentException {
+    public static UwbAddress fromBytes(@NonNull byte[] address) {
         if (address.length != SHORT_ADDRESS_BYTE_LENGTH
                 && address.length != EXTENDED_ADDRESS_BYTE_LENGTH) {
             throw new IllegalArgumentException("Invalid UwbAddress length " + address.length);
@@ -107,7 +107,7 @@
     }
 
     @Override
-    public void writeToParcel(Parcel dest, int flags) {
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeInt(mAddressBytes.length);
         dest.writeByteArray(mAddressBytes);
     }
diff --git a/core/java/android/uwb/UwbManager.java b/core/java/android/uwb/UwbManager.java
index ed5cf36..f4d8018 100644
--- a/core/java/android/uwb/UwbManager.java
+++ b/core/java/android/uwb/UwbManager.java
@@ -49,12 +49,16 @@
     private IUwbAdapter mUwbAdapter;
     private static final String SERVICE_NAME = "uwb";
 
-    private AdapterStateListener mAdapterStateListener;
+    private final AdapterStateListener mAdapterStateListener;
+    private final RangingManager mRangingManager;
 
     /**
      * Interface for receiving UWB adapter state changes
      */
     public interface AdapterStateCallback {
+        /**
+         * @hide
+         */
         @Retention(RetentionPolicy.SOURCE)
         @IntDef(value = {
                 STATE_CHANGED_REASON_SESSION_STARTED,
@@ -116,6 +120,7 @@
     private UwbManager(IUwbAdapter adapter) {
         mUwbAdapter = adapter;
         mAdapterStateListener = new AdapterStateListener(adapter);
+        mRangingManager = new RangingManager(adapter);
     }
 
     /**
@@ -195,6 +200,9 @@
         }
     }
 
+    /**
+     * @hide
+     */
     @Retention(RetentionPolicy.SOURCE)
     @IntDef(value = {
             ANGLE_OF_ARRIVAL_SUPPORT_TYPE_NONE,
@@ -387,8 +395,8 @@
      */
     @NonNull
     public AutoCloseable openRangingSession(@NonNull PersistableBundle parameters,
-            @NonNull Executor executor,
+            @NonNull @CallbackExecutor Executor executor,
             @NonNull RangingSession.Callback callbacks) {
-        throw new UnsupportedOperationException();
+        return mRangingManager.openSession(parameters, executor, callbacks);
     }
 }
diff --git a/core/java/android/view/OWNERS b/core/java/android/view/OWNERS
index 72fa4c3..bae6ee8 100644
--- a/core/java/android/view/OWNERS
+++ b/core/java/android/view/OWNERS
@@ -47,11 +47,13 @@
 per-file View.java = file:/graphics/java/android/graphics/OWNERS
 per-file View.java = file:/services/core/java/com/android/server/input/OWNERS
 per-file View.java = file:/services/core/java/com/android/server/wm/OWNERS
+per-file View.java = file:/core/java/android/view/inputmethod/OWNERS
 per-file ViewRootImpl.java = file:/services/accessibility/OWNERS
 per-file ViewRootImpl.java = file:/core/java/android/service/autofill/OWNERS
 per-file ViewRootImpl.java = file:/graphics/java/android/graphics/OWNERS
 per-file ViewRootImpl.java = file:/services/core/java/com/android/server/input/OWNERS
 per-file ViewRootImpl.java = file:/services/core/java/com/android/server/wm/OWNERS
+per-file ViewRootImpl.java = file:/core/java/android/view/inputmethod/OWNERS
 
 # WindowManager
 per-file DisplayCutout.aidl = file:/services/core/java/com/android/server/wm/OWNERS
diff --git a/core/java/com/android/internal/app/OWNERS b/core/java/com/android/internal/app/OWNERS
index 108ab92..382b49e 100644
--- a/core/java/com/android/internal/app/OWNERS
+++ b/core/java/com/android/internal/app/OWNERS
@@ -1 +1,4 @@
 per-file *AppOp* = file:/core/java/android/permission/OWNERS
+per-file *Resolver* = file:/packages/SystemUI/OWNERS
+per-file *Chooser* = file:/packages/SystemUI/OWNERS
+per-file SimpleIconFactory.java = file:/packages/SystemUI/OWNERS
diff --git a/core/java/com/android/internal/app/chooser/OWNERS b/core/java/com/android/internal/app/chooser/OWNERS
new file mode 100644
index 0000000..a6f1632
--- /dev/null
+++ b/core/java/com/android/internal/app/chooser/OWNERS
@@ -0,0 +1 @@
+file:/packages/SystemUI/OWNERS
\ No newline at end of file
diff --git a/core/java/com/android/internal/util/AnnotationValidations.java b/core/java/com/android/internal/util/AnnotationValidations.java
index 2d3b450..cf5e48f 100644
--- a/core/java/com/android/internal/util/AnnotationValidations.java
+++ b/core/java/com/android/internal/util/AnnotationValidations.java
@@ -182,7 +182,7 @@
             Annotation ignored, int value, Object... params) {}
     public static void validate(Class<? extends Annotation> annotation,
             Annotation ignored, int value) {
-        if (("android.annotation".equals(annotation.getPackageName$())
+        if (("android.annotation".equals(annotation.getPackageName())
                 && annotation.getSimpleName().endsWith("Res"))
                 || ColorInt.class.equals(annotation)) {
             if (value < 0) {
@@ -192,7 +192,7 @@
     }
     public static void validate(Class<? extends Annotation> annotation,
             Annotation ignored, long value) {
-        if ("android.annotation".equals(annotation.getPackageName$())
+        if ("android.annotation".equals(annotation.getPackageName())
                 && annotation.getSimpleName().endsWith("Long")) {
             if (value < 0L) {
                 invalid(annotation, value);
diff --git a/core/res/OWNERS b/core/res/OWNERS
index 263d638..02cf0b7 100644
--- a/core/res/OWNERS
+++ b/core/res/OWNERS
@@ -6,6 +6,7 @@
 hackbod@google.com
 jsharkey@android.com
 jsharkey@google.com
+juliacr@google.com
 michaelwr@google.com
 nandana@google.com
 narayan@google.com
diff --git a/core/tests/coretests/BstatsTestApp/OWNERS b/core/tests/coretests/BstatsTestApp/OWNERS
new file mode 100644
index 0000000..4068e2b
--- /dev/null
+++ b/core/tests/coretests/BstatsTestApp/OWNERS
@@ -0,0 +1 @@
+include /BATTERY_STATS_OWNERS
diff --git a/core/tests/coretests/src/com/android/internal/os/OWNERS b/core/tests/coretests/src/com/android/internal/os/OWNERS
new file mode 100644
index 0000000..4068e2b
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/os/OWNERS
@@ -0,0 +1 @@
+include /BATTERY_STATS_OWNERS
diff --git a/core/tests/uwbtests/OWNERS b/core/tests/uwbtests/OWNERS
new file mode 100644
index 0000000..c7b09a2
--- /dev/null
+++ b/core/tests/uwbtests/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/uwb/OWNERS
diff --git a/core/tests/uwbtests/src/android/uwb/AngleOfArrivalMeasurementTest.java b/core/tests/uwbtests/src/android/uwb/AngleOfArrivalMeasurementTest.java
index 077b08f..e0884e3 100644
--- a/core/tests/uwbtests/src/android/uwb/AngleOfArrivalMeasurementTest.java
+++ b/core/tests/uwbtests/src/android/uwb/AngleOfArrivalMeasurementTest.java
@@ -48,8 +48,8 @@
         builder.setAzimuthAngleMeasurement(azimuth);
         AngleOfArrivalMeasurement measurement = tryBuild(builder, true);
 
-        assertEquals(azimuth, measurement.getAzimuth());
-        assertEquals(altitude, measurement.getAltitude());
+        assertEquals(azimuth, measurement.getAzimuthAngleMeasurement());
+        assertEquals(altitude, measurement.getAltitudeAngleMeasurement());
     }
 
     private AngleMeasurement getAngleMeasurement(double radian, double error, double confidence) {
diff --git a/core/tests/uwbtests/src/android/uwb/RangingManagerTest.java b/core/tests/uwbtests/src/android/uwb/RangingManagerTest.java
new file mode 100644
index 0000000..6df1c3e
--- /dev/null
+++ b/core/tests/uwbtests/src/android/uwb/RangingManagerTest.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.uwb;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Test of {@link AdapterStateListener}.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class RangingManagerTest {
+
+    private static final IUwbAdapter ADAPTER = mock(IUwbAdapter.class);
+    private static final Executor EXECUTOR = UwbTestUtils.getExecutor();
+    private static final PersistableBundle PARAMS = new PersistableBundle();
+    private static final @CloseReason int CLOSE_REASON = CloseReason.UNKNOWN;
+
+    @Test
+    public void testOpenSession_StartRangingInvoked() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+        verify(ADAPTER, times(1)).startRanging(eq(rangingManager), eq(PARAMS));
+    }
+
+    @Test
+    public void testOpenSession_ErrorIfSameSessionHandleReturned() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+
+        // Calling openSession will cause the same session handle to be returned. The onClosed
+        // callback should be invoked
+        RangingSession.Callback callback2 = mock(RangingSession.Callback.class);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback2);
+        verify(callback, times(0)).onClosed(anyInt(), any());
+        verify(callback2, times(1)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingStarted_ValidSessionHandle() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+        rangingManager.onRangingStarted(handle, PARAMS);
+        verify(callback, times(1)).onOpenSuccess(any(), any());
+    }
+
+    @Test
+    public void testOnRangingStarted_InvalidSessionHandle() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+
+        rangingManager.onRangingStarted(new SessionHandle(2), PARAMS);
+        verify(callback, times(0)).onOpenSuccess(any(), any());
+    }
+
+    @Test
+    public void testOnRangingStarted_MultipleSessionsRegistered() throws RemoteException {
+        SessionHandle sessionHandle1 = new SessionHandle(1);
+        SessionHandle sessionHandle2 = new SessionHandle(2);
+        RangingSession.Callback callback1 = mock(RangingSession.Callback.class);
+        RangingSession.Callback callback2 = mock(RangingSession.Callback.class);
+
+        when(ADAPTER.startRanging(any(), any()))
+                .thenReturn(sessionHandle1)
+                .thenReturn(sessionHandle2);
+
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback1);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback2);
+
+        rangingManager.onRangingStarted(sessionHandle1, PARAMS);
+        verify(callback1, times(1)).onOpenSuccess(any(), any());
+        verify(callback2, times(0)).onOpenSuccess(any(), any());
+
+        rangingManager.onRangingStarted(sessionHandle2, PARAMS);
+        verify(callback1, times(1)).onOpenSuccess(any(), any());
+        verify(callback2, times(1)).onOpenSuccess(any(), any());
+    }
+
+    @Test
+    public void testOnRangingClosed_OnRangingClosedCalled() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+
+        rangingManager.onRangingClosed(handle, CLOSE_REASON, PARAMS);
+        verify(callback, times(1)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingClosed_MultipleSessionsRegistered() throws RemoteException {
+        // Verify that if multiple sessions are registered, only the session that is
+        // requested to close receives the associated callbacks
+        SessionHandle sessionHandle1 = new SessionHandle(1);
+        SessionHandle sessionHandle2 = new SessionHandle(2);
+        RangingSession.Callback callback1 = mock(RangingSession.Callback.class);
+        RangingSession.Callback callback2 = mock(RangingSession.Callback.class);
+
+        when(ADAPTER.startRanging(any(), any()))
+                .thenReturn(sessionHandle1)
+                .thenReturn(sessionHandle2);
+
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback1);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback2);
+
+        rangingManager.onRangingClosed(sessionHandle1, CLOSE_REASON, PARAMS);
+        verify(callback1, times(1)).onClosed(anyInt(), any());
+        verify(callback2, times(0)).onClosed(anyInt(), any());
+
+        rangingManager.onRangingClosed(sessionHandle2, CLOSE_REASON, PARAMS);
+        verify(callback1, times(1)).onClosed(anyInt(), any());
+        verify(callback2, times(1)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingReport_OnReportReceived() throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+        rangingManager.onRangingStarted(handle, PARAMS);
+
+        RangingReport report = UwbTestUtils.getRangingReports(1);
+        rangingManager.onRangingResult(handle, report);
+        verify(callback, times(1)).onReportReceived(eq(report));
+    }
+
+    @Test
+    public void testOnRangingReport_MultipleSessionsRegistered() throws RemoteException {
+        SessionHandle sessionHandle1 = new SessionHandle(1);
+        SessionHandle sessionHandle2 = new SessionHandle(2);
+        RangingSession.Callback callback1 = mock(RangingSession.Callback.class);
+        RangingSession.Callback callback2 = mock(RangingSession.Callback.class);
+
+        when(ADAPTER.startRanging(any(), any()))
+                .thenReturn(sessionHandle1)
+                .thenReturn(sessionHandle2);
+
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback1);
+        rangingManager.onRangingStarted(sessionHandle1, PARAMS);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback2);
+        rangingManager.onRangingStarted(sessionHandle2, PARAMS);
+
+        rangingManager.onRangingResult(sessionHandle1, UwbTestUtils.getRangingReports(1));
+        verify(callback1, times(1)).onReportReceived(any());
+        verify(callback2, times(0)).onReportReceived(any());
+
+        rangingManager.onRangingResult(sessionHandle2, UwbTestUtils.getRangingReports(1));
+        verify(callback1, times(1)).onReportReceived(any());
+        verify(callback2, times(1)).onReportReceived(any());
+    }
+
+    @Test
+    public void testOnClose_Reasons() throws RemoteException {
+        runOnClose_Reason(CloseReason.LOCAL_API,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_CLOSE_API);
+
+        runOnClose_Reason(CloseReason.MAX_SESSIONS_REACHED,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED);
+
+        runOnClose_Reason(CloseReason.PROTOCOL_SPECIFIC,
+                RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC);
+
+        runOnClose_Reason(CloseReason.REMOTE_REQUEST,
+                RangingSession.Callback.CLOSE_REASON_REMOTE_REQUEST);
+
+        runOnClose_Reason(CloseReason.SYSTEM_POLICY,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY);
+
+        runOnClose_Reason(CloseReason.UNKNOWN,
+                RangingSession.Callback.CLOSE_REASON_UNKNOWN);
+    }
+
+    private void runOnClose_Reason(@CloseReason int reasonIn,
+            @RangingSession.Callback.CloseReason int reasonOut) throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+
+        rangingManager.onRangingClosed(handle, reasonIn, PARAMS);
+        verify(callback, times(1)).onClosed(eq(reasonOut), eq(PARAMS));
+    }
+
+    @Test
+    public void testStartFailureReasons() throws RemoteException {
+        runOnRangingStartFailed_Reason(StartFailureReason.BAD_PARAMETERS,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_BAD_PARAMETERS);
+
+        runOnRangingStartFailed_Reason(StartFailureReason.MAX_SESSIONS_REACHED,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_MAX_SESSIONS_REACHED);
+
+        runOnRangingStartFailed_Reason(StartFailureReason.PROTOCOL_SPECIFIC,
+                RangingSession.Callback.CLOSE_REASON_PROTOCOL_SPECIFIC);
+
+        runOnRangingStartFailed_Reason(StartFailureReason.SYSTEM_POLICY,
+                RangingSession.Callback.CLOSE_REASON_LOCAL_SYSTEM_POLICY);
+
+        runOnRangingStartFailed_Reason(StartFailureReason.UNKNOWN,
+                RangingSession.Callback.CLOSE_REASON_UNKNOWN);
+    }
+
+    private void runOnRangingStartFailed_Reason(@StartFailureReason int reasonIn,
+            @RangingSession.Callback.CloseReason int reasonOut) throws RemoteException {
+        RangingManager rangingManager = new RangingManager(ADAPTER);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        SessionHandle handle = new SessionHandle(1);
+        when(ADAPTER.startRanging(any(), any())).thenReturn(handle);
+        rangingManager.openSession(PARAMS, EXECUTOR, callback);
+
+        rangingManager.onRangingStartFailed(handle, reasonIn, PARAMS);
+        verify(callback, times(1)).onClosed(eq(reasonOut), eq(PARAMS));
+    }
+}
diff --git a/core/tests/uwbtests/src/android/uwb/RangingMeasurementTest.java b/core/tests/uwbtests/src/android/uwb/RangingMeasurementTest.java
index a7559d8..edd4d08 100644
--- a/core/tests/uwbtests/src/android/uwb/RangingMeasurementTest.java
+++ b/core/tests/uwbtests/src/android/uwb/RangingMeasurementTest.java
@@ -63,8 +63,8 @@
         assertEquals(status, measurement.getStatus());
         assertEquals(address, measurement.getRemoteDeviceAddress());
         assertEquals(time, measurement.getElapsedRealtimeNanos());
-        assertEquals(angleMeasurement, measurement.getAngleOfArrival());
-        assertEquals(distanceMeasurement, measurement.getDistance());
+        assertEquals(angleMeasurement, measurement.getAngleOfArrivalMeasurement());
+        assertEquals(distanceMeasurement, measurement.getDistanceMeasurement());
     }
 
     private RangingMeasurement tryBuild(RangingMeasurement.Builder builder,
diff --git a/core/tests/uwbtests/src/android/uwb/RangingSessionTest.java b/core/tests/uwbtests/src/android/uwb/RangingSessionTest.java
new file mode 100644
index 0000000..702c68e
--- /dev/null
+++ b/core/tests/uwbtests/src/android/uwb/RangingSessionTest.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.uwb;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import android.os.PersistableBundle;
+import android.os.RemoteException;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Test of {@link RangingSession}.
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class RangingSessionTest {
+    private static final IUwbAdapter ADAPTER = mock(IUwbAdapter.class);
+    private static final Executor EXECUTOR = UwbTestUtils.getExecutor();
+    private static final PersistableBundle PARAMS = new PersistableBundle();
+    private static final @RangingSession.Callback.CloseReason int CLOSE_REASON =
+            RangingSession.Callback.CLOSE_REASON_LOCAL_GENERIC_ERROR;
+
+    @Test
+    public void testOnRangingStarted_OnOpenSuccessCalled() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+        verifyOpenState(session, false);
+
+        session.onRangingStarted(PARAMS);
+        verifyOpenState(session, true);
+
+        // Verify that the onOpenSuccess callback was invoked
+        verify(callback, times(1)).onOpenSuccess(eq(session), any());
+        verify(callback, times(0)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingStarted_CannotOpenClosedSession() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+
+        session.onRangingStarted(PARAMS);
+        verifyOpenState(session, true);
+        verify(callback, times(1)).onOpenSuccess(eq(session), any());
+        verify(callback, times(0)).onClosed(anyInt(), any());
+
+        session.onRangingClosed(CLOSE_REASON, PARAMS);
+        verifyOpenState(session, false);
+        verify(callback, times(1)).onOpenSuccess(eq(session), any());
+        verify(callback, times(1)).onClosed(anyInt(), any());
+
+        // Now invoke the ranging started callback and ensure the session remains closed
+        session.onRangingStarted(PARAMS);
+        verifyOpenState(session, false);
+        verify(callback, times(1)).onOpenSuccess(eq(session), any());
+        verify(callback, times(1)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingClosed_OnClosedCalledWhenSessionNotOpen() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+        verifyOpenState(session, false);
+
+        session.onRangingClosed(CLOSE_REASON, PARAMS);
+        verifyOpenState(session, false);
+
+        // Verify that the onOpenSuccess callback was invoked
+        verify(callback, times(0)).onOpenSuccess(eq(session), any());
+        verify(callback, times(1)).onClosed(anyInt(), any());
+    }
+
+    @Test public void testOnRangingClosed_OnClosedCalled() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+        session.onRangingStarted(PARAMS);
+        session.onRangingClosed(CLOSE_REASON, PARAMS);
+        verify(callback, times(1)).onClosed(anyInt(), any());
+
+        verifyOpenState(session, false);
+        session.onRangingClosed(CLOSE_REASON, PARAMS);
+        verify(callback, times(2)).onClosed(anyInt(), any());
+    }
+
+    @Test
+    public void testOnRangingResult_OnReportReceivedCalled() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+        verifyOpenState(session, false);
+
+        session.onRangingStarted(PARAMS);
+        verifyOpenState(session, true);
+
+        RangingReport report = UwbTestUtils.getRangingReports(1);
+        session.onRangingResult(report);
+        verify(callback, times(1)).onReportReceived(eq(report));
+    }
+
+    @Test
+    public void testClose() throws RemoteException {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+        session.onRangingStarted(PARAMS);
+
+        // Calling close multiple times should invoke closeRanging until the session receives
+        // the onClosed callback.
+        int totalCallsBeforeOnRangingClosed = 3;
+        for (int i = 1; i <= totalCallsBeforeOnRangingClosed; i++) {
+            session.close();
+            verifyOpenState(session, true);
+            verify(ADAPTER, times(i)).closeRanging(handle);
+            verify(callback, times(0)).onClosed(anyInt(), any());
+        }
+
+        // After onClosed is invoked, then the adapter should no longer be called for each call to
+        // the session's close.
+        final int totalCallsAfterOnRangingClosed = 2;
+        for (int i = 1; i <= totalCallsAfterOnRangingClosed; i++) {
+            session.onRangingClosed(CLOSE_REASON, PARAMS);
+            verifyOpenState(session, false);
+            verify(ADAPTER, times(totalCallsBeforeOnRangingClosed)).closeRanging(handle);
+            verify(callback, times(i)).onClosed(anyInt(), any());
+        }
+    }
+
+    @Test
+    public void testOnRangingResult_OnReportReceivedCalledWhenOpen() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+
+        assertFalse(session.isOpen());
+        session.onRangingStarted(PARAMS);
+        assertTrue(session.isOpen());
+
+        // Verify that the onReportReceived callback was invoked
+        RangingReport report = UwbTestUtils.getRangingReports(1);
+        session.onRangingResult(report);
+        verify(callback, times(1)).onReportReceived(report);
+    }
+
+    @Test
+    public void testOnRangingResult_OnReportReceivedNotCalledWhenNotOpen() {
+        SessionHandle handle = new SessionHandle(123);
+        RangingSession.Callback callback = mock(RangingSession.Callback.class);
+        RangingSession session = new RangingSession(EXECUTOR, callback, ADAPTER, handle);
+
+        assertFalse(session.isOpen());
+
+        // Verify that the onReportReceived callback was invoked
+        RangingReport report = UwbTestUtils.getRangingReports(1);
+        session.onRangingResult(report);
+        verify(callback, times(0)).onReportReceived(report);
+    }
+
+    private void verifyOpenState(RangingSession session, boolean expected) {
+        assertEquals(expected, session.isOpen());
+    }
+}
diff --git a/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java b/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
index fb75092..b4b2e30 100644
--- a/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
+++ b/core/tests/uwbtests/src/android/uwb/UwbTestUtils.java
@@ -22,6 +22,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.Executor;
 
 public class UwbTestUtils {
     private UwbTestUtils() {}
@@ -96,4 +97,13 @@
         }
         return UwbAddress.fromBytes(addressBytes);
     }
+
+    public static Executor getExecutor() {
+        return new Executor() {
+            @Override
+            public void execute(Runnable command) {
+                command.run();
+            }
+        };
+    }
 }
diff --git a/data/etc/car/Android.bp b/data/etc/car/Android.bp
index e549271..12bd0f5 100644
--- a/data/etc/car/Android.bp
+++ b/data/etc/car/Android.bp
@@ -158,6 +158,13 @@
 }
 
 prebuilt_etc {
+    name: "privapp_allowlist_com.google.android.car.networking.preferenceupdater",
+    sub_dir: "permissions",
+    src: "com.google.android.car.networking.preferenceupdater.xml",
+    filename_from_src: true,
+}
+
+prebuilt_etc {
     name: "privapp_whitelist_com.android.car.ui.paintbooth",
     sub_dir: "permissions",
     src: "com.android.car.ui.paintbooth.xml",
diff --git a/data/etc/car/com.google.android.car.networking.preferenceupdater.xml b/data/etc/car/com.google.android.car.networking.preferenceupdater.xml
new file mode 100644
index 0000000..489ce1b
--- /dev/null
+++ b/data/etc/car/com.google.android.car.networking.preferenceupdater.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License
+  -->
+<permissions>
+    <privapp-permissions package="com.google.android.car.networking.preferenceupdater">
+        <permission name="android.permission.ACCESS_NETWORK_STATE"/>
+        <permission name="android.permission.ACCESS_WIFI_STATE"/>
+        <permission name="android.permission.ACTIVITY_EMBEDDING"/>
+        <permission name="android.permission.INTERACT_ACROSS_USERS"/>
+        <permission name="android.permission.INTERACT_ACROSS_USERS_FULL"/>
+        <permission name="android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS"/>
+        <permission name="android.permission.LOCATION_HARDWARE"/>
+    </privapp-permissions>
+</permissions>
diff --git a/data/etc/privapp-permissions-platform.xml b/data/etc/privapp-permissions-platform.xml
index 6555fe9..057c012 100644
--- a/data/etc/privapp-permissions-platform.xml
+++ b/data/etc/privapp-permissions-platform.xml
@@ -436,6 +436,8 @@
         <permission name="android.permission.MANAGE_DEBUGGING" />
         <!-- Permissions required for CTS test - TimeManagerTest -->
         <permission name="android.permission.MANAGE_TIME_AND_ZONE_DETECTION" />
+        <!-- Permissions required for CTS test - CtsHdmiCecHostTestCases -->
+        <permission name="android.permission.HDMI_CEC"/>
     </privapp-permissions>
 
     <privapp-permissions package="com.android.statementservice">
diff --git a/graphics/java/android/graphics/OWNERS b/graphics/java/android/graphics/OWNERS
index a8a3631..9fa8f1b 100644
--- a/graphics/java/android/graphics/OWNERS
+++ b/graphics/java/android/graphics/OWNERS
@@ -4,6 +4,8 @@
 jreck@google.com
 njawad@google.com
 sumir@google.com
+djsollen@google.com
+scroggo@google.com
 
 per-file BLASTBufferQueue.java = file:/services/core/java/com/android/server/wm/OWNERS
 per-file FontFamily.java = file:fonts/OWNERS
diff --git a/packages/Shell/AndroidManifest.xml b/packages/Shell/AndroidManifest.xml
index 5d6c4c3..0fdb282 100644
--- a/packages/Shell/AndroidManifest.xml
+++ b/packages/Shell/AndroidManifest.xml
@@ -334,6 +334,9 @@
     <!-- Permission needed for CTS test - TimeManagerTest -->
     <uses-permission android:name="android.permission.MANAGE_TIME_AND_ZONE_DETECTION" />
 
+    <!-- Permission needed for CTS test - CtsHdmiCecHostTestCases -->
+    <uses-permission android:name="android.permission.HDMI_CEC" />
+
     <application android:label="@string/app_label"
                 android:theme="@android:style/Theme.DeviceDefault.DayNight"
                 android:defaultToDeviceProtectedStorage="true"
diff --git a/services/core/Android.bp b/services/core/Android.bp
index 4b9d0f1..77cb125 100644
--- a/services/core/Android.bp
+++ b/services/core/Android.bp
@@ -196,7 +196,6 @@
         "java/com/android/server/connectivity/KeepaliveTracker.java",
         "java/com/android/server/connectivity/LingerMonitor.java",
         "java/com/android/server/connectivity/MockableSystemProperties.java",
-        "java/com/android/server/connectivity/MultipathPolicyTracker.java",
         "java/com/android/server/connectivity/Nat464Xlat.java",
         "java/com/android/server/connectivity/NetdEventListenerService.java",
         "java/com/android/server/connectivity/NetworkAgentInfo.java",
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 2c765bd..184f1bf 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -876,6 +876,10 @@
      */
     @VisibleForTesting
     public static class Dependencies {
+        public int getCallingUid() {
+            return Binder.getCallingUid();
+        }
+
         /**
          * Get system properties to use in ConnectivityService.
          */
@@ -1408,7 +1412,7 @@
     @Override
     public NetworkInfo getActiveNetworkInfo() {
         enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         final NetworkState state = getUnfilteredActiveNetworkState(uid);
         filterNetworkStateForUid(state, uid, false);
         maybeLogBlockedNetworkInfo(state.networkInfo, uid);
@@ -1418,7 +1422,7 @@
     @Override
     public Network getActiveNetwork() {
         enforceAccessPermission();
-        return getActiveNetworkForUidInternal(Binder.getCallingUid(), false);
+        return getActiveNetworkForUidInternal(mDeps.getCallingUid(), false);
     }
 
     @Override
@@ -1458,7 +1462,7 @@
     // Public because it's used by mLockdownTracker.
     public NetworkInfo getActiveNetworkInfoUnfiltered() {
         enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         NetworkState state = getUnfilteredActiveNetworkState(uid);
         return state.networkInfo;
     }
@@ -1474,7 +1478,7 @@
     @Override
     public NetworkInfo getNetworkInfo(int networkType) {
         enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         if (getVpnUnderlyingNetworks(uid) != null) {
             // A VPN is active, so we may need to return one of its underlying networks. This
             // information is not available in LegacyTypeTracker, so we have to get it from
@@ -1519,7 +1523,7 @@
     @Override
     public Network getNetworkForType(int networkType) {
         enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         NetworkState state = getFilteredNetworkState(networkType, uid);
         if (!isNetworkWithLinkPropertiesBlocked(state.linkProperties, uid, false)) {
             return state.network;
@@ -1566,7 +1570,7 @@
             result.put(
                     nai.network,
                     maybeSanitizeLocationInfoForCaller(
-                            nc, Binder.getCallingUid(), callingPackageName));
+                            nc, mDeps.getCallingUid(), callingPackageName));
         }
 
         synchronized (mVpns) {
@@ -1581,7 +1585,7 @@
                                 result.put(
                                         network,
                                         maybeSanitizeLocationInfoForCaller(
-                                                nc, Binder.getCallingUid(), callingPackageName));
+                                                nc, mDeps.getCallingUid(), callingPackageName));
                             }
                         }
                     }
@@ -1611,7 +1615,7 @@
     @Override
     public LinkProperties getActiveLinkProperties() {
         enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         NetworkState state = getUnfilteredActiveNetworkState(uid);
         if (state.linkProperties == null) return null;
         return linkPropertiesRestrictedForCallerPermissions(state.linkProperties,
@@ -1625,7 +1629,7 @@
         final LinkProperties lp = getLinkProperties(nai);
         if (lp == null) return null;
         return linkPropertiesRestrictedForCallerPermissions(
-                lp, Binder.getCallingPid(), Binder.getCallingUid());
+                lp, Binder.getCallingPid(), mDeps.getCallingUid());
     }
 
     // TODO - this should be ALL networks
@@ -1635,7 +1639,7 @@
         final LinkProperties lp = getLinkProperties(getNetworkAgentInfoForNetwork(network));
         if (lp == null) return null;
         return linkPropertiesRestrictedForCallerPermissions(
-                lp, Binder.getCallingPid(), Binder.getCallingUid());
+                lp, Binder.getCallingPid(), mDeps.getCallingUid());
     }
 
     @Nullable
@@ -1657,17 +1661,17 @@
         synchronized (nai) {
             if (nai.networkCapabilities == null) return null;
             return networkCapabilitiesRestrictedForCallerPermissions(
-                    nai.networkCapabilities, Binder.getCallingPid(), Binder.getCallingUid());
+                    nai.networkCapabilities, Binder.getCallingPid(), mDeps.getCallingUid());
         }
     }
 
     @Override
     public NetworkCapabilities getNetworkCapabilities(Network network, String callingPackageName) {
-        mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackageName);
+        mAppOpsManager.checkPackage(mDeps.getCallingUid(), callingPackageName);
         enforceAccessPermission();
         return maybeSanitizeLocationInfoForCaller(
                 getNetworkCapabilitiesInternal(network),
-                Binder.getCallingUid(), callingPackageName);
+                mDeps.getCallingUid(), callingPackageName);
     }
 
     @VisibleForTesting
@@ -1755,7 +1759,7 @@
     }
 
     private void restrictBackgroundRequestForCaller(NetworkCapabilities nc) {
-        if (!mPermissionMonitor.hasUseBackgroundNetworksPermission(Binder.getCallingUid())) {
+        if (!mPermissionMonitor.hasUseBackgroundNetworksPermission(mDeps.getCallingUid())) {
             nc.addCapability(NET_CAPABILITY_FOREGROUND);
         }
     }
@@ -1808,7 +1812,7 @@
         // requestRouteToHost. In Q, GnssLocationProvider is changed to not call requestRouteToHost
         // for devices launched with Q and above. However, existing devices upgrading to Q and
         // above must continued to be supported for few more releases.
-        if (isSystem(Binder.getCallingUid()) && SystemProperties.getInt(
+        if (isSystem(mDeps.getCallingUid()) && SystemProperties.getInt(
                 "ro.product.first_api_level", 0) > Build.VERSION_CODES.P) {
             log("This method exists only for app backwards compatibility"
                     + " and must not be called by system services.");
@@ -1874,7 +1878,7 @@
             return false;
         }
 
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         final long token = Binder.clearCallingIdentity();
         try {
             LinkProperties lp;
@@ -2294,7 +2298,7 @@
      */
     @Override
     public void systemReady() {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+        if (mDeps.getCallingUid() != Process.SYSTEM_UID) {
             throw new SecurityException("Calling Uid is not system uid.");
         }
         systemReadyInternal();
@@ -2520,7 +2524,7 @@
         if (context.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
                 != PackageManager.PERMISSION_GRANTED) {
             pw.println("Permission Denial: can't dump " + tag + " from from pid="
-                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                    + Binder.getCallingPid() + ", uid=" + mDeps.getCallingUid()
                     + " due to missing android.permission.DUMP permission");
             return false;
         } else {
@@ -3900,7 +3904,7 @@
 
             if (request == CaptivePortal.APP_REQUEST_REEVALUATION_REQUIRED) {
                 checkNetworkStackPermission();
-                nm.forceReevaluation(Binder.getCallingUid());
+                nm.forceReevaluation(mDeps.getCallingUid());
             }
         }
 
@@ -4367,7 +4371,7 @@
     public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
         enforceAccessPermission();
         enforceInternetPermission();
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         final int connectivityInfo = encodeBool(hasConnectivity);
 
         // Handle ConnectivityDiagnostics event before attempting to revalidate the network. This
@@ -4437,13 +4441,13 @@
         if (globalProxy != null) return globalProxy;
         if (network == null) {
             // Get the network associated with the calling UID.
-            final Network activeNetwork = getActiveNetworkForUidInternal(Binder.getCallingUid(),
+            final Network activeNetwork = getActiveNetworkForUidInternal(mDeps.getCallingUid(),
                     true);
             if (activeNetwork == null) {
                 return null;
             }
             return getLinkPropertiesProxyInfo(activeNetwork);
-        } else if (mDeps.queryUserAccess(Binder.getCallingUid(), network.getNetId())) {
+        } else if (mDeps.queryUserAccess(mDeps.getCallingUid(), network.getNetId())) {
             // Don't call getLinkProperties() as it requires ACCESS_NETWORK_STATE permission, which
             // caller may not have.
             return getLinkPropertiesProxyInfo(network);
@@ -4612,7 +4616,7 @@
      */
     @Override
     public ParcelFileDescriptor establishVpn(VpnConfig config) {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
+        int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             throwIfLockdownEnabled();
             return mVpns.get(user).establish(config);
@@ -4633,7 +4637,7 @@
      */
     @Override
     public boolean provisionVpnProfile(@NonNull VpnProfile profile, @NonNull String packageName) {
-        final int user = UserHandle.getUserId(Binder.getCallingUid());
+        final int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             return mVpns.get(user).provisionVpnProfile(packageName, profile, mKeyStore);
         }
@@ -4651,7 +4655,7 @@
      */
     @Override
     public void deleteVpnProfile(@NonNull String packageName) {
-        final int user = UserHandle.getUserId(Binder.getCallingUid());
+        final int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             mVpns.get(user).deleteVpnProfile(packageName, mKeyStore);
         }
@@ -4668,7 +4672,7 @@
      */
     @Override
     public void startVpnProfile(@NonNull String packageName) {
-        final int user = UserHandle.getUserId(Binder.getCallingUid());
+        final int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             throwIfLockdownEnabled();
             mVpns.get(user).startVpnProfile(packageName, mKeyStore);
@@ -4685,7 +4689,7 @@
      */
     @Override
     public void stopVpnProfile(@NonNull String packageName) {
-        final int user = UserHandle.getUserId(Binder.getCallingUid());
+        final int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             mVpns.get(user).stopVpnProfile(packageName);
         }
@@ -4697,7 +4701,7 @@
      */
     @Override
     public void startLegacyVpn(VpnProfile profile) {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
+        int user = UserHandle.getUserId(mDeps.getCallingUid());
         final LinkProperties egress = getActiveLinkProperties();
         if (egress == null) {
             throw new IllegalStateException("Missing active network connection");
@@ -4846,7 +4850,7 @@
 
     @Override
     public boolean updateLockdownVpn() {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+        if (mDeps.getCallingUid() != Process.SYSTEM_UID) {
             logw("Lockdown VPN only available to AID_SYSTEM");
             return false;
         }
@@ -4868,7 +4872,7 @@
                     setLockdownTracker(null);
                     return true;
                 }
-                int user = UserHandle.getUserId(Binder.getCallingUid());
+                int user = UserHandle.getUserId(mDeps.getCallingUid());
                 Vpn vpn = mVpns.get(user);
                 if (vpn == null) {
                     logw("VPN for user " + user + " not ready yet. Skipping lockdown");
@@ -5433,7 +5437,7 @@
             messenger = null;
             mBinder = null;
             mPid = getCallingPid();
-            mUid = getCallingUid();
+            mUid = mDeps.getCallingUid();
             enforceRequestCountLimit();
         }
 
@@ -5445,7 +5449,7 @@
             ensureAllNetworkRequestsHaveType(mRequests);
             mBinder = binder;
             mPid = getCallingPid();
-            mUid = getCallingUid();
+            mUid = mDeps.getCallingUid();
             mPendingIntent = null;
             enforceRequestCountLimit();
 
@@ -5588,7 +5592,7 @@
     }
 
     private boolean checkUnsupportedStartingFrom(int version, String callingPackageName) {
-        final UserHandle user = UserHandle.getUserHandleForUid(Binder.getCallingUid());
+        final UserHandle user = UserHandle.getUserHandleForUid(mDeps.getCallingUid());
         final PackageManager pm =
                 mContext.createContextAsUser(user, 0 /* flags */).getPackageManager();
         try {
@@ -5608,7 +5612,7 @@
                 throw new SecurityException("Insufficient permissions to specify legacy type");
             }
         }
-        final int callingUid = Binder.getCallingUid();
+        final int callingUid = mDeps.getCallingUid();
         final NetworkRequest.Type type = (networkCapabilities == null)
                 ? NetworkRequest.Type.TRACK_DEFAULT
                 : NetworkRequest.Type.REQUEST;
@@ -5678,7 +5682,7 @@
         if (nai != null) {
             nai.asyncChannel.sendMessage(android.net.NetworkAgent.CMD_REQUEST_BANDWIDTH_UPDATE);
             synchronized (mBandwidthRequests) {
-                final int uid = Binder.getCallingUid();
+                final int uid = mDeps.getCallingUid();
                 Integer uidReqs = mBandwidthRequests.get(uid);
                 if (uidReqs == null) {
                     uidReqs = 0;
@@ -5695,7 +5699,7 @@
     }
 
     private void enforceMeteredApnPolicy(NetworkCapabilities networkCapabilities) {
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         if (isSystem(uid)) {
             // Exemption for system uid.
             return;
@@ -5715,7 +5719,7 @@
             PendingIntent operation, @NonNull String callingPackageName,
             @Nullable String callingAttributionTag) {
         Objects.requireNonNull(operation, "PendingIntent cannot be null.");
-        final int callingUid = Binder.getCallingUid();
+        final int callingUid = mDeps.getCallingUid();
         networkCapabilities = new NetworkCapabilities(networkCapabilities);
         enforceNetworkRequestPermissions(networkCapabilities, callingPackageName,
                 callingAttributionTag);
@@ -5774,7 +5778,7 @@
     @Override
     public NetworkRequest listenForNetwork(NetworkCapabilities networkCapabilities,
             Messenger messenger, IBinder binder, @NonNull String callingPackageName) {
-        final int callingUid = Binder.getCallingUid();
+        final int callingUid = mDeps.getCallingUid();
         if (!hasWifiNetworkListenPermission(networkCapabilities)) {
             enforceAccessPermission();
         }
@@ -5804,7 +5808,7 @@
     public void pendingListenForNetwork(NetworkCapabilities networkCapabilities,
             PendingIntent operation, @NonNull String callingPackageName) {
         Objects.requireNonNull(operation, "PendingIntent cannot be null.");
-        final int callingUid = Binder.getCallingUid();
+        final int callingUid = mDeps.getCallingUid();
         if (!hasWifiNetworkListenPermission(networkCapabilities)) {
             enforceAccessPermission();
         }
@@ -5905,7 +5909,7 @@
         } else {
             enforceNetworkFactoryPermission();
         }
-        mHandler.post(() -> handleReleaseNetworkRequest(request, Binder.getCallingUid(), true));
+        mHandler.post(() -> handleReleaseNetworkRequest(request, mDeps.getCallingUid(), true));
     }
 
     // NOTE: Accessed on multiple threads, must be synchronized on itself.
@@ -5999,7 +6003,7 @@
             enforceNetworkFactoryPermission();
         }
 
-        final int uid = Binder.getCallingUid();
+        final int uid = mDeps.getCallingUid();
         final long token = Binder.clearCallingIdentity();
         try {
             return registerNetworkAgentInternal(messenger, networkInfo, linkProperties,
@@ -7653,7 +7657,7 @@
 
     @Override
     public boolean addVpnAddress(String address, int prefixLength) {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
+        int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             throwIfLockdownEnabled();
             return mVpns.get(user).addAddress(address, prefixLength);
@@ -7662,7 +7666,7 @@
 
     @Override
     public boolean removeVpnAddress(String address, int prefixLength) {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
+        int user = UserHandle.getUserId(mDeps.getCallingUid());
         synchronized (mVpns) {
             throwIfLockdownEnabled();
             return mVpns.get(user).removeAddress(address, prefixLength);
@@ -7671,7 +7675,7 @@
 
     @Override
     public boolean setUnderlyingNetworksForVpn(Network[] networks) {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
+        int user = UserHandle.getUserId(mDeps.getCallingUid());
         final boolean success;
         synchronized (mVpns) {
             throwIfLockdownEnabled();
@@ -7898,7 +7902,7 @@
 
     @GuardedBy("mVpns")
     private Vpn getVpnIfOwner() {
-        return getVpnIfOwner(Binder.getCallingUid());
+        return getVpnIfOwner(mDeps.getCallingUid());
     }
 
     @GuardedBy("mVpns")
@@ -8376,7 +8380,7 @@
             throw new IllegalArgumentException("ConnectivityManager.TYPE_* are deprecated."
                     + " Please use NetworkCapabilities instead.");
         }
-        final int callingUid = Binder.getCallingUid();
+        final int callingUid = mDeps.getCallingUid();
         mAppOpsManager.checkPackage(callingUid, callingPackageName);
 
         // This NetworkCapabilities is only used for matching to Networks. Clear out its owner uid
@@ -8411,7 +8415,7 @@
                 mConnectivityDiagnosticsHandler.obtainMessage(
                         ConnectivityDiagnosticsHandler
                                 .EVENT_UNREGISTER_CONNECTIVITY_DIAGNOSTICS_CALLBACK,
-                        Binder.getCallingUid(),
+                        mDeps.getCallingUid(),
                         0,
                         callback));
     }
@@ -8427,7 +8431,7 @@
         }
 
         final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
-        if (nai == null || nai.creatorUid != Binder.getCallingUid()) {
+        if (nai == null || nai.creatorUid != mDeps.getCallingUid()) {
             throw new SecurityException("Data Stall simulation is only possible for network "
                 + "creators");
         }
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index cabfbc0..228ad588 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -246,7 +246,12 @@
         void checkInterruptAndDelay(boolean sleepLonger) throws InterruptedException;
     }
 
-    static class Dependencies {
+    @VisibleForTesting
+    public static class Dependencies {
+        public boolean isCallerSystem() {
+            return Binder.getCallingUid() == Process.SYSTEM_UID;
+        }
+
         public void startService(final String serviceName) {
             SystemService.start(serviceName);
         }
@@ -267,6 +272,10 @@
             return new File("/data/misc/vpn/state");
         }
 
+        public DeviceIdleInternal getDeviceIdleInternal() {
+            return LocalServices.getService(DeviceIdleInternal.class);
+        }
+
         public void sendArgumentsToDaemon(
                 final String daemon, final LocalSocket socket, final String[] arguments,
                 final RetryScheduler retryScheduler) throws IOException, InterruptedException {
@@ -373,6 +382,14 @@
     }
 
     @VisibleForTesting
+    public Vpn(Looper looper, Context context, Dependencies deps,
+            INetworkManagementService netService, INetd netd, @UserIdInt int userId,
+            @NonNull KeyStore keyStore) {
+        this(looper, context, deps, netService, netd, userId, keyStore,
+                new SystemServices(context), new Ikev2SessionCreator());
+    }
+
+    @VisibleForTesting
     protected Vpn(Looper looper, Context context, Dependencies deps,
             INetworkManagementService netService, INetd netd,
             int userId, @NonNull KeyStore keyStore, SystemServices systemServices,
@@ -772,8 +789,7 @@
 
             // Tell the OS that background services in this app need to be allowed for
             // a short time, so we can bootstrap the VPN service.
-            DeviceIdleInternal idleController =
-                    LocalServices.getService(DeviceIdleInternal.class);
+            DeviceIdleInternal idleController = mDeps.getDeviceIdleInternal();
             idleController.addPowerSaveTempWhitelistApp(Process.myUid(), alwaysOnPackage,
                     VPN_LAUNCH_IDLE_ALLOWLIST_DURATION_MS, mUserId, false, "vpn");
 
@@ -1959,10 +1975,6 @@
             return mContext.createContextAsUser(
                     UserHandle.of(userId), 0 /* flags */).getContentResolver();
         }
-
-        public boolean isCallerSystem() {
-            return Binder.getCallingUid() == Process.SYSTEM_UID;
-        }
     }
 
     private native int jniCreate(int mtu);
@@ -3112,7 +3124,7 @@
     @VisibleForTesting
     @Nullable
     VpnProfile getVpnProfilePrivileged(@NonNull String packageName, @NonNull KeyStore keyStore) {
-        if (!mSystemServices.isCallerSystem()) {
+        if (!mDeps.isCallerSystem()) {
             Log.wtf(TAG, "getVpnProfilePrivileged called as non-System UID ");
             return null;
         }
diff --git a/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java b/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java
index ea24532..c24973d 100644
--- a/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java
+++ b/services/core/java/com/android/server/hdmi/HdmiCecMessageValidator.java
@@ -156,7 +156,6 @@
         addValidationInfo(Constants.MESSAGE_GIVE_DECK_STATUS, statusRequestValidator, DEST_DIRECT);
         addValidationInfo(Constants.MESSAGE_PLAY, new PlayModeValidator(), DEST_DIRECT);
 
-        // TODO: Handle messages for the Tuner Control.
         addValidationInfo(
                 Constants.MESSAGE_GIVE_TUNER_DEVICE_STATUS, statusRequestValidator, DEST_DIRECT);
         addValidationInfo(
@@ -167,6 +166,10 @@
                 Constants.MESSAGE_SELECT_DIGITAL_SERVICE,
                 new SelectDigitalServiceValidator(),
                 DEST_DIRECT);
+        addValidationInfo(
+                Constants.MESSAGE_TUNER_DEVICE_STATUS,
+                new TunerDeviceStatusValidator(),
+                DEST_DIRECT);
 
         // Messages for the Vendor Specific Commands.
         VariableLengthValidator maxLengthValidator = new VariableLengthValidator(0, 14);
@@ -306,7 +309,14 @@
     }
 
     private boolean isValidPhysicalAddress(byte[] params, int offset) {
-        // TODO: Add more logic like validating 1.0.1.0.
+        int physicalAddress = HdmiUtils.twoBytesToInt(params, offset);
+        while (physicalAddress != 0) {
+            int maskedAddress = physicalAddress & 0xF000;
+            physicalAddress = (physicalAddress << 4) & 0xFFFF;
+            if (maskedAddress == 0 && physicalAddress != 0) {
+                return false;
+            }
+        }
 
         if (!mService.isTvDevice()) {
             // If the device is not TV, we can't convert path to port-id, so stop here.
@@ -722,6 +732,35 @@
                 || (isWithinRange(value, 0xC1, 0xC3)));
     }
 
+    /*
+     * Check if the given value is a valid Tuner Device info. A valid value is one which falls
+     * within the range description defined in CEC 1.4 Specification : Operand Descriptions
+     * (Section 17)
+     *
+     * @param params Tuner device info
+     * @return true if the Tuner device info is valid
+     */
+    private boolean isValidTunerDeviceInfo(byte[] params) {
+        int tunerDisplayInfo = params[0] & 0x7F;
+        if (tunerDisplayInfo == 0x00) {
+            // Displaying digital tuner
+            if (params.length >= 5) {
+                return isValidDigitalServiceIdentification(params, 1);
+            }
+        } else if (tunerDisplayInfo == 0x01) {
+            // Not displaying Tuner
+            return true;
+        } else if (tunerDisplayInfo == 0x02) {
+            // Displaying Analogue tuner
+            if (params.length >= 5) {
+                return (isValidAnalogueBroadcastType(params[1])
+                        && isValidAnalogueFrequency(HdmiUtils.twoBytesToInt(params, 2))
+                        && isValidBroadcastSystem(params[4]));
+            }
+        }
+        return false;
+    }
+
     private class PhysicalAddressValidator implements ParameterValidator {
         @Override
         public int isValid(byte[] params) {
@@ -1000,6 +1039,21 @@
         }
     }
 
+    /**
+     * Check if the given tuner device status parameter is valid. A valid parameter should lie
+     * within the range description defined in CEC 1.4 Specification : Operand Descriptions (Section
+     * 17)
+     */
+    private class TunerDeviceStatusValidator implements ParameterValidator {
+        @Override
+        public int isValid(byte[] params) {
+            if (params.length < 1) {
+                return ERROR_PARAMETER_SHORT;
+            }
+            return toErrorCode(isValidTunerDeviceInfo(params));
+        }
+    }
+
     /** Check if the given user control press parameter is valid. */
     private class UserControlPressedValidator implements ParameterValidator {
         @Override
diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java
index e2145f0..8e50bb4 100644
--- a/services/core/java/com/android/server/hdmi/HdmiControlService.java
+++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java
@@ -66,6 +66,8 @@
 import android.os.PowerManager;
 import android.os.RemoteCallbackList;
 import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.os.ShellCallback;
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.UserHandle;
@@ -2291,6 +2293,16 @@
         }
 
         @Override
+        public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
+                @Nullable FileDescriptor err, String[] args,
+                @Nullable ShellCallback callback, ResultReceiver resultReceiver)
+                throws RemoteException {
+            enforceAccessPermission();
+            new HdmiControlShellCommand(this)
+                    .exec(this, in, out, err, args, callback, resultReceiver);
+        }
+
+        @Override
         protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) {
             if (!DumpUtils.checkDumpPermission(getContext(), TAG, writer)) return;
             final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
diff --git a/services/core/java/com/android/server/hdmi/HdmiControlShellCommand.java b/services/core/java/com/android/server/hdmi/HdmiControlShellCommand.java
new file mode 100644
index 0000000..ee3427f
--- /dev/null
+++ b/services/core/java/com/android/server/hdmi/HdmiControlShellCommand.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.hdmi;
+
+
+import android.hardware.hdmi.HdmiControlManager;
+import android.hardware.hdmi.IHdmiControlCallback;
+import android.hardware.hdmi.IHdmiControlService;
+import android.os.RemoteException;
+import android.os.ShellCommand;
+import android.util.Slog;
+
+import java.io.PrintWriter;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+final class HdmiControlShellCommand extends ShellCommand {
+
+    private static final String TAG = "HdmiShellCommand";
+
+    private final IHdmiControlService.Stub mBinderService;
+
+
+    HdmiControlShellCommand(IHdmiControlService.Stub binderService) {
+        mBinderService = binderService;
+    }
+
+    @Override
+    public int onCommand(String cmd) {
+        if (cmd == null) {
+            return handleDefaultCommands(cmd);
+        }
+
+        try {
+            return handleShellCommand(cmd);
+        } catch (Exception e) {
+            getErrPrintWriter().println(
+                    "Caught error for command '" + cmd + "': " + e.getMessage());
+            Slog.e(TAG, "Error handling hdmi_control shell command: " + cmd, e);
+            return 1;
+        }
+    }
+
+    @Override
+    public void onHelp() {
+        PrintWriter pw = getOutPrintWriter();
+
+        pw.println("HdmiControlManager (hdmi_control) commands:");
+        pw.println("  help");
+        pw.println("      Print this help text.");
+        pw.println("  onetouchplay, otp");
+        pw.println("      Send the \"One Touch Play\" feature from a source to the TV");
+        pw.println("  vendorcommand --device_type <originating device type>");
+        pw.println("                --destination <destination device>");
+        pw.println("                --args <vendor specific arguments>");
+        pw.println("                [--id <true if vendor command should be sent with vendor id>]");
+        pw.println("      Send a Vendor Command to the given target device");
+    }
+
+    private int handleShellCommand(String cmd) throws RemoteException {
+        PrintWriter pw = getOutPrintWriter();
+
+        switch (cmd) {
+            case "otp":
+            case "onetouchplay":
+                return oneTouchPlay(pw);
+            case "vendorcommand":
+                return vendorCommand(pw);
+        }
+
+        getErrPrintWriter().println("Unhandled command: " + cmd);
+        return 1;
+    }
+
+    private int oneTouchPlay(PrintWriter pw) throws RemoteException {
+        final CountDownLatch latch = new CountDownLatch(1);
+        AtomicInteger cecResult = new AtomicInteger();
+        pw.print("Sending One Touch Play...");
+        mBinderService.oneTouchPlay(new IHdmiControlCallback.Stub() {
+            @Override
+            public void onComplete(int result) {
+                pw.println(" done (" + result + ")");
+                latch.countDown();
+                cecResult.set(result);
+            }
+        });
+
+        try {
+            if (!latch.await(HdmiConfig.TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
+                getErrPrintWriter().println("One Touch Play timed out.");
+                return 1;
+            }
+        } catch (InterruptedException e) {
+            getErrPrintWriter().println("Caught InterruptedException");
+            Thread.currentThread().interrupt();
+        }
+        return cecResult.get() == HdmiControlManager.RESULT_SUCCESS ? 0 : 1;
+    }
+
+    private int vendorCommand(PrintWriter pw) throws RemoteException {
+        if (6 > getRemainingArgsCount()) {
+            throw new IllegalArgumentException("Expected 3 arguments.");
+        }
+
+        int deviceType = -1;
+        int destination = -1;
+        String parameters = "";
+        boolean hasVendorId = false;
+
+        String arg = getNextOption();
+        while (arg != null) {
+            switch (arg) {
+                case "-t":
+                case "--device_type":
+                    deviceType = Integer.parseInt(getNextArgRequired());
+                    break;
+                case "-d":
+                case "--destination":
+                    destination = Integer.parseInt(getNextArgRequired());
+                    break;
+                case "-a":
+                case "--args":
+                    parameters = getNextArgRequired();
+                    break;
+                case "-i":
+                case "--id":
+                    hasVendorId = Boolean.parseBoolean(getNextArgRequired());
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unknown argument: " + arg);
+            }
+            arg = getNextArg();
+        }
+
+        String[] parts = parameters.split(":");
+        byte[] params = new byte[parts.length];
+        for (int i = 0; i < params.length; i++) {
+            params[i] = (byte) Integer.parseInt(parts[i], 16);
+        }
+
+        pw.println("Sending <Vendor Command>");
+        mBinderService.sendVendorCommand(deviceType, destination, params, hasVendorId);
+        return 0;
+    }
+}
diff --git a/services/tests/mockingservicestests/src/com/android/server/devicepolicy/OWNERS b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/OWNERS
new file mode 100644
index 0000000..e95633a
--- /dev/null
+++ b/services/tests/mockingservicestests/src/com/android/server/devicepolicy/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/app/admin/OWNERS
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecMessageValidatorTest.java b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecMessageValidatorTest.java
index 24a01003..ae7f422 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecMessageValidatorTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/HdmiCecMessageValidatorTest.java
@@ -121,6 +121,16 @@
     }
 
     @Test
+    public void isValid_systemAudioModeRequest() {
+        assertMessageValidity("40:70:00:00").isEqualTo(OK);
+        assertMessageValidity("40:70").isEqualTo(OK);
+
+        assertMessageValidity("F0:70").isEqualTo(ERROR_SOURCE);
+        // Invalid physical address
+        assertMessageValidity("40:70:10:10").isEqualTo(ERROR_PARAMETER);
+    }
+
+    @Test
     public void isValid_setSystemAudioMode() {
         assertMessageValidity("40:72:00").isEqualTo(OK);
         assertMessageValidity("4F:72:01:03").isEqualTo(OK);
@@ -340,6 +350,8 @@
         assertMessageValidity("40:A2:14:09:12:28:4B:19:10:08:10:00").isEqualTo(ERROR_PARAMETER);
         // Invalid External PLug
         assertMessageValidity("04:A1:0C:08:15:05:04:1E:02:04:00").isEqualTo(ERROR_PARAMETER);
+        // Invalid Physical Address
+        assertMessageValidity("40:A2:14:09:12:28:4B:19:10:05:10:10").isEqualTo(ERROR_PARAMETER);
     }
 
     @Test
@@ -476,6 +488,51 @@
     }
 
     @Test
+    public void isValid_tunerDeviceStatus() {
+        // Displaying digital tuner
+        assertMessageValidity("40:07:00:00:11:CE:90:0F:00:78").isEqualTo(OK);
+        assertMessageValidity("40:07:80:10:13:0B:34:38").isEqualTo(OK);
+        assertMessageValidity("40:07:00:9A:06:F9:D3:E6").isEqualTo(OK);
+        assertMessageValidity("40:07:00:91:09:F4:40:C8").isEqualTo(OK);
+        // Not displaying tuner
+        assertMessageValidity("40:07:01").isEqualTo(OK);
+        assertMessageValidity("40:07:81:07:64:B9:02").isEqualTo(OK);
+        // Displaying analogue tuner
+        assertMessageValidity("40:07:02:00:13:0F:00:96").isEqualTo(OK);
+        assertMessageValidity("40:07:82:02:EA:60:1F").isEqualTo(OK);
+
+        assertMessageValidity("4F:07:00:00:11:CE:90:0F:00:78").isEqualTo(ERROR_DESTINATION);
+        assertMessageValidity("F0:07:82:02:EA:60:1F").isEqualTo(ERROR_SOURCE);
+        assertMessageValidity("40:07").isEqualTo(ERROR_PARAMETER_SHORT);
+
+        // Invalid display info
+        assertMessageValidity("40:07:09:A1:8C:17:51").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("40:07:A7:0C:29").isEqualTo(ERROR_PARAMETER);
+        // Invalid Digital Broadcast System
+        assertMessageValidity("40:07:00:14:11:CE:90:0F:00:78").isEqualTo(ERROR_PARAMETER);
+        // Invalid Digital Broadcast System
+        assertMessageValidity("40:07:80:A0:07:95:F1").isEqualTo(ERROR_PARAMETER);
+        // Insufficient data for ARIB Broadcast system
+        assertMessageValidity("40:07:00:00:11:CE:90:0F:00").isEqualTo(ERROR_PARAMETER);
+        // Insufficient data for ATSC Broadcast system
+        assertMessageValidity("40:07:80:10:13:0B:34").isEqualTo(ERROR_PARAMETER);
+        // Insufficient data for DVB Broadcast system
+        assertMessageValidity("40:07:00:18:BE:77:00:7D:01").isEqualTo(ERROR_PARAMETER);
+        // Invalid channel number format
+        assertMessageValidity("40:07:80:9A:10:F9:D3").isEqualTo(ERROR_PARAMETER);
+        // Insufficient data for 1 part channel number
+        assertMessageValidity("40:07:00:90:04:F7").isEqualTo(ERROR_PARAMETER);
+        // Insufficient data for 2 part channel number
+        assertMessageValidity("40:07:80:91:09:F4:40").isEqualTo(ERROR_PARAMETER);
+        // Invalid Analogue Broadcast type
+        assertMessageValidity("40:07:02:03:EA:60:1F").isEqualTo(ERROR_PARAMETER);
+        // Invalid Analogue Frequency
+        assertMessageValidity("40:07:82:00:FF:FF:00").isEqualTo(ERROR_PARAMETER);
+        // Invalid Broadcast system
+        assertMessageValidity("40:07:02:02:EA:60:20").isEqualTo(ERROR_PARAMETER);
+    }
+
+    @Test
     public void isValid_UserControlPressed() {
         assertMessageValidity("40:44:07").isEqualTo(OK);
         assertMessageValidity("40:44:52:A7").isEqualTo(OK);
@@ -518,6 +575,59 @@
         assertMessageValidity("40:44:57:40").isEqualTo(ERROR_PARAMETER);
     }
 
+    @Test
+    public void isValid_physicalAddress() {
+        assertMessageValidity("4F:82:10:00").isEqualTo(OK);
+        assertMessageValidity("4F:82:12:34").isEqualTo(OK);
+        assertMessageValidity("0F:82:00:00").isEqualTo(OK);
+        assertMessageValidity("40:9D:14:00").isEqualTo(OK);
+        assertMessageValidity("40:9D:10:00").isEqualTo(OK);
+        assertMessageValidity("0F:81:44:20").isEqualTo(OK);
+        assertMessageValidity("4F:81:13:10").isEqualTo(OK);
+        assertMessageValidity("4F:86:14:14").isEqualTo(OK);
+        assertMessageValidity("0F:86:15:24").isEqualTo(OK);
+
+        assertMessageValidity("4F:82:10").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("40:9D:14").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("0F:81:44").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("0F:86:15").isEqualTo(ERROR_PARAMETER_SHORT);
+
+        assertMessageValidity("4F:82:10:10").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("4F:82:10:06").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("40:9D:14:04").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("40:9D:10:01").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("0F:81:44:02").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("4F:81:13:05").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("4F:86:10:14").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("0F:86:10:24").isEqualTo(ERROR_PARAMETER);
+    }
+
+    @Test
+    public void isValid_reportPhysicalAddress() {
+        assertMessageValidity("4F:84:10:00:04").isEqualTo(OK);
+        assertMessageValidity("0F:84:00:00:00").isEqualTo(OK);
+
+        assertMessageValidity("4F:84:10:00").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("0F:84:00").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("40:84:10:00:04").isEqualTo(ERROR_DESTINATION);
+        // Invalid Physical Address
+        assertMessageValidity("4F:84:10:10:04").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("0F:84:00:30:00").isEqualTo(ERROR_PARAMETER);
+        // Invalid Device Type
+        assertMessageValidity("4F:84:12:34:08").isEqualTo(ERROR_PARAMETER);
+    }
+
+    @Test
+    public void isValid_routingChange() {
+        assertMessageValidity("0F:80:10:00:40:00").isEqualTo(OK);
+        assertMessageValidity("4F:80:12:00:50:00").isEqualTo(OK);
+
+        assertMessageValidity("0F:80:10:00:40").isEqualTo(ERROR_PARAMETER_SHORT);
+        assertMessageValidity("40:80:12:00:50:00").isEqualTo(ERROR_DESTINATION);
+        assertMessageValidity("0F:80:10:01:40:00").isEqualTo(ERROR_PARAMETER);
+        assertMessageValidity("4F:80:12:00:50:50").isEqualTo(ERROR_PARAMETER);
+    }
+
     private IntegerSubject assertMessageValidity(String message) {
         return assertThat(mHdmiCecMessageValidator.isValid(buildMessage(message)));
     }
diff --git a/services/tests/servicestests/src/com/android/server/recoverysystem/OWNERS b/services/tests/servicestests/src/com/android/server/recoverysystem/OWNERS
new file mode 100644
index 0000000..3880038
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/recoverysystem/OWNERS
@@ -0,0 +1 @@
+include /services/core/java/com/android/server/recoverysystem/OWNERS
diff --git a/startop/iorap/src/com/google/android/startop/iorap/IorapForwardingService.java b/startop/iorap/src/com/google/android/startop/iorap/IorapForwardingService.java
index 3104c7e..f923721 100644
--- a/startop/iorap/src/com/google/android/startop/iorap/IorapForwardingService.java
+++ b/startop/iorap/src/com/google/android/startop/iorap/IorapForwardingService.java
@@ -34,6 +34,7 @@
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.SystemProperties;
+import android.provider.DeviceConfig;
 import android.util.ArraySet;
 import android.util.Log;
 
@@ -154,9 +155,27 @@
 
     @VisibleForTesting
     protected boolean isIorapEnabled() {
+        // These two mendel flags should match those in iorapd native process
+        // system/iorapd/src/common/property.h
+        boolean isTracingEnabled =
+            getMendelFlag("iorap_perfetto_enable", "iorapd.perfetto.enable", false);
+        boolean isReadAheadEnabled =
+            getMendelFlag("iorap_readahead_enable", "iorapd.readahead.enable", false);
         // Same as the property in iorapd.rc -- disabling this will mean the 'iorapd' binder process
         // never comes up, so all binder connections will fail indefinitely.
-        return IS_ENABLED;
+        return IS_ENABLED && (isTracingEnabled || isReadAheadEnabled);
+    }
+
+    private boolean getMendelFlag(String mendelFlag, String sysProperty, boolean defaultValue) {
+        // TODO(yawanng) use DeviceConfig to get mendel property.
+        // DeviceConfig doesn't work and the reason is not clear.
+        // Provider service is already up before IORapForwardService.
+        String mendelProperty = "persist.device_config."
+            + DeviceConfig.NAMESPACE_RUNTIME_NATIVE_BOOT
+            + "."
+            + mendelFlag;
+        return SystemProperties.getBoolean(mendelProperty,
+            SystemProperties.getBoolean(sysProperty, defaultValue));
     }
 
     //</editor-fold>
@@ -239,7 +258,9 @@
         //
         // TODO: it would be good to get nodified of 'adb shell stop iorapd' to avoid
         // printing this warning.
-        Log.w(TAG, "Failed to connect to iorapd, is it down? Delay for " + sleepTime);
+        if (DEBUG) {
+            Log.v(TAG, "Failed to connect to iorapd, is it down? Delay for " + sleepTime);
+        }
 
         // Use a handler instead of Thread#sleep to avoid backing up the binder thread
         // when this is called from the death recipient callback.
@@ -275,7 +296,9 @@
         // Connect to the native binder service.
         mIorapRemote = provideIorapRemote();
         if (mIorapRemote == null) {
-            Log.e(TAG, "connectToRemoteAndConfigure - null iorap remote. check for Log.wtf?");
+            if (DEBUG) {
+                Log.e(TAG, "connectToRemoteAndConfigure - null iorap remote. check for Log.wtf?");
+            }
             return false;
         }
         invokeRemote(mIorapRemote,
diff --git a/telephony/java/android/telephony/CellSignalStrengthLte.java b/telephony/java/android/telephony/CellSignalStrengthLte.java
index db7d10a..7addf33 100644
--- a/telephony/java/android/telephony/CellSignalStrengthLte.java
+++ b/telephony/java/android/telephony/CellSignalStrengthLte.java
@@ -443,10 +443,12 @@
     /**
      * Get table index for channel quality indicator
      *
+     * Reference: 3GPP TS 136.213 section 7.2.3.
+     *
      * @return the CQI table index if available or
      *         {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
      */
-    /** @hide */
+    @IntRange(from = 1, to = 6)
     public int getCqiTableIndex() {
         return mCqiTableIndex;
     }
@@ -454,9 +456,12 @@
     /**
      * Get channel quality indicator
      *
+     * Reference: 3GPP TS 136.213 section 7.2.3.
+     *
      * @return the CQI if available or
      *         {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
      */
+    @IntRange(from = 0, to = 15)
     public int getCqi() {
         return mCqi;
     }
diff --git a/telephony/java/android/telephony/CellSignalStrengthNr.java b/telephony/java/android/telephony/CellSignalStrengthNr.java
index 1518190..bde62fb 100644
--- a/telephony/java/android/telephony/CellSignalStrengthNr.java
+++ b/telephony/java/android/telephony/CellSignalStrengthNr.java
@@ -294,9 +294,10 @@
      *
      * Reference: 3GPP TS 138.214 section 5.2.2.1.
      *
-     * Range [1, 3].
+     * @return the CQI table index if available or
+     *         {@link android.telephony.CellInfo#UNAVAILABLE UNAVAILABLE} if unavailable.
      */
-    /** @hide */
+    @IntRange(from = 1, to = 3)
     public int getCsiCqiTableIndex() {
         return mCsiCqiTableIndex;
     }
@@ -310,10 +311,10 @@
      *
      * Reference: 3GPP TS 138.214 section 5.2.2.1.
      *
-     * Range [0, 15] for each CQI.
+     * @return the CQIs for all subbands if available or empty list if unavailable.
      */
-    /** @hide */
     @NonNull
+    @IntRange(from = 0, to = 15)
     public List<Integer> getCsiCqiReport() {
         return mCsiCqiReport;
     }
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 8368e3a..dd4b642 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -1494,6 +1494,16 @@
     public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL = 4;
 
     /**
+     * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE}
+     * to indicate that default subscription for data/sms/voice is now determined, that
+     * it should dismiss any dialog or pop-ups that is asking user to select default sub.
+     * This is used when, for example, opportunistic subscription is configured. At that
+     * time the primary becomes default sub there's no need to ask user to select anymore.
+     * @hide
+     */
+    public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS = 5;
+
+    /**
      * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED}
      * to indicate if the SIM combination in DSDS has limitation or compatible issue.
      * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios.
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 21cca4c..52f263f 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -521,6 +521,8 @@
     int RIL_REQUEST_CANCEL_HANDOVER = 218;
     int RIL_REQUEST_GET_SYSTEM_SELECTION_CHANNELS = 219;
     int RIL_REQUEST_SET_DATA_THROTTLING = 221;
+    int RIL_REQUEST_SET_ALLOWED_NETWORK_TYPE_BITMAP = 222;
+    int RIL_REQUEST_GET_ALLOWED_NETWORK_TYPE_BITMAP = 223;
 
     /* Responses begin */
     int RIL_RESPONSE_ACKNOWLEDGEMENT = 800;
diff --git a/test-mock/src/android/test/mock/OWNERS b/test-mock/src/android/test/mock/OWNERS
index 36d9cb2..72e8ffc 100644
--- a/test-mock/src/android/test/mock/OWNERS
+++ b/test-mock/src/android/test/mock/OWNERS
@@ -1 +1 @@
-set noparent
+*
diff --git a/tests/BatteryStatsPerfTest/OWNERS b/tests/BatteryStatsPerfTest/OWNERS
new file mode 100644
index 0000000..4068e2b
--- /dev/null
+++ b/tests/BatteryStatsPerfTest/OWNERS
@@ -0,0 +1 @@
+include /BATTERY_STATS_OWNERS
diff --git a/tests/BatteryWaster/OWNERS b/tests/BatteryWaster/OWNERS
new file mode 100644
index 0000000..4068e2b
--- /dev/null
+++ b/tests/BatteryWaster/OWNERS
@@ -0,0 +1 @@
+include /BATTERY_STATS_OWNERS
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 8c403f1..21dbbc6 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -39,6 +39,7 @@
 import static android.net.ConnectivityManager.TYPE_MOBILE_FOTA;
 import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
 import static android.net.ConnectivityManager.TYPE_MOBILE_SUPL;
+import static android.net.ConnectivityManager.TYPE_VPN;
 import static android.net.ConnectivityManager.TYPE_WIFI;
 import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_DNS;
 import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_FALLBACK;
@@ -101,6 +102,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.AdditionalMatchers.aryEq;
+import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.argThat;
@@ -132,6 +135,7 @@
 import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
+import android.content.ComponentName;
 import android.content.ContentProvider;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -140,6 +144,8 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.location.LocationManager;
@@ -176,6 +182,7 @@
 import android.net.NetworkCapabilities;
 import android.net.NetworkFactory;
 import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
 import android.net.NetworkRequest;
 import android.net.NetworkSpecifier;
 import android.net.NetworkStack;
@@ -332,12 +339,13 @@
     private static final String WIFI_WOL_IFNAME = "test_wlan_wol";
     private static final String VPN_IFNAME = "tun10042";
     private static final String TEST_PACKAGE_NAME = "com.android.test.package";
-    private static final String[] EMPTY_STRING_ARRAY = new String[0];
+    private static final String ALWAYS_ON_PACKAGE = "com.android.test.alwaysonvpn";
 
     private static final String INTERFACE_NAME = "interface";
 
     private MockContext mServiceContext;
     private HandlerThread mCsHandlerThread;
+    private ConnectivityService.Dependencies mDeps;
     private ConnectivityService mService;
     private WrappedConnectivityManager mCm;
     private TestNetworkAgentWrapper mWiFiNetworkAgent;
@@ -353,6 +361,7 @@
     @Mock IIpConnectivityMetrics mIpConnectivityMetrics;
     @Mock IpConnectivityMetrics.Logger mMetricsService;
     @Mock DefaultNetworkMetrics mDefaultNetworkMetrics;
+    @Mock DeviceIdleInternal mDeviceIdleInternal;
     @Mock INetworkManagementService mNetworkManagementService;
     @Mock INetworkStatsService mStatsService;
     @Mock IBatteryStats mBatteryStatsService;
@@ -450,6 +459,15 @@
         }
 
         @Override
+        public ComponentName startService(Intent service) {
+            final String action = service.getAction();
+            if (!VpnConfig.SERVICE_INTERFACE.equals(action)) {
+                fail("Attempt to start unknown service, action=" + action);
+            }
+            return new ComponentName(service.getPackage(), "com.android.test.Service");
+        }
+
+        @Override
         public Object getSystemService(String name) {
             if (Context.CONNECTIVITY_SERVICE.equals(name)) return mCm;
             if (Context.NOTIFICATION_SERVICE.equals(name)) return mNotificationManager;
@@ -1055,9 +1073,19 @@
         private VpnInfo mVpnInfo;
 
         public MockVpn(int userId) {
-            super(startHandlerThreadAndReturnLooper(), mServiceContext, mNetworkManagementService,
-                    mMockNetd, userId, mock(KeyStore.class));
-            mConfig = new VpnConfig();
+            super(startHandlerThreadAndReturnLooper(), mServiceContext,
+                    new Dependencies() {
+                        @Override
+                        public boolean isCallerSystem() {
+                            return true;
+                        }
+
+                        @Override
+                        public DeviceIdleInternal getDeviceIdleInternal() {
+                            return mDeviceIdleInternal;
+                        }
+                    },
+                    mNetworkManagementService, mMockNetd, userId, mock(KeyStore.class));
         }
 
         public void setUids(Set<UidRange> uids) {
@@ -1086,9 +1114,16 @@
             return mVpnType;
         }
 
+        private LinkProperties makeLinkProperties() {
+            final LinkProperties lp = new LinkProperties();
+            lp.setInterfaceName(VPN_IFNAME);
+            return lp;
+        }
+
         private void registerAgent(boolean isAlwaysMetered, Set<UidRange> uids, LinkProperties lp)
                 throws Exception {
             if (mAgentRegistered) throw new IllegalStateException("already registered");
+            mConfig = new VpnConfig();
             setUids(uids);
             if (!isAlwaysMetered) mNetworkCapabilities.addCapability(NET_CAPABILITY_NOT_METERED);
             mInterface = VPN_IFNAME;
@@ -1101,12 +1136,13 @@
             verify(mMockNetd, never())
                     .networkRemoveUidRanges(eq(mMockVpn.getNetId()), any());
             mAgentRegistered = true;
+            updateState(NetworkInfo.DetailedState.CONNECTED, "registerAgent");
             mNetworkCapabilities.set(mMockNetworkAgent.getNetworkCapabilities());
             mNetworkAgent = mMockNetworkAgent.getNetworkAgent();
         }
 
         private void registerAgent(Set<UidRange> uids) throws Exception {
-            registerAgent(false /* isAlwaysMetered */, uids, new LinkProperties());
+            registerAgent(false /* isAlwaysMetered */, uids, makeLinkProperties());
         }
 
         private void connect(boolean validated, boolean hasInternet, boolean isStrictMode) {
@@ -1142,12 +1178,12 @@
         public void establishForMyUid(boolean validated, boolean hasInternet, boolean isStrictMode)
                 throws Exception {
             final int uid = Process.myUid();
-            establish(new LinkProperties(), uid, uidRangesForUid(uid), validated, hasInternet,
+            establish(makeLinkProperties(), uid, uidRangesForUid(uid), validated, hasInternet,
                     isStrictMode);
         }
 
         public void establishForMyUid() throws Exception {
-            establishForMyUid(new LinkProperties());
+            establishForMyUid(makeLinkProperties());
         }
 
         public void sendLinkProperties(LinkProperties lp) {
@@ -1155,7 +1191,10 @@
         }
 
         public void disconnect() {
-            if (mMockNetworkAgent != null) mMockNetworkAgent.disconnect();
+            if (mMockNetworkAgent != null) {
+                mMockNetworkAgent.disconnect();
+                updateState(NetworkInfo.DetailedState.DISCONNECTED, "disconnect");
+            }
             mAgentRegistered = false;
         }
 
@@ -1229,6 +1268,17 @@
         fail("ConditionVariable was blocked for more than " + TIMEOUT_MS + "ms");
     }
 
+    private void registerNetworkCallbackAsUid(NetworkRequest request, NetworkCallback callback,
+            int uid) {
+        when(mDeps.getCallingUid()).thenReturn(uid);
+        try {
+            mCm.registerNetworkCallback(request, callback);
+            waitForIdle();
+        } finally {
+            returnRealCallingUid();
+        }
+    }
+
     private static final int VPN_USER = 0;
     private static final int APP1_UID = UserHandle.getUid(VPN_USER, 10100);
     private static final int APP2_UID = UserHandle.getUid(VPN_USER, 10101);
@@ -1271,7 +1321,8 @@
         initAlarmManager(mAlarmManager, mAlarmManagerThread.getThreadHandler());
 
         mCsHandlerThread = new HandlerThread("TestConnectivityService");
-        final ConnectivityService.Dependencies deps = makeDependencies();
+        mDeps = makeDependencies();
+        returnRealCallingUid();
         mService = new ConnectivityService(mServiceContext,
                 mNetworkManagementService,
                 mStatsService,
@@ -1279,9 +1330,9 @@
                 mMockDnsResolver,
                 mock(IpConnectivityLog.class),
                 mMockNetd,
-                deps);
+                mDeps);
         mService.mLingerDelayMs = TEST_LINGER_DELAY_MS;
-        verify(deps).makeMultinetworkPolicyTracker(any(), any(), any());
+        verify(mDeps).makeMultinetworkPolicyTracker(any(), any(), any());
 
         final ArgumentCaptor<INetworkPolicyListener> policyListenerCaptor =
                 ArgumentCaptor.forClass(INetworkPolicyListener.class);
@@ -1301,6 +1352,10 @@
         setPrivateDnsSettings(PRIVATE_DNS_MODE_OFF, "ignored.example.com");
     }
 
+    private void returnRealCallingUid() {
+        doAnswer((invocationOnMock) -> Binder.getCallingUid()).when(mDeps).getCallingUid();
+    }
+
     private ConnectivityService.Dependencies makeDependencies() {
         doReturn(TEST_TCP_INIT_RWND).when(mSystemProperties)
                 .getInt("net.tcp.default_init_rwnd", 0);
@@ -1376,13 +1431,13 @@
     }
 
     private void mockDefaultPackages() throws Exception {
-        final String testPackageName = mContext.getPackageName();
-        final PackageInfo testPackageInfo = mContext.getPackageManager().getPackageInfo(
-                testPackageName, PackageManager.GET_PERMISSIONS);
+        final String myPackageName = mContext.getPackageName();
+        final PackageInfo myPackageInfo = mContext.getPackageManager().getPackageInfo(
+                myPackageName, PackageManager.GET_PERMISSIONS);
         when(mPackageManager.getPackagesForUid(Binder.getCallingUid())).thenReturn(
-                new String[] {testPackageName});
-        when(mPackageManager.getPackageInfoAsUser(eq(testPackageName), anyInt(),
-                eq(UserHandle.getCallingUserId()))).thenReturn(testPackageInfo);
+                new String[] {myPackageName});
+        when(mPackageManager.getPackageInfoAsUser(eq(myPackageName), anyInt(),
+                eq(UserHandle.getCallingUserId()))).thenReturn(myPackageInfo);
 
         when(mPackageManager.getInstalledPackages(eq(GET_PERMISSIONS | MATCH_ANY_USER))).thenReturn(
                 Arrays.asList(new PackageInfo[] {
@@ -1390,6 +1445,25 @@
                         buildPackageInfo(/* SYSTEM */ false, APP2_UID),
                         buildPackageInfo(/* SYSTEM */ false, VPN_UID)
                 }));
+
+        // Create a fake always-on VPN package.
+        final int userId = UserHandle.getCallingUserId();
+        final ApplicationInfo applicationInfo = new ApplicationInfo();
+        applicationInfo.targetSdkVersion = Build.VERSION_CODES.R;  // Always-on supported in N+.
+        when(mPackageManager.getApplicationInfoAsUser(eq(ALWAYS_ON_PACKAGE), anyInt(),
+                eq(userId))).thenReturn(applicationInfo);
+
+        // Minimal mocking to keep Vpn#isAlwaysOnPackageSupported happy.
+        ResolveInfo rInfo = new ResolveInfo();
+        rInfo.serviceInfo = new ServiceInfo();
+        rInfo.serviceInfo.metaData = new Bundle();
+        final List<ResolveInfo> services = Arrays.asList(new ResolveInfo[]{rInfo});
+        when(mPackageManager.queryIntentServicesAsUser(any(), eq(PackageManager.GET_META_DATA),
+                eq(userId))).thenReturn(services);
+        when(mPackageManager.getPackageUidAsUser(TEST_PACKAGE_NAME, userId))
+                .thenReturn(Process.myUid());
+        when(mPackageManager.getPackageUidAsUser(ALWAYS_ON_PACKAGE, userId))
+                .thenReturn(VPN_UID);
     }
 
     private void verifyActiveNetwork(int transport) {
@@ -2252,10 +2326,10 @@
     }
 
     private void grantUsingBackgroundNetworksPermissionForUid(final int uid) throws Exception {
-        final String testPackageName = mContext.getPackageName();
-        when(mPackageManager.getPackageInfo(eq(testPackageName), eq(GET_PERMISSIONS)))
+        final String myPackageName = mContext.getPackageName();
+        when(mPackageManager.getPackageInfo(eq(myPackageName), eq(GET_PERMISSIONS)))
                 .thenReturn(buildPackageInfo(true, uid));
-        mService.mPermissionMonitor.onPackageAdded(testPackageName, uid);
+        mService.mPermissionMonitor.onPackageAdded(myPackageName, uid);
     }
 
     @Test
@@ -5831,10 +5905,21 @@
         assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
     }
 
+    private void assertDefaultNetworkCapabilities(int userId, NetworkAgentWrapper... networks) {
+        final NetworkCapabilities[] defaultCaps = mService.getDefaultNetworkCapabilitiesForUser(
+                userId, "com.android.calling.package");
+        final String defaultCapsString = Arrays.toString(defaultCaps);
+        assertEquals(defaultCapsString, defaultCaps.length, networks.length);
+        final Set<NetworkCapabilities> defaultCapsSet = new ArraySet<>(defaultCaps);
+        for (NetworkAgentWrapper network : networks) {
+            final NetworkCapabilities nc = mCm.getNetworkCapabilities(network.getNetwork());
+            final String msg = "Did not find " + nc + " in " + Arrays.toString(defaultCaps);
+            assertTrue(msg, defaultCapsSet.contains(nc));
+        }
+    }
+
     @Test
     public void testVpnSetUnderlyingNetworks() throws Exception {
-        final int uid = Process.myUid();
-
         final TestNetworkCallback vpnNetworkCallback = new TestNetworkCallback();
         final NetworkRequest vpnNetworkRequest = new NetworkRequest.Builder()
                 .removeCapability(NET_CAPABILITY_NOT_VPN)
@@ -5857,6 +5942,9 @@
         // A VPN without underlying networks is not suspended.
         assertTrue(nc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
 
+        final int userId = UserHandle.getUserId(Process.myUid());
+        assertDefaultNetworkCapabilities(userId /* no networks */);
+
         // Connect cell and use it as an underlying network.
         mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
         mCellNetworkAgent.addCapability(NET_CAPABILITY_NOT_SUSPENDED);
@@ -5870,6 +5958,7 @@
                 && caps.hasTransport(TRANSPORT_CELLULAR) && !caps.hasTransport(TRANSPORT_WIFI)
                 && !caps.hasCapability(NET_CAPABILITY_NOT_METERED)
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent);
 
         mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
         mWiFiNetworkAgent.addCapability(NET_CAPABILITY_NOT_METERED);
@@ -5884,6 +5973,7 @@
                 && caps.hasTransport(TRANSPORT_CELLULAR) && caps.hasTransport(TRANSPORT_WIFI)
                 && !caps.hasCapability(NET_CAPABILITY_NOT_METERED)
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent, mWiFiNetworkAgent);
 
         // Don't disconnect, but note the VPN is not using wifi any more.
         mService.setUnderlyingNetworksForVpn(
@@ -5894,6 +5984,9 @@
                 && caps.hasTransport(TRANSPORT_CELLULAR) && !caps.hasTransport(TRANSPORT_WIFI)
                 && !caps.hasCapability(NET_CAPABILITY_NOT_METERED)
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
+        // The return value of getDefaultNetworkCapabilitiesForUser always includes the default
+        // network (wifi) as well as the underlying networks (cell).
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent, mWiFiNetworkAgent);
 
         // Remove NOT_SUSPENDED from the only network and observe VPN is now suspended.
         mCellNetworkAgent.removeCapability(NET_CAPABILITY_NOT_SUSPENDED);
@@ -5922,6 +6015,7 @@
                 && !caps.hasTransport(TRANSPORT_CELLULAR) && caps.hasTransport(TRANSPORT_WIFI)
                 && caps.hasCapability(NET_CAPABILITY_NOT_METERED)
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
+        assertDefaultNetworkCapabilities(userId, mWiFiNetworkAgent);
 
         // Use both again.
         mService.setUnderlyingNetworksForVpn(
@@ -5932,6 +6026,7 @@
                 && caps.hasTransport(TRANSPORT_CELLULAR) && caps.hasTransport(TRANSPORT_WIFI)
                 && !caps.hasCapability(NET_CAPABILITY_NOT_METERED)
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent, mWiFiNetworkAgent);
 
         // Cell is suspended again. As WiFi is not, this should not cause a callback.
         mCellNetworkAgent.removeCapability(NET_CAPABILITY_NOT_SUSPENDED);
@@ -5949,6 +6044,7 @@
         // a bug in ConnectivityService, but as the SUSPENDED and RESUMED callbacks have never
         // been public and are deprecated and slated for removal, there is no sense in spending
         // resources fixing this bug now.
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent, mWiFiNetworkAgent);
 
         // Use both again.
         mService.setUnderlyingNetworksForVpn(
@@ -5961,6 +6057,7 @@
                 && caps.hasCapability(NET_CAPABILITY_NOT_SUSPENDED));
         // As above, the RESUMED callback not being sent here is a bug, but not a bug that's
         // worth anybody's time to fix.
+        assertDefaultNetworkCapabilities(userId, mCellNetworkAgent, mWiFiNetworkAgent);
 
         // Disconnect cell. Receive update without even removing the dead network from the
         // underlying networks – it's dead anyway. Not metered any more.
@@ -5969,6 +6066,7 @@
                 (caps) -> caps.hasTransport(TRANSPORT_VPN)
                 && !caps.hasTransport(TRANSPORT_CELLULAR) && caps.hasTransport(TRANSPORT_WIFI)
                 && caps.hasCapability(NET_CAPABILITY_NOT_METERED));
+        assertDefaultNetworkCapabilities(userId, mWiFiNetworkAgent);
 
         // Disconnect wifi too. No underlying networks means this is now metered.
         mWiFiNetworkAgent.disconnect();
@@ -5976,6 +6074,11 @@
                 (caps) -> caps.hasTransport(TRANSPORT_VPN)
                 && !caps.hasTransport(TRANSPORT_CELLULAR) && !caps.hasTransport(TRANSPORT_WIFI)
                 && !caps.hasCapability(NET_CAPABILITY_NOT_METERED));
+        // When a network disconnects, the callbacks are fired before all state is updated, so for a
+        // short time, synchronous calls will behave as if the network is still connected. Wait for
+        // things to settle.
+        waitForIdle();
+        assertDefaultNetworkCapabilities(userId /* no networks */);
 
         mMockVpn.disconnect();
     }
@@ -6276,6 +6379,7 @@
         // Despite VPN using WiFi (which is unmetered), VPN itself is marked as always metered.
         assertTrue(mCm.isActiveNetworkMetered());
 
+
         // VPN explicitly declares WiFi as its underlying network.
         mService.setUnderlyingNetworksForVpn(
                 new Network[] { mWiFiNetworkAgent.getNetwork() });
@@ -6389,6 +6493,189 @@
         mCm.unregisterNetworkCallback(defaultCallback);
     }
 
+    private void expectNetworkRejectNonSecureVpn(InOrder inOrder, boolean add,
+            UidRangeParcel... expected) throws Exception {
+        inOrder.verify(mMockNetd).networkRejectNonSecureVpn(eq(add), aryEq(expected));
+    }
+
+    private void checkNetworkInfo(NetworkInfo ni, int type, DetailedState state) {
+        assertNotNull(ni);
+        assertEquals(type, ni.getType());
+        assertEquals(ConnectivityManager.getNetworkTypeName(type), state, ni.getDetailedState());
+    }
+
+    private void assertActiveNetworkInfo(int type, DetailedState state) {
+        checkNetworkInfo(mCm.getActiveNetworkInfo(), type, state);
+    }
+    private void assertNetworkInfo(int type, DetailedState state) {
+        checkNetworkInfo(mCm.getNetworkInfo(type), type, state);
+    }
+
+    @Test
+    public void testNetworkBlockedStatusAlwaysOnVpn() throws Exception {
+        mServiceContext.setPermission(
+                Manifest.permission.CONTROL_ALWAYS_ON_VPN, PERMISSION_GRANTED);
+        mServiceContext.setPermission(
+                Manifest.permission.CONTROL_VPN, PERMISSION_GRANTED);
+        mServiceContext.setPermission(
+                Manifest.permission.NETWORK_SETTINGS, PERMISSION_GRANTED);
+
+        final TestNetworkCallback callback = new TestNetworkCallback();
+        final NetworkRequest request = new NetworkRequest.Builder()
+                .removeCapability(NET_CAPABILITY_NOT_VPN)
+                .build();
+        mCm.registerNetworkCallback(request, callback);
+
+        final TestNetworkCallback defaultCallback = new TestNetworkCallback();
+        mCm.registerDefaultNetworkCallback(defaultCallback);
+
+        final TestNetworkCallback vpnUidCallback = new TestNetworkCallback();
+        final NetworkRequest vpnUidRequest = new NetworkRequest.Builder().build();
+        registerNetworkCallbackAsUid(vpnUidRequest, vpnUidCallback, VPN_UID);
+
+        final int uid = Process.myUid();
+        final int userId = UserHandle.getUserId(uid);
+        final ArrayList<String> allowList = new ArrayList<>();
+        mService.setAlwaysOnVpnPackage(userId, ALWAYS_ON_PACKAGE, true /* lockdown */, allowList);
+
+        UidRangeParcel firstHalf = new UidRangeParcel(1, VPN_UID - 1);
+        UidRangeParcel secondHalf = new UidRangeParcel(VPN_UID + 1, 99999);
+        InOrder inOrder = inOrder(mMockNetd);
+        expectNetworkRejectNonSecureVpn(inOrder, true, firstHalf, secondHalf);
+
+        // Connect a network when lockdown is active, expect to see it blocked.
+        mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
+        mWiFiNetworkAgent.connect(false /* validated */);
+        callback.expectAvailableCallbacksUnvalidatedAndBlocked(mWiFiNetworkAgent);
+        defaultCallback.expectAvailableCallbacksUnvalidatedAndBlocked(mWiFiNetworkAgent);
+        vpnUidCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertNull(mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+        // Mobile is BLOCKED even though it's not actually connected.
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+
+        // Disable lockdown, expect to see the network unblocked.
+        // There are no callbacks because they are not implemented yet.
+        mService.setAlwaysOnVpnPackage(userId, null, false /* lockdown */, allowList);
+        expectNetworkRejectNonSecureVpn(inOrder, false, firstHalf, secondHalf);
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        // Add our UID to the allowlist and re-enable lockdown, expect network is not blocked.
+        allowList.add(TEST_PACKAGE_NAME);
+        mService.setAlwaysOnVpnPackage(userId, ALWAYS_ON_PACKAGE, true /* lockdown */, allowList);
+        callback.assertNoCallback();
+        defaultCallback.assertNoCallback();
+        vpnUidCallback.assertNoCallback();
+
+        // The following requires that the UID of this test package is greater than VPN_UID. This
+        // is always true in practice because a plain AOSP build with no apps installed has almost
+        // 200 packages installed.
+        final UidRangeParcel piece1 = new UidRangeParcel(1, VPN_UID - 1);
+        final UidRangeParcel piece2 = new UidRangeParcel(VPN_UID + 1, uid - 1);
+        final UidRangeParcel piece3 = new UidRangeParcel(uid + 1, 99999);
+        expectNetworkRejectNonSecureVpn(inOrder, true, piece1, piece2, piece3);
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        // Connect a new network, expect it to be unblocked.
+        mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
+        mCellNetworkAgent.connect(false /* validated */);
+        callback.expectAvailableCallbacksUnvalidated(mCellNetworkAgent);
+        defaultCallback.assertNoCallback();
+        vpnUidCallback.expectAvailableCallbacksUnvalidated(mCellNetworkAgent);
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        // Cellular is DISCONNECTED because it's not the default and there are no requests for it.
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        // Disable lockdown, remove our UID from the allowlist, and re-enable lockdown.
+        // Everything should now be blocked.
+        mService.setAlwaysOnVpnPackage(userId, null, false /* lockdown */, allowList);
+        expectNetworkRejectNonSecureVpn(inOrder, false, piece1, piece2, piece3);
+        allowList.clear();
+        mService.setAlwaysOnVpnPackage(userId, ALWAYS_ON_PACKAGE, true /* lockdown */, allowList);
+        expectNetworkRejectNonSecureVpn(inOrder, true, firstHalf, secondHalf);
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertNull(mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+
+        // Disable lockdown. Everything is unblocked.
+        mService.setAlwaysOnVpnPackage(userId, null, false /* lockdown */, allowList);
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        // Enable and disable an always-on VPN package without lockdown. Expect no changes.
+        reset(mMockNetd);
+        mService.setAlwaysOnVpnPackage(userId, ALWAYS_ON_PACKAGE, false /* lockdown */, allowList);
+        inOrder.verify(mMockNetd, never()).networkRejectNonSecureVpn(anyBoolean(), any());
+        callback.assertNoCallback();
+        defaultCallback.assertNoCallback();
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        mService.setAlwaysOnVpnPackage(userId, null, false /* lockdown */, allowList);
+        inOrder.verify(mMockNetd, never()).networkRejectNonSecureVpn(anyBoolean(), any());
+        callback.assertNoCallback();
+        defaultCallback.assertNoCallback();
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        // Enable lockdown and connect a VPN. The VPN is not blocked.
+        mService.setAlwaysOnVpnPackage(userId, ALWAYS_ON_PACKAGE, true /* lockdown */, allowList);
+        vpnUidCallback.assertNoCallback();
+        assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetworkForUid(VPN_UID));
+        assertNull(mCm.getActiveNetwork());
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.BLOCKED);
+
+        mMockVpn.establishForMyUid();
+        defaultCallback.expectAvailableThenValidatedCallbacks(mMockVpn);
+        vpnUidCallback.assertNoCallback();  // vpnUidCallback has NOT_VPN capability.
+        assertEquals(mMockVpn.getNetwork(), mCm.getActiveNetwork());
+        assertEquals(null, mCm.getActiveNetworkForUid(VPN_UID));  // BUG?
+        assertActiveNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_MOBILE, DetailedState.DISCONNECTED);
+        assertNetworkInfo(TYPE_VPN, DetailedState.CONNECTED);
+        assertNetworkInfo(TYPE_WIFI, DetailedState.CONNECTED);
+
+        mMockVpn.disconnect();
+        defaultCallback.expectCallback(CallbackEntry.LOST, mMockVpn);
+        defaultCallback.expectAvailableCallbacksUnvalidatedAndBlocked(mWiFiNetworkAgent);
+        assertNull(mCm.getActiveNetwork());
+
+        mCm.unregisterNetworkCallback(callback);
+        mCm.unregisterNetworkCallback(defaultCallback);
+        mCm.unregisterNetworkCallback(vpnUidCallback);
+    }
+
     @Test
     public final void testLoseTrusted() throws Exception {
         final NetworkRequest trustedRequest = new NetworkRequest.Builder()
diff --git a/tests/net/java/com/android/server/connectivity/VpnTest.java b/tests/net/java/com/android/server/connectivity/VpnTest.java
index 6e380be..cc47317 100644
--- a/tests/net/java/com/android/server/connectivity/VpnTest.java
+++ b/tests/net/java/com/android/server/connectivity/VpnTest.java
@@ -228,7 +228,6 @@
                         R.string.config_customVpnAlwaysOnDisconnectedDialogComponent));
         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_IPSEC_TUNNELS))
                 .thenReturn(true);
-        when(mSystemServices.isCallerSystem()).thenReturn(true);
 
         // Used by {@link Notification.Builder}
         ApplicationInfo applicationInfo = new ApplicationInfo();
@@ -1102,6 +1101,11 @@
         }
 
         @Override
+        public boolean isCallerSystem() {
+            return true;
+        }
+
+        @Override
         public void startService(final String serviceName) {
             mRunningServices.put(serviceName, true);
         }
diff --git a/tools/stats_log_api_gen/.clang-format b/tools/stats_log_api_gen/.clang-format
deleted file mode 100644
index cead3a0..0000000
--- a/tools/stats_log_api_gen/.clang-format
+++ /dev/null
@@ -1,17 +0,0 @@
-BasedOnStyle: Google
-AllowShortIfStatementsOnASingleLine: true
-AllowShortFunctionsOnASingleLine: false
-AllowShortLoopsOnASingleLine: true
-BinPackArguments: true
-BinPackParameters: true
-ColumnLimit: 100
-CommentPragmas: NOLINT:.*
-ContinuationIndentWidth: 8
-DerivePointerAlignment: false
-IndentWidth: 4
-PointerAlignment: Left
-TabWidth: 4
-AccessModifierOffset: -4
-IncludeCategories:
-  - Regex:    '^"Log\.h"'
-    Priority:    -1
diff --git a/tools/stats_log_api_gen/Android.bp b/tools/stats_log_api_gen/Android.bp
deleted file mode 100644
index c0893f7..0000000
--- a/tools/stats_log_api_gen/Android.bp
+++ /dev/null
@@ -1,134 +0,0 @@
-//
-// Copyright (C) 2017 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-// ==========================================================
-// Build the host executable: stats-log-api-gen
-// ==========================================================
-cc_binary_host {
-    name: "stats-log-api-gen",
-    srcs: [
-        "Collation.cpp",
-        "java_writer.cpp",
-        "java_writer_q.cpp",
-        "main.cpp",
-        "native_writer.cpp",
-        "utils.cpp",
-    ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-
-    shared_libs: [
-        "libstats_proto_host",
-        "libprotobuf-cpp-full",
-        "libbase",
-    ],
-
-    proto: {
-        type: "full",
-    },
-}
-
-// ==========================================================
-// Build the host test executable: stats-log-api-gen
-// ==========================================================
-cc_test_host {
-    name: "stats-log-api-gen-test",
-    cflags: [
-        "-Wall",
-        "-Wextra",
-        "-Werror",
-        "-g",
-        "-DUNIT_TEST",
-    ],
-    srcs: [
-        "Collation.cpp",
-        "test_collation.cpp",
-        "test.proto",
-    ],
-
-    static_libs: [
-        "libgmock_host",
-    ],
-
-    shared_libs: [
-        "libstats_proto_host",
-        "libprotobuf-cpp-full",
-    ],
-
-    proto: {
-        type: "full",
-        include_dirs: [
-            "external/protobuf/src",
-        ],
-    },
-}
-
-// ==========================================================
-// Native library
-// ==========================================================
-genrule {
-    name: "statslog.h",
-    tools: ["stats-log-api-gen"],
-    cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog.h",
-    out: [
-        "statslog.h",
-    ],
-}
-
-genrule {
-    name: "statslog.cpp",
-    tools: ["stats-log-api-gen"],
-    cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog.cpp",
-    out: [
-        "statslog.cpp",
-    ],
-}
-
-cc_library {
-    name: "libstatslog",
-    host_supported: true,
-    generated_sources: [
-        "statslog.cpp",
-    ],
-    generated_headers: [
-        "statslog.h"
-    ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    export_generated_headers: [
-        "statslog.h"
-    ],
-    shared_libs: [
-        "liblog",
-        "libcutils",
-    ],
-    target: {
-        android: {
-            shared_libs: ["libstatssocket"],
-        },
-        host: {
-            static_libs: ["libstatssocket"],
-        },
-        darwin: {
-            enabled: false,
-        },
-    },
-}
-
diff --git a/tools/stats_log_api_gen/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp
deleted file mode 100644
index 2608097..0000000
--- a/tools/stats_log_api_gen/Collation.cpp
+++ /dev/null
@@ -1,576 +0,0 @@
-/*
- * Copyright (C) 2017, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Collation.h"
-
-#include <stdio.h>
-
-#include <map>
-
-#include "frameworks/proto_logging/stats/atoms.pb.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using google::protobuf::EnumDescriptor;
-using google::protobuf::FieldDescriptor;
-using google::protobuf::FileDescriptor;
-using google::protobuf::SourceLocation;
-using std::make_shared;
-using std::map;
-
-const bool dbg = false;
-
-//
-// AtomDecl class
-//
-
-AtomDecl::AtomDecl() : code(0), name() {
-}
-
-AtomDecl::AtomDecl(const AtomDecl& that)
-    : code(that.code),
-      name(that.name),
-      message(that.message),
-      fields(that.fields),
-      fieldNumberToAnnotations(that.fieldNumberToAnnotations),
-      primaryFields(that.primaryFields),
-      exclusiveField(that.exclusiveField),
-      defaultState(that.defaultState),
-      triggerStateReset(that.triggerStateReset),
-      nested(that.nested),
-      uidField(that.uidField) {
-}
-
-AtomDecl::AtomDecl(int c, const string& n, const string& m) : code(c), name(n), message(m) {
-}
-
-AtomDecl::~AtomDecl() {
-}
-
-/**
- * Print an error message for a FieldDescriptor, including the file name and
- * line number.
- */
-static void print_error(const FieldDescriptor* field, const char* format, ...) {
-    const Descriptor* message = field->containing_type();
-    const FileDescriptor* file = message->file();
-
-    SourceLocation loc;
-    if (field->GetSourceLocation(&loc)) {
-        // TODO: this will work if we can figure out how to pass
-        // --include_source_info to protoc
-        fprintf(stderr, "%s:%d: ", file->name().c_str(), loc.start_line);
-    } else {
-        fprintf(stderr, "%s: ", file->name().c_str());
-    }
-    va_list args;
-    va_start(args, format);
-    vfprintf(stderr, format, args);
-    va_end(args);
-}
-
-/**
- * Convert a protobuf type into a java type.
- */
-static java_type_t java_type(const FieldDescriptor* field) {
-    int protoType = field->type();
-    switch (protoType) {
-        case FieldDescriptor::TYPE_DOUBLE:
-            return JAVA_TYPE_DOUBLE;
-        case FieldDescriptor::TYPE_FLOAT:
-            return JAVA_TYPE_FLOAT;
-        case FieldDescriptor::TYPE_INT64:
-            return JAVA_TYPE_LONG;
-        case FieldDescriptor::TYPE_UINT64:
-            return JAVA_TYPE_LONG;
-        case FieldDescriptor::TYPE_INT32:
-            return JAVA_TYPE_INT;
-        case FieldDescriptor::TYPE_FIXED64:
-            return JAVA_TYPE_LONG;
-        case FieldDescriptor::TYPE_FIXED32:
-            return JAVA_TYPE_INT;
-        case FieldDescriptor::TYPE_BOOL:
-            return JAVA_TYPE_BOOLEAN;
-        case FieldDescriptor::TYPE_STRING:
-            return JAVA_TYPE_STRING;
-        case FieldDescriptor::TYPE_GROUP:
-            return JAVA_TYPE_UNKNOWN;
-        case FieldDescriptor::TYPE_MESSAGE:
-            // TODO: not the final package name
-            if (field->message_type()->full_name() == "android.os.statsd.AttributionNode") {
-                return JAVA_TYPE_ATTRIBUTION_CHAIN;
-            } else if (field->message_type()->full_name() == "android.os.statsd.KeyValuePair") {
-                return JAVA_TYPE_KEY_VALUE_PAIR;
-            } else if (field->options().GetExtension(os::statsd::log_mode) ==
-                       os::statsd::LogMode::MODE_BYTES) {
-                return JAVA_TYPE_BYTE_ARRAY;
-            } else {
-                return JAVA_TYPE_OBJECT;
-            }
-        case FieldDescriptor::TYPE_BYTES:
-            return JAVA_TYPE_BYTE_ARRAY;
-        case FieldDescriptor::TYPE_UINT32:
-            return JAVA_TYPE_INT;
-        case FieldDescriptor::TYPE_ENUM:
-            return JAVA_TYPE_ENUM;
-        case FieldDescriptor::TYPE_SFIXED32:
-            return JAVA_TYPE_INT;
-        case FieldDescriptor::TYPE_SFIXED64:
-            return JAVA_TYPE_LONG;
-        case FieldDescriptor::TYPE_SINT32:
-            return JAVA_TYPE_INT;
-        case FieldDescriptor::TYPE_SINT64:
-            return JAVA_TYPE_LONG;
-        default:
-            return JAVA_TYPE_UNKNOWN;
-    }
-}
-
-/**
- * Gather the enums info.
- */
-void collate_enums(const EnumDescriptor& enumDescriptor, AtomField* atomField) {
-    for (int i = 0; i < enumDescriptor.value_count(); i++) {
-        atomField->enumValues[enumDescriptor.value(i)->number()] =
-                enumDescriptor.value(i)->name().c_str();
-    }
-}
-
-static void addAnnotationToAtomDecl(AtomDecl* atomDecl, const int fieldNumber,
-                                    const AnnotationId annotationId,
-                                    const AnnotationType annotationType,
-                                    const AnnotationValue annotationValue) {
-    if (dbg) {
-        printf("   Adding annotation to %s: [%d] = {id: %d, type: %d}\n", atomDecl->name.c_str(),
-               fieldNumber, annotationId, annotationType);
-    }
-    atomDecl->fieldNumberToAnnotations[fieldNumber].insert(
-            make_shared<Annotation>(annotationId, atomDecl->code, annotationType, annotationValue));
-}
-
-static int collate_field_annotations(AtomDecl* atomDecl, const FieldDescriptor* field,
-                                     const int fieldNumber, const java_type_t& javaType) {
-    int errorCount = 0;
-
-    if (field->options().HasExtension(os::statsd::state_field_option)) {
-        const os::statsd::StateAtomFieldOption& stateFieldOption =
-                field->options().GetExtension(os::statsd::state_field_option);
-        const bool primaryField = stateFieldOption.primary_field();
-        const bool exclusiveState = stateFieldOption.exclusive_state();
-        const bool primaryFieldFirstUid = stateFieldOption.primary_field_first_uid();
-
-        // Check the field is only one of primaryField, exclusiveState, or primaryFieldFirstUid.
-        if (primaryField + primaryFieldFirstUid + exclusiveState > 1) {
-            print_error(field,
-                        "Field can be max 1 of primary_field, exclusive_state, "
-                        "or primary_field_first_uid: '%s'\n",
-                        atomDecl->message.c_str());
-            errorCount++;
-        }
-
-        if (primaryField) {
-            if (javaType == JAVA_TYPE_UNKNOWN || javaType == JAVA_TYPE_ATTRIBUTION_CHAIN ||
-                javaType == JAVA_TYPE_OBJECT || javaType == JAVA_TYPE_BYTE_ARRAY) {
-                print_error(field, "Invalid primary state field: '%s'\n",
-                            atomDecl->message.c_str());
-                errorCount++;
-            } else {
-                atomDecl->primaryFields.push_back(fieldNumber);
-                addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_PRIMARY_FIELD,
-                                        ANNOTATION_TYPE_BOOL, AnnotationValue(true));
-            }
-        }
-
-        if (primaryFieldFirstUid) {
-            if (javaType != JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                print_error(field,
-                            "PRIMARY_FIELD_FIRST_UID annotation is only for AttributionChains: "
-                            "'%s'\n",
-                            atomDecl->message.c_str());
-                errorCount++;
-            } else {
-                atomDecl->primaryFields.push_back(FIRST_UID_IN_CHAIN_ID);
-                addAnnotationToAtomDecl(atomDecl, fieldNumber,
-                                        ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID, ANNOTATION_TYPE_BOOL,
-                                        AnnotationValue(true));
-            }
-        }
-
-        if (exclusiveState) {
-            if (javaType == JAVA_TYPE_UNKNOWN || javaType == JAVA_TYPE_ATTRIBUTION_CHAIN ||
-                javaType == JAVA_TYPE_OBJECT || javaType == JAVA_TYPE_BYTE_ARRAY) {
-                print_error(field, "Invalid exclusive state field: '%s'\n",
-                            atomDecl->message.c_str());
-                errorCount++;
-            }
-
-            if (atomDecl->exclusiveField != 0) {
-                print_error(field,
-                            "Cannot have more than one exclusive state field in an "
-                            "atom: '%s'\n",
-                            atomDecl->message.c_str());
-                errorCount++;
-            } else {
-                atomDecl->exclusiveField = fieldNumber;
-                addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_EXCLUSIVE_STATE,
-                                        ANNOTATION_TYPE_BOOL, AnnotationValue(true));
-            }
-
-            if (stateFieldOption.has_default_state_value()) {
-                const int defaultState = stateFieldOption.default_state_value();
-                atomDecl->defaultState = defaultState;
-
-                addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_DEFAULT_STATE,
-                                        ANNOTATION_TYPE_INT, AnnotationValue(defaultState));
-            }
-
-            if (stateFieldOption.has_trigger_state_reset_value()) {
-                const int triggerStateReset = stateFieldOption.trigger_state_reset_value();
-
-                atomDecl->triggerStateReset = triggerStateReset;
-                addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_TRIGGER_STATE_RESET,
-                                        ANNOTATION_TYPE_INT, AnnotationValue(triggerStateReset));
-            }
-
-            if (stateFieldOption.has_nested()) {
-                const bool nested = stateFieldOption.nested();
-                atomDecl->nested = nested;
-
-                addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_STATE_NESTED,
-                                        ANNOTATION_TYPE_BOOL, AnnotationValue(nested));
-            }
-        }
-    }
-
-    if (field->options().GetExtension(os::statsd::is_uid) == true) {
-        if (javaType != JAVA_TYPE_INT) {
-            print_error(field, "is_uid annotation can only be applied to int32 fields: '%s'\n",
-                        atomDecl->message.c_str());
-            errorCount++;
-        }
-
-        if (atomDecl->uidField == 0) {
-            atomDecl->uidField = fieldNumber;
-
-            addAnnotationToAtomDecl(atomDecl, fieldNumber, ANNOTATION_ID_IS_UID,
-                                    ANNOTATION_TYPE_BOOL, AnnotationValue(true));
-        } else {
-            print_error(field,
-                        "Cannot have more than one field in an atom with is_uid "
-                        "annotation: '%s'\n",
-                        atomDecl->message.c_str());
-            errorCount++;
-        }
-    }
-
-    return errorCount;
-}
-
-/**
- * Gather the info about an atom proto.
- */
-int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t>* signature) {
-    int errorCount = 0;
-
-    // Build a sorted list of the fields. Descriptor has them in source file
-    // order.
-    map<int, const FieldDescriptor*> fields;
-    for (int j = 0; j < atom->field_count(); j++) {
-        const FieldDescriptor* field = atom->field(j);
-        fields[field->number()] = field;
-    }
-
-    // Check that the parameters start at 1 and go up sequentially.
-    int expectedNumber = 1;
-    for (map<int, const FieldDescriptor*>::const_iterator it = fields.begin(); it != fields.end();
-         it++) {
-        const int number = it->first;
-        const FieldDescriptor* field = it->second;
-        if (number != expectedNumber) {
-            print_error(field,
-                        "Fields must be numbered consecutively starting at 1:"
-                        " '%s' is %d but should be %d\n",
-                        field->name().c_str(), number, expectedNumber);
-            errorCount++;
-            expectedNumber = number;
-            continue;
-        }
-        expectedNumber++;
-    }
-
-    // Check that only allowed types are present. Remove any invalid ones.
-    for (map<int, const FieldDescriptor*>::const_iterator it = fields.begin(); it != fields.end();
-         it++) {
-        const FieldDescriptor* field = it->second;
-        bool isBinaryField = field->options().GetExtension(os::statsd::log_mode) ==
-                             os::statsd::LogMode::MODE_BYTES;
-
-        java_type_t javaType = java_type(field);
-
-        if (javaType == JAVA_TYPE_UNKNOWN) {
-            print_error(field, "Unknown type for field: %s\n", field->name().c_str());
-            errorCount++;
-            continue;
-        } else if (javaType == JAVA_TYPE_OBJECT && atomDecl->code < PULL_ATOM_START_ID) {
-            // Allow attribution chain, but only at position 1.
-            print_error(field, "Message type not allowed for field in pushed atoms: %s\n",
-                        field->name().c_str());
-            errorCount++;
-            continue;
-        } else if (javaType == JAVA_TYPE_BYTE_ARRAY && !isBinaryField) {
-            print_error(field, "Raw bytes type not allowed for field: %s\n", field->name().c_str());
-            errorCount++;
-            continue;
-        }
-
-        if (isBinaryField && javaType != JAVA_TYPE_BYTE_ARRAY) {
-            print_error(field, "Cannot mark field %s as bytes.\n", field->name().c_str());
-            errorCount++;
-            continue;
-        }
-
-        // Doubles are not supported yet.
-        if (javaType == JAVA_TYPE_DOUBLE) {
-            print_error(field,
-                        "Doubles are not supported in atoms. Please change field %s "
-                        "to float\n",
-                        field->name().c_str());
-            errorCount++;
-            continue;
-        }
-
-        if (field->is_repeated() &&
-            !(javaType == JAVA_TYPE_ATTRIBUTION_CHAIN || javaType == JAVA_TYPE_KEY_VALUE_PAIR)) {
-            print_error(field,
-                        "Repeated fields are not supported in atoms. Please make "
-                        "field %s not "
-                        "repeated.\n",
-                        field->name().c_str());
-            errorCount++;
-            continue;
-        }
-    }
-
-    // Check that if there's an attribution chain, it's at position 1.
-    for (map<int, const FieldDescriptor*>::const_iterator it = fields.begin(); it != fields.end();
-         it++) {
-        int number = it->first;
-        if (number != 1) {
-            const FieldDescriptor* field = it->second;
-            java_type_t javaType = java_type(field);
-            if (javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                print_error(field,
-                            "AttributionChain fields must have field id 1, in message: '%s'\n",
-                            atom->name().c_str());
-                errorCount++;
-            }
-        }
-    }
-
-    // Build the type signature and the atom data.
-    for (map<int, const FieldDescriptor*>::const_iterator it = fields.begin(); it != fields.end();
-         it++) {
-        const FieldDescriptor* field = it->second;
-        java_type_t javaType = java_type(field);
-        bool isBinaryField = field->options().GetExtension(os::statsd::log_mode) ==
-                             os::statsd::LogMode::MODE_BYTES;
-
-        AtomField atField(field->name(), javaType);
-
-        if (javaType == JAVA_TYPE_ENUM) {
-            // All enums are treated as ints when it comes to function signatures.
-            collate_enums(*field->enum_type(), &atField);
-        }
-
-        // Generate signature for pushed atoms
-        if (atomDecl->code < PULL_ATOM_START_ID) {
-            if (javaType == JAVA_TYPE_ENUM) {
-                // All enums are treated as ints when it comes to function signatures.
-                signature->push_back(JAVA_TYPE_INT);
-            } else if (javaType == JAVA_TYPE_OBJECT && isBinaryField) {
-                signature->push_back(JAVA_TYPE_BYTE_ARRAY);
-            } else {
-                signature->push_back(javaType);
-            }
-        }
-
-        atomDecl->fields.push_back(atField);
-
-        errorCount += collate_field_annotations(atomDecl, field, it->first, javaType);
-    }
-
-    return errorCount;
-}
-
-// This function flattens the fields of the AttributionNode proto in an Atom
-// proto and generates the corresponding atom decl and signature.
-bool get_non_chained_node(const Descriptor* atom, AtomDecl* atomDecl,
-                          vector<java_type_t>* signature) {
-    // Build a sorted list of the fields. Descriptor has them in source file
-    // order.
-    map<int, const FieldDescriptor*> fields;
-    for (int j = 0; j < atom->field_count(); j++) {
-        const FieldDescriptor* field = atom->field(j);
-        fields[field->number()] = field;
-    }
-
-    AtomDecl attributionDecl;
-    vector<java_type_t> attributionSignature;
-    collate_atom(android::os::statsd::AttributionNode::descriptor(), &attributionDecl,
-                 &attributionSignature);
-
-    // Build the type signature and the atom data.
-    bool has_attribution_node = false;
-    for (map<int, const FieldDescriptor*>::const_iterator it = fields.begin(); it != fields.end();
-         it++) {
-        const FieldDescriptor* field = it->second;
-        java_type_t javaType = java_type(field);
-        if (javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-            atomDecl->fields.insert(atomDecl->fields.end(), attributionDecl.fields.begin(),
-                                    attributionDecl.fields.end());
-            signature->insert(signature->end(), attributionSignature.begin(),
-                              attributionSignature.end());
-            has_attribution_node = true;
-
-        } else {
-            AtomField atField(field->name(), javaType);
-            if (javaType == JAVA_TYPE_ENUM) {
-                // All enums are treated as ints when it comes to function signatures.
-                signature->push_back(JAVA_TYPE_INT);
-                collate_enums(*field->enum_type(), &atField);
-            } else {
-                signature->push_back(javaType);
-            }
-            atomDecl->fields.push_back(atField);
-        }
-    }
-    return has_attribution_node;
-}
-
-static void populateFieldNumberToAtomDeclSet(const shared_ptr<AtomDecl>& atomDecl,
-                                             FieldNumberToAtomDeclSet* fieldNumberToAtomDeclSet) {
-    for (FieldNumberToAnnotations::const_iterator it = atomDecl->fieldNumberToAnnotations.begin();
-         it != atomDecl->fieldNumberToAnnotations.end(); it++) {
-        const int fieldNumber = it->first;
-        (*fieldNumberToAtomDeclSet)[fieldNumber].insert(atomDecl);
-    }
-}
-
-/**
- * Gather the info about the atoms.
- */
-int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* atoms) {
-    int errorCount = 0;
-
-    for (int i = 0; i < descriptor->field_count(); i++) {
-        const FieldDescriptor* atomField = descriptor->field(i);
-
-        if (moduleName != DEFAULT_MODULE_NAME) {
-            const int moduleCount = atomField->options().ExtensionSize(os::statsd::module);
-            int j;
-            for (j = 0; j < moduleCount; ++j) {
-                const string atomModuleName =
-                        atomField->options().GetExtension(os::statsd::module, j);
-                if (atomModuleName == moduleName) {
-                    break;
-                }
-            }
-
-            // This atom is not in the module we're interested in; skip it.
-            if (moduleCount == j) {
-                if (dbg) {
-                    printf("   Skipping %s (%d)\n", atomField->name().c_str(), atomField->number());
-                }
-                continue;
-            }
-        }
-
-        if (dbg) {
-            printf("   %s (%d)\n", atomField->name().c_str(), atomField->number());
-        }
-
-        // StatsEvent only has one oneof, which contains only messages. Don't allow
-        // other types.
-        if (atomField->type() != FieldDescriptor::TYPE_MESSAGE) {
-            print_error(atomField,
-                        "Bad type for atom. StatsEvent can only have message type "
-                        "fields: %s\n",
-                        atomField->name().c_str());
-            errorCount++;
-            continue;
-        }
-
-        const Descriptor* atom = atomField->message_type();
-        shared_ptr<AtomDecl> atomDecl =
-                make_shared<AtomDecl>(atomField->number(), atomField->name(), atom->name());
-
-        if (atomDecl->code < PULL_ATOM_START_ID &&
-            atomField->options().GetExtension(os::statsd::truncate_timestamp)) {
-            addAnnotationToAtomDecl(atomDecl.get(), ATOM_ID_FIELD_NUMBER,
-                                    ANNOTATION_ID_TRUNCATE_TIMESTAMP, ANNOTATION_TYPE_BOOL,
-                                    AnnotationValue(true));
-            if (dbg) {
-                printf("%s can have timestamp truncated\n", atomField->name().c_str());
-            }
-        }
-
-        vector<java_type_t> signature;
-        errorCount += collate_atom(atom, atomDecl.get(), &signature);
-        if (atomDecl->primaryFields.size() != 0 && atomDecl->exclusiveField == 0) {
-            print_error(atomField, "Cannot have a primary field without an exclusive field: %s\n",
-                        atomField->name().c_str());
-            errorCount++;
-            continue;
-        }
-
-        FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = atoms->signatureInfoMap[signature];
-        populateFieldNumberToAtomDeclSet(atomDecl, &fieldNumberToAtomDeclSet);
-
-        atoms->decls.insert(atomDecl);
-
-        shared_ptr<AtomDecl> nonChainedAtomDecl =
-                make_shared<AtomDecl>(atomField->number(), atomField->name(), atom->name());
-        vector<java_type_t> nonChainedSignature;
-        if (get_non_chained_node(atom, nonChainedAtomDecl.get(), &nonChainedSignature)) {
-            FieldNumberToAtomDeclSet& nonChainedFieldNumberToAtomDeclSet =
-                    atoms->nonChainedSignatureInfoMap[nonChainedSignature];
-            populateFieldNumberToAtomDeclSet(nonChainedAtomDecl,
-                                             &nonChainedFieldNumberToAtomDeclSet);
-
-            atoms->non_chained_decls.insert(nonChainedAtomDecl);
-        }
-    }
-
-    if (dbg) {
-        printf("signatures = [\n");
-        for (SignatureInfoMap::const_iterator it = atoms->signatureInfoMap.begin();
-             it != atoms->signatureInfoMap.end(); it++) {
-            printf("   ");
-            for (vector<java_type_t>::const_iterator jt = it->first.begin(); jt != it->first.end();
-                 jt++) {
-                printf(" %d", (int)*jt);
-            }
-            printf("\n");
-        }
-        printf("]\n");
-    }
-
-    return errorCount;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/Collation.h b/tools/stats_log_api_gen/Collation.h
deleted file mode 100644
index 3deb3ae..0000000
--- a/tools/stats_log_api_gen/Collation.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (C) 2017, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_STATS_LOG_API_GEN_COLLATION_H
-#define ANDROID_STATS_LOG_API_GEN_COLLATION_H
-
-#include <google/protobuf/descriptor.h>
-#include <stdint.h>
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "frameworks/proto_logging/stats/atom_field_options.pb.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using google::protobuf::Descriptor;
-using google::protobuf::FieldDescriptor;
-using std::map;
-using std::set;
-using std::shared_ptr;
-using std::string;
-using std::vector;
-
-const int PULL_ATOM_START_ID = 10000;
-
-const int FIRST_UID_IN_CHAIN_ID = 0;
-
-enum AnnotationId : uint8_t {
-    ANNOTATION_ID_IS_UID = 1,
-    ANNOTATION_ID_TRUNCATE_TIMESTAMP = 2,
-    ANNOTATION_ID_PRIMARY_FIELD = 3,
-    ANNOTATION_ID_EXCLUSIVE_STATE = 4,
-    ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID = 5,
-    ANNOTATION_ID_DEFAULT_STATE = 6,
-    ANNOTATION_ID_TRIGGER_STATE_RESET = 7,
-    ANNOTATION_ID_STATE_NESTED = 8,
-};
-
-const int ATOM_ID_FIELD_NUMBER = -1;
-
-const string DEFAULT_MODULE_NAME = "DEFAULT";
-
-/**
- * The types for atom parameters.
- */
-typedef enum {
-    JAVA_TYPE_UNKNOWN = 0,
-
-    JAVA_TYPE_ATTRIBUTION_CHAIN = 1,
-    JAVA_TYPE_BOOLEAN = 2,
-    JAVA_TYPE_INT = 3,
-    JAVA_TYPE_LONG = 4,
-    JAVA_TYPE_FLOAT = 5,
-    JAVA_TYPE_DOUBLE = 6,
-    JAVA_TYPE_STRING = 7,
-    JAVA_TYPE_ENUM = 8,
-    JAVA_TYPE_KEY_VALUE_PAIR = 9,
-
-    JAVA_TYPE_OBJECT = -1,
-    JAVA_TYPE_BYTE_ARRAY = -2,
-} java_type_t;
-
-enum AnnotationType {
-    ANNOTATION_TYPE_UNKNOWN = 0,
-    ANNOTATION_TYPE_INT = 1,
-    ANNOTATION_TYPE_BOOL = 2,
-};
-
-union AnnotationValue {
-    int intValue;
-    bool boolValue;
-
-    AnnotationValue(const int value) : intValue(value) {
-    }
-    AnnotationValue(const bool value) : boolValue(value) {
-    }
-};
-
-struct Annotation {
-    const AnnotationId annotationId;
-    const int atomId;
-    AnnotationType type;
-    AnnotationValue value;
-
-    inline Annotation(AnnotationId annotationId, int atomId, AnnotationType type,
-                      AnnotationValue value)
-        : annotationId(annotationId), atomId(atomId), type(type), value(value) {
-    }
-    inline ~Annotation() {
-    }
-
-    inline bool operator<(const Annotation& that) const {
-        return atomId == that.atomId ? annotationId < that.annotationId : atomId < that.atomId;
-    }
-};
-
-struct SharedComparator {
-    template <typename T>
-    inline bool operator()(const shared_ptr<T>& lhs, const shared_ptr<T>& rhs) const {
-        return (*lhs) < (*rhs);
-    }
-};
-
-using AnnotationSet = set<shared_ptr<Annotation>, SharedComparator>;
-
-using FieldNumberToAnnotations = map<int, AnnotationSet>;
-
-/**
- * The name and type for an atom field.
- */
-struct AtomField {
-    string name;
-    java_type_t javaType;
-
-    // If the field is of type enum, the following map contains the list of enum
-    // values.
-    map<int /* numeric value */, string /* value name */> enumValues;
-
-    inline AtomField() : name(), javaType(JAVA_TYPE_UNKNOWN) {
-    }
-    inline AtomField(const AtomField& that)
-        : name(that.name), javaType(that.javaType), enumValues(that.enumValues) {
-    }
-
-    inline AtomField(string n, java_type_t jt) : name(n), javaType(jt) {
-    }
-    inline ~AtomField() {
-    }
-};
-
-/**
- * The name and code for an atom.
- */
-struct AtomDecl {
-    int code;
-    string name;
-
-    string message;
-    vector<AtomField> fields;
-
-    FieldNumberToAnnotations fieldNumberToAnnotations;
-
-    vector<int> primaryFields;
-    int exclusiveField = 0;
-    int defaultState = INT_MAX;
-    int triggerStateReset = INT_MAX;
-    bool nested = true;
-
-    int uidField = 0;
-
-    AtomDecl();
-    AtomDecl(const AtomDecl& that);
-    AtomDecl(int code, const string& name, const string& message);
-    ~AtomDecl();
-
-    inline bool operator<(const AtomDecl& that) const {
-        return (code == that.code) ? (name < that.name) : (code < that.code);
-    }
-};
-
-using AtomDeclSet = set<shared_ptr<AtomDecl>, SharedComparator>;
-
-// Maps a field number to a set of atoms that have annotation(s) for their field with that field
-// number.
-using FieldNumberToAtomDeclSet = map<int, AtomDeclSet>;
-
-using SignatureInfoMap = map<vector<java_type_t>, FieldNumberToAtomDeclSet>;
-
-struct Atoms {
-    SignatureInfoMap signatureInfoMap;
-    AtomDeclSet decls;
-    AtomDeclSet non_chained_decls;
-    SignatureInfoMap nonChainedSignatureInfoMap;
-};
-
-/**
- * Gather the information about the atoms.  Returns the number of errors.
- */
-int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* atoms);
-int collate_atom(const Descriptor* atom, AtomDecl* atomDecl, vector<java_type_t>* signature);
-
-}  // namespace stats_log_api_gen
-}  // namespace android
-
-#endif  // ANDROID_STATS_LOG_API_GEN_COLLATION_H
diff --git a/tools/stats_log_api_gen/OWNERS b/tools/stats_log_api_gen/OWNERS
deleted file mode 100644
index 41a0c95..0000000
--- a/tools/stats_log_api_gen/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-yro@google.com
diff --git a/tools/stats_log_api_gen/java_writer.cpp b/tools/stats_log_api_gen/java_writer.cpp
deleted file mode 100644
index f4c937c..0000000
--- a/tools/stats_log_api_gen/java_writer.cpp
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "java_writer.h"
-
-#include "java_writer_q.h"
-#include "utils.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-static int write_java_q_logger_class(FILE* out, const SignatureInfoMap& signatureInfoMap,
-                                     const AtomDecl& attributionDecl) {
-    fprintf(out, "\n");
-    fprintf(out, "    // Write logging helper methods for statsd in Q and earlier.\n");
-    fprintf(out, "    private static class QLogger {\n");
-
-    write_java_q_logging_constants(out, "        ");
-
-    // Print Q write methods.
-    fprintf(out, "\n");
-    fprintf(out, "        // Write methods.\n");
-    write_java_methods_q_schema(out, signatureInfoMap, attributionDecl, "        ");
-
-    fprintf(out, "    }\n");
-    return 0;
-}
-
-static void write_java_annotation_constants(FILE* out) {
-    fprintf(out, "    // Annotation constants.\n");
-
-    for (const auto& [id, name] : ANNOTATION_ID_CONSTANTS) {
-        fprintf(out, "    public static final byte %s = %hhu;\n", name.c_str(), id);
-    }
-    fprintf(out, "\n");
-}
-
-static void write_annotations(FILE* out, int argIndex,
-                              const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet) {
-    FieldNumberToAtomDeclSet::const_iterator fieldNumberToAtomDeclSetIt =
-            fieldNumberToAtomDeclSet.find(argIndex);
-    if (fieldNumberToAtomDeclSet.end() == fieldNumberToAtomDeclSetIt) {
-        return;
-    }
-    const AtomDeclSet& atomDeclSet = fieldNumberToAtomDeclSetIt->second;
-    for (const shared_ptr<AtomDecl>& atomDecl : atomDeclSet) {
-        const string atomConstant = make_constant_name(atomDecl->name);
-        fprintf(out, "        if (%s == code) {\n", atomConstant.c_str());
-        const AnnotationSet& annotations = atomDecl->fieldNumberToAnnotations.at(argIndex);
-        int resetState = -1;
-        int defaultState = -1;
-        for (const shared_ptr<Annotation>& annotation : annotations) {
-            const string& annotationConstant = ANNOTATION_ID_CONSTANTS.at(annotation->annotationId);
-            switch (annotation->type) {
-                case ANNOTATION_TYPE_INT:
-                    if (ANNOTATION_ID_TRIGGER_STATE_RESET == annotation->annotationId) {
-                        resetState = annotation->value.intValue;
-                    } else if (ANNOTATION_ID_DEFAULT_STATE == annotation->annotationId) {
-                        defaultState = annotation->value.intValue;
-                    } else {
-                        fprintf(out, "            builder.addIntAnnotation(%s, %d);\n",
-                                annotationConstant.c_str(), annotation->value.intValue);
-                    }
-                    break;
-                case ANNOTATION_TYPE_BOOL:
-                    fprintf(out, "            builder.addBooleanAnnotation(%s, %s);\n",
-                            annotationConstant.c_str(),
-                            annotation->value.boolValue ? "true" : "false");
-                    break;
-                default:
-                    break;
-            }
-        }
-        if (defaultState != -1 && resetState != -1) {
-            const string& annotationConstant =
-                    ANNOTATION_ID_CONSTANTS.at(ANNOTATION_ID_TRIGGER_STATE_RESET);
-            fprintf(out, "            if (arg%d == %d) {\n", argIndex, resetState);
-            fprintf(out, "                builder.addIntAnnotation(%s, %d);\n",
-                    annotationConstant.c_str(), defaultState);
-            fprintf(out, "            }\n");
-        }
-        fprintf(out, "        }\n");
-    }
-}
-
-static int write_java_methods(FILE* out, const SignatureInfoMap& signatureInfoMap,
-                              const AtomDecl& attributionDecl, const bool supportQ) {
-    for (auto signatureInfoMapIt = signatureInfoMap.begin();
-         signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) {
-        // Print method signature.
-        fprintf(out, "    public static void write(int code");
-        const vector<java_type_t>& signature = signatureInfoMapIt->first;
-        const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = signatureInfoMapIt->second;
-        int argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                for (auto chainField : attributionDecl.fields) {
-                    fprintf(out, ", %s[] %s", java_type_name(chainField.javaType),
-                            chainField.name.c_str());
-                }
-            } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-                fprintf(out, ", android.util.SparseArray<Object> valueMap");
-            } else {
-                fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
-            }
-            argIndex++;
-        }
-        fprintf(out, ") {\n");
-
-        // Print method body.
-        string indent("");
-        if (supportQ) {
-            fprintf(out, "        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n");
-            indent = "    ";
-        }
-
-        // Start StatsEvent.Builder.
-        fprintf(out,
-                "%s        final StatsEvent.Builder builder = "
-                "StatsEvent.newBuilder();\n",
-                indent.c_str());
-
-        // Write atom code.
-        fprintf(out, "%s        builder.setAtomId(code);\n", indent.c_str());
-        write_annotations(out, ATOM_ID_FIELD_NUMBER, fieldNumberToAtomDeclSet);
-
-        // Write the args.
-        argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            switch (*arg) {
-                case JAVA_TYPE_BOOLEAN:
-                    fprintf(out, "%s        builder.writeBoolean(arg%d);\n", indent.c_str(),
-                            argIndex);
-                    break;
-                case JAVA_TYPE_INT:
-                case JAVA_TYPE_ENUM:
-                    fprintf(out, "%s        builder.writeInt(arg%d);\n", indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_FLOAT:
-                    fprintf(out, "%s        builder.writeFloat(arg%d);\n", indent.c_str(),
-                            argIndex);
-                    break;
-                case JAVA_TYPE_LONG:
-                    fprintf(out, "%s        builder.writeLong(arg%d);\n", indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_STRING:
-                    fprintf(out, "%s        builder.writeString(arg%d);\n", indent.c_str(),
-                            argIndex);
-                    break;
-                case JAVA_TYPE_BYTE_ARRAY:
-                    fprintf(out,
-                            "%s        builder.writeByteArray(null == arg%d ? new byte[0] : "
-                            "arg%d);\n",
-                            indent.c_str(), argIndex, argIndex);
-                    break;
-                case JAVA_TYPE_ATTRIBUTION_CHAIN: {
-                    const char* uidName = attributionDecl.fields.front().name.c_str();
-                    const char* tagName = attributionDecl.fields.back().name.c_str();
-
-                    fprintf(out, "%s        builder.writeAttributionChain(\n", indent.c_str());
-                    fprintf(out, "%s                null == %s ? new int[0] : %s,\n",
-                            indent.c_str(), uidName, uidName);
-                    fprintf(out, "%s                null == %s ? new String[0] : %s);\n",
-                            indent.c_str(), tagName, tagName);
-                    break;
-                }
-                case JAVA_TYPE_KEY_VALUE_PAIR:
-                    fprintf(out, "\n");
-                    fprintf(out, "%s        // Write KeyValuePairs.\n", indent.c_str());
-                    fprintf(out, "%s        final int count = valueMap.size();\n", indent.c_str());
-                    fprintf(out, "%s        android.util.SparseIntArray intMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s        android.util.SparseLongArray longMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s        android.util.SparseArray<String> stringMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s        android.util.SparseArray<Float> floatMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s        for (int i = 0; i < count; i++) {\n", indent.c_str());
-                    fprintf(out, "%s            final int key = valueMap.keyAt(i);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            final Object value = valueMap.valueAt(i);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            if (value instanceof Integer) {\n", indent.c_str());
-                    fprintf(out, "%s                if (null == intMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                    intMap = new "
-                            "android.util.SparseIntArray();\n",
-                            indent.c_str());
-                    fprintf(out, "%s                }\n", indent.c_str());
-                    fprintf(out, "%s                intMap.put(key, (Integer) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            } else if (value instanceof Long) {\n",
-                            indent.c_str());
-                    fprintf(out, "%s                if (null == longMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                    longMap = new "
-                            "android.util.SparseLongArray();\n",
-                            indent.c_str());
-                    fprintf(out, "%s                }\n", indent.c_str());
-                    fprintf(out, "%s                longMap.put(key, (Long) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            } else if (value instanceof String) {\n",
-                            indent.c_str());
-                    fprintf(out, "%s                if (null == stringMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                    stringMap = new "
-                            "android.util.SparseArray<>();\n",
-                            indent.c_str());
-                    fprintf(out, "%s                }\n", indent.c_str());
-                    fprintf(out, "%s                stringMap.put(key, (String) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            } else if (value instanceof Float) {\n",
-                            indent.c_str());
-                    fprintf(out, "%s                if (null == floatMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                    floatMap = new "
-                            "android.util.SparseArray<>();\n",
-                            indent.c_str());
-                    fprintf(out, "%s                }\n", indent.c_str());
-                    fprintf(out, "%s                floatMap.put(key, (Float) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s            }\n", indent.c_str());
-                    fprintf(out, "%s        }\n", indent.c_str());
-                    fprintf(out,
-                            "%s        builder.writeKeyValuePairs("
-                            "intMap, longMap, stringMap, floatMap);\n",
-                            indent.c_str());
-                    break;
-                default:
-                    // Unsupported types: OBJECT, DOUBLE.
-                    fprintf(stderr, "Encountered unsupported type.");
-                    return 1;
-            }
-            write_annotations(out, argIndex, fieldNumberToAtomDeclSet);
-            argIndex++;
-        }
-
-        fprintf(out, "\n");
-        fprintf(out, "%s        builder.usePooledBuffer();\n", indent.c_str());
-        fprintf(out, "%s        StatsLog.write(builder.build());\n", indent.c_str());
-
-        // Add support for writing using Q schema if this is not the default module.
-        if (supportQ) {
-            fprintf(out, "        } else {\n");
-            fprintf(out, "            QLogger.write(code");
-            argIndex = 1;
-            for (vector<java_type_t>::const_iterator arg = signature.begin();
-                 arg != signature.end(); arg++) {
-                if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                    const char* uidName = attributionDecl.fields.front().name.c_str();
-                    const char* tagName = attributionDecl.fields.back().name.c_str();
-                    fprintf(out, ", %s, %s", uidName, tagName);
-                } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-                    // Module logging does not yet support key value pair.
-                    fprintf(stderr, "Module logging does not yet support key value pair.\n");
-                    return 1;
-                } else {
-                    fprintf(out, ", arg%d", argIndex);
-                }
-                argIndex++;
-            }
-            fprintf(out, ");\n");
-            fprintf(out, "        }\n");  // if
-        }
-
-        fprintf(out, "    }\n");  // method
-        fprintf(out, "\n");
-    }
-    return 0;
-}
-
-int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                         const string& javaClass, const string& javaPackage, const bool supportQ,
-                         const bool supportWorkSource) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-    fprintf(out, "package %s;\n", javaPackage.c_str());
-    fprintf(out, "\n");
-    fprintf(out, "\n");
-    if (supportQ) {
-        fprintf(out, "import android.os.Build;\n");
-        fprintf(out, "import android.os.SystemClock;\n");
-    }
-
-    fprintf(out, "import android.util.StatsEvent;\n");
-    fprintf(out, "import android.util.StatsLog;\n");
-
-    fprintf(out, "\n");
-    fprintf(out, "\n");
-    fprintf(out, "/**\n");
-    fprintf(out, " * Utility class for logging statistics events.\n");
-    fprintf(out, " */\n");
-    fprintf(out, "public class %s {\n", javaClass.c_str());
-
-    write_java_atom_codes(out, atoms);
-    write_java_enum_values(out, atoms);
-    write_java_annotation_constants(out);
-
-    int errors = 0;
-
-    // Print write methods.
-    fprintf(out, "    // Write methods\n");
-    errors += write_java_methods(out, atoms.signatureInfoMap, attributionDecl, supportQ);
-    errors += write_java_non_chained_methods(out, atoms.nonChainedSignatureInfoMap);
-    if (supportWorkSource) {
-        errors += write_java_work_source_methods(out, atoms.signatureInfoMap);
-    }
-
-    if (supportQ) {
-        errors += write_java_q_logger_class(out, atoms.signatureInfoMap, attributionDecl);
-    }
-
-    fprintf(out, "}\n");
-
-    return errors;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/java_writer.h b/tools/stats_log_api_gen/java_writer.h
deleted file mode 100644
index 8b3b505..0000000
--- a/tools/stats_log_api_gen/java_writer.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "Collation.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using namespace std;
-
-int write_stats_log_java(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                         const string& javaClass, const string& javaPackage, const bool supportQ,
-                         const bool supportWorkSource);
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/java_writer_q.cpp b/tools/stats_log_api_gen/java_writer_q.cpp
deleted file mode 100644
index d21e270..0000000
--- a/tools/stats_log_api_gen/java_writer_q.cpp
+++ /dev/null
@@ -1,601 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "java_writer_q.h"
-
-#include "utils.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-void write_java_q_logging_constants(FILE* out, const string& indent) {
-    fprintf(out, "%s// Payload limits.\n", indent.c_str());
-    fprintf(out, "%sprivate static final int LOGGER_ENTRY_MAX_PAYLOAD = 4068;\n", indent.c_str());
-    fprintf(out,
-            "%sprivate static final int MAX_EVENT_PAYLOAD = "
-            "LOGGER_ENTRY_MAX_PAYLOAD - 4;\n",
-            indent.c_str());
-
-    // Value types. Must match with EventLog.java and log.h.
-    fprintf(out, "\n");
-    fprintf(out, "%s// Value types.\n", indent.c_str());
-    fprintf(out, "%sprivate static final byte INT_TYPE = 0;\n", indent.c_str());
-    fprintf(out, "%sprivate static final byte LONG_TYPE = 1;\n", indent.c_str());
-    fprintf(out, "%sprivate static final byte STRING_TYPE = 2;\n", indent.c_str());
-    fprintf(out, "%sprivate static final byte LIST_TYPE = 3;\n", indent.c_str());
-    fprintf(out, "%sprivate static final byte FLOAT_TYPE = 4;\n", indent.c_str());
-
-    // Size of each value type.
-    // Booleans, ints, floats, and enums take 5 bytes, 1 for the type and 4 for
-    // the value.
-    fprintf(out, "\n");
-    fprintf(out, "%s// Size of each value type.\n", indent.c_str());
-    fprintf(out, "%sprivate static final int INT_TYPE_SIZE = 5;\n", indent.c_str());
-    fprintf(out, "%sprivate static final int FLOAT_TYPE_SIZE = 5;\n", indent.c_str());
-    // Longs take 9 bytes, 1 for the type and 8 for the value.
-    fprintf(out, "%sprivate static final int LONG_TYPE_SIZE = 9;\n", indent.c_str());
-    // Strings take 5 metadata bytes: 1 byte is for the type, 4 are for the
-    // length.
-    fprintf(out, "%sprivate static final int STRING_TYPE_OVERHEAD = 5;\n", indent.c_str());
-    fprintf(out, "%sprivate static final int LIST_TYPE_OVERHEAD = 2;\n", indent.c_str());
-}
-
-int write_java_methods_q_schema(FILE* out, const SignatureInfoMap& signatureInfoMap,
-                                const AtomDecl& attributionDecl, const string& indent) {
-    int requiredHelpers = 0;
-    for (auto signatureInfoMapIt = signatureInfoMap.begin();
-         signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) {
-        // Print method signature.
-        vector<java_type_t> signature = signatureInfoMapIt->first;
-        fprintf(out, "%spublic static void write(int code", indent.c_str());
-        int argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                for (auto chainField : attributionDecl.fields) {
-                    fprintf(out, ", %s[] %s", java_type_name(chainField.javaType),
-                            chainField.name.c_str());
-                }
-            } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-                fprintf(out, ", android.util.SparseArray<Object> valueMap");
-            } else {
-                fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
-            }
-            argIndex++;
-        }
-        fprintf(out, ") {\n");
-
-        // Calculate the size of the buffer.
-        fprintf(out, "%s    // Initial overhead of the list, timestamp, and atom tag.\n",
-                indent.c_str());
-        fprintf(out,
-                "%s    int needed = LIST_TYPE_OVERHEAD + LONG_TYPE_SIZE + "
-                "INT_TYPE_SIZE;\n",
-                indent.c_str());
-        argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            switch (*arg) {
-                case JAVA_TYPE_BOOLEAN:
-                case JAVA_TYPE_INT:
-                case JAVA_TYPE_FLOAT:
-                case JAVA_TYPE_ENUM:
-                    fprintf(out, "%s    needed += INT_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_LONG:
-                    // Longs take 9 bytes, 1 for the type and 8 for the value.
-                    fprintf(out, "%s    needed += LONG_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_STRING:
-                    // Strings take 5 metadata bytes + length of byte encoded string.
-                    fprintf(out, "%s    if (arg%d == null) {\n", indent.c_str(), argIndex);
-                    fprintf(out, "%s        arg%d = \"\";\n", indent.c_str(), argIndex);
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out,
-                            "%s    byte[] arg%dBytes = "
-                            "arg%d.getBytes(java.nio.charset.StandardCharsets.UTF_8);\n",
-                            indent.c_str(), argIndex, argIndex);
-                    fprintf(out, "%s    needed += STRING_TYPE_OVERHEAD + arg%dBytes.length;\n",
-                            indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_BYTE_ARRAY:
-                    // Byte arrays take 5 metadata bytes + length of byte array.
-                    fprintf(out, "%s    if (arg%d == null) {\n", indent.c_str(), argIndex);
-                    fprintf(out, "%s        arg%d = new byte[0];\n", indent.c_str(), argIndex);
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out, "%s    needed += STRING_TYPE_OVERHEAD + arg%d.length;\n",
-                            indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_ATTRIBUTION_CHAIN: {
-                    const char* uidName = attributionDecl.fields.front().name.c_str();
-                    const char* tagName = attributionDecl.fields.back().name.c_str();
-                    // Null checks on the params.
-                    fprintf(out, "%s    if (%s == null) {\n", indent.c_str(), uidName);
-                    fprintf(out, "%s        %s = new %s[0];\n", indent.c_str(), uidName,
-                            java_type_name(attributionDecl.fields.front().javaType));
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out, "%s    if (%s == null) {\n", indent.c_str(), tagName);
-                    fprintf(out, "%s        %s = new %s[0];\n", indent.c_str(), tagName,
-                            java_type_name(attributionDecl.fields.back().javaType));
-                    fprintf(out, "%s    }\n", indent.c_str());
-
-                    // First check that the lengths of the uid and tag arrays are the
-                    // same.
-                    fprintf(out, "%s    if (%s.length != %s.length) {\n", indent.c_str(), uidName,
-                            tagName);
-                    fprintf(out, "%s        return;\n", indent.c_str());
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out, "%s    int attrSize = LIST_TYPE_OVERHEAD;\n", indent.c_str());
-                    fprintf(out, "%s    for (int i = 0; i < %s.length; i++) {\n", indent.c_str(),
-                            tagName);
-                    fprintf(out, "%s        String str%d = (%s[i] == null) ? \"\" : %s[i];\n",
-                            indent.c_str(), argIndex, tagName, tagName);
-                    fprintf(out,
-                            "%s        int str%dlen = "
-                            "str%d.getBytes(java.nio.charset.StandardCharsets.UTF_8)."
-                            "length;\n",
-                            indent.c_str(), argIndex, argIndex);
-                    fprintf(out,
-                            "%s        attrSize += "
-                            "LIST_TYPE_OVERHEAD + INT_TYPE_SIZE + STRING_TYPE_OVERHEAD + "
-                            "str%dlen;\n",
-                            indent.c_str(), argIndex);
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out, "%s    needed += attrSize;\n", indent.c_str());
-                    break;
-                }
-                case JAVA_TYPE_KEY_VALUE_PAIR: {
-                    fprintf(out, "%s    // Calculate bytes needed by Key Value Pairs.\n",
-                            indent.c_str());
-                    fprintf(out, "%s    final int count = valueMap.size();\n", indent.c_str());
-                    fprintf(out, "%s    android.util.SparseIntArray intMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s    android.util.SparseLongArray longMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s    android.util.SparseArray<String> stringMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s    android.util.SparseArray<Float> floatMap = null;\n",
-                            indent.c_str());
-                    fprintf(out, "%s    int keyValuePairSize = LIST_TYPE_OVERHEAD;\n",
-                            indent.c_str());
-                    fprintf(out, "%s    for (int i = 0; i < count; i++) {\n", indent.c_str());
-                    fprintf(out, "%s        final int key = valueMap.keyAt(i);\n", indent.c_str());
-                    fprintf(out, "%s        final Object value = valueMap.valueAt(i);\n",
-                            indent.c_str());
-                    fprintf(out, "%s        if (value instanceof Integer) {\n", indent.c_str());
-                    fprintf(out, "%s            keyValuePairSize += LIST_TYPE_OVERHEAD\n",
-                            indent.c_str());
-                    fprintf(out, "%s                    + INT_TYPE_SIZE + INT_TYPE_SIZE;\n",
-                            indent.c_str());
-                    fprintf(out, "%s            if (null == intMap) {\n", indent.c_str());
-                    fprintf(out, "%s                intMap = new android.util.SparseIntArray();\n",
-                            indent.c_str());
-                    fprintf(out, "%s            }\n", indent.c_str());
-                    fprintf(out, "%s            intMap.put(key, (Integer) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s        } else if (value instanceof Long) {\n", indent.c_str());
-                    fprintf(out, "%s            keyValuePairSize += LIST_TYPE_OVERHEAD\n",
-                            indent.c_str());
-                    fprintf(out, "%s                    + INT_TYPE_SIZE + LONG_TYPE_SIZE;\n",
-                            indent.c_str());
-                    fprintf(out, "%s            if (null == longMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                longMap = new "
-                            "android.util.SparseLongArray();\n",
-                            indent.c_str());
-                    fprintf(out, "%s            }\n", indent.c_str());
-                    fprintf(out, "%s            longMap.put(key, (Long) value);\n", indent.c_str());
-                    fprintf(out, "%s        } else if (value instanceof String) {\n",
-                            indent.c_str());
-                    fprintf(out,
-                            "%s            final String str = (value == null) ? \"\" : "
-                            "(String) value;\n",
-                            indent.c_str());
-                    fprintf(out,
-                            "%s            final int len = "
-                            "str.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;\n",
-                            indent.c_str());
-                    fprintf(out,
-                            "%s            keyValuePairSize += LIST_TYPE_OVERHEAD + "
-                            "INT_TYPE_SIZE\n",
-                            indent.c_str());
-                    fprintf(out, "%s                    + STRING_TYPE_OVERHEAD + len;\n",
-                            indent.c_str());
-                    fprintf(out, "%s            if (null == stringMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                stringMap = new "
-                            "android.util.SparseArray<>();\n",
-                            indent.c_str());
-                    fprintf(out, "%s            }\n", indent.c_str());
-                    fprintf(out, "%s            stringMap.put(key, str);\n", indent.c_str());
-                    fprintf(out, "%s        } else if (value instanceof Float) {\n",
-                            indent.c_str());
-                    fprintf(out, "%s            keyValuePairSize += LIST_TYPE_OVERHEAD\n",
-                            indent.c_str());
-                    fprintf(out, "%s                    + INT_TYPE_SIZE + FLOAT_TYPE_SIZE;\n",
-                            indent.c_str());
-                    fprintf(out, "%s            if (null == floatMap) {\n", indent.c_str());
-                    fprintf(out,
-                            "%s                floatMap = new "
-                            "android.util.SparseArray<>();\n",
-                            indent.c_str());
-                    fprintf(out, "%s            }\n", indent.c_str());
-                    fprintf(out, "%s            floatMap.put(key, (Float) value);\n",
-                            indent.c_str());
-                    fprintf(out, "%s        }\n", indent.c_str());
-                    fprintf(out, "%s    }\n", indent.c_str());
-                    fprintf(out, "%s    needed += keyValuePairSize;\n", indent.c_str());
-                    break;
-                }
-                default:
-                    // Unsupported types: OBJECT, DOUBLE.
-                    fprintf(stderr, "Module logging does not yet support Object and Double.\n");
-                    return 1;
-            }
-            argIndex++;
-        }
-
-        // Now we have the size that is needed. Check for overflow and return if
-        // needed.
-        fprintf(out, "%s    if (needed > MAX_EVENT_PAYLOAD) {\n", indent.c_str());
-        fprintf(out, "%s        return;\n", indent.c_str());
-        fprintf(out, "%s    }\n", indent.c_str());
-
-        // Create new buffer, and associated data types.
-        fprintf(out, "%s    byte[] buff = new byte[needed];\n", indent.c_str());
-        fprintf(out, "%s    int pos = 0;\n", indent.c_str());
-
-        // Initialize the buffer with list data type.
-        fprintf(out, "%s    buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s    buff[pos + 1] = %zu;\n", indent.c_str(), signature.size() + 2);
-        fprintf(out, "%s    pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-
-        // Write timestamp.
-        fprintf(out, "%s    long elapsedRealtime = SystemClock.elapsedRealtimeNanos();\n",
-                indent.c_str());
-        fprintf(out, "%s    buff[pos] = LONG_TYPE;\n", indent.c_str());
-        fprintf(out, "%s    copyLong(buff, pos + 1, elapsedRealtime);\n", indent.c_str());
-        fprintf(out, "%s    pos += LONG_TYPE_SIZE;\n", indent.c_str());
-
-        // Write atom code.
-        fprintf(out, "%s    buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s    copyInt(buff, pos + 1, code);\n", indent.c_str());
-        fprintf(out, "%s    pos += INT_TYPE_SIZE;\n", indent.c_str());
-
-        // Write the args.
-        argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            switch (*arg) {
-                case JAVA_TYPE_BOOLEAN:
-                    fprintf(out, "%s    buff[pos] = INT_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyInt(buff, pos + 1, arg%d? 1 : 0);\n", indent.c_str(),
-                            argIndex);
-                    fprintf(out, "%s    pos += INT_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_INT:
-                case JAVA_TYPE_ENUM:
-                    fprintf(out, "%s    buff[pos] = INT_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyInt(buff, pos + 1, arg%d);\n", indent.c_str(),
-                            argIndex);
-                    fprintf(out, "%s    pos += INT_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_FLOAT:
-                    requiredHelpers |= JAVA_MODULE_REQUIRES_FLOAT;
-                    fprintf(out, "%s    buff[pos] = FLOAT_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyFloat(buff, pos + 1, arg%d);\n", indent.c_str(),
-                            argIndex);
-                    fprintf(out, "%s    pos += FLOAT_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_LONG:
-                    fprintf(out, "%s    buff[pos] = LONG_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyLong(buff, pos + 1, arg%d);\n", indent.c_str(),
-                            argIndex);
-                    fprintf(out, "%s    pos += LONG_TYPE_SIZE;\n", indent.c_str());
-                    break;
-                case JAVA_TYPE_STRING:
-                    fprintf(out, "%s    buff[pos] = STRING_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyInt(buff, pos + 1, arg%dBytes.length);\n",
-                            indent.c_str(), argIndex);
-                    fprintf(out,
-                            "%s    System.arraycopy("
-                            "arg%dBytes, 0, buff, pos + STRING_TYPE_OVERHEAD, "
-                            "arg%dBytes.length);\n",
-                            indent.c_str(), argIndex, argIndex);
-                    fprintf(out, "%s    pos += STRING_TYPE_OVERHEAD + arg%dBytes.length;\n",
-                            indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_BYTE_ARRAY:
-                    fprintf(out, "%s    buff[pos] = STRING_TYPE;\n", indent.c_str());
-                    fprintf(out, "%s    copyInt(buff, pos + 1, arg%d.length);\n", indent.c_str(),
-                            argIndex);
-                    fprintf(out,
-                            "%s    System.arraycopy("
-                            "arg%d, 0, buff, pos + STRING_TYPE_OVERHEAD, arg%d.length);\n",
-                            indent.c_str(), argIndex, argIndex);
-                    fprintf(out, "%s    pos += STRING_TYPE_OVERHEAD + arg%d.length;\n",
-                            indent.c_str(), argIndex);
-                    break;
-                case JAVA_TYPE_ATTRIBUTION_CHAIN: {
-                    requiredHelpers |= JAVA_MODULE_REQUIRES_ATTRIBUTION;
-                    const char* uidName = attributionDecl.fields.front().name.c_str();
-                    const char* tagName = attributionDecl.fields.back().name.c_str();
-
-                    fprintf(out, "%s    writeAttributionChain(buff, pos, %s, %s);\n",
-                            indent.c_str(), uidName, tagName);
-                    fprintf(out, "%s    pos += attrSize;\n", indent.c_str());
-                    break;
-                }
-                case JAVA_TYPE_KEY_VALUE_PAIR:
-                    requiredHelpers |= JAVA_MODULE_REQUIRES_FLOAT;
-                    requiredHelpers |= JAVA_MODULE_REQUIRES_KEY_VALUE_PAIRS;
-                    fprintf(out,
-                            "%s    writeKeyValuePairs(buff, pos, (byte) count, intMap, "
-                            "longMap, "
-                            "stringMap, floatMap);\n",
-                            indent.c_str());
-                    fprintf(out, "%s    pos += keyValuePairSize;\n", indent.c_str());
-                    break;
-                default:
-                    // Unsupported types: OBJECT, DOUBLE.
-                    fprintf(stderr, "Object and Double are not supported in module logging");
-                    return 1;
-            }
-            argIndex++;
-        }
-
-        fprintf(out, "%s    StatsLog.writeRaw(buff, pos);\n", indent.c_str());
-        fprintf(out, "%s}\n", indent.c_str());
-        fprintf(out, "\n");
-    }
-
-    write_java_helpers_for_q_schema_methods(out, attributionDecl, requiredHelpers, indent);
-
-    return 0;
-}
-
-void write_java_helpers_for_q_schema_methods(FILE* out, const AtomDecl& attributionDecl,
-                                             const int requiredHelpers, const string& indent) {
-    fprintf(out, "\n");
-    fprintf(out, "%s// Helper methods for copying primitives\n", indent.c_str());
-    fprintf(out, "%sprivate static void copyInt(byte[] buff, int pos, int val) {\n",
-            indent.c_str());
-    fprintf(out, "%s    buff[pos] = (byte) (val);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 1] = (byte) (val >> 8);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 2] = (byte) (val >> 16);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 3] = (byte) (val >> 24);\n", indent.c_str());
-    fprintf(out, "%s    return;\n", indent.c_str());
-    fprintf(out, "%s}\n", indent.c_str());
-    fprintf(out, "\n");
-
-    fprintf(out, "%sprivate static void copyLong(byte[] buff, int pos, long val) {\n",
-            indent.c_str());
-    fprintf(out, "%s    buff[pos] = (byte) (val);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 1] = (byte) (val >> 8);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 2] = (byte) (val >> 16);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 3] = (byte) (val >> 24);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 4] = (byte) (val >> 32);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 5] = (byte) (val >> 40);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 6] = (byte) (val >> 48);\n", indent.c_str());
-    fprintf(out, "%s    buff[pos + 7] = (byte) (val >> 56);\n", indent.c_str());
-    fprintf(out, "%s    return;\n", indent.c_str());
-    fprintf(out, "%s}\n", indent.c_str());
-    fprintf(out, "\n");
-
-    if (requiredHelpers & JAVA_MODULE_REQUIRES_FLOAT) {
-        fprintf(out, "%sprivate static void copyFloat(byte[] buff, int pos, float val) {\n",
-                indent.c_str());
-        fprintf(out, "%s    copyInt(buff, pos, Float.floatToIntBits(val));\n", indent.c_str());
-        fprintf(out, "%s    return;\n", indent.c_str());
-        fprintf(out, "%s}\n", indent.c_str());
-        fprintf(out, "\n");
-    }
-
-    if (requiredHelpers & JAVA_MODULE_REQUIRES_ATTRIBUTION) {
-        fprintf(out, "%sprivate static void writeAttributionChain(byte[] buff, int pos",
-                indent.c_str());
-        for (auto chainField : attributionDecl.fields) {
-            fprintf(out, ", %s[] %s", java_type_name(chainField.javaType), chainField.name.c_str());
-        }
-        fprintf(out, ") {\n");
-
-        const char* uidName = attributionDecl.fields.front().name.c_str();
-        const char* tagName = attributionDecl.fields.back().name.c_str();
-
-        // Write the first list begin.
-        fprintf(out, "%s    buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s    buff[pos + 1] = (byte) (%s.length);\n", indent.c_str(), tagName);
-        fprintf(out, "%s    pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-
-        // Iterate through the attribution chain and write the nodes.
-        fprintf(out, "%s    for (int i = 0; i < %s.length; i++) {\n", indent.c_str(), tagName);
-        // Write the list begin.
-        fprintf(out, "%s        buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos + 1] = %lu;\n", indent.c_str(),
-                attributionDecl.fields.size());
-        fprintf(out, "%s        pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-
-        // Write the uid.
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, %s[i]);\n", indent.c_str(), uidName);
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-
-        // Write the tag.
-        fprintf(out, "%s        String %sStr = (%s[i] == null) ? \"\" : %s[i];\n", indent.c_str(),
-                tagName, tagName, tagName);
-        fprintf(out,
-                "%s        byte[] %sByte = "
-                "%sStr.getBytes(java.nio.charset.StandardCharsets.UTF_8);\n",
-                indent.c_str(), tagName, tagName);
-        fprintf(out, "%s        buff[pos] = STRING_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, %sByte.length);\n", indent.c_str(), tagName);
-        fprintf(out,
-                "%s        System.arraycopy("
-                "%sByte, 0, buff, pos + STRING_TYPE_OVERHEAD, %sByte.length);\n",
-                indent.c_str(), tagName, tagName);
-        fprintf(out, "%s        pos += STRING_TYPE_OVERHEAD + %sByte.length;\n", indent.c_str(),
-                tagName);
-        fprintf(out, "%s    }\n", indent.c_str());
-        fprintf(out, "%s}\n", indent.c_str());
-        fprintf(out, "\n");
-    }
-
-    if (requiredHelpers & JAVA_MODULE_REQUIRES_KEY_VALUE_PAIRS) {
-        fprintf(out,
-                "%sprivate static void writeKeyValuePairs(byte[] buff, int pos, "
-                "byte numPairs,\n",
-                indent.c_str());
-        fprintf(out, "%s        final android.util.SparseIntArray intMap,\n", indent.c_str());
-        fprintf(out, "%s        final android.util.SparseLongArray longMap,\n", indent.c_str());
-        fprintf(out, "%s        final android.util.SparseArray<String> stringMap,\n",
-                indent.c_str());
-        fprintf(out, "%s        final android.util.SparseArray<Float> floatMap) {\n",
-                indent.c_str());
-
-        // Start list of lists.
-        fprintf(out, "%s    buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s    buff[pos + 1] = (byte) numPairs;\n", indent.c_str());
-        fprintf(out, "%s    pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-
-        // Write integers.
-        fprintf(out, "%s    final int intMapSize = null == intMap ? 0 : intMap.size();\n",
-                indent.c_str());
-        fprintf(out, "%s    for (int i = 0; i < intMapSize; i++) {\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos + 1] = (byte) 2;\n", indent.c_str());
-        fprintf(out, "%s        pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-        fprintf(out, "%s        final int key = intMap.keyAt(i);\n", indent.c_str());
-        fprintf(out, "%s        final int value = intMap.valueAt(i);\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, key);\n", indent.c_str());
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, value);\n", indent.c_str());
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s    }\n", indent.c_str());
-
-        // Write longs.
-        fprintf(out, "%s    final int longMapSize = null == longMap ? 0 : longMap.size();\n",
-                indent.c_str());
-        fprintf(out, "%s    for (int i = 0; i < longMapSize; i++) {\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos + 1] = (byte) 2;\n", indent.c_str());
-        fprintf(out, "%s        pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-        fprintf(out, "%s        final int key = longMap.keyAt(i);\n", indent.c_str());
-        fprintf(out, "%s        final long value = longMap.valueAt(i);\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, key);\n", indent.c_str());
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = LONG_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyLong(buff, pos + 1, value);\n", indent.c_str());
-        fprintf(out, "%s        pos += LONG_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s    }\n", indent.c_str());
-
-        // Write Strings.
-        fprintf(out,
-                "%s    final int stringMapSize = null == stringMap ? 0 : "
-                "stringMap.size();\n",
-                indent.c_str());
-        fprintf(out, "%s    for (int i = 0; i < stringMapSize; i++) {\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos + 1] = (byte) 2;\n", indent.c_str());
-        fprintf(out, "%s        pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-        fprintf(out, "%s        final int key = stringMap.keyAt(i);\n", indent.c_str());
-        fprintf(out, "%s        final String value = stringMap.valueAt(i);\n", indent.c_str());
-        fprintf(out,
-                "%s        final byte[] valueBytes = "
-                "value.getBytes(java.nio.charset.StandardCharsets.UTF_8);\n",
-                indent.c_str());
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, key);\n", indent.c_str());
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = STRING_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, valueBytes.length);\n", indent.c_str());
-        fprintf(out,
-                "%s        System.arraycopy("
-                "valueBytes, 0, buff, pos + STRING_TYPE_OVERHEAD, "
-                "valueBytes.length);\n",
-                indent.c_str());
-        fprintf(out, "%s        pos += STRING_TYPE_OVERHEAD + valueBytes.length;\n",
-                indent.c_str());
-        fprintf(out, "%s    }\n", indent.c_str());
-
-        // Write floats.
-        fprintf(out,
-                "%s    final int floatMapSize = null == floatMap ? 0 : "
-                "floatMap.size();\n",
-                indent.c_str());
-        fprintf(out, "%s    for (int i = 0; i < floatMapSize; i++) {\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = LIST_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos + 1] = (byte) 2;\n", indent.c_str());
-        fprintf(out, "%s        pos += LIST_TYPE_OVERHEAD;\n", indent.c_str());
-        fprintf(out, "%s        final int key = floatMap.keyAt(i);\n", indent.c_str());
-        fprintf(out, "%s        final float value = floatMap.valueAt(i);\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = INT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyInt(buff, pos + 1, key);\n", indent.c_str());
-        fprintf(out, "%s        pos += INT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s        buff[pos] = FLOAT_TYPE;\n", indent.c_str());
-        fprintf(out, "%s        copyFloat(buff, pos + 1, value);\n", indent.c_str());
-        fprintf(out, "%s        pos += FLOAT_TYPE_SIZE;\n", indent.c_str());
-        fprintf(out, "%s    }\n", indent.c_str());
-        fprintf(out, "%s}\n", indent.c_str());
-        fprintf(out, "\n");
-    }
-}
-
-// This method is called in main.cpp to generate StatsLog for modules that's
-// compatible with Q at compile-time.
-int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
-                                      const AtomDecl& attributionDecl, const string& javaClass,
-                                      const string& javaPackage, const bool supportWorkSource) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-    fprintf(out, "package %s;\n", javaPackage.c_str());
-    fprintf(out, "\n");
-    fprintf(out, "import static java.nio.charset.StandardCharsets.UTF_8;\n");
-    fprintf(out, "\n");
-    fprintf(out, "import android.util.StatsLog;\n");
-    fprintf(out, "import android.os.SystemClock;\n");
-    fprintf(out, "\n");
-    fprintf(out, "\n");
-    fprintf(out, "/**\n");
-    fprintf(out, " * Utility class for logging statistics events.\n");
-    fprintf(out, " */\n");
-    fprintf(out, "public class %s {\n", javaClass.c_str());
-
-    write_java_q_logging_constants(out, "    ");
-
-    write_java_atom_codes(out, atoms);
-
-    write_java_enum_values(out, atoms);
-
-    int errors = 0;
-    // Print write methods
-    fprintf(out, "    // Write methods\n");
-    errors += write_java_methods_q_schema(out, atoms.signatureInfoMap, attributionDecl, "    ");
-    errors += write_java_non_chained_methods(out, atoms.nonChainedSignatureInfoMap);
-    if (supportWorkSource) {
-        errors += write_java_work_source_methods(out, atoms.signatureInfoMap);
-    }
-
-    fprintf(out, "}\n");
-
-    return errors;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/java_writer_q.h b/tools/stats_log_api_gen/java_writer_q.h
deleted file mode 100644
index c511a84..0000000
--- a/tools/stats_log_api_gen/java_writer_q.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "Collation.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using namespace std;
-
-void write_java_q_logging_constants(FILE* out, const string& indent);
-
-int write_java_methods_q_schema(FILE* out, const SignatureInfoMap& signatureInfoMap,
-                                const AtomDecl& attributionDecl, const string& indent);
-
-void write_java_helpers_for_q_schema_methods(FILE* out, const AtomDecl& attributionDecl,
-                                             const int requiredHelpers, const string& indent);
-
-int write_stats_log_java_q_for_module(FILE* out, const Atoms& atoms,
-                                      const AtomDecl& attributionDecl, const string& javaClass,
-                                      const string& javaPackage, const bool supportWorkSource);
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp
deleted file mode 100644
index 416dfdd..0000000
--- a/tools/stats_log_api_gen/main.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-
-#include <getopt.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "Collation.h"
-#include "frameworks/proto_logging/stats/atoms.pb.h"
-#include "java_writer.h"
-#include "java_writer_q.h"
-#include "native_writer.h"
-#include "utils.h"
-
-using namespace google::protobuf;
-using namespace std;
-
-namespace android {
-namespace stats_log_api_gen {
-
-using android::os::statsd::Atom;
-
-static void print_usage() {
-    fprintf(stderr, "usage: stats-log-api-gen OPTIONS\n");
-    fprintf(stderr, "\n");
-    fprintf(stderr, "OPTIONS\n");
-    fprintf(stderr, "  --cpp FILENAME       the header file to output for write helpers\n");
-    fprintf(stderr, "  --header FILENAME    the cpp file to output for write helpers\n");
-    fprintf(stderr, "  --help               this message\n");
-    fprintf(stderr, "  --java FILENAME      the java file to output\n");
-    fprintf(stderr, "  --module NAME        optional, module name to generate outputs for\n");
-    fprintf(stderr,
-            "  --namespace COMMA,SEP,NAMESPACE   required for cpp/header with "
-            "module\n");
-    fprintf(stderr,
-            "                                    comma separated namespace of "
-            "the files\n");
-    fprintf(stderr,
-            "  --importHeader NAME  required for cpp/jni to say which header to "
-            "import "
-            "for write helpers\n");
-    fprintf(stderr, "  --javaPackage PACKAGE             the package for the java file.\n");
-    fprintf(stderr, "                                    required for java with module\n");
-    fprintf(stderr, "  --javaClass CLASS    the class name of the java class.\n");
-    fprintf(stderr, "                       Optional for Java with module.\n");
-    fprintf(stderr, "                       Default is \"StatsLogInternal\"\n");
-    fprintf(stderr, "  --supportQ           Include runtime support for Android Q.\n");
-    fprintf(stderr,
-            "  --worksource         Include support for logging WorkSource "
-            "objects.\n");
-    fprintf(stderr,
-            "  --compileQ           Include compile-time support for Android Q "
-            "(Java only).\n");
-}
-
-/**
- * Do the argument parsing and execute the tasks.
- */
-static int run(int argc, char const* const* argv) {
-    string cppFilename;
-    string headerFilename;
-    string javaFilename;
-    string javaPackage;
-    string javaClass;
-
-    string moduleName = DEFAULT_MODULE_NAME;
-    string cppNamespace = DEFAULT_CPP_NAMESPACE;
-    string cppHeaderImport = DEFAULT_CPP_HEADER_IMPORT;
-    bool supportQ = false;
-    bool supportWorkSource = false;
-    bool compileQ = false;
-
-    int index = 1;
-    while (index < argc) {
-        if (0 == strcmp("--help", argv[index])) {
-            print_usage();
-            return 0;
-        } else if (0 == strcmp("--cpp", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            cppFilename = argv[index];
-        } else if (0 == strcmp("--header", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            headerFilename = argv[index];
-        } else if (0 == strcmp("--java", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            javaFilename = argv[index];
-        } else if (0 == strcmp("--module", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            moduleName = argv[index];
-        } else if (0 == strcmp("--namespace", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            cppNamespace = argv[index];
-        } else if (0 == strcmp("--importHeader", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            cppHeaderImport = argv[index];
-        } else if (0 == strcmp("--javaPackage", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            javaPackage = argv[index];
-        } else if (0 == strcmp("--javaClass", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            javaClass = argv[index];
-        } else if (0 == strcmp("--supportQ", argv[index])) {
-            supportQ = true;
-        } else if (0 == strcmp("--worksource", argv[index])) {
-            supportWorkSource = true;
-        } else if (0 == strcmp("--compileQ", argv[index])) {
-            compileQ = true;
-        }
-
-        index++;
-    }
-
-    if (cppFilename.size() == 0 && headerFilename.size() == 0 && javaFilename.size() == 0) {
-        print_usage();
-        return 1;
-    }
-
-    if (DEFAULT_MODULE_NAME == moduleName && (supportQ || compileQ)) {
-        // Support for Q schema is not needed for default module.
-        fprintf(stderr, "%s cannot support Q schema\n", moduleName.c_str());
-        return 1;
-    }
-
-    if (supportQ && compileQ) {
-        // Runtime Q support is redundant if compile-time Q support is required.
-        fprintf(stderr, "Cannot specify compileQ and supportQ simultaneously.\n");
-        return 1;
-    }
-
-    // Collate the parameters
-    Atoms atoms;
-    int errorCount = collate_atoms(Atom::descriptor(), moduleName, &atoms);
-    if (errorCount != 0) {
-        return 1;
-    }
-
-    AtomDecl attributionDecl;
-    vector<java_type_t> attributionSignature;
-    collate_atom(android::os::statsd::AttributionNode::descriptor(), &attributionDecl,
-                 &attributionSignature);
-
-    // Write the .cpp file
-    if (cppFilename.size() != 0) {
-        FILE* out = fopen(cppFilename.c_str(), "w");
-        if (out == NULL) {
-            fprintf(stderr, "Unable to open file for write: %s\n", cppFilename.c_str());
-            return 1;
-        }
-        // If this is for a specific module, the namespace must also be provided.
-        if (moduleName != DEFAULT_MODULE_NAME && cppNamespace == DEFAULT_CPP_NAMESPACE) {
-            fprintf(stderr, "Must supply --namespace if supplying a specific module\n");
-            return 1;
-        }
-        // If this is for a specific module, the header file to import must also be
-        // provided.
-        if (moduleName != DEFAULT_MODULE_NAME && cppHeaderImport == DEFAULT_CPP_HEADER_IMPORT) {
-            fprintf(stderr, "Must supply --headerImport if supplying a specific module\n");
-            return 1;
-        }
-        errorCount = android::stats_log_api_gen::write_stats_log_cpp(
-                out, atoms, attributionDecl, cppNamespace, cppHeaderImport, supportQ);
-        fclose(out);
-    }
-
-    // Write the .h file
-    if (headerFilename.size() != 0) {
-        FILE* out = fopen(headerFilename.c_str(), "w");
-        if (out == NULL) {
-            fprintf(stderr, "Unable to open file for write: %s\n", headerFilename.c_str());
-            return 1;
-        }
-        // If this is for a specific module, the namespace must also be provided.
-        if (moduleName != DEFAULT_MODULE_NAME && cppNamespace == DEFAULT_CPP_NAMESPACE) {
-            fprintf(stderr, "Must supply --namespace if supplying a specific module\n");
-        }
-        errorCount = android::stats_log_api_gen::write_stats_log_header(out, atoms, attributionDecl,
-                                                                        cppNamespace);
-        fclose(out);
-    }
-
-    // Write the .java file
-    if (javaFilename.size() != 0) {
-        if (javaClass.size() == 0) {
-            fprintf(stderr, "Must supply --javaClass if supplying a Java filename");
-            return 1;
-        }
-
-        if (javaPackage.size() == 0) {
-            fprintf(stderr, "Must supply --javaPackage if supplying a Java filename");
-            return 1;
-        }
-
-        if (moduleName.size() == 0) {
-            fprintf(stderr, "Must supply --module if supplying a Java filename");
-            return 1;
-        }
-
-        FILE* out = fopen(javaFilename.c_str(), "w");
-        if (out == NULL) {
-            fprintf(stderr, "Unable to open file for write: %s\n", javaFilename.c_str());
-            return 1;
-        }
-
-        if (compileQ) {
-            errorCount = android::stats_log_api_gen::write_stats_log_java_q_for_module(
-                    out, atoms, attributionDecl, javaClass, javaPackage, supportWorkSource);
-        } else {
-            errorCount = android::stats_log_api_gen::write_stats_log_java(
-                    out, atoms, attributionDecl, javaClass, javaPackage, supportQ,
-                    supportWorkSource);
-        }
-
-        fclose(out);
-    }
-
-    return errorCount;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
-
-/**
- * Main.
- */
-int main(int argc, char const* const* argv) {
-    GOOGLE_PROTOBUF_VERIFY_VERSION;
-
-    return android::stats_log_api_gen::run(argc, argv);
-}
diff --git a/tools/stats_log_api_gen/native_writer.cpp b/tools/stats_log_api_gen/native_writer.cpp
deleted file mode 100644
index 0c6c009..0000000
--- a/tools/stats_log_api_gen/native_writer.cpp
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "native_writer.h"
-
-#include "utils.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-static void write_native_annotation_constants(FILE* out) {
-    fprintf(out, "// Annotation constants.\n");
-
-    for (const auto& [id, name] : ANNOTATION_ID_CONSTANTS) {
-        fprintf(out, "const uint8_t %s = %hhu;\n", name.c_str(), id);
-    }
-    fprintf(out, "\n");
-}
-
-static void write_annotations(FILE* out, int argIndex,
-                              const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet,
-                              const string& methodPrefix, const string& methodSuffix) {
-    FieldNumberToAtomDeclSet::const_iterator fieldNumberToAtomDeclSetIt =
-            fieldNumberToAtomDeclSet.find(argIndex);
-    if (fieldNumberToAtomDeclSet.end() == fieldNumberToAtomDeclSetIt) {
-        return;
-    }
-    const AtomDeclSet& atomDeclSet = fieldNumberToAtomDeclSetIt->second;
-    for (const shared_ptr<AtomDecl>& atomDecl : atomDeclSet) {
-        const string atomConstant = make_constant_name(atomDecl->name);
-        fprintf(out, "    if (%s == code) {\n", atomConstant.c_str());
-        const AnnotationSet& annotations = atomDecl->fieldNumberToAnnotations.at(argIndex);
-        int resetState = -1;
-        int defaultState = -1;
-        for (const shared_ptr<Annotation>& annotation : annotations) {
-            const string& annotationConstant = ANNOTATION_ID_CONSTANTS.at(annotation->annotationId);
-            switch (annotation->type) {
-                case ANNOTATION_TYPE_INT:
-                    if (ANNOTATION_ID_TRIGGER_STATE_RESET == annotation->annotationId) {
-                        resetState = annotation->value.intValue;
-                    } else if (ANNOTATION_ID_DEFAULT_STATE == annotation->annotationId) {
-                        defaultState = annotation->value.intValue;
-                    } else {
-                        fprintf(out, "        %saddInt32Annotation(%s%s, %d);\n",
-                                methodPrefix.c_str(), methodSuffix.c_str(),
-                                annotationConstant.c_str(), annotation->value.intValue);
-                    }
-                    break;
-                case ANNOTATION_TYPE_BOOL:
-                    // TODO(b/151786433): Write annotation constant name instead of
-                    // annotation id literal.
-                    fprintf(out, "        %saddBoolAnnotation(%s%s, %s);\n", methodPrefix.c_str(),
-                            methodSuffix.c_str(), annotationConstant.c_str(),
-                            annotation->value.boolValue ? "true" : "false");
-                    break;
-                default:
-                    break;
-            }
-        }
-        if (defaultState != -1 && resetState != -1) {
-            const string& annotationConstant =
-                    ANNOTATION_ID_CONSTANTS.at(ANNOTATION_ID_TRIGGER_STATE_RESET);
-            fprintf(out, "        if (arg%d == %d) {\n", argIndex, resetState);
-            fprintf(out, "            %saddInt32Annotation(%s%s, %d);\n", methodPrefix.c_str(),
-                    methodSuffix.c_str(), annotationConstant.c_str(), defaultState);
-            fprintf(out, "        }\n");
-        }
-        fprintf(out, "    }\n");
-    }
-}
-
-static int write_native_stats_write_methods(FILE* out, const Atoms& atoms,
-                                            const AtomDecl& attributionDecl, const bool supportQ) {
-    fprintf(out, "\n");
-    for (auto signatureInfoMapIt = atoms.signatureInfoMap.begin();
-         signatureInfoMapIt != atoms.signatureInfoMap.end(); signatureInfoMapIt++) {
-        vector<java_type_t> signature = signatureInfoMapIt->first;
-        const FieldNumberToAtomDeclSet& fieldNumberToAtomDeclSet = signatureInfoMapIt->second;
-        // Key value pairs not supported in native.
-        if (find(signature.begin(), signature.end(), JAVA_TYPE_KEY_VALUE_PAIR) != signature.end()) {
-            continue;
-        }
-        write_native_method_signature(out, "int stats_write", signature, attributionDecl, " {");
-
-        int argIndex = 1;
-        if (supportQ) {
-            fprintf(out, "    StatsEventCompat event;\n");
-            fprintf(out, "    event.setAtomId(code);\n");
-            write_annotations(out, ATOM_ID_FIELD_NUMBER, fieldNumberToAtomDeclSet, "event.", "");
-            for (vector<java_type_t>::const_iterator arg = signature.begin();
-                 arg != signature.end(); arg++) {
-                switch (*arg) {
-                    case JAVA_TYPE_ATTRIBUTION_CHAIN: {
-                        const char* uidName = attributionDecl.fields.front().name.c_str();
-                        const char* tagName = attributionDecl.fields.back().name.c_str();
-                        fprintf(out, "    event.writeAttributionChain(%s, %s_length, %s);\n",
-                                uidName, uidName, tagName);
-                        break;
-                    }
-                    case JAVA_TYPE_BYTE_ARRAY:
-                        fprintf(out, "    event.writeByteArray(arg%d.arg, arg%d.arg_length);\n",
-                                argIndex, argIndex);
-                        break;
-                    case JAVA_TYPE_BOOLEAN:
-                        fprintf(out, "    event.writeBool(arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_INT:  // Fall through.
-                    case JAVA_TYPE_ENUM:
-                        fprintf(out, "    event.writeInt32(arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_FLOAT:
-                        fprintf(out, "    event.writeFloat(arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_LONG:
-                        fprintf(out, "    event.writeInt64(arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_STRING:
-                        fprintf(out, "    event.writeString(arg%d);\n", argIndex);
-                        break;
-                    default:
-                        // Unsupported types: OBJECT, DOUBLE, KEY_VALUE_PAIRS.
-                        fprintf(stderr, "Encountered unsupported type.");
-                        return 1;
-                }
-                write_annotations(out, argIndex, fieldNumberToAtomDeclSet, "event.", "");
-                argIndex++;
-            }
-            fprintf(out, "    return event.writeToSocket();\n");
-        } else {
-            fprintf(out, "    AStatsEvent* event = AStatsEvent_obtain();\n");
-            fprintf(out, "    AStatsEvent_setAtomId(event, code);\n");
-            write_annotations(out, ATOM_ID_FIELD_NUMBER, fieldNumberToAtomDeclSet, "AStatsEvent_",
-                              "event, ");
-            for (vector<java_type_t>::const_iterator arg = signature.begin();
-                 arg != signature.end(); arg++) {
-                switch (*arg) {
-                    case JAVA_TYPE_ATTRIBUTION_CHAIN: {
-                        const char* uidName = attributionDecl.fields.front().name.c_str();
-                        const char* tagName = attributionDecl.fields.back().name.c_str();
-                        fprintf(out,
-                                "    AStatsEvent_writeAttributionChain(event, "
-                                "reinterpret_cast<const uint32_t*>(%s), %s.data(), "
-                                "static_cast<uint8_t>(%s_length));\n",
-                                uidName, tagName, uidName);
-                        break;
-                    }
-                    case JAVA_TYPE_BYTE_ARRAY:
-                        fprintf(out,
-                                "    AStatsEvent_writeByteArray(event, "
-                                "reinterpret_cast<const uint8_t*>(arg%d.arg), "
-                                "arg%d.arg_length);\n",
-                                argIndex, argIndex);
-                        break;
-                    case JAVA_TYPE_BOOLEAN:
-                        fprintf(out, "    AStatsEvent_writeBool(event, arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_INT:  // Fall through.
-                    case JAVA_TYPE_ENUM:
-                        fprintf(out, "    AStatsEvent_writeInt32(event, arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_FLOAT:
-                        fprintf(out, "    AStatsEvent_writeFloat(event, arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_LONG:
-                        fprintf(out, "    AStatsEvent_writeInt64(event, arg%d);\n", argIndex);
-                        break;
-                    case JAVA_TYPE_STRING:
-                        fprintf(out, "    AStatsEvent_writeString(event, arg%d);\n", argIndex);
-                        break;
-                    default:
-                        // Unsupported types: OBJECT, DOUBLE, KEY_VALUE_PAIRS
-                        fprintf(stderr, "Encountered unsupported type.");
-                        return 1;
-                }
-                write_annotations(out, argIndex, fieldNumberToAtomDeclSet, "AStatsEvent_",
-                                  "event, ");
-                argIndex++;
-            }
-            fprintf(out, "    const int ret = AStatsEvent_write(event);\n");
-            fprintf(out, "    AStatsEvent_release(event);\n");
-            fprintf(out, "    return ret;\n");
-        }
-        fprintf(out, "}\n\n");
-    }
-    return 0;
-}
-
-static void write_native_stats_write_non_chained_methods(FILE* out, const Atoms& atoms,
-                                                         const AtomDecl& attributionDecl) {
-    fprintf(out, "\n");
-    for (auto signature_it = atoms.nonChainedSignatureInfoMap.begin();
-         signature_it != atoms.nonChainedSignatureInfoMap.end(); signature_it++) {
-        vector<java_type_t> signature = signature_it->first;
-        // Key value pairs not supported in native.
-        if (find(signature.begin(), signature.end(), JAVA_TYPE_KEY_VALUE_PAIR) != signature.end()) {
-            continue;
-        }
-
-        write_native_method_signature(out, "int stats_write_non_chained", signature,
-                                      attributionDecl, " {");
-
-        vector<java_type_t> newSignature;
-
-        // First two args form the attribution node so size goes down by 1.
-        newSignature.reserve(signature.size() - 1);
-
-        // First arg is Attribution Chain.
-        newSignature.push_back(JAVA_TYPE_ATTRIBUTION_CHAIN);
-
-        // Followed by the originial signature except the first 2 args.
-        newSignature.insert(newSignature.end(), signature.begin() + 2, signature.end());
-
-        const char* uidName = attributionDecl.fields.front().name.c_str();
-        const char* tagName = attributionDecl.fields.back().name.c_str();
-        fprintf(out, "    const int32_t* %s = &arg1;\n", uidName);
-        fprintf(out, "    const size_t %s_length = 1;\n", uidName);
-        fprintf(out, "    const std::vector<char const*> %s(1, arg2);\n", tagName);
-        fprintf(out, "    return ");
-        write_native_method_call(out, "stats_write", newSignature, attributionDecl, 2);
-
-        fprintf(out, "}\n\n");
-    }
-}
-
-static void write_native_method_header(FILE* out, const string& methodName,
-                                       const SignatureInfoMap& signatureInfoMap,
-                                       const AtomDecl& attributionDecl) {
-    for (auto signatureInfoMapIt = signatureInfoMap.begin();
-         signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) {
-        vector<java_type_t> signature = signatureInfoMapIt->first;
-
-        // Key value pairs not supported in native.
-        if (find(signature.begin(), signature.end(), JAVA_TYPE_KEY_VALUE_PAIR) != signature.end()) {
-            continue;
-        }
-        write_native_method_signature(out, methodName, signature, attributionDecl, ";");
-    }
-}
-
-int write_stats_log_cpp(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                        const string& cppNamespace, const string& importHeader,
-                        const bool supportQ) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-
-    fprintf(out, "#include <%s>\n", importHeader.c_str());
-    if (supportQ) {
-        fprintf(out, "#include <StatsEventCompat.h>\n");
-    } else {
-        fprintf(out, "#include <stats_event.h>\n");
-    }
-
-    fprintf(out, "\n");
-    write_namespace(out, cppNamespace);
-
-    write_native_stats_write_methods(out, atoms, attributionDecl, supportQ);
-    write_native_stats_write_non_chained_methods(out, atoms, attributionDecl);
-
-    // Print footer
-    fprintf(out, "\n");
-    write_closing_namespace(out, cppNamespace);
-
-    return 0;
-}
-
-int write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                           const string& cppNamespace) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-    fprintf(out, "#pragma once\n");
-    fprintf(out, "\n");
-    fprintf(out, "#include <stdint.h>\n");
-    fprintf(out, "#include <vector>\n");
-    fprintf(out, "#include <map>\n");
-    fprintf(out, "#include <set>\n");
-    fprintf(out, "\n");
-
-    write_namespace(out, cppNamespace);
-    fprintf(out, "\n");
-    fprintf(out, "/*\n");
-    fprintf(out, " * API For logging statistics events.\n");
-    fprintf(out, " */\n");
-    fprintf(out, "\n");
-
-    write_native_atom_constants(out, atoms, attributionDecl);
-
-    // Print constants for the enum values.
-    fprintf(out, "//\n");
-    fprintf(out, "// Constants for enum values\n");
-    fprintf(out, "//\n\n");
-    for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();
-         atomIt++) {
-        for (vector<AtomField>::const_iterator field = (*atomIt)->fields.begin();
-             field != (*atomIt)->fields.end(); field++) {
-            if (field->javaType == JAVA_TYPE_ENUM) {
-                fprintf(out, "// Values for %s.%s\n", (*atomIt)->message.c_str(),
-                        field->name.c_str());
-                for (map<int, string>::const_iterator value = field->enumValues.begin();
-                     value != field->enumValues.end(); value++) {
-                    fprintf(out, "const int32_t %s__%s__%s = %d;\n",
-                            make_constant_name((*atomIt)->message).c_str(),
-                            make_constant_name(field->name).c_str(),
-                            make_constant_name(value->second).c_str(), value->first);
-                }
-                fprintf(out, "\n");
-            }
-        }
-    }
-
-    write_native_annotation_constants(out);
-
-    fprintf(out, "struct BytesField {\n");
-    fprintf(out,
-            "  BytesField(char const* array, size_t len) : arg(array), "
-            "arg_length(len) {}\n");
-    fprintf(out, "  char const* arg;\n");
-    fprintf(out, "  size_t arg_length;\n");
-    fprintf(out, "};\n");
-    fprintf(out, "\n");
-
-    // Print write methods
-    fprintf(out, "//\n");
-    fprintf(out, "// Write methods\n");
-    fprintf(out, "//\n");
-    write_native_method_header(out, "int stats_write", atoms.signatureInfoMap, attributionDecl);
-
-    fprintf(out, "//\n");
-    fprintf(out, "// Write flattened methods\n");
-    fprintf(out, "//\n");
-    write_native_method_header(out, "int stats_write_non_chained", atoms.nonChainedSignatureInfoMap,
-                               attributionDecl);
-
-    fprintf(out, "\n");
-    write_closing_namespace(out, cppNamespace);
-
-    return 0;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/native_writer.h b/tools/stats_log_api_gen/native_writer.h
deleted file mode 100644
index 264d4db..0000000
--- a/tools/stats_log_api_gen/native_writer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-#include "Collation.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using namespace std;
-
-int write_stats_log_cpp(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                        const string& cppNamespace, const string& importHeader,
-                        const bool supportQ);
-
-int write_stats_log_header(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl,
-                           const string& cppNamespace);
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/test.proto b/tools/stats_log_api_gen/test.proto
deleted file mode 100644
index a3ea785..0000000
--- a/tools/stats_log_api_gen/test.proto
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-syntax = "proto2";
-
-import "frameworks/proto_logging/stats/atoms.proto";
-import "frameworks/proto_logging/stats/atom_field_options.proto";
-
-package android.stats_log_api_gen;
-
-message IntAtom {
-    optional int32 field1 = 1;
-}
-
-message AnotherIntAtom {
-    optional int32 field1 = 1;
-}
-
-message OutOfOrderAtom {
-    optional int32 field2 = 2;
-    optional int32 field1 = 1;
-}
-
-enum AnEnum {
-    VALUE0 = 0;
-    VALUE1 = 1;
-}
-
-message AllTypesAtom {
-  repeated android.os.statsd.AttributionNode attribution_chain = 1;
-  optional float float_field = 2;
-  optional int64 int64_field = 3;
-  optional uint64 uint64_field = 4;
-  optional int32 int32_field = 5;
-  optional fixed64 fixed64_field = 6;
-  optional fixed32 fixed32_field = 7;
-  optional bool bool_field = 8;
-  optional string string_field = 9;
-  optional uint32 uint32_field = 10;
-  optional AnEnum enum_field = 11;
-  optional sfixed32 sfixed32_field = 12;
-  optional sfixed64 sfixed64_field = 13;
-  optional sint32 sint32_field = 14;
-  optional sint64 sint64_field = 15;
-}
-
-message Event {
-    oneof event {
-        OutOfOrderAtom out_of_order_atom = 2;
-        IntAtom int_atom = 1;
-        AnotherIntAtom another_int_atom = 3;
-        AllTypesAtom all_types_atom = 4;
-    }
-}
-
-message BadTypesAtom {
-    optional IntAtom bad_int_atom = 1;
-    optional bytes bad_bytes = 2;
-    repeated int32 repeated_field = 3;
-    optional double double_field = 4;
-}
-
-message BadTypesEvent {
-    oneof event {
-        BadTypesAtom bad_types_atom = 1;
-    }
-}
-
-message BadSkippedFieldSingleAtom {
-    optional int32 field2 = 2;
-}
-
-message BadSkippedFieldSingle {
-    oneof event {
-        BadSkippedFieldSingleAtom bad = 1;
-    }
-}
-
-message BadSkippedFieldMultipleAtom {
-    optional int32 field1 = 1;
-    optional int32 field3 = 3;
-    optional int32 field5 = 5;
-}
-
-message BadSkippedFieldMultiple {
-    oneof event {
-        BadSkippedFieldMultipleAtom bad = 1;
-    }
-}
-
-message BadAttributionNodePositionAtom {
-  optional int32 field1 = 1;
-  repeated android.os.statsd.AttributionNode attribution = 2;
-}
-
-message BadAttributionNodePosition {
-  oneof event { BadAttributionNodePositionAtom bad = 1; }
-}
-
-message GoodEventWithBinaryFieldAtom {
-    oneof event { GoodBinaryFieldAtom field1 = 1; }
-}
-
-message ComplexField {
-    optional string str = 1;
-}
-
-message GoodBinaryFieldAtom {
-    optional int32 field1 = 1;
-    optional ComplexField bf = 2 [(android.os.statsd.log_mode) = MODE_BYTES];
-}
-
-message BadEventWithBinaryFieldAtom {
-    oneof event { BadBinaryFieldAtom field1 = 1; }
-}
-
-message BadBinaryFieldAtom {
-    optional int32 field1 = 1;
-    optional ComplexField bf = 2;
-}
-
-message BadStateAtoms {
-    oneof event {
-        BadStateAtom1 bad1 = 1;
-        BadStateAtom2 bad2 = 2;
-        BadStateAtom3 bad3 = 3;
-    }
-}
-
-message GoodStateAtoms {
-    oneof event {
-        GoodStateAtom1 good1 = 1;
-        GoodStateAtom2 good2 = 2;
-    }
-}
-
-// The atom has only primary field but no exclusive state field.
-message BadStateAtom1 {
-    optional int32 uid = 1 [(android.os.statsd.state_field_option).primary_field = true];
-}
-
-// Only primative types can be annotated.
-message BadStateAtom2 {
-    repeated android.os.statsd.AttributionNode attribution = 1
-            [(android.os.statsd.state_field_option).primary_field = true];
-    optional int32 state = 2 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-// Having 2 exclusive state field in the atom means the atom is badly designed.
-// E.g., putting bluetooth state and wifi state in the same atom.
-message BadStateAtom3 {
-    optional int32 uid = 1 [(android.os.statsd.state_field_option).primary_field = true];
-    optional int32 state = 2 [(android.os.statsd.state_field_option).exclusive_state = true];
-    optional int32 state2 = 3 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-message GoodStateAtom1 {
-    optional int32 uid = 1 [(android.os.statsd.state_field_option).primary_field = true];
-    optional int32 state = 2 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-// Atoms can have exclusive state field, but no primary field. That means
-// the state is globally exclusive (e.g., DisplayState).
-message GoodStateAtom2 {
-    optional int32 uid = 1;
-    optional int32 state = 2 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-// We can have more than one primary fields. That means their combination is a
-// primary key.
-message GoodStateAtom3 {
-    optional int32 uid = 1 [(android.os.statsd.state_field_option).primary_field = true];
-    optional int32 tid = 2 [(android.os.statsd.state_field_option).primary_field = true];
-    optional int32 state = 3 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-message ModuleOneAtom {
-    optional int32 field = 1 [(android.os.statsd.is_uid) = true];
-}
-
-message ModuleTwoAtom {
-    optional int32 field = 1;
-}
-
-message ModuleOneAndTwoAtom {
-    optional int32 field = 1 [(android.os.statsd.state_field_option).exclusive_state = true];
-}
-
-message NoModuleAtom {
-    optional string field = 1;
-}
-
-message ModuleAtoms {
-    oneof event {
-        ModuleOneAtom module_one_atom = 1 [(android.os.statsd.module) = "module1"];
-        ModuleTwoAtom module_two_atom = 2 [(android.os.statsd.module) = "module2"];
-        ModuleOneAndTwoAtom module_one_and_two_atom = 3 [
-                (android.os.statsd.module) = "module1", (android.os.statsd.module) = "module2"
-        ];
-        NoModuleAtom no_module_atom = 4;
-    }
-}
diff --git a/tools/stats_log_api_gen/test_collation.cpp b/tools/stats_log_api_gen/test_collation.cpp
deleted file mode 100644
index dbae588..0000000
--- a/tools/stats_log_api_gen/test_collation.cpp
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * Copyright (C) 2017, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-#include <stdio.h>
-
-#include "Collation.h"
-#include "frameworks/base/tools/stats_log_api_gen/test.pb.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using std::map;
-using std::set;
-using std::vector;
-
-/**
- * Return whether the map contains a vector of the elements provided.
- */
-static bool map_contains_vector(const SignatureInfoMap& s, int count, ...) {
-    va_list args;
-    vector<java_type_t> v;
-
-    va_start(args, count);
-    for (int i = 0; i < count; i++) {
-        v.push_back((java_type_t)va_arg(args, int));
-    }
-    va_end(args);
-
-    return s.find(v) != s.end();
-}
-
-/**
- * Expect that the provided map contains the elements provided.
- */
-#define EXPECT_MAP_CONTAINS_SIGNATURE(s, ...)                    \
-    do {                                                         \
-        int count = sizeof((int[]){__VA_ARGS__}) / sizeof(int);  \
-        EXPECT_TRUE(map_contains_vector(s, count, __VA_ARGS__)); \
-    } while (0)
-
-/** Expects that the provided atom has no enum values for any field. */
-#define EXPECT_NO_ENUM_FIELD(atom)                                           \
-    do {                                                                     \
-        for (vector<AtomField>::const_iterator field = atom->fields.begin(); \
-             field != atom->fields.end(); field++) {                         \
-            EXPECT_TRUE(field->enumValues.empty());                          \
-        }                                                                    \
-    } while (0)
-
-/** Expects that exactly one specific field has expected enum values. */
-#define EXPECT_HAS_ENUM_FIELD(atom, field_name, values)                      \
-    do {                                                                     \
-        for (vector<AtomField>::const_iterator field = atom->fields.begin(); \
-             field != atom->fields.end(); field++) {                         \
-            if (field->name == field_name) {                                 \
-                EXPECT_EQ(field->enumValues, values);                        \
-            } else {                                                         \
-                EXPECT_TRUE(field->enumValues.empty());                      \
-            }                                                                \
-        }                                                                    \
-    } while (0)
-
-/**
- * Test a correct collation, with all the types.
- */
-TEST(CollationTest, CollateStats) {
-    Atoms atoms;
-    int errorCount = collate_atoms(Event::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(0, errorCount);
-    EXPECT_EQ(3ul, atoms.signatureInfoMap.size());
-
-    // IntAtom, AnotherIntAtom
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap, JAVA_TYPE_INT);
-
-    // OutOfOrderAtom
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap, JAVA_TYPE_INT, JAVA_TYPE_INT);
-
-    // AllTypesAtom
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap,
-                                  JAVA_TYPE_ATTRIBUTION_CHAIN,  // AttributionChain
-                                  JAVA_TYPE_FLOAT,              // float
-                                  JAVA_TYPE_LONG,               // int64
-                                  JAVA_TYPE_LONG,               // uint64
-                                  JAVA_TYPE_INT,                // int32
-                                  JAVA_TYPE_LONG,               // fixed64
-                                  JAVA_TYPE_INT,                // fixed32
-                                  JAVA_TYPE_BOOLEAN,            // bool
-                                  JAVA_TYPE_STRING,             // string
-                                  JAVA_TYPE_INT,                // uint32
-                                  JAVA_TYPE_INT,                // AnEnum
-                                  JAVA_TYPE_INT,                // sfixed32
-                                  JAVA_TYPE_LONG,               // sfixed64
-                                  JAVA_TYPE_INT,                // sint32
-                                  JAVA_TYPE_LONG                // sint64
-    );
-
-    EXPECT_EQ(4ul, atoms.decls.size());
-
-    AtomDeclSet::const_iterator atomIt = atoms.decls.begin();
-    EXPECT_EQ(1, (*atomIt)->code);
-    EXPECT_EQ("int_atom", (*atomIt)->name);
-    EXPECT_EQ("IntAtom", (*atomIt)->message);
-    EXPECT_NO_ENUM_FIELD((*atomIt));
-    atomIt++;
-
-    EXPECT_EQ(2, (*atomIt)->code);
-    EXPECT_EQ("out_of_order_atom", (*atomIt)->name);
-    EXPECT_EQ("OutOfOrderAtom", (*atomIt)->message);
-    EXPECT_NO_ENUM_FIELD((*atomIt));
-    atomIt++;
-
-    EXPECT_EQ(3, (*atomIt)->code);
-    EXPECT_EQ("another_int_atom", (*atomIt)->name);
-    EXPECT_EQ("AnotherIntAtom", (*atomIt)->message);
-    EXPECT_NO_ENUM_FIELD((*atomIt));
-    atomIt++;
-
-    EXPECT_EQ(4, (*atomIt)->code);
-    EXPECT_EQ("all_types_atom", (*atomIt)->name);
-    EXPECT_EQ("AllTypesAtom", (*atomIt)->message);
-    map<int, string> enumValues;
-    enumValues[0] = "VALUE0";
-    enumValues[1] = "VALUE1";
-    EXPECT_HAS_ENUM_FIELD((*atomIt), "enum_field", enumValues);
-    atomIt++;
-
-    EXPECT_EQ(atoms.decls.end(), atomIt);
-}
-
-/**
- * Test that event class that contains stuff other than the atoms is rejected.
- */
-TEST(CollationTest, NonMessageTypeFails) {
-    Atoms atoms;
-    int errorCount = collate_atoms(IntAtom::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(1, errorCount);
-}
-
-/**
- * Test that atoms that have non-primitive types or repeated fields are
- * rejected.
- */
-TEST(CollationTest, FailOnBadTypes) {
-    Atoms atoms;
-    int errorCount = collate_atoms(BadTypesEvent::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(4, errorCount);
-}
-
-/**
- * Test that atoms that skip field numbers (in the first position) are rejected.
- */
-TEST(CollationTest, FailOnSkippedFieldsSingle) {
-    Atoms atoms;
-    int errorCount =
-            collate_atoms(BadSkippedFieldSingle::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(1, errorCount);
-}
-
-/**
- * Test that atoms that skip field numbers (not in the first position, and
- * multiple times) are rejected.
- */
-TEST(CollationTest, FailOnSkippedFieldsMultiple) {
-    Atoms atoms;
-    int errorCount =
-            collate_atoms(BadSkippedFieldMultiple::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(2, errorCount);
-}
-
-/**
- * Test that atoms that have an attribution chain not in the first position are
- * rejected.
- */
-TEST(CollationTest, FailBadAttributionNodePosition) {
-    Atoms atoms;
-    int errorCount =
-            collate_atoms(BadAttributionNodePosition::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(1, errorCount);
-}
-
-TEST(CollationTest, FailOnBadStateAtomOptions) {
-    Atoms atoms;
-    int errorCount = collate_atoms(BadStateAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-
-    EXPECT_EQ(3, errorCount);
-}
-
-TEST(CollationTest, PassOnGoodStateAtomOptions) {
-    Atoms atoms;
-    int errorCount = collate_atoms(GoodStateAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_EQ(0, errorCount);
-}
-
-TEST(CollationTest, PassOnGoodBinaryFieldAtom) {
-    Atoms atoms;
-    int errorCount =
-            collate_atoms(GoodEventWithBinaryFieldAtom::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_EQ(0, errorCount);
-}
-
-TEST(CollationTest, FailOnBadBinaryFieldAtom) {
-    Atoms atoms;
-    int errorCount =
-            collate_atoms(BadEventWithBinaryFieldAtom::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_TRUE(errorCount > 0);
-}
-
-TEST(CollationTest, PassOnLogFromModuleAtom) {
-    Atoms atoms;
-    int errorCount = collate_atoms(ModuleAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_EQ(errorCount, 0);
-    EXPECT_EQ(atoms.decls.size(), 4ul);
-}
-
-TEST(CollationTest, RecognizeModuleAtom) {
-    Atoms atoms;
-    int errorCount = collate_atoms(ModuleAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_EQ(errorCount, 0);
-    EXPECT_EQ(atoms.decls.size(), 4ul);
-    EXPECT_EQ(atoms.signatureInfoMap.size(), 2u);
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap, JAVA_TYPE_INT);
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap, JAVA_TYPE_STRING);
-
-    SignatureInfoMap::const_iterator signatureInfoMapIt;
-    const vector<java_type_t>* signature;
-    const FieldNumberToAtomDeclSet* fieldNumberToAtomDeclSet;
-    FieldNumberToAtomDeclSet::const_iterator fieldNumberToAtomDeclSetIt;
-    const AtomDeclSet* atomDeclSet;
-    AtomDeclSet::const_iterator atomDeclSetIt;
-    AtomDecl* atomDecl;
-    FieldNumberToAnnotations* fieldNumberToAnnotations;
-    FieldNumberToAnnotations::const_iterator fieldNumberToAnnotationsIt;
-    const AnnotationSet* annotationSet;
-    AnnotationSet::const_iterator annotationSetIt;
-    Annotation* annotation;
-
-    signatureInfoMapIt = atoms.signatureInfoMap.begin();
-    signature = &(signatureInfoMapIt->first);
-    fieldNumberToAtomDeclSet = &signatureInfoMapIt->second;
-    EXPECT_EQ(1ul, signature->size());
-    EXPECT_EQ(JAVA_TYPE_INT, signature->at(0));
-    EXPECT_EQ(1ul, fieldNumberToAtomDeclSet->size());
-    fieldNumberToAtomDeclSetIt = fieldNumberToAtomDeclSet->begin();
-    EXPECT_EQ(1, fieldNumberToAtomDeclSetIt->first);
-    atomDeclSet = &fieldNumberToAtomDeclSetIt->second;
-    EXPECT_EQ(2ul, atomDeclSet->size());
-    atomDeclSetIt = atomDeclSet->begin();
-    atomDecl = atomDeclSetIt->get();
-    EXPECT_EQ(1, atomDecl->code);
-    fieldNumberToAnnotations = &atomDecl->fieldNumberToAnnotations;
-    fieldNumberToAnnotationsIt = fieldNumberToAnnotations->find(1);
-    EXPECT_NE(fieldNumberToAnnotations->end(), fieldNumberToAnnotationsIt);
-    annotationSet = &fieldNumberToAnnotationsIt->second;
-    EXPECT_EQ(1ul, annotationSet->size());
-    annotationSetIt = annotationSet->begin();
-    annotation = annotationSetIt->get();
-    EXPECT_EQ(ANNOTATION_ID_IS_UID, annotation->annotationId);
-    EXPECT_EQ(1, annotation->atomId);
-    EXPECT_EQ(ANNOTATION_TYPE_BOOL, annotation->type);
-    EXPECT_TRUE(annotation->value.boolValue);
-
-    atomDeclSetIt++;
-    atomDecl = atomDeclSetIt->get();
-    EXPECT_EQ(3, atomDecl->code);
-    fieldNumberToAnnotations = &atomDecl->fieldNumberToAnnotations;
-    fieldNumberToAnnotationsIt = fieldNumberToAnnotations->find(1);
-    EXPECT_NE(fieldNumberToAnnotations->end(), fieldNumberToAnnotationsIt);
-    annotationSet = &fieldNumberToAnnotationsIt->second;
-    EXPECT_EQ(1ul, annotationSet->size());
-    annotationSetIt = annotationSet->begin();
-    annotation = annotationSetIt->get();
-    EXPECT_EQ(ANNOTATION_ID_EXCLUSIVE_STATE, annotation->annotationId);
-    EXPECT_EQ(3, annotation->atomId);
-    EXPECT_EQ(ANNOTATION_TYPE_BOOL, annotation->type);
-    EXPECT_TRUE(annotation->value.boolValue);
-
-    signatureInfoMapIt++;
-    signature = &signatureInfoMapIt->first;
-    fieldNumberToAtomDeclSet = &signatureInfoMapIt->second;
-    EXPECT_EQ(1ul, signature->size());
-    EXPECT_EQ(JAVA_TYPE_STRING, signature->at(0));
-    EXPECT_EQ(0ul, fieldNumberToAtomDeclSet->size());
-}
-
-TEST(CollationTest, RecognizeModule1Atom) {
-    Atoms atoms;
-    const string moduleName = "module1";
-    int errorCount = collate_atoms(ModuleAtoms::descriptor(), moduleName, &atoms);
-    EXPECT_EQ(errorCount, 0);
-    EXPECT_EQ(atoms.decls.size(), 2ul);
-    EXPECT_EQ(atoms.signatureInfoMap.size(), 1u);
-    EXPECT_MAP_CONTAINS_SIGNATURE(atoms.signatureInfoMap, JAVA_TYPE_INT);
-
-    SignatureInfoMap::const_iterator signatureInfoMapIt;
-    const vector<java_type_t>* signature;
-    const FieldNumberToAtomDeclSet* fieldNumberToAtomDeclSet;
-    FieldNumberToAtomDeclSet::const_iterator fieldNumberToAtomDeclSetIt;
-    const AtomDeclSet* atomDeclSet;
-    AtomDeclSet::const_iterator atomDeclSetIt;
-    AtomDecl* atomDecl;
-    FieldNumberToAnnotations* fieldNumberToAnnotations;
-    FieldNumberToAnnotations::const_iterator fieldNumberToAnnotationsIt;
-    const AnnotationSet* annotationSet;
-    AnnotationSet::const_iterator annotationSetIt;
-    Annotation* annotation;
-
-    signatureInfoMapIt = atoms.signatureInfoMap.begin();
-    signature = &(signatureInfoMapIt->first);
-    fieldNumberToAtomDeclSet = &signatureInfoMapIt->second;
-    EXPECT_EQ(1ul, signature->size());
-    EXPECT_EQ(JAVA_TYPE_INT, signature->at(0));
-    EXPECT_EQ(1ul, fieldNumberToAtomDeclSet->size());
-    fieldNumberToAtomDeclSetIt = fieldNumberToAtomDeclSet->begin();
-    EXPECT_EQ(1, fieldNumberToAtomDeclSetIt->first);
-    atomDeclSet = &fieldNumberToAtomDeclSetIt->second;
-    EXPECT_EQ(2ul, atomDeclSet->size());
-    atomDeclSetIt = atomDeclSet->begin();
-    atomDecl = atomDeclSetIt->get();
-    EXPECT_EQ(1, atomDecl->code);
-    fieldNumberToAnnotations = &atomDecl->fieldNumberToAnnotations;
-    fieldNumberToAnnotationsIt = fieldNumberToAnnotations->find(1);
-    EXPECT_NE(fieldNumberToAnnotations->end(), fieldNumberToAnnotationsIt);
-    annotationSet = &fieldNumberToAnnotationsIt->second;
-    EXPECT_EQ(1ul, annotationSet->size());
-    annotationSetIt = annotationSet->begin();
-    annotation = annotationSetIt->get();
-    EXPECT_EQ(ANNOTATION_ID_IS_UID, annotation->annotationId);
-    EXPECT_EQ(1, annotation->atomId);
-    EXPECT_EQ(ANNOTATION_TYPE_BOOL, annotation->type);
-    EXPECT_TRUE(annotation->value.boolValue);
-
-    atomDeclSetIt++;
-    atomDecl = atomDeclSetIt->get();
-    EXPECT_EQ(3, atomDecl->code);
-    fieldNumberToAnnotations = &atomDecl->fieldNumberToAnnotations;
-    fieldNumberToAnnotationsIt = fieldNumberToAnnotations->find(1);
-    EXPECT_NE(fieldNumberToAnnotations->end(), fieldNumberToAnnotationsIt);
-    annotationSet = &fieldNumberToAnnotationsIt->second;
-    EXPECT_EQ(1ul, annotationSet->size());
-    annotationSetIt = annotationSet->begin();
-    annotation = annotationSetIt->get();
-    EXPECT_EQ(ANNOTATION_ID_EXCLUSIVE_STATE, annotation->annotationId);
-    EXPECT_EQ(3, annotation->atomId);
-    EXPECT_EQ(ANNOTATION_TYPE_BOOL, annotation->type);
-    EXPECT_TRUE(annotation->value.boolValue);
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/utils.cpp b/tools/stats_log_api_gen/utils.cpp
deleted file mode 100644
index abb8913..0000000
--- a/tools/stats_log_api_gen/utils.cpp
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "utils.h"
-
-#include "android-base/strings.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-static void build_non_chained_decl_map(const Atoms& atoms,
-                                       std::map<int, AtomDeclSet::const_iterator>* decl_map) {
-    for (AtomDeclSet::const_iterator atomIt = atoms.non_chained_decls.begin();
-         atomIt != atoms.non_chained_decls.end(); atomIt++) {
-        decl_map->insert(std::make_pair((*atomIt)->code, atomIt));
-    }
-}
-
-/**
- * Turn lower and camel case into upper case with underscores.
- */
-string make_constant_name(const string& str) {
-    string result;
-    const int N = str.size();
-    bool underscore_next = false;
-    for (int i = 0; i < N; i++) {
-        char c = str[i];
-        if (c >= 'A' && c <= 'Z') {
-            if (underscore_next) {
-                result += '_';
-                underscore_next = false;
-            }
-        } else if (c >= 'a' && c <= 'z') {
-            c = 'A' + c - 'a';
-            underscore_next = true;
-        } else if (c == '_') {
-            underscore_next = false;
-        }
-        result += c;
-    }
-    return result;
-}
-
-const char* cpp_type_name(java_type_t type) {
-    switch (type) {
-        case JAVA_TYPE_BOOLEAN:
-            return "bool";
-        case JAVA_TYPE_INT:
-        case JAVA_TYPE_ENUM:
-            return "int32_t";
-        case JAVA_TYPE_LONG:
-            return "int64_t";
-        case JAVA_TYPE_FLOAT:
-            return "float";
-        case JAVA_TYPE_DOUBLE:
-            return "double";
-        case JAVA_TYPE_STRING:
-            return "char const*";
-        case JAVA_TYPE_BYTE_ARRAY:
-            return "const BytesField&";
-        default:
-            return "UNKNOWN";
-    }
-}
-
-const char* java_type_name(java_type_t type) {
-    switch (type) {
-        case JAVA_TYPE_BOOLEAN:
-            return "boolean";
-        case JAVA_TYPE_INT:
-        case JAVA_TYPE_ENUM:
-            return "int";
-        case JAVA_TYPE_LONG:
-            return "long";
-        case JAVA_TYPE_FLOAT:
-            return "float";
-        case JAVA_TYPE_DOUBLE:
-            return "double";
-        case JAVA_TYPE_STRING:
-            return "java.lang.String";
-        case JAVA_TYPE_BYTE_ARRAY:
-            return "byte[]";
-        default:
-            return "UNKNOWN";
-    }
-}
-
-// Native
-// Writes namespaces for the cpp and header files, returning the number of
-// namespaces written.
-void write_namespace(FILE* out, const string& cppNamespaces) {
-    vector<string> cppNamespaceVec = android::base::Split(cppNamespaces, ",");
-    for (string cppNamespace : cppNamespaceVec) {
-        fprintf(out, "namespace %s {\n", cppNamespace.c_str());
-    }
-}
-
-// Writes namespace closing brackets for cpp and header files.
-void write_closing_namespace(FILE* out, const string& cppNamespaces) {
-    vector<string> cppNamespaceVec = android::base::Split(cppNamespaces, ",");
-    for (auto it = cppNamespaceVec.rbegin(); it != cppNamespaceVec.rend(); ++it) {
-        fprintf(out, "} // namespace %s\n", it->c_str());
-    }
-}
-
-static void write_cpp_usage(FILE* out, const string& method_name, const string& atom_code_name,
-                            const shared_ptr<AtomDecl> atom, const AtomDecl& attributionDecl) {
-    fprintf(out, "     * Usage: %s(StatsLog.%s", method_name.c_str(), atom_code_name.c_str());
-
-    for (vector<AtomField>::const_iterator field = atom->fields.begin();
-         field != atom->fields.end(); field++) {
-        if (field->javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-            for (auto chainField : attributionDecl.fields) {
-                if (chainField.javaType == JAVA_TYPE_STRING) {
-                    fprintf(out, ", const std::vector<%s>& %s", cpp_type_name(chainField.javaType),
-                            chainField.name.c_str());
-                } else {
-                    fprintf(out, ", const %s* %s, size_t %s_length",
-                            cpp_type_name(chainField.javaType), chainField.name.c_str(),
-                            chainField.name.c_str());
-                }
-            }
-        } else if (field->javaType == JAVA_TYPE_KEY_VALUE_PAIR) {
-            fprintf(out,
-                    ", const std::map<int, int32_t>& %s_int"
-                    ", const std::map<int, int64_t>& %s_long"
-                    ", const std::map<int, char const*>& %s_str"
-                    ", const std::map<int, float>& %s_float",
-                    field->name.c_str(), field->name.c_str(), field->name.c_str(),
-                    field->name.c_str());
-        } else {
-            fprintf(out, ", %s %s", cpp_type_name(field->javaType), field->name.c_str());
-        }
-    }
-    fprintf(out, ");\n");
-}
-
-void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl) {
-    fprintf(out, "/**\n");
-    fprintf(out, " * Constants for atom codes.\n");
-    fprintf(out, " */\n");
-    fprintf(out, "enum {\n");
-
-    std::map<int, AtomDeclSet::const_iterator> atom_code_to_non_chained_decl_map;
-    build_non_chained_decl_map(atoms, &atom_code_to_non_chained_decl_map);
-
-    size_t i = 0;
-    // Print atom constants
-    for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();
-         atomIt++) {
-        string constant = make_constant_name((*atomIt)->name);
-        fprintf(out, "\n");
-        fprintf(out, "    /**\n");
-        fprintf(out, "     * %s %s\n", (*atomIt)->message.c_str(), (*atomIt)->name.c_str());
-        write_cpp_usage(out, "stats_write", constant, *atomIt, attributionDecl);
-
-        auto non_chained_decl = atom_code_to_non_chained_decl_map.find((*atomIt)->code);
-        if (non_chained_decl != atom_code_to_non_chained_decl_map.end()) {
-            write_cpp_usage(out, "stats_write_non_chained", constant, *non_chained_decl->second,
-                            attributionDecl);
-        }
-        fprintf(out, "     */\n");
-        char const* const comma = (i == atoms.decls.size() - 1) ? "" : ",";
-        fprintf(out, "    %s = %d%s\n", constant.c_str(), (*atomIt)->code, comma);
-        i++;
-    }
-    fprintf(out, "\n");
-    fprintf(out, "};\n");
-    fprintf(out, "\n");
-}
-
-void write_native_method_signature(FILE* out, const string& methodName,
-                                   const vector<java_type_t>& signature,
-                                   const AtomDecl& attributionDecl, const string& closer) {
-    fprintf(out, "%s(int32_t code", methodName.c_str());
-    int argIndex = 1;
-    for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-         arg++) {
-        if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-            for (auto chainField : attributionDecl.fields) {
-                if (chainField.javaType == JAVA_TYPE_STRING) {
-                    fprintf(out, ", const std::vector<%s>& %s", cpp_type_name(chainField.javaType),
-                            chainField.name.c_str());
-                } else {
-                    fprintf(out, ", const %s* %s, size_t %s_length",
-                            cpp_type_name(chainField.javaType), chainField.name.c_str(),
-                            chainField.name.c_str());
-                }
-            }
-        } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-            fprintf(out,
-                    ", const std::map<int, int32_t>& arg%d_1, "
-                    "const std::map<int, int64_t>& arg%d_2, "
-                    "const std::map<int, char const*>& arg%d_3, "
-                    "const std::map<int, float>& arg%d_4",
-                    argIndex, argIndex, argIndex, argIndex);
-        } else {
-            fprintf(out, ", %s arg%d", cpp_type_name(*arg), argIndex);
-        }
-        argIndex++;
-    }
-    fprintf(out, ")%s\n", closer.c_str());
-}
-
-void write_native_method_call(FILE* out, const string& methodName,
-                              const vector<java_type_t>& signature, const AtomDecl& attributionDecl,
-                              int argIndex) {
-    fprintf(out, "%s(code", methodName.c_str());
-    for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-         arg++) {
-        if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-            for (auto chainField : attributionDecl.fields) {
-                if (chainField.javaType == JAVA_TYPE_STRING) {
-                    fprintf(out, ", %s", chainField.name.c_str());
-                } else {
-                    fprintf(out, ",  %s,  %s_length", chainField.name.c_str(),
-                            chainField.name.c_str());
-                }
-            }
-        } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-            fprintf(out, ", arg%d_1, arg%d_2, arg%d_3, arg%d_4", argIndex, argIndex, argIndex,
-                    argIndex);
-        } else {
-            fprintf(out, ", arg%d", argIndex);
-        }
-        argIndex++;
-    }
-    fprintf(out, ");\n");
-}
-
-// Java
-void write_java_atom_codes(FILE* out, const Atoms& atoms) {
-    fprintf(out, "    // Constants for atom codes.\n");
-
-    std::map<int, AtomDeclSet::const_iterator> atom_code_to_non_chained_decl_map;
-    build_non_chained_decl_map(atoms, &atom_code_to_non_chained_decl_map);
-
-    // Print constants for the atom codes.
-    for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();
-         atomIt++) {
-        string constant = make_constant_name((*atomIt)->name);
-        fprintf(out, "\n");
-        fprintf(out, "    /**\n");
-        fprintf(out, "     * %s %s<br>\n", (*atomIt)->message.c_str(), (*atomIt)->name.c_str());
-        write_java_usage(out, "write", constant, **atomIt);
-        auto non_chained_decl = atom_code_to_non_chained_decl_map.find((*atomIt)->code);
-        if (non_chained_decl != atom_code_to_non_chained_decl_map.end()) {
-            write_java_usage(out, "write_non_chained", constant, **(non_chained_decl->second));
-        }
-        fprintf(out, "     */\n");
-        fprintf(out, "    public static final int %s = %d;\n", constant.c_str(), (*atomIt)->code);
-    }
-    fprintf(out, "\n");
-}
-
-void write_java_enum_values(FILE* out, const Atoms& atoms) {
-    fprintf(out, "    // Constants for enum values.\n\n");
-    for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();
-         atomIt++) {
-        for (vector<AtomField>::const_iterator field = (*atomIt)->fields.begin();
-             field != (*atomIt)->fields.end(); field++) {
-            if (field->javaType == JAVA_TYPE_ENUM) {
-                fprintf(out, "    // Values for %s.%s\n", (*atomIt)->message.c_str(),
-                        field->name.c_str());
-                for (map<int, string>::const_iterator value = field->enumValues.begin();
-                     value != field->enumValues.end(); value++) {
-                    fprintf(out, "    public static final int %s__%s__%s = %d;\n",
-                            make_constant_name((*atomIt)->message).c_str(),
-                            make_constant_name(field->name).c_str(),
-                            make_constant_name(value->second).c_str(), value->first);
-                }
-                fprintf(out, "\n");
-            }
-        }
-    }
-}
-
-void write_java_usage(FILE* out, const string& method_name, const string& atom_code_name,
-                      const AtomDecl& atom) {
-    fprintf(out, "     * Usage: StatsLog.%s(StatsLog.%s", method_name.c_str(),
-            atom_code_name.c_str());
-    for (vector<AtomField>::const_iterator field = atom.fields.begin(); field != atom.fields.end();
-         field++) {
-        if (field->javaType == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-            fprintf(out, ", android.os.WorkSource workSource");
-        } else if (field->javaType == JAVA_TYPE_KEY_VALUE_PAIR) {
-            fprintf(out, ", android.util.SparseArray<Object> value_map");
-        } else if (field->javaType == JAVA_TYPE_BYTE_ARRAY) {
-            fprintf(out, ", byte[] %s", field->name.c_str());
-        } else {
-            fprintf(out, ", %s %s", java_type_name(field->javaType), field->name.c_str());
-        }
-    }
-    fprintf(out, ");<br>\n");
-}
-
-int write_java_non_chained_methods(FILE* out, const SignatureInfoMap& signatureInfoMap) {
-    for (auto signatureInfoMapIt = signatureInfoMap.begin();
-         signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) {
-        // Print method signature.
-        fprintf(out, "    public static void write_non_chained(int code");
-        vector<java_type_t> signature = signatureInfoMapIt->first;
-        int argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                fprintf(stderr, "Non chained signatures should not have attribution chains.\n");
-                return 1;
-            } else if (*arg == JAVA_TYPE_KEY_VALUE_PAIR) {
-                fprintf(stderr, "Module logging does not yet support key value pair.\n");
-                return 1;
-            } else {
-                fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
-            }
-            argIndex++;
-        }
-        fprintf(out, ") {\n");
-
-        fprintf(out, "        write(code");
-        argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            // First two args are uid and tag of attribution chain.
-            if (argIndex == 1) {
-                fprintf(out, ", new int[] {arg%d}", argIndex);
-            } else if (argIndex == 2) {
-                fprintf(out, ", new java.lang.String[] {arg%d}", argIndex);
-            } else {
-                fprintf(out, ", arg%d", argIndex);
-            }
-            argIndex++;
-        }
-        fprintf(out, ");\n");
-        fprintf(out, "    }\n");
-        fprintf(out, "\n");
-    }
-    return 0;
-}
-
-int write_java_work_source_methods(FILE* out, const SignatureInfoMap& signatureInfoMap) {
-    fprintf(out, "    // WorkSource methods.\n");
-    for (auto signatureInfoMapIt = signatureInfoMap.begin();
-         signatureInfoMapIt != signatureInfoMap.end(); signatureInfoMapIt++) {
-        vector<java_type_t> signature = signatureInfoMapIt->first;
-        // Determine if there is Attribution in this signature.
-        int attributionArg = -1;
-        int argIndexMax = 0;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            argIndexMax++;
-            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                if (attributionArg > -1) {
-                    fprintf(stderr, "An atom contains multiple AttributionNode fields.\n");
-                    fprintf(stderr, "This is not supported. Aborting WorkSource method writing.\n");
-                    fprintf(out,
-                            "\n// Invalid for WorkSource: more than one attribution "
-                            "chain.\n");
-                    return 1;
-                }
-                attributionArg = argIndexMax;
-            }
-        }
-        if (attributionArg < 0) {
-            continue;
-        }
-
-        fprintf(out, "\n");
-        // Method header (signature)
-        fprintf(out, "    public static void write(int code");
-        int argIndex = 1;
-        for (vector<java_type_t>::const_iterator arg = signature.begin(); arg != signature.end();
-             arg++) {
-            if (*arg == JAVA_TYPE_ATTRIBUTION_CHAIN) {
-                fprintf(out, ", android.os.WorkSource ws");
-            } else {
-                fprintf(out, ", %s arg%d", java_type_name(*arg), argIndex);
-            }
-            argIndex++;
-        }
-        fprintf(out, ") {\n");
-
-        // write_non_chained() component. TODO: Remove when flat uids are no longer
-        // needed.
-        fprintf(out, "        for (int i = 0; i < ws.size(); ++i) {\n");
-        fprintf(out, "            write_non_chained(code");
-        for (int argIndex = 1; argIndex <= argIndexMax; argIndex++) {
-            if (argIndex == attributionArg) {
-                fprintf(out, ", ws.getUid(i), ws.getPackageName(i)");
-            } else {
-                fprintf(out, ", arg%d", argIndex);
-            }
-        }
-        fprintf(out, ");\n");
-        fprintf(out, "        }\n");  // close for-loop
-
-        // write() component.
-        fprintf(out,
-                "        java.util.List<android.os.WorkSource.WorkChain> workChains = "
-                "ws.getWorkChains();\n");
-        fprintf(out, "        if (workChains != null) {\n");
-        fprintf(out,
-                "            for (android.os.WorkSource.WorkChain wc : workChains) "
-                "{\n");
-        fprintf(out, "                write(code");
-        for (int argIndex = 1; argIndex <= argIndexMax; argIndex++) {
-            if (argIndex == attributionArg) {
-                fprintf(out, ", wc.getUids(), wc.getTags()");
-            } else {
-                fprintf(out, ", arg%d", argIndex);
-            }
-        }
-        fprintf(out, ");\n");
-        fprintf(out, "            }\n");  // close for-loop
-        fprintf(out, "        }\n");      // close if
-        fprintf(out, "    }\n");          // close method
-    }
-    return 0;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/utils.h b/tools/stats_log_api_gen/utils.h
deleted file mode 100644
index 73e0cb8..0000000
--- a/tools/stats_log_api_gen/utils.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "Collation.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using namespace std;
-
-const string DEFAULT_CPP_NAMESPACE = "android,util";
-const string DEFAULT_CPP_HEADER_IMPORT = "statslog.h";
-
-const int JAVA_MODULE_REQUIRES_FLOAT = 0x01;
-const int JAVA_MODULE_REQUIRES_ATTRIBUTION = 0x02;
-const int JAVA_MODULE_REQUIRES_KEY_VALUE_PAIRS = 0x04;
-
-const map<AnnotationId, string> ANNOTATION_ID_CONSTANTS = {
-        {ANNOTATION_ID_IS_UID, "ANNOTATION_ID_IS_UID"},
-        {ANNOTATION_ID_TRUNCATE_TIMESTAMP, "ANNOTATION_ID_TRUNCATE_TIMESTAMP"},
-        {ANNOTATION_ID_PRIMARY_FIELD, "ANNOTATION_ID_PRIMARY_FIELD"},
-        {ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID, "ANNOTATION_ID_PRIMARY_FIELD_FIRST_UID"},
-        {ANNOTATION_ID_EXCLUSIVE_STATE, "ANNOTATION_ID_EXCLUSIVE_STATE"},
-        {ANNOTATION_ID_TRIGGER_STATE_RESET, "ANNOTATION_ID_TRIGGER_STATE_RESET"},
-        {ANNOTATION_ID_STATE_NESTED, "ANNOTATION_ID_STATE_NESTED"}};
-
-string make_constant_name(const string& str);
-
-const char* cpp_type_name(java_type_t type);
-
-const char* java_type_name(java_type_t type);
-
-// Common Native helpers
-void write_namespace(FILE* out, const string& cppNamespaces);
-
-void write_closing_namespace(FILE* out, const string& cppNamespaces);
-
-void write_native_atom_constants(FILE* out, const Atoms& atoms, const AtomDecl& attributionDecl);
-
-void write_native_method_signature(FILE* out, const string& methodName,
-                                   const vector<java_type_t>& signature,
-                                   const AtomDecl& attributionDecl, const string& closer);
-
-void write_native_method_call(FILE* out, const string& methodName,
-                              const vector<java_type_t>& signature, const AtomDecl& attributionDecl,
-                              int argIndex = 1);
-
-// Common Java helpers.
-void write_java_atom_codes(FILE* out, const Atoms& atoms);
-
-void write_java_enum_values(FILE* out, const Atoms& atoms);
-
-void write_java_usage(FILE* out, const string& method_name, const string& atom_code_name,
-                      const AtomDecl& atom);
-
-int write_java_non_chained_methods(FILE* out, const SignatureInfoMap& signatureInfoMap);
-
-int write_java_work_source_methods(FILE* out, const SignatureInfoMap& signatureInfoMap);
-
-}  // namespace stats_log_api_gen
-}  // namespace android