Create a separate package for ScriptExecutor. DO NOT MERGE

Important changes:
1. Create a separate library for ScriptExecutor interfaces, that
both ScriptExecutor and CarService would depend on.
2. Put all ScriptExecutor code under the same namespace.
3. Break all dependencies of ScriptExecutor on CarService.
4. Add instructions on how to run unit tests.

Test: atest ScriptExecutorUnitTest:ScriptExecutorTest
Bug: 193028600

Change-Id: Ia8b5b16cb0d114ffb1a6f4695290372de38a4beb
diff --git a/car-lib/Android.bp b/car-lib/Android.bp
index 033307b..84bbc0d 100644
--- a/car-lib/Android.bp
+++ b/car-lib/Android.bp
@@ -423,9 +423,3 @@
         "api/system-removed.txt",
     ],
 }
-
-filegroup {
-    name: "iscriptexecutorconstants_aidl",
-    srcs: ["src/android/car/telemetry/IScriptExecutorConstants.aidl"],
-    path: "src",
-}
\ No newline at end of file
diff --git a/car_product/build/car.mk b/car_product/build/car.mk
index 5b99320..67202f2 100644
--- a/car_product/build/car.mk
+++ b/car_product/build/car.mk
@@ -129,6 +129,7 @@
     car-frameworks-service \
     com.android.car.procfsinspector \
     libcar-framework-service-jni \
+    ScriptExecutor \
 
 # RROs
 PRODUCT_PACKAGES += \
diff --git a/cpp/telemetry/script_executor/Android.bp b/packages/ScriptExecutor/Android.bp
similarity index 60%
rename from cpp/telemetry/script_executor/Android.bp
rename to packages/ScriptExecutor/Android.bp
index 5df2670..6e35f4e 100644
--- a/cpp/telemetry/script_executor/Android.bp
+++ b/packages/ScriptExecutor/Android.bp
@@ -11,16 +11,17 @@
 // 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 {
