<commit_before>package duell.run.main.platformrunner;

import duell.objects.Arguments;
import duell.helpers.LogHelper;
import duell.run.main.helpers.Device;
import duell.run.main.emulator.Emulator;
import duell.run.main.emulator.commands.IEmulatorCommand;
import duell.run.main.emulator.commands.CreateEmulatorCommand;
import duell.run.main.emulator.commands.WaitUntilReadyCommand;
import duell.run.main.emulator.commands.UninstallAppCommand;
import duell.run.main.emulator.commands.InstallAndStartAppCommand;
import duell.run.main.emulator.commands.KillServerCommand;
import duell.run.main.emulator.commands.StartServerCommand;
import duell.run.main.emulator.commands.GetDeviceArchitectureCommand;

class AndroidTestRunner extends TestingPlatformRunner
{
	private static inline var DELAY_BETWEEN_PYTHON_LISTENER_AND_RUNNING_THE_APP = 1;
	private static inline var DEFAULT_ARMV7_EMULATOR = "duellarmv7";
    private static inline var DEFAULT_X86_EMULATOR = "duellx86";
	private var emulator : Emulator;
    private var emulatorName : String = null;
    private var emulatorArch : EmulatorArchitecture = null;
    private var commands : Array<IEmulatorCommand>;

	public function new()
	{
		super("android");
	}

	override public function prepareTestRun() : Void
	{
		super.prepareTestRun();

        setArchitecture();
        initializeEmulator();

        if(Arguments.isSet('-devicename'))
        {
            checkDeviceUsage();
        }
        else
        {
            checkReuseEmulator();
        }
	}

	override public function runTests() : Void 
	{
        emulator.runEmulator( commands );
	}

    private function setArchitecture()
    {
        var isX86 = Arguments.isSet("-x86");

        if(isX86)
        {
            emulatorName = DEFAULT_X86_EMULATOR;
            emulatorArch = X86;
        }
        else
        {
            emulatorName = DEFAULT_ARMV7_EMULATOR;
            emulatorArch = ARM;
        }
    }

    private function initializeEmulator()
    {
        emulator = new Emulator();
        emulator.initialize();
    }

    private function checkDeviceUsage()
    {
        var deviceName = Arguments.get('-devicename');
        var choosedDevice = emulator.getDeviceByName( deviceName );
        if(choosedDevice == null || !choosedDevice.isOnline() )
        {
            LogHelper.exitWithFormattedError("No device with name '" + deviceName + "' found or the device is not online! Device: " + choosedDevice);
        }

        if( emulator.isEmulatorDevice( choosedDevice.name ) )
        {
            //check if architecture is correct
            if( choosedDevice.arch != emulatorArch )
            {
                LogHelper.exitWithFormattedError("Selected emulator device architecture doesn't match. Set device architecture by using '-x86' or don't set anything to use the default one (ARM).");
            }

            setupReuseProcess( choosedDevice );
        }
        else
        {
            setupRealDeviceProcess( choosedDevice );
        }
    }

    private function setupRealDeviceProcess( realDevice : Device )
    {
        emulator.useDevice( realDevice );

        LogHelper.info("", "Using the real device: " + realDevice);

        //create real device commands
        commands = new Array<IEmulatorCommand>();
        commands.push(new UninstallAppCommand( realDevice.name, config.getPackage() ));
        commands.push(new InstallAndStartAppCommand( realDevice, getAppPath(), config.getPackage(), listener));
    }<commit_msg>- wording fix ;)<commit_after>package duell.run.main.platformrunner;

import duell.objects.Arguments;
import duell.helpers.LogHelper;
import duell.run.main.helpers.Device;
import duell.run.main.emulator.Emulator;
import duell.run.main.emulator.commands.IEmulatorCommand;
import duell.run.main.emulator.commands.CreateEmulatorCommand;
import duell.run.main.emulator.commands.WaitUntilReadyCommand;
import duell.run.main.emulator.commands.UninstallAppCommand;
import duell.run.main.emulator.commands.InstallAndStartAppCommand;
import duell.run.main.emulator.commands.KillServerCommand;
import duell.run.main.emulator.commands.StartServerCommand;
import duell.run.main.emulator.commands.GetDeviceArchitectureCommand;

class AndroidTestRunner extends TestingPlatformRunner
{
	private static inline var DELAY_BETWEEN_PYTHON_LISTENER_AND_RUNNING_THE_APP = 1;
	private static inline var DEFAULT_ARMV7_EMULATOR = "duellarmv7";
    private static inline var DEFAULT_X86_EMULATOR = "duellx86";
	private var emulator : Emulator;
    private var emulatorName : String = null;
    private var emulatorArch : EmulatorArchitecture = null;
    private var commands : Array<IEmulatorCommand>;

	public function new()
	{
		super("android");
	}

	override public function prepareTestRun() : Void
	{
		super.prepareTestRun();

        setArchitecture();
        initializeEmulator();

        if(Arguments.isSet('-devicename'))
        {
            checkDeviceUsage();
        }
        else
        {
            checkReuseEmulator();
        }
	}

	override public function runTests() : Void 
	{
        emulator.runEmulator( commands );
	}

    private function setArchitecture()
    {
        var isX86 = Arguments.isSet("-x86");

        if(isX86)
        {
            emulatorName = DEFAULT_X86_EMULATOR;
            emulatorArch = X86;
        }
        else
        {
            emulatorName = DEFAULT_ARMV7_EMULATOR;
            emulatorArch = ARM;
        }
    }

    private function initializeEmulator()
    {
        emulator = new Emulator();
        emulator.initialize();
    }

    private function checkDeviceUsage()
    {
        var deviceName = Arguments.get('-devicename');
        var chosenDevice = emulator.getDeviceByName( deviceName );
        if(chosenDevice == null || !chosenDevice.isOnline() )
        {
            LogHelper.exitWithFormattedError("No device with name '" + deviceName + "' found or the device is not online! Device: " + chosenDevice);
        }

        if( emulator.isEmulatorDevice( chosenDevice.name ) )
        {
            //check if architecture is correct
            if( chosenDevice.arch != emulatorArch )
            {
                LogHelper.exitWithFormattedError("Selected emulator device architecture doesn't match. Set device architecture by using '-x86' or don't set anything to use the default one (ARM).");
            }

            setupReuseProcess( chosenDevice );
        }
        else
        {
            setupRealDeviceProcess( chosenDevice );
        }
    }

    private function setupRealDeviceProcess( realDevice : Device )
    {
        emulator.useDevice( realDevice );

        LogHelper.info("", "Using the real device: " + realDevice);

        //create real device commands
        commands = new Array<IEmulatorCommand>();
        commands.push(new UninstallAppCommand( realDevice.name, config.getPackage() ));
        commands.push(new InstallAndStartAppCommand( realDevice, getAppPath(), config.getPackage(), listener));
    }
{'fraction_non_alphanumeric': 0.09171302239338183, 'fraction_numerical': 0.005705320211096848, 'mean_word_length': 2.8254228041462084, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4147131', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1943, 'n_words': 417}