apkcrawler: Initial commit.
Currently, the program successively installs each APK located in
/apkcrawler/apks, launches the default activity, and prints information
about each of the visual components, followed by the ids of the
clickable components.
Change-Id: Ia3325a4843d64bd30426fec1bf458c16d706526a
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c6f377d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.pyc
+*.py~
+*.apk
diff --git a/crawlui.py b/crawlui.py
new file mode 100644
index 0000000..83d8e52
--- /dev/null
+++ b/crawlui.py
@@ -0,0 +1,29 @@
+"""A module for installing and crawling the UI of Android application."""
+
+import subprocess
+import sys
+import os
+
+_ADB_PATH = os.path.expanduser('~') + "/Android/Sdk/platform-tools/adb"
+
+from com.dtmilano.android.viewclient import ViewClient, View
+
+def crawl_package(apk_dir, package_name, vc, device):
+
+ # Install the app.
+ subprocess.call([_ADB_PATH, 'install', '-r', apk_dir + package_name + ".apk"])
+
+ # Launch the app.
+ subprocess.call([_ADB_PATH, 'shell', 'monkey', '-p', package_name, '-c',
+ 'android.intent.category.LAUNCHER', '1'])
+
+ view = vc.dump()
+
+ # Print the details of every component in the view.
+ for component in view:
+ print ">>Component:", component
+
+ # Print only the names of clickable components.
+ for component in view:
+ if (component.isClickable()):
+ print ">>Clickable component:", component['uniqueId']
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..9fbad7b
--- /dev/null
+++ b/main.py
@@ -0,0 +1,43 @@
+"""The main module for the APK Crawler application."""
+
+import sys
+import subprocess
+import os
+import crawlui
+
+_ADB_PATH = os.path.expanduser('~') + "/Android/Sdk/platform-tools/adb"
+_APK_DIR = os.path.dirname(os.path.abspath(__file__)) + "/apks/"
+
+# PyDev sets PYTHONPATH, use it
+try:
+ for p in os.environ['PYTHONPATH'].split(':'):
+ if not p in sys.path:
+ sys.path.append(p)
+except:
+ pass
+
+try:
+ sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
+except:
+ pass
+
+from com.dtmilano.android.viewclient import ViewClient
+
+
+if __name__ == '__main__':
+
+ kwargs1 = {'verbose': True, 'ignoresecuredevice': True}
+ kwargs2 = {'startviewserver': True, 'forceviewserveruse': True,
+ 'autodump': False, 'ignoreuiautomatorkilled': True}
+ device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
+ vc = ViewClient(device, serialno, **kwargs2)
+
+ # Simple setup
+ #device, serialno = ViewClient.connectToDeviceOrExit()
+ #vc = ViewClient(device, serialno)
+
+ package_list = os.listdir(_APK_DIR)
+ for package in package_list:
+ app_name = package.split(".apk")[0]
+ print app_name
+ crawlui.crawl_package(_APK_DIR, app_name, vc, device)