Merge "Support to create OpenWrt devices for local instance mode."
diff --git a/create/local_image_local_instance.py b/create/local_image_local_instance.py
index 2c90854..0982be0 100644
--- a/create/local_image_local_instance.py
+++ b/create/local_image_local_instance.py
@@ -97,6 +97,8 @@
 _CMD_LAUNCH_CVD_SUPER_IMAGE_ARG = " -super_image=%s"
 _CMD_LAUNCH_CVD_BOOT_IMAGE_ARG = " -boot_image=%s"
 _CMD_LAUNCH_CVD_NO_ADB_ARG = " -run_adb_connector=false"
+# Connect the OpenWrt device via console file.
+_CMD_LAUNCH_CVD_CONSOLE_ARG = " -console=true"
 _CONFIG_RE = re.compile(r"^config=(?P<config>.+)")
 _MAX_REPORTED_ERROR_LINES = 10
 
@@ -243,7 +245,8 @@
                                        super_image_path,
                                        artifact_paths.boot_image,
                                        avd_spec.launch_args,
-                                       config or avd_spec.flavor)
+                                       config or avd_spec.flavor,
+                                       avd_spec.openwrt)
 
         result_report = report.Report(command="create")
         instance_name = instance.GetLocalInstanceName(local_instance_id)
@@ -468,7 +471,7 @@
     def PrepareLaunchCVDCmd(launch_cvd_path, hw_property, connect_adb,
                             image_dir, runtime_dir, connect_webrtc,
                             connect_vnc, super_image_path, boot_image_path,
-                            launch_args, config):
+                            launch_args, config, openwrt=False):
         """Prepare launch_cvd command.
 
         Create the launch_cvd commands with all the required args and add
@@ -486,6 +489,7 @@
             boot_image_path: String of non-default boot image path.
             launch_args: String of launch args.
             config: String of config name.
+            openwrt: Boolean of enable OpenWrt devices.
 
         Returns:
             String, launch_cvd cmd.
@@ -519,6 +523,9 @@
                                  _CMD_LAUNCH_CVD_BOOT_IMAGE_ARG %
                                  boot_image_path)
 
+        if openwrt:
+            launch_cvd_w_args = launch_cvd_w_args + _CMD_LAUNCH_CVD_CONSOLE_ARG
+
         if launch_args:
             launch_cvd_w_args = launch_cvd_w_args + " " + launch_args
 
diff --git a/create/local_image_local_instance_test.py b/create/local_image_local_instance_test.py
index 8e14fb2..ee6a903 100644
--- a/create/local_image_local_instance_test.py
+++ b/create/local_image_local_instance_test.py
@@ -64,6 +64,11 @@
 launch_cvd -daemon -config=phone -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,config -report_anonymous_usage_stats=y -start_vnc_server=true -setupwizard_mode=REQUIRED
 EOF"""
 
+    LAUNCH_CVD_CMD_WITH_OPENWRT = """sg group1 <<EOF
+sg group2
+launch_cvd -daemon -config=phone -system_image_dir fake_image_dir -instance_dir fake_cvd_dir -undefok=report_anonymous_usage_stats,config -report_anonymous_usage_stats=y -start_vnc_server=true -console=true
+EOF"""
+
     _EXPECTED_DEVICES_IN_REPORT = [
         {
             "instance_name": "local-instance-1",
@@ -395,6 +400,13 @@
             "-setupwizard_mode=REQUIRED", "phone")
         self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_ARGS)
 
+        # Test with "openwrt" is enabled.
+        launch_cmd = self.local_image_local_instance.PrepareLaunchCVDCmd(
+            constants.CMD_LAUNCH_CVD, None, True, "fake_image_dir",
+            "fake_cvd_dir", False, True, None, None, None,
+            "phone", openwrt=True)
+        self.assertEqual(launch_cmd, self.LAUNCH_CVD_CMD_WITH_OPENWRT)
+
     @mock.patch.object(utils, "GetUserAnswerYes")
     @mock.patch.object(list_instance, "GetActiveCVD")
     def testCheckRunningCvd(self, mock_cvd_running, mock_get_answer):