-    default_applicable_licenses: ["Android-Apache-2.0"],
-}
 
 cc_defaults {
     name: "scriptexecutor_defaults",
+
     cflags: [
         "-Wno-unused-parameter",
     ],
+
     static_libs: [
         "libbase",
         "liblog",
@@ -30,9 +31,11 @@
 
 cc_library {
     name: "libscriptexecutor",
+
     defaults: [
         "scriptexecutor_defaults",
     ],
+
     srcs: [
         ":iscriptexecutorconstants_aidl",
         "src/BundleWrapper.cpp",
@@ -40,46 +43,95 @@
         "src/LuaEngine.cpp",
         "src/ScriptExecutorListener.cpp",
     ],
+
     shared_libs: [
         "libandroid_runtime",
-        "libbase",
         "libbinder",
         "libnativehelper",
         "libutils",
     ],
-    // Allow dependents to use the header files.
-    export_include_dirs: [
-        "src",
-    ],
-    aidl: {
-        include_dirs: ["packages/services/Car/car-lib/src/android/car/telemetry"],
-    },
-}
 
-cc_library_shared {
-    name: "libscriptexecutorjniutils-test",
-    defaults: [
-        "scriptexecutor_defaults",
-    ],
-    srcs: [
-        "src/tests/JniUtilsTestHelper.cpp",
-    ],
-    shared_libs: [
-        "libnativehelper",
-        "libscriptexecutor",
-    ],
+    // Allow dependents to use the header files.
+    export_include_dirs: ["src"],
 }
 
 cc_library {
     name: "libscriptexecutorjni",
+
     defaults: [
         "scriptexecutor_defaults",
     ],
+
     srcs: [
         "src/ScriptExecutorJni.cpp",
     ],
+
     shared_libs: [
         "libnativehelper",
         "libscriptexecutor",
     ],
 }
+
+android_app {
+    name: "ScriptExecutor",
+
+    srcs: ["src/**/*.java"],
+
+    resource_dirs: ["res"],
+
+    platform_apis: true,
+
+    // Each update should be signed by OEMs
+    certificate: "platform",
+
+    privileged: false,
+
+    // TODO(b/196053524): Enable optimization.
+    optimize: {
+        enabled: false,
+    },
+
+    static_libs: [
+        "com.android.car.scriptexecutor-interface-lib",
+    ],
+
+    jni_libs: [
+        "libscriptexecutorjni",
+    ],
+
+}
+
+
+android_library {
+    name: "com.android.car.scriptexecutor-interface-lib",
+
+    srcs: [
+        "interface/**/*.aidl",
+    ],
+
+    sdk_version: "system_current",
+
+    aidl: {
+        local_include_dirs: [
+            "interface",
+        ],
+    },
+}
+
+java_test_helper_library {
+    name: "scriptexecutor-test-lib",
+
+    srcs: [
+        "src/**/*.java",
+    ],
+
+    static_libs: ["com.android.car.scriptexecutor-interface-lib"],
+}
+
+filegroup {
+    name: "iscriptexecutorconstants_aidl",
+
+    srcs: ["interface/com/android/car/scriptexecutor/IScriptExecutorConstants.aidl"],
+
+    path: "interface",
+}
diff --git a/packages/ScriptExecutor/AndroidManifest.xml b/packages/ScriptExecutor/AndroidManifest.xml
new file mode 100644
index 0000000..9a59ba2
--- /dev/null
+++ b/packages/ScriptExecutor/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+     package="com.android.car.scriptexecutor">
+
+    <application android:label="@string/app_title"
+         android:allowBackup="false">
+
+        <service android:name=".ScriptExecutor"
+            android:exported="true"
+            android:isolatedProcess="true"/>
+    </application>
+</manifest>
diff --git a/car-lib/src/android/car/telemetry/IScriptExecutor.aidl b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutor.aidl
similarity index 93%
rename from car-lib/src/android/car/telemetry/IScriptExecutor.aidl
rename to packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutor.aidl
index 83ea3f0..a18bedb 100644
--- a/car-lib/src/android/car/telemetry/IScriptExecutor.aidl
+++ b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutor.aidl
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-package android.car.telemetry;
+package com.android.car.scriptexecutor;
 
-import android.car.telemetry.IScriptExecutorListener;
+import com.android.car.scriptexecutor.IScriptExecutorListener;
 import android.os.Bundle;
 
 /**
diff --git a/car-lib/src/android/car/telemetry/IScriptExecutorConstants.aidl b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorConstants.aidl
similarity index 96%
rename from car-lib/src/android/car/telemetry/IScriptExecutorConstants.aidl
rename to packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorConstants.aidl
index f1df929..3d969b0 100644
--- a/car-lib/src/android/car/telemetry/IScriptExecutorConstants.aidl
+++ b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorConstants.aidl
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.car.telemetry;
+package com.android.car.scriptexecutor;
 
 // TODO(b/194324369): Investigate if we could combine it
 // with IScriptExecutorListener.aidl
diff --git a/car-lib/src/android/car/telemetry/IScriptExecutorListener.aidl b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorListener.aidl
similarity index 97%
rename from car-lib/src/android/car/telemetry/IScriptExecutorListener.aidl
rename to packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorListener.aidl
index a3d9fc8..8295f5a 100644
--- a/car-lib/src/android/car/telemetry/IScriptExecutorListener.aidl
+++ b/packages/ScriptExecutor/interface/com/android/car/scriptexecutor/IScriptExecutorListener.aidl
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.car.telemetry;
+package com.android.car.scriptexecutor;
 
 import android.os.Bundle;
 
diff --git a/packages/ScriptExecutor/res/values/strings.xml b/packages/ScriptExecutor/res/values/strings.xml
new file mode 100644
index 0000000..bb219dd
--- /dev/null
+++ b/packages/ScriptExecutor/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <string name="app_title" translatable="false">Script executor service</string>
+</resources>
diff --git a/cpp/telemetry/script_executor/src/BundleWrapper.cpp b/packages/ScriptExecutor/src/BundleWrapper.cpp
similarity index 94%
rename from cpp/telemetry/script_executor/src/BundleWrapper.cpp
rename to packages/ScriptExecutor/src/BundleWrapper.cpp
index 77d2a5f..28412cc 100644
--- a/cpp/telemetry/script_executor/src/BundleWrapper.cpp
+++ b/packages/ScriptExecutor/src/BundleWrapper.cpp
@@ -19,10 +19,10 @@
 #include <android-base/logging.h>
 #include <android_runtime/AndroidRuntime.h>
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 BundleWrapper::BundleWrapper(JNIEnv* env) {
     mJNIEnv = env;
@@ -73,7 +73,7 @@
     return mBundle;
 }
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
diff --git a/cpp/telemetry/script_executor/src/BundleWrapper.h b/packages/ScriptExecutor/src/BundleWrapper.h
similarity index 83%
rename from cpp/telemetry/script_executor/src/BundleWrapper.h
rename to packages/ScriptExecutor/src/BundleWrapper.h
index 8c42c46..aff63bc 100644
--- a/cpp/telemetry/script_executor/src/BundleWrapper.h
+++ b/packages/ScriptExecutor/src/BundleWrapper.h
@@ -14,15 +14,15 @@
  * limitations under the License.
  */
 
-#ifndef CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_BUNDLEWRAPPER_H_
-#define CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_BUNDLEWRAPPER_H_
+#ifndef PACKAGES_SCRIPTEXECUTOR_SRC_BUNDLEWRAPPER_H_
+#define PACKAGES_SCRIPTEXECUTOR_SRC_BUNDLEWRAPPER_H_
 
 #include "jni.h"
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 // Used to create a java bundle object and populate its fields one at a time.
 class BundleWrapper {
@@ -55,9 +55,9 @@
     JNIEnv* mJNIEnv;  // not owned
 };
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
 
-#endif  // CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_BUNDLEWRAPPER_H_
+#endif  // PACKAGES_SCRIPTEXECUTOR_SRC_BUNDLEWRAPPER_H_
diff --git a/cpp/telemetry/script_executor/src/JniUtils.cpp b/packages/ScriptExecutor/src/JniUtils.cpp
similarity index 96%
rename from cpp/telemetry/script_executor/src/JniUtils.cpp
rename to packages/ScriptExecutor/src/JniUtils.cpp
index cfe1da4..df3c899 100644
--- a/cpp/telemetry/script_executor/src/JniUtils.cpp
+++ b/packages/ScriptExecutor/src/JniUtils.cpp
@@ -16,10 +16,10 @@
 
 #include "JniUtils.h"
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 void pushBundleToLuaTable(JNIEnv* env, LuaEngine* luaEngine, jobject bundle) {
     lua_newtable(luaEngine->getLuaState());
@@ -89,7 +89,7 @@
     }
 }
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
diff --git a/cpp/telemetry/script_executor/src/JniUtils.h b/packages/ScriptExecutor/src/JniUtils.h
similarity index 77%
rename from cpp/telemetry/script_executor/src/JniUtils.h
rename to packages/ScriptExecutor/src/JniUtils.h
index 85034d7..57aeb9f 100644
--- a/cpp/telemetry/script_executor/src/JniUtils.h
+++ b/packages/ScriptExecutor/src/JniUtils.h
@@ -13,16 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#ifndef CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_JNIUTILS_H_
-#define CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_JNIUTILS_H_
+#ifndef PACKAGES_SCRIPTEXECUTOR_SRC_JNIUTILS_H_
+#define PACKAGES_SCRIPTEXECUTOR_SRC_JNIUTILS_H_
 
 #include "LuaEngine.h"
 #include "jni.h"
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 // Helper function which takes android.os.Bundle object in "bundle" argument
 // and converts it to Lua table on top of Lua stack. All key-value pairs are
@@ -31,9 +31,9 @@
 // integer, double and String types in Java.
 void pushBundleToLuaTable(JNIEnv* env, LuaEngine* luaEngine, jobject bundle);
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
 
-#endif  // CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_JNIUTILS_H_
+#endif  // PACKAGES_SCRIPTEXECUTOR_SRC_JNIUTILS_H_
diff --git a/cpp/telemetry/script_executor/src/LuaEngine.cpp b/packages/ScriptExecutor/src/LuaEngine.cpp
similarity index 95%
rename from cpp/telemetry/script_executor/src/LuaEngine.cpp
rename to packages/ScriptExecutor/src/LuaEngine.cpp
index e4be1df..4b86c2e 100644
--- a/cpp/telemetry/script_executor/src/LuaEngine.cpp
+++ b/packages/ScriptExecutor/src/LuaEngine.cpp
@@ -19,7 +19,7 @@
 #include "BundleWrapper.h"
 
 #include <android-base/logging.h>
-#include <android/car/telemetry/IScriptExecutorConstants.h>
+#include <com/android/car/scriptexecutor/IScriptExecutorConstants.h>
 
 #include <utility>
 
@@ -29,12 +29,10 @@
 #include "lualib.h"
 }
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
-
-using android::car::telemetry::IScriptExecutorConstants;
+namespace car {
+namespace scriptexecutor {
 
 namespace {
 
@@ -172,7 +170,7 @@
     return ZERO_RETURNED_RESULTS;
 }
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
diff --git a/cpp/telemetry/script_executor/src/LuaEngine.h b/packages/ScriptExecutor/src/LuaEngine.h
similarity index 91%
rename from cpp/telemetry/script_executor/src/LuaEngine.h
rename to packages/ScriptExecutor/src/LuaEngine.h
index 03252a7..20c7ae5 100644
--- a/cpp/telemetry/script_executor/src/LuaEngine.h
+++ b/packages/ScriptExecutor/src/LuaEngine.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_LUAENGINE_H_
-#define CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_LUAENGINE_H_
+#ifndef PACKAGES_SCRIPTEXECUTOR_SRC_LUAENGINE_H_
+#define PACKAGES_SCRIPTEXECUTOR_SRC_LUAENGINE_H_
 
 #include "ScriptExecutorListener.h"
 
@@ -25,10 +25,10 @@
 #include "lua.h"
 }
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 // Encapsulates Lua script execution environment.
 class LuaEngine {
@@ -92,9 +92,9 @@
     lua_State* mLuaState;  // owned
 };
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
 
-#endif  // CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_LUAENGINE_H_
+#endif  // PACKAGES_SCRIPTEXECUTOR_SRC_LUAENGINE_H_
diff --git a/cpp/telemetry/script_executor/src/ScriptExecutorJni.cpp b/packages/ScriptExecutor/src/ScriptExecutorJni.cpp
similarity index 91%
rename from cpp/telemetry/script_executor/src/ScriptExecutorJni.cpp
rename to packages/ScriptExecutor/src/ScriptExecutorJni.cpp
index 0bdc692..6cb0670 100644
--- a/cpp/telemetry/script_executor/src/ScriptExecutorJni.cpp
+++ b/packages/ScriptExecutor/src/ScriptExecutorJni.cpp
@@ -23,20 +23,20 @@
 
 #include <cstdint>
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 extern "C" {
 
-JNIEXPORT jlong JNICALL
-Java_com_android_car_telemetry_ScriptExecutor_nativeInitLuaEngine(JNIEnv* env, jobject object) {
+JNIEXPORT jlong JNICALL Java_com_android_car_scriptexecutor_ScriptExecutor_nativeInitLuaEngine(
+        JNIEnv* env, jobject object) {
     // Cast first to intptr_t to ensure int can hold the pointer without loss.
     return static_cast<jlong>(reinterpret_cast<intptr_t>(new LuaEngine()));
 }
 
-JNIEXPORT void JNICALL Java_com_android_car_telemetry_ScriptExecutor_nativeDestroyLuaEngine(
+JNIEXPORT void JNICALL Java_com_android_car_scriptexecutor_ScriptExecutor_nativeDestroyLuaEngine(
         JNIEnv* env, jobject object, jlong luaEnginePtr) {
     delete reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
 }
@@ -67,7 +67,7 @@
 //
 // Finally, once parsing and pushing to Lua stack is complete, we go on to the final step,
 // Step 6: Attempt to run the provided function.
-JNIEXPORT void JNICALL Java_com_android_car_telemetry_ScriptExecutor_nativeInvokeScript(
+JNIEXPORT void JNICALL Java_com_android_car_scriptexecutor_ScriptExecutor_nativeInvokeScript(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jstring scriptBody, jstring functionName,
         jobject publishedData, jobject savedState, jobject listener) {
     if (!luaEnginePtr) {
@@ -130,7 +130,7 @@
 
 }  // extern "C"
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
diff --git a/cpp/telemetry/script_executor/src/ScriptExecutorListener.cpp b/packages/ScriptExecutor/src/ScriptExecutorListener.cpp
similarity index 93%
rename from cpp/telemetry/script_executor/src/ScriptExecutorListener.cpp
rename to packages/ScriptExecutor/src/ScriptExecutorListener.cpp
index 75a5e8d..1a70259 100644
--- a/cpp/telemetry/script_executor/src/ScriptExecutorListener.cpp
+++ b/packages/ScriptExecutor/src/ScriptExecutorListener.cpp
@@ -18,10 +18,10 @@
 
 #include <android-base/logging.h>
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 ScriptExecutorListener::~ScriptExecutorListener() {
     JNIEnv* env = getCurrentJNIEnv();
@@ -70,7 +70,7 @@
     return env;
 }
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
diff --git a/cpp/telemetry/script_executor/src/ScriptExecutorListener.h b/packages/ScriptExecutor/src/ScriptExecutorListener.h
similarity index 79%
rename from cpp/telemetry/script_executor/src/ScriptExecutorListener.h
rename to packages/ScriptExecutor/src/ScriptExecutorListener.h
index f86476c..f58ba0d 100644
--- a/cpp/telemetry/script_executor/src/ScriptExecutorListener.h
+++ b/packages/ScriptExecutor/src/ScriptExecutorListener.h
@@ -14,17 +14,17 @@
  * limitations under the License.
  */
 
-#ifndef CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
-#define CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
+#ifndef PACKAGES_SCRIPTEXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
+#define PACKAGES_SCRIPTEXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
 
 #include "jni.h"
 
 #include <string>
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 
 //  Wrapper class for IScriptExecutorListener.aidl.
 class ScriptExecutorListener {
@@ -51,9 +51,9 @@
     JavaVM* mJavaVM;
 };
 
-}  // namespace script_executor
-}  // namespace telemetry
-}  // namespace automotive
+}  // namespace scriptexecutor
+}  // namespace car
 }  // namespace android
