Work2Code > Android Testing  > Random notes #1 – Learning Android Application Testing

Random notes #1 – Learning Android Application Testing

How to Root your Android device / phone?

# Go to http://kingoapp.com/

# Download and Install “KingoRoot for WIndows”

# After Installation:

  • Make sure your Anroid Developer Options is enabled
    • Go to “Settings” of your Android Device
    • Go to “About” Device and Tap 7 times on the Build Number
    • And then you should see “Developer Options” in “Settings”
  • Go to “Settings” → “Developer Options”
    • Turn the switch to ON for Developer Options
    • Also, turn “USB Debugging” option to ON.
  • Connect your device to the Computer (Windows Operating System) through USB

# Start the executable of KingoRoot.

[ Wait for your device to be connected ]

# Click on “Root” once the connection has been established between your computer and your android device.

[ Recommendation: It is good to have a good enough internet connectivity and speed ]

 

If you see “Root Succeeded” message on your Computer, it means your phone is rooted. Your device will restart and boot again. [ This is normal, don’t worry ].

 

Also, you should be able to see “Super User” app icon on the screen in your phone once the phone is rooted and restarted.

 

How to install Sqlite3 on Mac?

  1. Go to https://www.macports.org/install.php
  2. Download and install Macports (Check the Mac version and download the specific version of Mac Ports)
  3. Open the terminal → enter the command as “sudo port -v selfupdate”
  4. Once it is updated, enter the command as “sudo port install sqlite3”

[ You may see a prompt to continue or stop. Type ‘Y’ and hit ENTER ].

 

After this, you must be able to use sqlite3 and interact with the .db files or database files which use sqlite.

 

In the terminal, just type the command as “sqlite3” and hit ENTER.

 

Rooting using TWRP approach?

# Go to http://teamw.in/

# Check for devices compatibility for rooting your phone using TWRP

# Download the Odin software for your specific device which you want to root

# For instance: Samsung Galaxy Note II Android Device → 

  • Reboot your phone in Download Mode. Use “Volume Down + Power Button + Home Button” at a time.
  • Use Volume UP button when you see the booting instructions on the screen after restarting.

 

Android - Tester’s tool-kit (From Playstore)

Backup App - Download and install “Titanium Backup Root”

SuperSu Pro (Commercial, but better one than free one which you already have if you have rooted your phone)

Download and Install BusyBox

Terminal Emulator for Android 

ES File Explorer Manager

Tasker - Automation App [ Commercial ]

 

Cereberus Anti theft APK Download - https://www.cerberusapp.com/get

[ Download the standard version apk file. Make sure you rename the APK so that the thief doesn’t get to know that device is being tracked by Cereberus app ]

 

How to install Sqlite3 on Mac?

  1. Go to https://www.macports.org/install.php
  2. Download and install Macports (Check the Mac version and download the specific version of Mac Ports)
  3. Open the terminal → enter the command as “sudo port -v selfupdate”
  4. Once it is updated, enter the command as “sudo port install sqlite3”

[ You may see a prompt to continue or stop. Type ‘Y’ and hit ENTER ].

 

After this, you must be able to use sqlite3 and interact with the .db files or database files which use sqlite.

 

In the terminal, just type the command as “sqlite3” and hit ENTER.

 

Also, you can download GUI-based SQLite Browser from http://sqlitebrowser.org/ 

 

How to install battery historian and successfully generate the output html file?

# Pre-requisites: Install python and make sure you know to use adb commands and enabling developer options to allow USB debugging.

 

  • Download battery historian / clone battery historian.

              # git clone https://github.com/google/battery-historian

  • Find historian.py file in the folder that’s uncompressed or extracted
  • Once you find it, copy it to writable directory. That can be Desktop.
  • Connect your android device to the computer 
    • and start the adb by using ./adb start-server
    • ./adb devices
    • And reset the battery by ./adb shell dumpsys batterystats --reset
    • And then unplug the device from your computer and do some random activity or structured activity on phone.
    • After some time, connect it back to the computer
    • Use “./adb shell dumpsys > batterystats.txt
    • And once it is generated, use “python historian.py batterystats.txt > batterystats.html
    • Open the html file in a web browser
    • Good to go ahead with analysis of the report generated

 

Checklist to debug when things don’t work

  • Check if you have enabled USB debugging from Developer Options.

