Tuesday 24 May 2016

Android debugging

Android Debugging Tools and Techniques

How to download the offline Google maps and navigate to particular location 

 Go through this link
https://support.google.com/maps/answer/6291838?co=GENIE.Platform%3DAndroid&hl=en






How to confirm how much density your android application is supporting
1.    Download your apk file
2.    Extract you apk file , if you don’t have tool  to extract got to this link http://www.javadecompilers.com/
3.    You can see manifest file inside the you can see some kind of code
4.  <?xml version="1.0" encoding="utf-8"?>
5.  <manifest xmlns:"http://schemas.android.com/apk/res/android" android:versionCode="8" android:versionName="1.0.3" android:installLocation="preferExternal" package="com.bossastudios.twadroid">
6.      <supports-screens android:anyDensity="true" android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" />
7.      <compatible-screens>
8.          <screen android:screenSize="normal" android:screenDensity="mdpi" />
9.          <screen android:screenSize="normal" android:screenDensity="hdpi" />
10.         <screen android:screenSize="normal" android:screenDensity="xhdpi" />
11.         <screen android:screenSize="large" android:screenDensity="mdpi" />
12.         <screen android:screenSize="large" android:screenDensity="hdpi" />
13.         <screen android:screenSize="large" android:screenDensity="xhdpi" />
14.         <screen android:screenSize="xlarge" android:screenDensity="mdpi" />
15.         <screen android:screenSize="xlarge" android:screenDensity="hdpi" />
16.         <screen android:screenSize="xlarge" android:screenDensity="xhdpi" />
17.         <screen android:screenSize="large" android:screenDensity="UNKNOWN_DATA_0xd5" />
18.         <screen android:screenSize="normal" android:screenDensity="UNKNOWN_DATA_0x1e0" />
19.         <screen android:screenSize="large" android:screenDensity="UNKNOWN_DATA_0x1e0" />
20.         <screen android:screenSize="xlarge" android:screenDensity="UNKNOWN_DATA_0x1e0" />
21.         <screen android:screenSize="normal" android:screenDensity="UNKNOWN_DATA_0x280" />
22.         <screen android:screenSize="large" android:screenDensity="UNKNOWN_DATA_0x280" />
23.         <screen android:screenSize="xlarge" android:screenDensity="UNKNOWN_DATA_0x280" />
24.     </compatible-screens>
Highlighted point android:screenDensity="mdpi = ~160dpi
Mdpi has some value
A set of six generalized densities:
·         ldpi (low) ~120dpi
·         mdpi (medium) ~160dpi
·         hdpi (high) ~240dpi
·         xhdpi (extra-high) ~320dpi
·         xxhdpi (extra-extra-high) ~480dpi
·         xxxhdpi (extra-extra-extra-high) ~640dpi

you can confirm application supporting density

 for More detail you can go through this link  https://developer.android.com/guide/practices/screens_support.html



Android logs

Android maintains several continuous logs:
  • Main logs - debug statements from apps. Uses this class android.util.Logs.
  • System logs - used to record certain system level events such as GC , Activity Manager state , System watchdogs etc
  • Radio logs - radio and telephony activity such as RIL. Messages with the Special tags like “RIL”,”ConnectivyServices” will be route to radio buffer.
  • Event logs - sequence of important operations in apps and framework
  • Kernel logs - debug output showing Linux kernel activity
      1. Getting logs from the device

  • All eng and userdebug builds have logging enabled via aplogd. Also in user builds aplogd is present but disabled.
  • Connect usb and pull logs from the phone using adb command .
  • Dump from aplogd prior to pulling it from device. aplogcat utility located in /system/bin on the device is used to retrieve logs
  • To get the current Bootup logs command used :
adb shell aplogcat -d -o /cache/tmp/ -n 1
  • For Previous bootup :
adb shell aplogcat --dump -o /cache/ -k 10 -n 1 , K= number of reboot.
  • These logs help root cause an issue by analysing the event around the time an issue occurs
      1. Android Types of Errors

        1. Application Not Responding