+}  // namespace com
 
-#endif  // CPP_TELEMETRY_SCRIPT_EXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
+#endif  // PACKAGES_SCRIPTEXECUTOR_SRC_SCRIPTEXECUTORLISTENER_H_
diff --git a/service/src/com/android/car/telemetry/ScriptExecutor.java b/packages/ScriptExecutor/src/com/android/car/scriptexecutor/ScriptExecutor.java
similarity index 73%
rename from service/src/com/android/car/telemetry/ScriptExecutor.java
rename to packages/ScriptExecutor/src/com/android/car/scriptexecutor/ScriptExecutor.java
index d791481..462196e 100644
--- a/service/src/com/android/car/telemetry/ScriptExecutor.java
+++ b/packages/ScriptExecutor/src/com/android/car/scriptexecutor/ScriptExecutor.java
@@ -14,19 +14,14 @@
  * limitations under the License.
  */
 
-package com.android.car.telemetry;
+package com.android.car.scriptexecutor;
 
 import android.app.Service;
-import android.car.telemetry.IScriptExecutor;
-import android.car.telemetry.IScriptExecutorListener;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
-import android.util.Log;
-
-import com.android.car.CarServiceUtils;
 
 /**
  * Executes Lua code in an isolated process with provided source code
@@ -54,6 +49,7 @@
                             savedState, listener));
         }
     }
+
     private IScriptExecutorImpl mScriptExecutorBinder;
 
     // Memory location of Lua Engine object which is allocated in native code.
@@ -63,11 +59,8 @@
     public void onCreate() {
         super.onCreate();
 
-        mNativeHandlerThread = CarServiceUtils.getHandlerThread(
-            ScriptExecutor.class.getSimpleName());
-        // TODO(b/192284628): Remove this once start handling all recoverable errors via onError
-        // callback.
-        mNativeHandlerThread.setUncaughtExceptionHandler((t, e) -> Log.e(TAG, e.getMessage()));
+        mNativeHandlerThread = new HandlerThread(ScriptExecutor.class.getSimpleName());
+        mNativeHandlerThread.start();
         mNativeHandler = new Handler(mNativeHandlerThread.getLooper());
 
         mLuaEnginePtr = nativeInitLuaEngine();
@@ -87,10 +80,10 @@
     }
 
     /**
-    * Initializes Lua Engine.
-    *
-    * <p>Returns memory location of Lua Engine.
-    */
+     * Initializes Lua Engine.
+     *
+     * <p>Returns memory location of Lua Engine.
+     */
     private native long nativeInitLuaEngine();
 
     /**
@@ -101,13 +94,15 @@
     /**
      * Calls provided Lua function.
      *
-     * @param luaEnginePtr memory address of the stored LuaEngine instance.
-     * @param scriptBody complete body of Lua script that also contains the function to be invoked.
-     * @param functionName the name of the function to execute.
+     * @param luaEnginePtr  memory address of the stored LuaEngine instance.
+     * @param scriptBody    complete body of Lua script that also contains the function to be
+     *                      invoked.
+     * @param functionName  the name of the function to execute.
      * @param publishedData input data provided by the source which the function handles.
-     * @param savedState key-value pairs preserved from the previous invocation of the function.
-     * @param listener callback for the sandboxed environent to report back script execution results
-     * and errors.
+     * @param savedState    key-value pairs preserved from the previous invocation of the function.
+     * @param listener      callback for the sandboxed environent to report back script execution
+     *                      results
+     *                      and errors.
      */
     private native void nativeInvokeScript(long luaEnginePtr, String scriptBody,
             String functionName, Bundle publishedData, Bundle savedState,
diff --git a/packages/ScriptExecutor/tests/unit/Android.bp b/packages/ScriptExecutor/tests/unit/Android.bp
new file mode 100644
index 0000000..07efd38
--- /dev/null
+++ b/packages/ScriptExecutor/tests/unit/Android.bp
@@ -0,0 +1,50 @@
+// 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 {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_test {
+    name: "ScriptExecutorUnitTest",
+
+    srcs: ["src/**/*.java"],
+
+    platform_apis: true,
+
+    certificate: "platform",
+
+    optimize: {
+        enabled: true,
+    },
+
+    instrumentation_for: "ScriptExecutor",
+
+    static_libs: [
+        "androidx.test.core",
+        "androidx.test.runner",
+        "junit",
+        "scriptexecutor-test-lib",
+        "truth-prebuilt",
+    ],
+
+    test_suites: ["general-tests"],
+
+    jni_libs: [
+        "libscriptexecutorjni",
+        "libscriptexecutorjniutils-test",
+    ],
+}
diff --git a/packages/ScriptExecutor/tests/unit/AndroidManifest.xml b/packages/ScriptExecutor/tests/unit/AndroidManifest.xml
new file mode 100644
index 0000000..cd6ac04
--- /dev/null
+++ b/packages/ScriptExecutor/tests/unit/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ 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.
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="com.android.car.scriptexecutor_unittest">
+
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="com.android.car.scriptexecutor_unittest"
+                     android:label="Unit Tests for ScriptExecutor"/>
+</manifest>
diff --git a/packages/ScriptExecutor/tests/unit/README.md b/packages/ScriptExecutor/tests/unit/README.md
new file mode 100644
index 0000000..8c5a67a
--- /dev/null
+++ b/packages/ScriptExecutor/tests/unit/README.md
@@ -0,0 +1,52 @@
+<!--
+  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
+  -->
+
+# How to run unit tests for ScriptExecutor
+
+**1. Navigate to the root of the repo and do full build:**
+
+`m -j`
+
+**2. Flash the device with this build:**
+
+`aae flash`
+
+**3. Run the tests. For example**
+
+`atest ScriptExecutorUnitTest:ScriptExecutorTest`
+
+
+## How to rerun the tests after changes
+Sometimes a test needs to be modified. These are the steps to do incremental update instead of full
+device flash.
+
+**1. Navigate to ScriptExecutor unit test location and build its targets:**
+`cd packages/services/Car/packages/ScriptExecutor/tests/unit`
+
+`mm -j`
+
+**2. Sync the device with all the files that need to be updated:**
+
+`adb root`
+
+`adb remount`
+
+`adb sync && adb shell stop && adb shell start`
+
+**3. At this point we are ready to run the tests again. For example:**
+
+`atest ScriptExecutorUnitTest:ScriptExecutorTest`
+
diff --git a/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/Android.bp b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/Android.bp
new file mode 100644
index 0000000..6ce5d26
--- /dev/null
+++ b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/Android.bp
@@ -0,0 +1,35 @@
+// 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 {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library_shared {
+    name: "libscriptexecutorjniutils-test",
+
+    defaults: [
+        "scriptexecutor_defaults",
+    ],
+
+    srcs: [
+        "JniUtilsTestHelper.cpp",
+    ],
+
+    shared_libs: [
+        "libnativehelper",
+        "libscriptexecutor",
+    ],
+}
+
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/JniUtilsTest.java b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTest.java
similarity index 98%
rename from tests/carservice_unit_test/src/com/android/car/telemetry/JniUtilsTest.java
rename to packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTest.java
index 67a5ac8..13379cc 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/JniUtilsTest.java
+++ b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.car.telemetry;
+package com.android.car.scriptexecutor;
 
 import static com.google.common.truth.Truth.assertThat;
 
