Simulating Other Devices Using ADB Shell WM Commands

Simulating Other Devices Using ADB Shell WM Commands

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Simulating different devices on your Android tablet or phone can be extremely useful for development and testing purposes. The ADB Shell WM command allows you to adjust the size, density, and overscan of your device’s display, effectively simulating other devices. However, this process can sometimes lead to unexpected results. This guide will help you use these commands effectively and avoid common pitfalls.

Setting Size and Density

To simulate another device, you can use the following commands:

  • adb shell wm size 800x480
  • adb shell wm density 240
  • adb shell wm overscan reset

However, changing the size and density might mess up the menu bar, especially when at the home screen. To avoid this, start your app first, then adjust the size and density while it’s running. Simply press the power button to turn off the screen, adjust the size and density as needed, then power the screen back on and unlock it.

Understanding the Overscan Command

The overscan command is primarily intended for TVs and other displays where not all of the screen is guaranteed to be usable or visible. It is less relevant for regular phones or tablets. For example, using adb shell wm overscan 200,200,200,200 will set margins on the display, but the effect might not be clear on the home screen.

Rendering Screen Pixels

Unfortunately, there is no way to make the device render the screen using 1 pixel of the new size to 1 pixel of the physical screen. The primary purpose of the ADB Shell WM commands is to test layout rather than achieve pixel-perfect graphics.

Simulating Phone Behavior

Simulating a phone’s behavior on a tablet, particularly in terms of menu bar behavior during orientation changes, can be unpredictable. The menu bar might behave in bizarre and inconsistent ways. If you encounter issues, it may be necessary to restart the device.

Effective Use of ADB Shell WM Commands

To use these commands effectively, follow these steps:

  1. Set the desired size in pixels, e.g., adb shell wm size 1024x600.
  2. Set the DPI, keeping in mind the formula: dp = px * (160 / dpi). For instance, setting the DPI to 160 will make the app believe the available space is 1024dp x 600dp.

Understanding how DPI affects the virtual application space is critical. Lower densities result in a larger virtual area, but the image will appear smaller on the physical screen.

Additional Tips

If your device crashes after changing the resolution, you can avoid a factory reset by connecting your device via USB and quickly sending the command to reset the original dimensions before the device crashes.

Enhancing Your Testing Workflow

For a more efficient testing workflow, consider using Repeato, a no-code test automation tool for iOS and Android. Repeato allows you to create, run, and maintain automated tests quickly and effectively. It supports ADB commands and can sequence them using script steps, ensuring proper timing and execution. This makes it an excellent tool for developers looking to streamline their testing process.

For more information, check out our Getting Started guide or visit our blog for additional tips and insights.

Like this article? there’s more where that came from!