How to prevent the problem that the volume is too loud and the WiFi is turned off during the monkey test

Table of contents

1. How to prevent the problem that the volume is too loud and the WiFi is turned off during the monkey test

2. If WIFI is turned off, how to detect it in the background cycle and turn it on automatically

3. Combine the above two detection methods together and give detailed operation steps

4. /system/bin/sh: ./auto_check.sh: can't execute: Permission denied , how to solve it



1. How to prevent the problem that the volume is too loud and the WiFi is turned off during the monkey test

During the Monkey test, to ensure the volume is appropriate and to prevent issues with WiFi shutting down, you can take the following steps:

  1. volume control:

    • Before running the Monkey test, you can manually set the volume of your device to a suitable level to avoid excessive volume.
    • Another way is to use ADB commands to set the volume. The volume of the device can be set to a fixed value with the following command:
      adb shell media volume --set <volume_level>
      Will be <volume_level>replaced with the desired volume level, in the range 0-15.
  2. Prevent WiFi from turning off:

    • Make sure that the WiFi status of the device remains on while running the Monkey test. You can add the following ADB command to your Monkey test script to keep WiFi on:
      adb shell svc wifi enable
    • It is possible to manually ensure that the device's WiFi is turned on prior to the Monkey test.

Note that Monkey testing is an automated test that may generate random user input, so some surprises may arise during the test. In order to minimize problems, it is recommended to keep the device in a stable environment during the Monkey test and ensure that the test script includes appropriate instructions to control the volume and WiFi status.

2. If WIFI is turned off, how to detect it in the background cycle and turn it on automatically

If the WiFi is turned off during the Monkey test, you can write a script to detect and automatically turn on the WiFi in the background loop. You can use the following steps to achieve this:

  1. Use ADB command in script to check WiFi status:

    adb shell settings get global wifi_on

    This command will return a value indicating the status of WiFi. If the return value is 1, it means WiFi is turned on; if the return value is 0, it means WiFi is turned off.

  2. Add a loop to the script to constantly check the WiFi status:

    while true do wifi_status=$(adb shell settings get global wifi_on) if [[ $wifi_status -eq 0 ]] then adb shell svc wifi enable fi sleep 5 # 每隔5秒检测一次 done

    This script will constantly check the WiFi status, if the WiFi is turned off, use adb shell svc wifi enablethe command to turn on the WiFi.

  3. Save the script as a file (eg wifi_check.sh) and run the script in a command prompt or terminal window:

    sh wifi_check.sh

    This will start the script and start a background loop to detect WiFi status and automatically turn on WiFi.

Please note that when using this script, you need to make sure that you have configured the correct ADB environment and that the device is connected to the computer via USB. sleepIn addition, you can also customize the time interval of loop detection ( the number of seconds after the command) according to your needs .

This script can be used as a reference, you can modify and extend it according to your own needs.

3. Combine the above two detection methods together and give detailed operation steps

Combining WiFi and volume detection creates a more comprehensive script that detects and automatically turns on WiFi and sets media and alarm volumes to 0. Here are the detailed steps:

  1. Configure the ADB environment:

    • Download and install the ADB (Android Debug Bridge) tool. You can download the Android SDK, which includes the ADB tool, from the Android Developers website.
    • Add ADB to your system's PATH environment variable so that ADB commands can be accessed from anywhere.
  2. Connected devices:

    • Connect the device to the computer with a USB cable.
    • Enable developer options on the device.
    • Enable USB debugging mode on the device.
  3. Create script file:

    • Create a new file in a text editor, eg auto_check.sh. Make sure the file is saved as an executable.
    • Copy and paste the following code into the script file:
      #!/bin/bash
      
      while true
      do
          wifi_status=$(adb shell settings get global wifi_on)
          media_volume=$(adb shell media volume --get)
          alarm_volume=$(adb shell settings get system alarm_volume)
      
          if [[ $wifi_status -eq 0 ]]
          then
              adb shell svc wifi enable
          fi
      
          if [[ $media_volume -ne 0 ]]
          then
              adb shell media volume --set 0
          fi
      
          if [[ $alarm_volume -ne 0 ]]
          then
              adb shell settings put system alarm_volume 0
          fi
      
          sleep 5  # 每隔5秒检测一次
      done
      

  4. Save and exit the script file.

  5. Add execution permission to the script file:

    • Open a terminal or command prompt window.
    • Navigate to the directory where you saved the script file.
    • Run the following command to add execute permission to the script file:
      chmod +x auto_check.sh
      

  6. Run the script:

    • In a terminal or command prompt window, navigate to the directory where you saved the script file.
    • Run the following command to start the script and start the background cycle to detect the WiFi status and volume status, and automatically turn on the WiFi, and set the multimedia volume and alarm volume to 0:
      ./auto_check.sh &
      

Now the script will run in the background and check the WiFi status and volume status every 5 seconds. If WiFi is turned off, it will automatically turn on WiFi. If the multimedia volume or alarm volume is not 0, it will set it to 0. You can minimize the terminal or command prompt window and the script will continue to run in the background.

Make sure your device is rooted to be able to turn WiFi on and off via ADB commands and control volume settings. If the device is not rooted, it is not possible to directly control WiFi status and volume settings using ADB commands.

4. /system/bin/sh: ./auto_check.sh: can't execute: Permission denied , how to solve it

A "Permission denied" error is usually caused by not having execute permissions for the script file. You can try the following methods to solve this problem:

  1. Make sure you have correctly added execute permission to the script file.

    • Open a terminal or command prompt window.
    • Navigate to the directory where you saved the script file.
    • Run the following command to add execute permission to the script file:
      chmod +x auto_check.sh
      

      Copy

  2. Check file permissions:

    • Check the permissions of the script file by running the following command:
      ls -l auto_check.sh
      

      Copy

    • Make sure the file's permissions contain an "x", which means the script file has execute permission. For example, the correct permissions would be something like "-rwxr-xr-x".
  3. Run the script with the sudo command (Linux and Mac users only):

    • In a terminal, navigate to the directory where you saved the script file.
    • Run the following command to run the script with sudo privileges:
      sudo ./auto_check.sh
      

      Copy

    • Enter the administrator password and press Enter.

If you have tried the above methods and still cannot solve the problem, it may be caused by other permission or setting restrictions. In some cases, it may be necessary to run script files as root. Note that running scripts as the root user may pose a security risk, so proceed with caution.

If you are not sure how to deal with this issue, it is recommended to consult your computer administrator or seek further technical support.

Measured results: This script requires root privileges to execute.

Guess you like

Origin blog.csdn.net/zh6526157/article/details/132338960