Bug 1462936 - Use QEMU 2 engine for android-emulator for x86-6.0 and x86-7.0 draft
authorRob Wu <rob@robwu.nl>
Sat, 19 May 2018 21:48:50 +0200
changeset 797495 51b2cfb2562e2805df8c7db553403ebdb5c27a1e
parent 797378 e1fafe357b36270b835acf86f17aef855ce76fa5
push id110498
push userbmo:rob@robwu.nl
push dateSat, 19 May 2018 20:51:53 +0000
bugs1462936
milestone62.0a1
Bug 1462936 - Use QEMU 2 engine for android-emulator for x86-6.0 and x86-7.0 Before this patch, the x86-6.0 and x86-7.0 Android emulators were unusable on macOS (tested 10.13.4 High Sierra). The emulator's UI appears (but with black screen), and the launcher icon in the dock has a default folder icon instead of the emulator. When I use "mach android-emulator --version=x86-6.0 --verbose", then the full emulator command is printed. I discovered that using the newer QEMU 2 engine ("-engine qemu2") fixes the issue, and that the emulator launches as expected. This option is documented at: https://developer.android.com/studio/run/emulator-commandline However, when I modify the source of these commands, then the emulator fails to start (as before). This is caused by the setpgid call via preexec_fn in testing/mozbase/mozprocess/mozprocess/processhandler.py . Passing ignore_children=True to ProcessHandler avoids the setpgid call and allows the emulator to be used as expected on macOS. The effect of not using setpgid is that the spawned process will not be put in the process group of the "mach" Python script. This is not a big deal. I can confirm that the emulator can still be killed by quitting or force-quitting it, and did not experience other issues. MozReview-Commit-ID: 4AKVqtwIoCj
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -85,27 +85,27 @@ AVD_DICT = {
                    ['-skip-adb-auth', '-verbose', '-show-kernel',
                     '-qemu', '-m', '1024', '-enable-kvm'],
                    True),
     'x86-6.0': AvdInfo('Android 6.0 x86',
                        'mozemulator-x86-6.0',
                        'testing/config/tooltool-manifests/androidx86_6_0/mach-emulator.manifest',
                        ['-skip-adb-auth', '-verbose', '-show-kernel',
                         '-ranchu',
-                        # does not boot if '-engine', 'qemu2',
+                        '-engine', 'qemu2',
                         '-memory', '3072', '-cores', '4',
                         '-qemu', '-enable-kvm'],
                        True),
     'x86-7.0': AvdInfo('Android 7.0 x86',
                        'mozemulator-x86-7.0',
                        'testing/config/tooltool-manifests/androidx86_7_0/mach-emulator.manifest',
                        ['-skip-adb-auth', '-verbose', '-show-kernel',
                         '-ranchu',
+                        '-engine', 'qemu2',
                         '-selinux', 'permissive',
-                        # does not boot if '-engine', 'qemu2',
                         '-memory', '3072', '-cores', '4',
                         '-qemu', '-enable-kvm'],
                        True)
 }
 
 
 def _get_device(substs, device_serial=None):
     global devices
@@ -525,17 +525,17 @@ class AndroidEmulator(object):
         log_path = os.path.join(EMULATOR_HOME_DIR, 'emulator.log')
         self.emulator_log = open(log_path, 'w')
         _log_debug("Starting the emulator with this command: %s" %
                    ' '.join(command))
         _log_debug("Emulator output will be written to '%s'" %
                    log_path)
         self.proc = ProcessHandler(
             command, storeOutput=False, processOutputLine=outputHandler,
-            env=env)
+            env=env, ignore_children=True)
         self.proc.run()
         _log_debug("Emulator started with pid %d" %
                    int(self.proc.proc.pid))
 
     def wait_for_start(self):
         """
            Verify that the emulator is running, the emulator device is visible
            to adb, and Android has booted.