System displays an ANR if an application cannot respond to user input within the time frame. For example, if a thread(Main/UI) is block by some operation , then the main application thread won't be
able to process incoming user input events for that application .So after some specified time the system thinks that the application is stuck , and displays the option to kill the application.
Activity Manager & Window Manager system services measures the responsiveness of the app.
Android will display the ANR dialog for an APP when it detects one of the below conditions:
  • No response to an input event (e.g. key press, screen touch) within 5 seconds
  • A BroadcastReceiver hasn't finished executing within 10 seconds
If the thread is not responding .ANR traces will be written to the “data/anr/traces.txt”.
Visible ANR:
In Android, if an application is found unresponsive for a long period of time, the system can prompt the user with the ANR dialog, and the user can choose either to stop it immediately or to continue waiting. Here’s an example of the ANR dialog:
Invisible ANR:
The Android system will kill the process of that application instead of showing the ANR dialog, if the unresponsive application is in background (i.e. invisible), and one of the following conditions is true:
1. The build type is “user”, i.e. the type of the products for end users
2. The property “debug.mot.killbganrs” is set to “1”
3.The value of the secure setting “anr_show_background” is “0”


The Android system reports an ANR issue when the main thread of an Android application is unable to process messages from user or from other Android processes.
The main thread is the only thread for Activities and Services. It’s thread ID equals the process ID.
The following operations in the main thread can lead to ANR:
  • Waiting on locks that can be held by other threads for a long time, or even in deadlock;
  • Entering an infinite loop so the main thread has no chances to process the messages in its message queue;
  • Network access, e.g. downloading files from Internet;
  • File access when the related storage partitions is busy doing I/O, typically the iowait is high
  • %iowait = (CPU Wait IO time)/(Total CPU time) * 100%
  • Accessing Database;
  • Accessing slow hardware (Camera, SIM card, etc.);
  • Invoking Thread.join(), Thread.sleep() or Object.wait();
  • Invoking blocking remote methods, e.g. methods in the other side of the Binder which modify files, run into deadlocks/deadloops, etc.
  • Invoking remote methods through Binder, but all the Binder threads (16 in total) in the peer process are occupied
The following operations in non-main threads can lead to ANR:
  • Blocked while holding locks which the main thread needs;
  • Blocking Binder transactions for a long time and finally the process has no free Binder thread
  • Sometimes the Android system reports an invalid ANR
  • For example, when it receives no response from a process, which died immediately after the system sends the message to the process;
  • These invalid ANR should be fixed in Android Framework, but not in applications
There are three kinds of ANR in Android:
  1. Key Dispatch timeout
It’s time out for key event response. If a key event can’t be handled within 10 seconds, there will be ANR generated.
Key dispatch overview architecture
  • Input Device (Touch screen/Keyborad, etc) driver writes the raw event into the input device file, eg, /dev/input/event4
  • In Framework layer, EventHub in InputReader reads the raw event from device file
  • The change in the input device files is detected by InputReader
  • InputReader reads the raw event and parses it
  • InputReader puts the parsed event into the queue in the InputDispatcher
  • InputDispatcher picks up the event and posts it to the real target window.


  1. Tools: AAPT


AAPT stands for Android Asset Packaging Tool. This tool is part of the SDK (and build system) and allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.
Build scripts and IDE plugins utilize this tool to package the apk file that constitutes an Android application.
    1. Usage

The parameters that can be used in AAPT are mentioned below
$ aapt
Android Asset Packaging Tool

Usage:
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
List contents of Zip-compatible archive.

aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
badging Print the label and icon for the app declared in APK.
permissions Print the permissions from the APK.
resources Print the resource table from the APK.
configurations Print the configurations in the APK.
xmltree Print the compiled xmls in the given assets.
xmlstrings Print the strings of the given compiled xml assets.

aapt p[ackage] [-d][-f][-m][-u][-v][-x][-z][-M AndroidManifest.xml] \
[-0 extension [-0 extension ...]] [-g tolerance] [-j jarfile] \
[--min-sdk-version VAL] [--target-sdk-version VAL] \
[--max-sdk-version VAL] [--app-version VAL] \
[--app-version-name TEXT] [--custom-package VAL] \
[-I base-package [-I base-package ...]] \
[-A asset-source-dir] [-G class-list-file] [-P public-definitions-file] \

[-S resource-sources [-S resource-sources ...]] [-F apk-file] [-J R-file-dir] \