Monday, June 04, 2012

monkeyrunner: Q&A

Thanks for the response.
To get more specific for what I was looking at is, to use getCallState()getDataActivity() etc.

[Reference:] is Monkeyrunner scripts.

Please let me know if this is a possible idea,

(This question was posted as a comment to monkeyrunner:  visual image comparison)

Taking the right approach this is pretty simple and straightforward. If you have been followed the posts in this blog you may have noticed some time ago we introduced AndroidViewClient in monkeyrunner: interacting with the Views. Well, we can use exactly the same technique to invoke Android services and get the results, but in this case we will be invoking the phone service instead.

#! /usr/bin/env monkeyrunner
Created on Jun 2, 2012

Take a look at:

@author: diego

import sys
import re

from import MonkeyRunner, MonkeyDevice

DEBUG = True
android_os_IBinder_FIRST_CALL_TRANSACTION = 1
TRANSACTION_getCallState = android_os_IBinder_FIRST_CALL_TRANSACTION + 28
TRANSACTION_getDataActivity = android_os_IBinder_FIRST_CALL_TRANSACTION + 29;

def telephonyManager(device, transaction):
    return serviceResponse('service call phone %d' % transaction))

def serviceResponse(response):
    m = re.match("Result: Parcel\((\d+) (\d+)   '........'\)\r\n", response)
    if m:
        return int(
    return -1

def main():
    device = MonkeyRunner.waitForConnection(60)

    print "call state: %d" % telephonyManager(device, TRANSACTION_getCallState)
    print "data activity: %d" % telephonyManager(device, TRANSACTION_getDataActivity)

if __name__ == '__main__':

Obviously, this can be extended to support other transactions or to interpret the results results in other ways.
Also, this same technique can be used to invoke other services.
Hope this helps.