Moved some event logs

- Events log tags are no longer exposed directly. Built-in library will have methods exposed for each tag.
- New CarService release need to check the version of the build-in library and have to call tag accordingly.

Bug: 202769950
Bug: 193798273
Test: m
Change-Id: I37cb1f78df0c02f70f4f9b33198b01fb2922d95d
diff --git a/car-builtin-lib/Android.bp b/car-builtin-lib/Android.bp
index 388c37c..176c548 100644
--- a/car-builtin-lib/Android.bp
+++ b/car-builtin-lib/Android.bp
@@ -22,6 +22,7 @@
     srcs: [
         "src/**/*.java",
         "src/**/*.aidl",
+        "src/android/car/builtin/util/EventLogTags.logtags",
     ],
 
     default_to_stubs: true,
diff --git a/car-builtin-lib/api/module-lib-current.txt b/car-builtin-lib/api/module-lib-current.txt
index 5fd37f8..f900adb 100644
--- a/car-builtin-lib/api/module-lib-current.txt
+++ b/car-builtin-lib/api/module-lib-current.txt
@@ -283,6 +283,19 @@
     method public static boolean exists(android.util.AtomicFile);
   }
 
+  public final class EventLogHelper {
+    method public static void writeCarServiceConnected(String);
+    method public static void writeCarServiceCreate(boolean);
+    method public static void writeCarServiceDestroy(boolean);
+    method public static void writeCarServiceInit(int);
+    method public static void writeCarServiceInitBootUser();
+    method public static void writeCarServiceOnUserLifecycle(int, int, int);
+    method public static void writeCarServiceOnUserRemoved(int);
+    method public static void writeCarServiceSetCarServiceHelper(int);
+    method public static void writeCarServiceVhalDied(long);
+    method public static void writeCarServiceVhalReconnected(int);
+  }
+
   public final class Slogf {
     method public static int d(@NonNull String, @NonNull String);
     method public static int d(@NonNull String, @NonNull String, @NonNull Throwable);
diff --git a/car-builtin-lib/src/android/car/builtin/util/EventLogHelper.java b/car-builtin-lib/src/android/car/builtin/util/EventLogHelper.java
new file mode 100644
index 0000000..2eb2e62
--- /dev/null
+++ b/car-builtin-lib/src/android/car/builtin/util/EventLogHelper.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2021 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.car.builtin.util;
+
+import android.annotation.SystemApi;
+import android.util.EventLog;
+
+/**
+ * Helper for {@link EventLog}
+ *
+ * @hide
+ */
+@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
+public final class EventLogHelper {
+
+    public static void writeCarServiceInit(int numberServices) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_INIT, numberServices);
+    }
+
+    public static void writeCarServiceVhalReconnected(int numberServices) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_VHAL_RECONNECTED, numberServices);
+    }
+
+    public static void writeCarServiceSetCarServiceHelper(int pid) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_SET_CAR_SERVICE_HELPER, pid);
+    }
+
+    public static void writeCarServiceOnUserLifecycle(int type, int fromUserId, int toUserId) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_ON_USER_LIFECYCLE, type, fromUserId, toUserId);
+    }
+
+    public static void writeCarServiceCreate(boolean hasVhal) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_CREATE, hasVhal ? 1 : 0);
+    }
+
+    public static void writeCarServiceConnected(String interfaceName) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_CONNECTED, interfaceName);
+    }
+
+    public static void writeCarServiceDestroy(boolean hasVhal) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_DESTROY, hasVhal ? 1 : 0);
+    }
+
+    public static void writeCarServiceVhalDied(long cookie) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_VHAL_DIED, cookie);
+    }
+
+    public static void writeCarServiceInitBootUser() {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_INIT_BOOT_USER);
+    }
+
+    public static void writeCarServiceOnUserRemoved(int userId) {
+        EventLog.writeEvent(EventLogTags.CAR_SERVICE_ON_USER_REMOVED, userId);
+    }
+
+    private EventLogHelper() {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/car-builtin-lib/src/android/car/builtin/util/EventLogTags.logtags b/car-builtin-lib/src/android/car/builtin/util/EventLogTags.logtags
new file mode 100644
index 0000000..286040b
--- /dev/null
+++ b/car-builtin-lib/src/android/car/builtin/util/EventLogTags.logtags
@@ -0,0 +1,39 @@
+# 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.
+#
+
+# See system/core/logcat/event.logtags for a description of the format of this file.
+
+option java_package android.car.builtin.util
+
+####
+#### Tags used by CarServiceHelperService
+####
+#### It uses the 150000 - 160000 range
+
+####
+#### Tags used by ICarImpl / CarService
+####
+
+150050 car_service_init (number_services|1)
+150051 car_service_vhal_reconnected (number_services|1)
+150052 car_service_set_car_service_helper (pid|1)
+150053 car_service_on_user_lifecycle (type|1),(from_user_id|1),(to_user_id|1)
+#150054 (Not_used_anymore) car_service_set_initial_user (user_id|1)
+150055 car_service_create (has_vhal|1)
+150056 car_service_connected (interface|3)
+150057 car_service_destroy (has_vhal|1)
+150058 car_service_vhal_died (cookie|2)
+150059 car_service_init_boot_user
+150060 car_service_on_user_removed (user_id|1)
diff --git a/car-lib/src/com/android/car/internal/common/EventLogTags.logtags b/car-lib/src/com/android/car/internal/common/EventLogTags.logtags
index ce07e2b..c955e29 100644
--- a/car-lib/src/com/android/car/internal/common/EventLogTags.logtags
+++ b/car-lib/src/com/android/car/internal/common/EventLogTags.logtags
@@ -41,22 +41,6 @@
 #150015 (Not_used_anymore) car_helper_pre_creation_status
 
 ####
-#### Tags used by ICarImpl / CarService
-####
-
-150050 car_service_init (number_services|1)
-150051 car_service_vhal_reconnected (number_services|1)
-150052 car_service_set_car_service_helper (pid|1)
-150053 car_service_on_user_lifecycle (type|1),(from_user_id|1),(to_user_id|1)
-#150054 (Not_used_anymore) car_service_set_initial_user (user_id|1)
-150055 car_service_create (has_vhal|1)
-150056 car_service_connected (interface|3)
-150057 car_service_destroy (has_vhal|1)
-150058 car_service_vhal_died (cookie|2)
-150059 car_service_init_boot_user
-150060 car_service_on_user_removed (user_id|1)
-
-####
 #### Tags used by CarService subsystems, like user and power management.
 ####
 #### They must be prefixed by car_xxx_svc, car_xxx_hal, or car_xxx_mgr, each representing the
diff --git a/service/src/com/android/car/CarServiceImpl.java b/service/src/com/android/car/CarServiceImpl.java
index 27f4d75..d10d45f 100644
--- a/service/src/com/android/car/CarServiceImpl.java
+++ b/service/src/com/android/car/CarServiceImpl.java
@@ -22,14 +22,13 @@
 import android.car.builtin.os.ServiceManagerHelper;
 import android.car.builtin.os.SystemPropertiesHelper;
 import android.car.builtin.os.TraceHelper;
+import android.car.builtin.util.EventLogHelper;
 import android.car.builtin.util.Slogf;
 import android.content.Intent;
 import android.os.IBinder;
 import android.os.Process;
-import android.util.EventLog;
 
 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
-import com.android.car.internal.common.EventLogTags;
 import com.android.car.systeminterface.SystemInterface;
 import com.android.car.util.LimitedTimingsTraceLog;
 
@@ -58,7 +57,7 @@
         mVehicle = new VehicleStub();
         initTiming.traceEnd(); // "getVehicle"
 
-        EventLog.writeEvent(EventLogTags.CAR_SERVICE_CREATE, mVehicle.isValid() ? 1 : 0);
+        EventLogHelper.writeCarServiceCreate(/* hasVhal= */ mVehicle.isValid());
 
         if (!mVehicle.isValid()) {
             throw new IllegalStateException("Vehicle HAL service is not available.");
@@ -67,7 +66,7 @@
         mVehicleInterfaceName = mVehicle.getInterfaceDescriptor();
 
         Slogf.i(CarLog.TAG_SERVICE, "Connected to " + mVehicleInterfaceName);
-        EventLog.writeEvent(EventLogTags.CAR_SERVICE_CONNECTED, mVehicleInterfaceName);
+        EventLogHelper.writeCarServiceConnected(mVehicleInterfaceName);
 
         mICarImpl = new ICarImpl(this,
                 getBuiltinPackageContext(),
@@ -91,7 +90,7 @@
     // cleanup task that you want to make sure happens on shutdown/reboot, see OnShutdownReboot.
     @Override
     public void onDestroy() {
-        EventLog.writeEvent(EventLogTags.CAR_SERVICE_DESTROY, mVehicle.isValid() ? 1 : 0);
+        EventLogHelper.writeCarServiceDestroy(/* hasVhal= */ mVehicle.isValid());
         Slogf.i(CarLog.TAG_SERVICE, "Service onDestroy");
         mICarImpl.release();
 
@@ -125,14 +124,14 @@
 
         @Override
         public void serviceDied(long cookie) {
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_VHAL_DIED, cookie);
+            EventLogHelper.writeCarServiceVhalDied(cookie);
             Slogf.wtf(CarLog.TAG_SERVICE, "***Vehicle HAL died. Car service will restart***");
             Process.killProcess(Process.myPid());
         }
 
         @Override
         public void binderDied() {
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_VHAL_DIED, /*cookie=*/0);
+            EventLogHelper.writeCarServiceVhalDied(/*cookie=*/ 0);
             Slogf.wtf(CarLog.TAG_SERVICE, "***Vehicle HAL died. Car service will restart***");
             Process.killProcess(Process.myPid());
         }
diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java
index 7dc4990..a1ce6a4 100644
--- a/service/src/com/android/car/ICarImpl.java
+++ b/service/src/com/android/car/ICarImpl.java
@@ -34,6 +34,7 @@
 import android.car.builtin.os.BuildHelper;
 import android.car.builtin.os.TraceHelper;
 import android.car.builtin.os.UserManagerHelper;
+import android.car.builtin.util.EventLogHelper;
 import android.car.builtin.util.Slogf;
 import android.car.builtin.util.TimingsTraceLog;
 import android.car.user.CarUserManager;
@@ -51,7 +52,6 @@
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.util.EventLog;
 
 import com.android.car.admin.CarDevicePolicyService;
 import com.android.car.am.CarActivityService;
@@ -68,7 +68,6 @@
 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
 import com.android.car.internal.ICarServiceHelper;
 import com.android.car.internal.ICarSystemServerClient;
-import com.android.car.internal.common.EventLogTags;
 import com.android.car.internal.util.IndentingPrintWriter;
 import com.android.car.pm.CarPackageManagerService;
 import com.android.car.power.CarPowerManagementService;
@@ -469,8 +468,7 @@
             ICarResultReceiver resultReceiver) {
         Bundle bundle;
         try {
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_SET_CAR_SERVICE_HELPER,
-                    Binder.getCallingPid());
+            EventLogHelper.writeCarServiceSetCarServiceHelper(Binder.getCallingPid());
             assertCallingFromSystemProcess();
             synchronized (mLock) {
                 mICarServiceHelper = carServiceHelper;
@@ -838,8 +836,7 @@
         public void onUserLifecycleEvent(int eventType, int fromUserId, int toUserId)
                 throws RemoteException {
             assertCallingFromSystemProcess();
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_ON_USER_LIFECYCLE, eventType, fromUserId,
-                    toUserId);
+            EventLogHelper.writeCarServiceOnUserLifecycle(eventType, fromUserId, toUserId);
             if (DBG) {
                 Slogf.d(TAG,
                         "onUserLifecycleEvent("
@@ -852,7 +849,7 @@
         @Override
         public void initBootUser() throws RemoteException {
             assertCallingFromSystemProcess();
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_INIT_BOOT_USER);
+            EventLogHelper.writeCarServiceInitBootUser();
             if (DBG) Slogf.d(TAG, "initBootUser(): ");
             mCarUserService.initBootUser();
         }
@@ -860,7 +857,7 @@
         @Override
         public void onUserRemoved(UserHandle user) throws RemoteException {
             assertCallingFromSystemProcess();
-            EventLog.writeEvent(EventLogTags.CAR_SERVICE_ON_USER_REMOVED, user.getIdentifier());
+            EventLogHelper.writeCarServiceOnUserRemoved(user.getIdentifier());
             if (DBG) Slogf.d(TAG, "onUserRemoved(): " + user.toString());
             mCarUserService.onUserRemoved(user);
         }