0

I'm doing a battery analysis of my app, I'm left with these options only:

  1. Disable USB charging on the device, which I have not been able to do yet and take screenshot using monkeyrunner of Settings -> Battery screen
  2. Without the USB cable attached, I can use simulate the down volume key + power key hold event through a shell script running on my rooted phone to take the screenshot of the Settings -> Battery screen
  3. Get the dumpsys battery which shows all processes like its listed in Settings -> Battery again using a shell script running in adb shell on a rooted phone, but I do not know the command

Every method has its own limitations. Is there any way in which I can achieve my objective??

Rohan
  • 1,705
  • 7
  • 17
  • 38
  • Which are the limitations you want to overcome? – Royston Pinto Oct 03 '12 at 10:00
  • limitations like disable USB charging, so that i can take the screenshots with the cable connected. if i disconnect the cable, then monkeyrunner's screenshot wont work, etc.. hope you got my point – Rohan Oct 03 '12 at 10:03

3 Answers3

1

If your goal is power consumption analysis, have a look at Application Resource Optimizer (ARO) from AT&T research labs. I think it's exactly what you're looking for. It will give you a much more accurate analysis than screenshots.

onon15
  • 3,620
  • 1
  • 18
  • 22
1

With the ICS and above, all phones are bundled in with a exe named screencap in /system/bin. Run the below command line to take a screenshot

screencap -p /sdcard/screenshot.png

This can also be done by grabbing shell using Java, so you can capture sceenshot as and when you will want to.

Royston Pinto
  • 6,681
  • 2
  • 28
  • 46
  • any idea if i can run this using a shell script. I wrote a shell script with the command and fired it in adb shell. The file was created but i cannot pull it. I'm on a rooted device. But if I run the command independently, it runs and i can pull the screenshot. Any pointers regarding this? – Rohan Oct 03 '12 at 11:24
  • I just tried it with a simple shell script and its working fine for me. Pulling might be relating to another problem and not with the actual file generated. – Royston Pinto Oct 03 '12 at 11:33
  • mine was just a one liner: screencap -p '/sdcard/rohan1.png' (with and without single quotes. also tried double quotes). can you share your script, if you don't mind!! had kept my shell script in system/bin folder\ – Rohan Oct 03 '12 at 11:35
  • same one liner, screencap -p /sdcard/rohan1.png (no quotes). Kept my script in /data/ folder. then did a chmod 777 .sh and ran it with /data/ – Royston Pinto Oct 03 '12 at 11:40
  • i did the same thing. were you able to pull? – Rohan Oct 03 '12 at 11:56
  • Yes, successfully! No issues seen on my side. – Royston Pinto Oct 03 '12 at 13:35
1

I have some expertise in this question. To my point of view you have two options:

  1. You can create local monkey script and run it from shell on your device.
  2. You can connect your device over TCP/IP (WiFi) and store battery consumption snapshots.

EDIT

To run monkey script from device you need to run the following command (if I do not mess smth):

adb shell monkey -v -f /mnt/sdcard/script.txt

Script in this case use a bit unusual sintax (just an example, this is a script for default contacts application for Nexus S with gingerbread):

# Start of Script
type= user
count= 150
speed= 1.0
start data >>

#launch browser com.android.contacts/.DialtactsContactsEntryActivity
LaunchActivity(com.android.contacts, com.android.contacts.DialtactsContactsEntryActivity)
UserWait(4000)

#go to favorites tab
Tap(415, 85)
UserWait(3000)

#go to phone tab
Tap(60, 85)
UserWait(3000)

#calllog
Tap(175,90)
UserWait(2000)

#contacts
Tap(300,90)
UserWait(4000)

#create new contact
DispatchPress(KEYCODE_MENU)
UserWait(2000)
Tap(360,650)
UserWait(4000)

#go name
Tap(200,340)
UserWait(8000)
DispatchString(123)
UserWait(5000)

Tap(125,385)

#launching launcher and exit com.android.launcher/com.android.launcher2.Launcher
UserWait(10000)
LaunchActivity(com.android.launcher, com.android.launcher2.Launcher)
quit

As for me, it's easier to use the second approach (and it's more error prone). You can connect to your device over WiFi (thus, your USB cable is detached). For this you should:

  1. Connect your device over USB and run adb tcpip <port_num>
  2. Then connect your device to a WiFi network
  3. Then execute on your computer (that is also connected to the network) adb connect <phone_ip_addres>:<port_num>

Now you can fire monkeyrunner commands over WiFi using standard way for monkeyrunner (monkeyrunner <script_name>.py)

Yury
  • 20,618
  • 7
  • 58
  • 86
  • Won't the monkey script require a USB connection? If you can help me disable USB charging, then this idea would work for me :). In the second approach, I would require a shell script that will run after every hour for 24 hours – Rohan Oct 03 '12 at 11:29