(For this your device has to be “developer” enabled. Go to About Phone and tap 7 times on       the Build Number to enable “Developer Options”).

  • Even if USB debugging (Developer Options) is enabled, try disabling and enabling it again.
  • Check if your USB cable is not just set to file transfer, but debugging
  • Check if your USB cable is functioning [I use USB connector checker device to check the cables].
  • Kill adb using “./adb kill-server” and start it again using “./adb start-server”. And then use “./adb devices” command.
  • Try reconnecting the USB to your computer and Android Phone if “device list shows as >> unauthorized <<”
  • If you see unauthorized when you type “./adb devices” (Like the following one)

Try the following way,

→ Go to “settings -> developer options” and tap on “Revoke USB debugging authorizations

→ And then turn off USB debugging and turn it ON again. Accept by tapping on “OK” buttons or “Allow” buttons.

→ Now, type “./adb devices” in your terminal window or command-line. You should see something like the following,

  • Make sure your Android Device is above 5.0
  • Maybe try changing the USB cable no matter it appears to work or not. (I mean, even though the Cable Tester said, cable is fine). Because sometimes the cable may be damaged for MTP / ADB, but only works for charging. Just charging it doesn’t mean that the cable is all great. Be skeptical. You’re a (passionate) tester.
  • Try using *#0808# and enable MTP + ADB from AP selection. (Not the CP). And then Reboot.
  • Try switching to different operating system (preferably, a pristine state OS if the existing used OS doesn’t yield any results).
  • If the above points do not work for you, try connecting to a different computer. Also, try checking if you can connect via WiFi.

 

ADB Commands that can help you be a better tester

  • ./adb start-server
  • ./adb kill-server
  • ./adb shell
  • ./adb devices
  • ./adb -s device-id shell
  • ./adb shell pm list packages
  • ./adb tcpip 5555
  • ./adb connect << ip-address-of-the-device-connected-to-the-same-wifi-as-computer >>
  • ./adb shell pm list packages
  • ./adb install < apk file location in the computer >
  • ./adb reboot ( Reboots the phone )
  • adb screencap filename.png
  • adb screenrecord 
  • adb pull /sdcard/filename.db << filename.db can be any other file >>
  • adb push 

 

Decompiling the Android App

  • Jadx or dex2jar or apktool
  • We will try installing apktool in this demonstration,
    • Prerequisite: Java 7 (JRE 1.7)
    • Once Java 7 (JRE 1.7) is installed, type “java -version” in your command-line terminal to see something like following,
    • Download the latest apktool jar file from https://bitbucket.org/iBotPeaches/apktool/downloads/
    • Rename the downloaded jar file to apktool.jar
    • NOTE: Use wrapper script for Mac / Linux / Windows and you can save it from https://ibotpeaches.github.io/Apktool/install/
    • I use Mac, so I move both apktool.jar file and apktool Mac wrapper scripts to /usr/bin directory
    • And then I run chmod +x for both the files to make them executable.
    • Finally, try using apktool command in your terminal. You should see it working.
  • Once you are done with apktool installation, use the following command to decompile an apk file.

Analysing and investigating via SQLite3 commands

  1. Copy  the database using “/data/data/jakhar.aseem.diva/databases/divanotes.db /mnt/sdcard” in the adb shell
  2. Exit the adb shell and use “./adb pull /mnt/sdcard/divanotes.db .” ← This will copy divanotes.db from sdcard to present working directory.
  3. Make sure you have installed sqlite3 using the above process using MacPorts and installing sqlite3.
  4. Use “sqlite3 divanotes.db”
  5. And then type “.tables” to display the tables.
  6. Use “select * from table_name”
  7. Also, you can neatly display the contents of the particular table using headers. Use “.headers on”.
  8. You also have various modes and one of the mode that I like is, “.mode column”. This lists the data very organised and readable. (Just like below)

Points to remember

  • Whenever you receive “permission denied” error in the adb shell, try using “su” and get the root access to access the files.

For example: When I wanted to access the package list under /data/data, I entered “ls” and the adb shell displayed “permission denied” error.

Later, I entered “su” command in the shell and then things worked well.

Santhosh Tuppad

Santhosh Tuppad has played different roles in his life which include being an entrepreneur, liar, lover, boyfriend, husband, thief, passionate software tester, blogger, reader, trainer, coach, black-hat hacker, white-hat hacker, grey-hat hacker and what not. In this amazing journey of life, he has experienced his salvation. Not to forget that, “Salvation comes at a price” and of course he has paid that price. Before he was known for being merciless, ruthless, unkind, evil, etc. And today he is known for kindness, humbleness, and some people call him “Privacy Fighter”.

No Comments

Leave a reply