diff --git a/cpp/telemetry/script_executor/src/tests/JniUtilsTestHelper.cpp b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTestHelper.cpp
similarity index 81%
rename from cpp/telemetry/script_executor/src/tests/JniUtilsTestHelper.cpp
rename to packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTestHelper.cpp
index 8cdf87a..eae1377 100644
--- a/cpp/telemetry/script_executor/src/tests/JniUtilsTestHelper.cpp
+++ b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/JniUtilsTestHelper.cpp
@@ -21,40 +21,41 @@
 #include <cstdint>
 #include <cstring>
 
+namespace com {
 namespace android {
-namespace automotive {
-namespace telemetry {
-namespace script_executor {
+namespace car {
+namespace scriptexecutor {
 namespace {
 
 extern "C" {
 
 #include "lua.h"
 
-JNIEXPORT jlong JNICALL
-Java_com_android_car_telemetry_JniUtilsTest_nativeCreateLuaEngine(JNIEnv* env, jobject object) {
+JNIEXPORT jlong JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeCreateLuaEngine(
+        JNIEnv* env, jobject object) {
     // Cast first to intptr_t to ensure int can hold the pointer without loss.
     return static_cast<jlong>(reinterpret_cast<intptr_t>(new LuaEngine()));
 }
 
-JNIEXPORT void JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeDestroyLuaEngine(
+JNIEXPORT void JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeDestroyLuaEngine(
         JNIEnv* env, jobject object, jlong luaEnginePtr) {
     delete reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
 }
 
-JNIEXPORT void JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativePushBundleToLuaTableCaller(
+JNIEXPORT void JNICALL
+Java_com_android_car_scriptexecutor_JniUtilsTest_nativePushBundleToLuaTableCaller(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jobject bundle) {
     pushBundleToLuaTable(env, reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr)),
                          bundle);
 }
 
-JNIEXPORT jint JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeGetObjectSize(
+JNIEXPORT jint JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeGetObjectSize(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jint index) {
     LuaEngine* engine = reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
     return lua_rawlen(engine->getLuaState(), static_cast<int>(index));
 }
 
-JNIEXPORT bool JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeHasBooleanValue(
+JNIEXPORT bool JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeHasBooleanValue(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jstring key, jboolean value) {
     const char* rawKey = env->GetStringUTFChars(key, nullptr);
     LuaEngine* engine = reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
@@ -71,7 +72,7 @@
     return result;
 }
 
-JNIEXPORT bool JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeHasIntValue(
+JNIEXPORT bool JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeHasIntValue(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jstring key, jint value) {
     const char* rawKey = env->GetStringUTFChars(key, nullptr);
     LuaEngine* engine = reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
@@ -89,7 +90,7 @@
     return result;
 }
 
-JNIEXPORT bool JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeHasDoubleValue(
+JNIEXPORT bool JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeHasDoubleValue(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jstring key, jdouble value) {
     const char* rawKey = env->GetStringUTFChars(key, nullptr);
     LuaEngine* engine = reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
@@ -107,7 +108,7 @@
     return result;
 }
 
-JNIEXPORT bool JNICALL Java_com_android_car_telemetry_JniUtilsTest_nativeHasStringValue(
+JNIEXPORT bool JNICALL Java_com_android_car_scriptexecutor_JniUtilsTest_nativeHasStringValue(
         JNIEnv* env, jobject object, jlong luaEnginePtr, jstring key, jstring value) {
     const char* rawKey = env->GetStringUTFChars(key, nullptr);
     LuaEngine* engine = reinterpret_cast<LuaEngine*>(static_cast<intptr_t>(luaEnginePtr));
@@ -131,8 +132,8 @@
 
 }  //  extern "C"
 
-}  //  namespace
-}  //  namespace script_executor
-}  //  namespace telemetry
-}  //  namespace automotive
-}  //  namespace android
+}  // namespace
+}  // namespace scriptexecutor
+}  // namespace car
+}  // namespace android
+}  // namespace com
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/ScriptExecutorTest.java b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/ScriptExecutorTest.java
similarity index 96%
rename from tests/carservice_unit_test/src/com/android/car/telemetry/ScriptExecutorTest.java
rename to packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/ScriptExecutorTest.java
index b2f0777..5d75766 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/ScriptExecutorTest.java
+++ b/packages/ScriptExecutor/tests/unit/src/com/android/car/scriptexecutor/ScriptExecutorTest.java
@@ -14,15 +14,12 @@
  * limitations under the License.
  */
 
-package com.android.car.telemetry;
+package com.android.car.scriptexecutor;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.junit.Assert.fail;
 
-import android.car.telemetry.IScriptExecutor;
-import android.car.telemetry.IScriptExecutorConstants;
-import android.car.telemetry.IScriptExecutorListener;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -144,11 +141,12 @@
 
     @Before
     public void setUp() throws InterruptedException {
-        mContext.bindIsolatedService(new Intent(mContext, ScriptExecutor.class),
-                Context.BIND_AUTO_CREATE, "scriptexecutor", mContext.getMainExecutor(),
-                mScriptExecutorConnection);
+        Intent intent = new Intent();
+        intent.setComponent(new ComponentName("com.android.car.scriptexecutor",
+                "com.android.car.scriptexecutor.ScriptExecutor"));
+        mContext.bindService(intent, mScriptExecutorConnection, Context.BIND_AUTO_CREATE);
         if (!mBindLatch.await(BIND_SERVICE_TIMEOUT_SEC, TimeUnit.SECONDS)) {
-            fail("Failed to bind to ScripExecutor service");
+            fail("Failed to bind to ScriptExecutor service");
         }
     }
 
diff --git a/service/Android.bp b/service/Android.bp
index b2456d1..c0bfb51 100644
--- a/service/Android.bp
+++ b/service/Android.bp
@@ -50,6 +50,7 @@
     "vehicle-hal-support-lib",
     "car-systemtest",
     "com.android.car.procfsinspector-client",
+    "com.android.car.scriptexecutor-interface-lib",
     "blestream-protos",
     "SettingsLib",
     "androidx.preference_preference",
@@ -86,7 +87,6 @@
 
     jni_libs: [
         "libcarservicejni",
-        "libscriptexecutorjni",
     ],
 
     required: ["allowed_privapp_com.android.car"],
diff --git a/service/AndroidManifest.xml b/service/AndroidManifest.xml
index fabe8e2..614e2af 100644
--- a/service/AndroidManifest.xml
+++ b/service/AndroidManifest.xml
@@ -936,9 +936,6 @@
         </service>
         <service android:name=".PerUserCarService"
             android:exported="false"/>
-        <service android:name=".telemetry.ScriptExecutor"
-            android:exported="false"
-            android:isolatedProcess="true"/>
 
         <activity android:name="com.android.car.pm.ActivityBlockingActivity"
              android:documentLaunchMode="always"
diff --git a/service/src/com/android/car/telemetry/databroker/DataBrokerImpl.java b/service/src/com/android/car/telemetry/databroker/DataBrokerImpl.java
index 04a7a7a..ad3b2e3 100644
--- a/service/src/com/android/car/telemetry/databroker/DataBrokerImpl.java
+++ b/service/src/com/android/car/telemetry/databroker/DataBrokerImpl.java
@@ -16,8 +16,6 @@
 
 package com.android.car.telemetry.databroker;
 
-import android.car.telemetry.IScriptExecutor;
-import android.car.telemetry.IScriptExecutorListener;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
@@ -35,8 +33,9 @@
 
 import com.android.car.CarLog;
 import com.android.car.CarServiceUtils;
+import com.android.car.scriptexecutor.IScriptExecutor;
+import com.android.car.scriptexecutor.IScriptExecutorListener;
 import com.android.car.telemetry.CarTelemetryService;
-import com.android.car.telemetry.ScriptExecutor;
 import com.android.car.telemetry.TelemetryProto;
 import com.android.car.telemetry.TelemetryProto.MetricsConfig;
 import com.android.car.telemetry.publisher.AbstractPublisher;
@@ -61,7 +60,8 @@
 public class DataBrokerImpl implements DataBroker {
 
     private static final int MSG_HANDLE_TASK = 1;
-    @VisibleForTesting static final int MSG_BIND_TO_SCRIPT_EXECUTOR = 2;
+    @VisibleForTesting
+    static final int MSG_BIND_TO_SCRIPT_EXECUTOR = 2;
 
     private final Context mContext;
     private final PublisherFactory mPublisherFactory;
@@ -127,8 +127,11 @@
         if (mDisabled.get() || mScriptExecutorRef.get() != null) {
             return;
         }
+        Intent intent = new Intent();
+        intent.setComponent(new ComponentName("com.android.car.scriptexecutor",
+                "com.android.car.scriptexecutor.ScriptExecutor"));
         boolean success = mContext.bindServiceAsUser(
-                new Intent(mContext, ScriptExecutor.class),
+                intent,
                 mServiceConnection,
                 Context.BIND_AUTO_CREATE,
                 UserHandle.SYSTEM);
@@ -283,8 +286,8 @@
      * the handler handles message in the order they come in, this means the task will be polled
      * sequentially instead of concurrently. Every task that is scheduled and run will be distinct.
      * TODO(b/187743369): If the threading behavior in DataSubscriber changes, ScriptExecutionTask
-     *                    will also have different threading behavior. Update javadoc when the
-     *                    behavior is decided.
+     * will also have different threading behavior. Update javadoc when the
+     * behavior is decided.
      */
     @Override
     public void scheduleNextTask() {
diff --git a/tests/carservice_unit_test/Android.bp b/tests/carservice_unit_test/Android.bp
index 1f22098..57e14d9 100644
--- a/tests/carservice_unit_test/Android.bp
+++ b/tests/carservice_unit_test/Android.bp
@@ -69,8 +69,6 @@
     // mockito-target-inline dependency
     jni_libs: [
         "libdexmakerjvmtiagent",
-	"libscriptexecutorjni",
-        "libscriptexecutorjniutils-test",
         "libstaticjvmtiagent",
     ],
 }
diff --git a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
index d1e0f2e..a458efd 100644
--- a/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/telemetry/databroker/DataBrokerUnitTest.java
@@ -27,8 +27,6 @@
 
 import android.annotation.Nullable;
 import android.car.hardware.CarPropertyConfig;
-import android.car.telemetry.IScriptExecutor;
-import android.car.telemetry.IScriptExecutorListener;
 import android.content.Context;
 import android.content.ServiceConnection;
 import android.os.Bundle;
@@ -38,6 +36,8 @@
 import android.os.SystemClock;
 
 import com.android.car.CarPropertyService;
+import com.android.car.scriptexecutor.IScriptExecutor;
+import com.android.car.scriptexecutor.IScriptExecutorListener;
 import com.android.car.telemetry.TelemetryProto;
 import com.android.car.telemetry.publisher.PublisherFactory;