AndroidShell
Android Developers are used to use an amount of shell commands in their everyday work, so I'm gonna recopilate some good shell commands to make search easier
Install / Use
/learn @cesards/AndroidShellREADME
AndroidShell (Mac Os Commands)
Table of Contents
- <a href="#sha1">SHA-1</a>
- <a href="#debug_keystore">Debug Keystore</a>
- <a href="#release_keystore">Release Keystore</a>
- <a href="#adb">ADB</a>
- Select a device when multiple devices are connected
- <a href="#server_actions">Server actions</a>
- Show launcher activity cold start time
- <a href="#database">Database</a>
- <a href="#watching_strictmode">Watching StrictMode</a>
- <a href="#view_connected_devices">View connected devices</a>
- <a href="#list_running_services">List of running services</a>
- <a href="#install_application">Install an application</a>
- <a href="#uninstall_application">Uninstall an application</a>
- <a href="#start_activity">Start an Activity</a>
- <a href="#open_deep_linking_intent">Open a deep linking intent</a>
- <a href="#take_screenshot">Take an screenshot</a>
- <a href="#power_button">Power button</a>
- <a href="#unlock_screen">Unlock screen</a>
- <a href="#print_installed_packages">Print all installed packages</a>
- <a href="#path_application">Get the path of an installed application</a>
- <a href="#simulate_application_being_killed">Simulate application being killed</a>
- <a href="#screen_recording_using_4_4">Screen recording using Android 4.4</a>
- <a href="#check_battery_stats">Check battery stats</a>
- <a href="#auto_backup_data_android_m">Auto Backup Data (only in Android M)</a>
- <a href="#simulate_fingerprint_inputs_android_m">Simulate fingerprint inputs (only in Android M)</a>
- <a href="#filter_tagname_logcat">Filter by tagname in Logcat</a>
- <a href="#filter_priority_logcat">Filter by priority in Logcat</a>
- <a href="#filter_using_grep_logcat">Filter using grep in Logcat</a>
- <a href="#see_executed_sql_statements_plain_text_logcat">See the executed SQL statements in plain text in Logcat</a>
- <a href="#execute_monkey_test_user_interaction">Testing - Execute Monkey to test user interaction</a>
- <a href="#find_out_processor_version_android">Find out processor version on Android Device (check if it's an ARM, for example)</a>
- Test Alarms
- Query a Content Provider
- <a href="#find_out_abi">Find out Application Binary Interface (ABI) in different devices</a>
- <a href="#retrieve_app_private_data_and_db_without_root">Retrieve application's private data and databases for non debug application without root access</a>
- <a href="#identify_frame_rate_issues">Indentify Frame Rate Issues (Dumpsys)</a>
- <a href="#adb_over_wifi">Use ADB over Wi-Fi without extra application or software</a>
- <a href="#test_new_marshmallow_permissions">Test new Marshmallow permissions</a>
- <a href="#test_app_with_app_standby">Testing your app with App Standby</a>
- <a href="#test_app_doze">Testing your app with Doze</a>
- <a href="#enabling_night_mode_android_nougat">Enabling Night Mode on Android Nougat</a>
- Copy files from/to a device/emulator
- Trigger a notification without GCM
- <a href="#aapt">AAPT</a>
- <a href="#check_permissions_avoid_play_store_app_filtering">Check Permissions in order to avoid Play Store app filtering</a>
SHA-1
In order to get SHA1 to use it in many services, like Google+ Sign In, Maps, In app purchases, we should generate keys for every keystore (certificate):
<a name="debug_keystore"> #### Debug KeyStore ```sh $ keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android ``` or$ keytool -list -v -keystore {path_to_keystore}/debug.keystore -alias androiddebugkey -storepass android -keypass android
<a name="release_keystore">
#### Release KeyStore
```sh
$ keytool -list -v -keystore {path_to_keystore}/my-release.keystore -alias {alias_name} -storepass {store_pass} -keypass {keypass}
```
<br>
<a name="adb">
### ADB
Select a device when multiple devices are connected
You can use adb devices -l to check information related to them, in order to select the one you want. Then:
adb -s <device-serial> <instructions>
where <device-serial> is the number listed when you use adb devices and <instructions> are the instructions you want to execute over the device.
The following command kills the adb server:
adb kill-server
This starts the adb server:
adb start-server
<br>
Show launcher activity cold start time
$ adb logcat | grep "ActivityManager"
The output would be something similar to:
ActivityManager: Displayed com.example.launchtime/: +666ms
If we also use want to show the content ready time, we should use the API method reportFullyDrawn:
ActivityCompatAdditions.reportFullyDrawn(this);
Then the time output will be the actual time that takes to Activity to be ready:
ActivityManager: Displayed com.example.launchtime/.LaunchTimeActivity: +666ms
ActivityManager: Fully drawn com.example.launchtime/.LaunchTimeActivity: +1s440ms
Amount of time that takes to draw the first frame + the content.
We can also use the Activity start command from ADB, with the W flag:
adb shell am start -W com.package.name/.LauncherScreenActivity
We will see 3 times related to starting times.
<br> <a name="database"> #### DatabaseThis is a Database getter script, developed by Ignasi
#!/bin/bash
# android 4.3+ changes app's internal directory permissions and you can not just pull your
# databases to your computer, so this is a workaround to extract your databases.
# I only use it for debug, use it under YOUR responsability. IT REQUIRES ROOT
package=$1
db_name=$2
path="/data/data/$package/"
rm $db_name
adb shell "su -c 'cd $path; chmod -R 777 databases; exit'; exit"
adb pull $path/databases/$db_name
open $db_name
<a name="watching_strictmode">
#### Watching StrictMode
If you’re using penaltyLog(), the default, just run
$ adb logcat
and watch the terminal output. Any violations will be logged to your console, slightly rate-limited for duplicate elimination.
If you want to get fancier, turn on penaltyDropbox() and they’ll be written to the DropBoxManager, where you can extract them later with
$ adb shell dumpsys dropbox data_app_strictmode --print
<a name="view_connected_devices">
#### View connected device
$ adb devices
If multiple devices are attached, use adb -s DEVICE_ID to target a specific device
$ adb shell dumpsys activity services
<a name="install_application">
#### Install an application
$ adb install -r file.apk // (or com.package.name)
# optional -r argument reinstalls and keeps any data if the application is already installed on the device.
# optional -s argument installs the app on the SD card instead of the internal storage.
<a name="uninstall_application">
#### Uninstall an application
$ adb uninstall com.package.name
To uninstall the application using uninstall dialog:
$ adb shell am start -a android.intent.action.DELETE -d package:com.package.name
To keep the data in the cache directory, add -k
$ adb uninstall -k com.package.name
<a name="start_activity">
#### Start an Activity
$ adb shell am start -n com.package.name/.ActivityName
$ adb shell am start -n com.package.name/com.package.name.ActivityName
<a name="open_deep_linking_intent">
#### Open a deep linking intent
$ adb shell am start -n android.intent.action.VIEW -d "scheme://app/deep/linking"
or
$ adb shell am start -n android.intent.action.VIEW -d "https://name.app/user-settings/324" com.packaging.app
<a name="take_screenshot">
#### Take an screenshot
$ adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen_name.png
Explanation of this command, here
<a name="power_button"> #### Power buttonThis command sends the power button event to turn the device ON/OFF.
$ adb shell input keyevent 26
$ adb shell inout text "KEYCODE_POWER"
<a name="unlock_screen">
#### Unlock screen
This command sends the event that unlocks the lockscreen on the device. It can be combined with the power button command above to turn on and unlock the device
$ adb shell input keyevent 82
$ adb shell inout text "KEYCODE_MENU"
$ adb shell input keyevent 26 82
$ adb shell inout text "KEYCODE_POWER" "KEYCODE_MENU"
<a name="print_installed_packages">
#### Print all installed packages
$ adb shell pm list packages -f
<a name="path_application">
#### Get the path of an installed application
$ adb shell pm path app.package.application-name
<a name="simulate_application_being_killed">
#### Simulate application being killed
# exit your app using home button
# After that.
$ adb shell ps // Find the process id
$ adb shell ps | grep your.app.package // Then find the line with app name package
$ adb shell kill -9 21997 // Kill the app by PID
# Now return to the app using the task switcher.
<a name="screen_recording_using_4_4">
#### Screen recording using Android 4.4
$ adb shell screenrecord --verbose /sdcard/nexus5.mp4 // Basic recording from shell
# Press Ctrl-C to stop.
$ screenrecord --verbose --time-limit 30 /sdcard/nexus5.mp4 // Recording for 30 seconds
$ screenrecord --verbose --bit-rate 8000000 --time-l
Security Score
Audited on Mar 19, 2026
