Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 private void PortForward(int remotePort, int localPort)
 {
     try
     {
         string parameters = string.Format("-d forward tcp:{0} tcp:{1}", remotePort, localPort);
         adb.startProcess(parameters);
     }
     catch (Exception e)
     {
         throw e;
     }
     Console.WriteLine("Port forwarded");
 }
Exemplo n.º 4
0
        public bool InstallApk()
        {
            bool   worked  = false;
            string apkName = "\"C:/Users/David/AppData/Local/Xamarin/Mono for Android/Archives/2016-12-15/TestDroid 12-15-16 1.19 PM.apkarchive/signed-apks/com.rohde_schwarz.testdroid.apk\"";

            try
            {
                string parameters = string.Format("-d install {0}", apkName);
                Console.WriteLine(adb.startProcess(parameters, true));
                worked = true;
            }
            catch (Exception e)
            {
                throw e;
            }

            return(worked);
        }