Ejemplo n.º 1
0
        /// <summary>
        /// Gets the flight mode status.
        /// </summary>
        /// <returns>The flight mode status (1=on, 0=off).</returns>
        private int GetFlightModeStatus()
        {
            int        status = 0;
            string     stringStatus;
            string     output;
            ADBhandler adb = new ADBhandler();

            // Tell the user that we are checking the flightmode.
            Console.WriteLine("Checking flightmode status...");

            // Set ADB arguments to check flightmode status and execute it:
            string checkAirplanemode = "-d shell settings get global airplane_mode_on";

            output = adb.startProcess(checkAirplanemode);

            // Parse the string output to an int (1/0)
            try
            {
                status = Int32.Parse(output);
            }
            catch (Exception ex)
            {
                // Somehow the output is not an int, write the exception.
                Console.WriteLine(ex.Message);
                Console.WriteLine("Error: " + output + " is not an int");
            }

            // Conditional operator changes the status to on/off and tells the user.
            stringStatus = (status == 1) ? "on" : "off";
            Console.WriteLine("Flightmode status = " + stringStatus);

            return(status);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the flightmode status.
        /// </summary>
        /// <returns><c>true</c>, if flightmode was changed, <c>false</c> otherwise.</returns>
        /// <param name="status">The status to change flightmode to, as an int.</param>
        private bool ChangeFlightmode(int status)
        {
            bool       didSucceed = false;
            string     stringSucceed;
            string     stringStatus;
            string     output;
            ADBhandler adb = new ADBhandler();

            // Converting 1/0 to on/off and print to the user what we are doing.
            stringStatus = (status == 1) ? "on" : "off";
            Console.WriteLine("Turning flightmode " + stringStatus + "...");

            // Create the ADB arguments for turning on airplane mode, and broadcasting to the phone, that we did.
            string flightmode = string.Format("-d shell settings put global airplane_mode_on {0}", status);
            string broadcast  = "-d shell am broadcast -a android.intent.action.AIRPLANE_MODE";

            // First change flightmode and then tell phone that we changed it.
            adb.startProcess(flightmode);
            output = adb.startProcess(broadcast);


            // Take output from the last command, and split at '=' (output will end with result=0 if it worked)
            var outputArray = output.Split('=');

            output     = outputArray[outputArray.Length - 1];
            didSucceed = output.Contains("0");

            // Tell the user if the flightmode change succeded
            stringSucceed = (didSucceed) ? "succeded" : "failed";
            Console.WriteLine("Flightmode change " + stringSucceed + ".");

            return(didSucceed);
        }
Ejemplo n.º 3
0
        private TCPConnection()
        {
            adb   = new ADBhandler();
            GotIO = false;
            int remotePort = 9001;
            int localPort  = 9001;

            try
            {
                PortForward(remotePort, localPort);
                InitClient(remotePort);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 4
0
 public ApkInstaller()
 {
     adb = new ADBhandler();
 }