Giter VIP home page Giter VIP logo

androidshell's Introduction

AndroidShell (Mac Os Commands)

Summary:
Maps
ADB
Database

### MAPS

Debug KeyStore

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
### ADB

View connected devices

``` adb devices ``` If multiple devices are attached, use `adb -s DEVICE_ID` to target a specific device

Install an application

``` adb install -r file.apk // Optional -r argument reinstalls and keeps any data if the application is already installed on the device ```

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 ```

Start an activity

``` adb shell am start -n com.package.name/.ActivityName adb shell am start -n com.package.name/com.package.name.ActivityName ```

Take a screenshot

``` adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen_name.png ``` Explanation of this command, [here](http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html)

Power button

``` adb shell input keyevent 26 adb shell inout text "KEYCODE_POWER" ``` This command sends the power button event to turn the device ON/OFF

Unlock screen

``` adb shell input keyevent 82 adb shell inout text "KEYCODE_MENU" ``` 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 26 82 adb shell inout text "KEYCODE_POWER" "KEYCODE_MENU" ```

Print all installed packages

``` adb shell pm list packages -f ```

Simulate application being killed

``` // 1 - Exit your app using home button // 2 - 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 // 3 - Now return to the app using the task switcher ```

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-limit 30 /sdcard/nexus5.mp4 // Recording for 30 seconds with 8Mbps bitrate screenrecord --verbose --rotate /sdcard/nexus5.mp4 // Record in portrait view / horizontal ```

Retrieve application's private data and databases for non debug application without root access

``` // Get a backup of your application data adb backup --apk com.package.name // Change the .ab in .tar dd if=backup.ab bs=24 skip=1 | openssl zlib -d > backup.tar // Untar backup.tar tar xfv backup.tar // Go in you app private dir cd apps/com.package.name ``` > You'll need : > - adb activated > - physical access to unlocked device > - works on Nexus 5 at least, might not work with other devices. > __allowBackup=false will break thos method__

Check Battery Stats

``` $adb shell dumpsys batterystats // Global and per-UID statistics // options: --help ```

Use ADB over Wi-Fi without extra application or software

__Prerequisites__ Android device and computer should be connected in same network. * Connect Android device with USB cable to computer * Use following command in terminal to make sure adb is running in USB mode. ``` $adb usb // Restarting in USB mode // Connect to the device over USB. ```
  • Execute following command in terminal to make sure adb identify/list gets connected with the device.
$adb devices
  • Change adb mode from USB to tcpip using following command.
$adb tcpip 5555
// Restarting in TCP mode port: 5555
  • Now, adb is running over TCP/IP mode, Let’s find IP address of Android device. Go to Settings in Android device -> About -> Status -> IP address. note down the IP address of connected Android Device.
  • Use following command to connect ADB with IP address
$adb connect #.#.#.# 
// Connected to #.#.#.#:5555
  • Now adb is working over Wi-fi, You can remove USB cable from Android device.
  • To confirm adb is working over Wi-fi and your device is still connect. you can use following command
$adb devices
#.#.#.#:5555 device

You’re now ready to go!, Enjoy ADB over Wi-fi. Use following command to change ADB mode to USB

$adb usb

Filter by tagname in logcat

``` adb logcat -s TAG_NAME adb logcat -s TAG_NAME_1 TAG_NAME_2 ```

Filter by priority in logcat

``` adb logcat "*:" // Where can be V (Verbose), D (Debug), I (Info), W (Warning), E (Error), F (Fatal), S (Silent) ``` It can be combined with tagname command, to filter by tagname and priority ``` adb logcat -s TEST: W ```

Filter using grep in logcat

``` adb logcat | grep "term" adb logcat | grep "term1\|term2" ````

See the executed SQL statements in plain text in logcat

``` adb shell setprop log.tag.SQLiteLog V adb shell setprop log.tag.SQLiteStatements V adb shell stop adb shell start ``` That's it. Whenever any of the installed apps now accesses the database you should see the executed statement in the log output.

Testing - Execute Monkey to test user interaction

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

adb shell monkey [options] <event-count>
// Basic, make 500 random actions
adb shell monkey -p your.package.name -v 500 

Complete information at http://developer.android.com/tools/help/monkey.html

Indentify Frame Rate Issues (Dumpsys)

``` cd platform-tools/ // Before executing next command, go to Settings --> Developer Options --> Enable Profile GPU rendering option // And make sure to kill your application first or at least to kill the window that you want to profile, and then you run the command: adb shell dumpsys gfxinfo ``` Purpose of Dumpsys is identifying frame rate issues and fix them.

What matter is the three columns shown. Copy paste results in a spreadsheet. And you will get a result like this one:

Image

This is the data you can grab. You can create a stack graph, so every bar contains the sum of the three columns on the left in the data we output. Is the time it takes to update the display list on every frame.

  • The middle column is called process display list. It's the time we take to draw the actual display list
  • The last column is the time we take to swap the buffers, so to give the buffer back to surface flinger. Scrolling or doing any kind of actions should be below 16 millisecond limit. So this app is running at 60FPS, we're vsync'd, everything is going great. You can see that most of the time, you should spend most of the time in process display list, so drawing, executing the display list should be where you spend the bulk of the time.
  • The blue part is your code. When you write your Java code, your onDraw() method, and this is where you can do most of the optimizations

There is a distinction between the GPU composition with frame buffers and overlays. So you can use a tool called dumpsys surface flinger to see the state of overlays and frame buffers in the system.

adb shell dumpsys SurfaceFlinger

You're going to get a list with all the windows currently visible on the screen.

More info about this tool, here

### Database

DB Getter (Script) 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

androidshell's People

Contributors

aracem avatar cesards avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.