Android Debug Bridge (adb) is a robust command-line tool that allows you to communicate with a connected Android device. Using adb commands, you can perform a variety of device actions, such as installing apps, granting permissions, profiling for performance, etc.
For security reasons, we launch the appium server on our platform with --relaxed-security setting off. This means that we won’t be able to support execution of ADB shell commands using the mobile: shell appium command. More details in Appium documentation. However, we provide custom implementation to run certain useful ADB commands on our Android devices.
This section provides details on how to run adb commands for the following use cases in an App Automate session:
In order to achieve this functionality in App Automate, use the browserstack.devicePreferences capability in your test sessions and set the log.tag.FA and log.tag.FA-SVC tags to VERBOSE inside the setprop object. The following code snippet demonstrates how to do this:
Upon setting this capability in your tests, logs for Firebase events will start appearing under device logs. You can capture the complete logs by using driver.manage().logs().get("logcat").filter(Level.ALL); command and then filter out the firebase events for your app in your test.
Debug Events
You can enable the debug mode for Firebase Analytics on an Android device by using the following adb shell setprop command:
To achieve this functionality in App Automate, use the browserstack.devicePreferences capability in your test sessions and set the debug.firebase.analytics.app value to your package_name inside the setprop object. The following code snippet demonstrates how to do this:
Upon setting this capability in your tests, your test session will begin on a device where debug mode has been enabled. You can then navigate to DebugView to view your app’s events being logged in the DebugView report.
Log Google Analytics events
You can enable the log feature of Google Analytics events by using the following adb shell setprop command:
adb shell setprop log.tag.GAv4 DEBUG
To achieve this functionality in App Automate, use the browserstack.devicePreferences capability in your test sessions and set the log.tag.GAv4 tag to any of the log filter types such as DEBUG, VERBOSE, INFO etc inside the setprop object. The following code snippet demonstrates how to do this:
Upon setting this capability in your tests, logs for Google Analytics events will start appearing under device logs. You can capture the complete logs by using driver.manage().logs().get("logcat").filter(Level.ALL); command and then filter out the Google Analytics events for your app in your test.
Set system-level preferences using settings commands
The adb shell settings put commands can be used to set system-level device preferences such as disabling pop-up notifications, disabling location services, changing device orientation etc.
The following table lists all the adb shell settings put commands that are supported in App Automate:
Command
Description
Allowed Values
adb shell settings put secure location_mode 0
Enable/Disable location services on an android device
Disable: 0 Enable: 3
adb shell settings put global heads_up_notifications_enabled 0
Enable/Disable pop-up notifications on an android device
Disable: 0 Enable: 1
adb shell settings put global always_finish_activities 0
Enable/Disable aggressive finishing of activities and processes
Disable: 0 Enable: 1
adb shell settings put system accelerometer_rotation 0
Important:
The location_mode setting can only be used on API level 19 (Android Version 4.4) to API level 28 (Android Version 9) devices.
To execute these commands, use the browserstack.devicePreferences capability in your tests and set the required settings to your desired values inside the appropriate setting type object. The following table shows the BrowserStack compatible JSON-object format for the settings:
var capabilities ={"bstack:options":{"devicePreferences":{"settings.global":{"headsUpNotificationsEnabled":0,"alwaysFinishActivities":0},"settings.secure":{"locationMode":0},"settings.system":{"accelerometerRotation":0,"userRotation":3}}}}
var capabilities ={"browserstack.devicePreferences":{"settings.global":{"headsUpNotificationsEnabled":0,"alwaysFinishActivities":0},"settings.secure":{"locationMode":0},"settings.system":{"accelerometerRotation":0,"userRotation":3}}}
Get diagnostic output for system services using dumpsys commands
dumpsys is a tool that runs on Android devices and offers information on system services. adb shell dumpsys commands provide vital diagnostic output for system services operating on a connected device.
The following table lists all the dumpsys commands that can be used in an App Automate session:
Provides even more detailed frame timing information from recent frames
adb shell dumpsys gfxinfo <package_name> reset
Resets the framemetrics data
Command
Description
adb shell dumpsys input
Dumps the state of the system’s input devices, such as keyboards and touchscreens, and the processing of input events
Command
Description
adb shell dumpsys cpuinfo
Provides info on CPU usage
adb shell dumpsys display
Provides info on display
adb shell dumpsys power
Provides info on power statistics
adb shell dumpsys alarm
Provides info on alarm
adb shell dumpsys location
Provides info on location
adb shell dumpsys window displays
Provides info like pixel resolution, FPS, and DPI of the device’s display
adb shell dumpsys telephony.registry
Gives information about wireless communication related parameters
adb shell dumpsys bluetooth_manager
Gives information about connected bluetooth devices, mac addresses etc.
Command
Description
adb shell dumpsys netstats
Displays network connections for the Transmission Control Protocol for both incoming and outgoing requests
adb shell dumpsys netstats detail
Outputs additional information, such as detailed unique user ID (UID) information
adb shell dumpsys connectivity
Provides the internet status and connectivity mode(cellular or Wi-Fi)
adb shell dumpsys netpolicy
Generates a report that includes the current global background network restriction setting, package UIDs that are currently allowed to bypass Data Saver, and the network permissions of other known packages
adb shell dumpsys network_management
Provides all information about device network management
Command
Description
adb shell dumpsys batterystats options
Generates interesting statistical data about battery usage on a device, organized by unique user ID (UID)
caps["javascriptEnabled"]="true"#include this capability for JavaScript Executors to work
driver.execute_script("browserstack_executor:{
\"action\":\"adbShell\",
\"arguments\":{
\"command\" : \"dumpsys gfxinfo <package_name>\"
}}"
);
The output of the above-mentioned dumpsys commands would be captured under text logs on the App Automate dashboard.
Note: For grep commands like adb shell dumpsys activity -p <package_name> activities | grep -E 'mResumedActivity', please ensure that the JSON is in one of the following formats:
caps["javascriptEnabled"]="true"#include this capability for JavaScript Executors to work
driver.execute_script("browserstack_executor:{
\"action\":\"adbShell\",
\"arguments\":{
\"command\" : \"getprop ro.system.build.version.sdk\"
}}"
);