/ docs / QA_Android.md
QA_Android.md
 1  ---
 2  id: QA_Android
 3  title: QA Android
 4  sidebar_label: QA Android
 5  ---
 6  
 7  
 8  
 9  # Testing Energy Consumption on Android
10  
11  ## Using Android Batterystats & Battery Historian
12  
13  Batterystats is a tool included in the Android framework that collects battery data on your device. Battery Historian converts the report from Batterystats into an HTML visualization that you can view in your browser.
14  
15  More info on [Batterystats & Battery Historian](https://developer.android.com/studio/profile/battery-historian.html).
16  
17  ### Prerequisites
18  
19  - docker
20  - git
21  - [adb](https://developer.android.com/studio/command-line/adb.html) (included in [Android SDK](https://developer.android.com/studio/index.html) Platform-Tools package)
22  - real Android device to measure battery consumption
23  
24  ### Setup
25  
26  1. Install and run Battery Historian:
27  ```
28  docker run -p 9999:9999 bhaavan/battery-historian
29  ```
30  2. Navigate to Battery Historian in your browser to confirm that it is running:
31  http://localhost:9999/
32  
33  ### Measure battery consumption
34  
35  Now it's time to measure battery consumption while performing a test / experiment. To get an idea what kind of test you should perform, check [types of experiments](./QA.md)
36  
37  
38  
39  1. First, make sure your device is recognized:
40  ```
41  adb devices
42  ```
43  2. Reset old battery data that has been gathered so far
44  ```
45  adb shell dumpsys batterystats --reset
46  ```
47  3. Disconnect your device from your computer so that you are only drawing current from the device's battery.
48  4. Perform actions for which you would like to test energy consumption.
49  5. Reconnect your phone.
50  6. Make sure your phone is recognized:
51  ```
52  adb devices
53  ```
54  7. Create a bugreport in current directory. The report contains logs the battery stats we are interested in
55  ```
56  adb bugreport
57  ```
58  
59  ### Analyse battery consumption
60  
61  Open the bugreport in Battery Historian:
62  1. Navigate to http://localhost:9999/
63  2. Click **Browse** and select the bugreport file
64  3. Click **Submit**
65  
66  #### Android Components actively drawing energy
67  
68  Historian chart describes Android components like WiFi, Camera, etc. that were actively drawing energy during the test. It also shows how battery level has was changing (**Show line overlay**).
69  
70  One of the most interesting components to check are SyncManager and JobScheduler. Their visualizations can make us aware if your app performs syncs and executes jobs more frequently than necessary.
71  
72  #### App specific data
73  
74  When you scroll down to **App Selection** and select Status (im.status.ethereum) you will see Status stats like:
75  - Device estimated power use (and power use due to CPU usage)
76  - Mobile data transfered
77  - Wakelocks time (how many times the app needed to wake up screen or CPU to complete some work which is a really costly activity)
78  - Time spent in foreground and background
79  
80  
81  ----
82  
83  Here is full description of how to analyse power usage with [Battery Historian](https://developer.android.com/topic/performance/power/battery-historian.html)