Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Version 35 (modified by justinc, 7 years ago)

--

Seattle on Android

This page discusses our port of Seattle to the Android platform. You will be able to download a native Android installer (APK) Real Soon Now from our clearinghouse web site. In the meantime, find instructions how to install Python, the Seattle runtime, and the Seattle Node Manager below.


 Our device here is a ZTE Blade Android 2.3 ("Gingerbread") phone running  CyanogenMod 7.


Overview

Here is a general outline of steps to be performed. You will get access to Python, Repy (Seattle's runtime), and the Seattle Node Manager, respectively.

  1. Set up  Python for Android (Py4A).
  2. Check out? the latest version of Seattle from SVN (r5656 and later should work): svn co https://seattle.cs.washington.edu/svn/seattle/
  3. Install Seattle on the command line. This won't give you autostart capabilities, though.

(If you want to work on the SeattleOnAndroid GUI (not discussed here), import the code in seattle/trunk/dist/android as an "existing Android project" from within Eclipse. Then just "run as" on the android emulator or your device.)

Quite a few command line settings on this page requires your device to be rooted, i.e., you need root privilege on your phone to run these settings. How to root a device largely depends on the phone, Android version, etc. Fortunately  CyanogenMod firmware is rooted by default.

PS: Terminal commands on Android are either the limited version of standard Linux, or even not implemented (when you use adb shell, you can see all of the implemented commands in /system/bin). There is an app called Busybox in Play store which has better implementation of many (but not all) commands. To use Busybox, your device needs to be rooted.

Setting up Python for Android

  1. On the home screen, press Menu. Go to Settings > Applications and make sure Unknown Sources is checked. This is needed for installing non-Market APKs right after downloading them.
  2. Download the Python 2.6.2 interpreter for Android ([Py4A]) from  here. Tap on the download notification to install. Congratulations! You can now run Python code from within the Py4A GUI, either using scripts from files or an interactive interpreter.
  3. Undo Step 1 for obvious security reasons.

Python from shell

To get shell access to your device, run adb shell which comes within your android-sdk/platform-tools (the location may vary depending on your OS or other settings).  adb is Android debug bridge, which lets you communicate with a connected Android device or emulator instance.

Shell access to the Python interpreter is tricky to add because the shell knows nothing about Python's paths yet. Depending on which shell you have, there are different routes to take from here. Be sure to adapt the actual paths to your device/installation.

For sh (which is the default shell also greeting you via  adb's shell command), I don't know yet where it takes its run commands (.shrc) from. If you have  Jackpal's AndroidTerm2 installed, you could write an rc script and configure AndroidTerm to run it on startup: Press Menu, go to Settings > Start command and enter /path/to/your/script.

For bash, mount /system/etc writable by issuing mount -o rw,remount /system as the superuser (you need a rooted device here). Add the following lines to /system/etc/bash/bashrc (The last line puts the Python interpreter on your $PATH, so you can type python to access it right away):

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.googlecode.pythonforandroid/files/python/lib
export PYTHONPATH=/mnt/sdcard/com.googlecode.pythonforandroid/extras/python:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6:/data/data/com.googlecode.pythonforandroid/files/python/lib/python2.6/lib-dynload
export PYTHONHOME=/data/data/com.googlecode.pythonforandroid/files/python
export TEMP=$TEMP:/mnt/sdcard/com.googlecode.pythonforandroid/extras/python/tmp/
export PATH=$PATH:/data/data/com.googlecode.pythonforandroid/files/python/bin

These lines are inspired by  this file in the Py4A repository.

Setting up Repy

Repy is the restricted version of Python Seattle supports. To install the Repy runtime environment, you need to prepare the required files beforehand:

  1. Check out trunk (>=r5656) from Seattle's SVN
  2. Create a directory for the files we will upload to the Android device, let's call it /target.
  3. Inside trunk, run python preparetest.py /target.
  4. Download a restrictions file such as this one to /target.
  5. Finally, upload the contents of /path/to/files to your Android device, e.g. using adb push /target /seattle/on/android/directory.

If you want to allow Repy to collect data from your phone, you have to get a  Seattle Sensor running.  Here is one implementation that interfaces lots of sensors on your Android device, and makes values available in a GUI and programmatically over an XML-RPC interface.

Congrats, now you can run python repy.py restrictions.that_you_have your_script.repy from the command line!

Setting up the Seattle Node Manager

This doesn't work at the moment. seattleinstaller.py is not in the list of files preparetests.py thinks are necessary.


Attachments