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

Version 25 (modified by albert, 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.


 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.

  1. Setting up Python. (I found this the hardest part.)
  2. Patching Seattle's nix_common_api.py so you can run scripts locally, and/or
  3. Patching Seattle's nix_common_api.py and runonce.py so you can run the installer which will configure the node manager (for donating resources).
  4. Running the node manager.

We can't setup Seattle for running at boot time using Python, but our native installer can.

Setting up Python

As far as I know, you cannot install Python as a standalone app right now. Therefore, these steps cover the installation of the Scripting Layer for Android, into which the actual Python interpreter will be installed. (Note to self: Restore our phone from a plain image and try out all the steps. I'm pretty sure I'm forgetting something.) (Another note to self: Include links to the official installation instructions for SL4A and  Py4A.)

  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 Scripting Layer for Android ( SL4A) from  here. Tap on the download notification to install.
  3. Download the Python 2.6.2 interpreter for Android ([Py4A]) from  here. Again, tap on the download notification to install. Congratulations! You can now run Python code from within SL4A, either using scripts from files or an interactive interpreter.
  4. Undo Step 1 for obvious security reasons.

For running Repy programs locally, SL4A is not the optimal choice, but 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.

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, add the following lines to /system/etc/bash/bashrc (Make sure /system/etc is mounted writable by issuing mount -o rw,remount /system as the superuser) :

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

(The last line is needed to make the Popen calls to the Python interpreter work). These lines are inspired by  this file in the Py4A repository, but not all of their path names work on our phone. I'm not blaming the original authors -- pathnames are a botch in Android, everything shows up in multiple places (/etc == /system/etc and so on), and all of a sudden you find yourself on a device not supporting links (sdcard, its filesystem is VFAT) or mounted read-only but listed as temp directory.

On my installation with bash, the Python interpreter can now be run from any path in the filesystem, and can import socket etc.

You can now proceed to downloading Seattle.

Seattle

General Installation Pitfalls

Download the Seattle Linux installer (it could be a customized installer as well). If you downloaded Seattle to the standard download folder on the SD card, it won't run even if correctly patched (stating "Bad interpreter: Permission denied") unless you remount the SD card with the exec option (as hinted  here). I rather moved the Seattle directory to /data/data/edu.washington.cs.seattle/, where the patched scripts can finally be started.

Running Repy Scripts Locally

Put a restrictions file (e.g. the one from the  Seattle demokit) into your seattle_repy directory. Patch nix_common_api.py because ctypes.util.find_library fails on Android. ( The Python docs say find_library uses ldconfig, gcc, and objdump to locate the library, neither of which are available on our Android.) Here's the relevant patch (you'll probably need to adapt the path/to/libc on your device):

localhost seattle_repy # diff ../../seattle/seattle_repy/nix_common_api.py nix_common_api.py
--- ../../seattle/seattle_repy/nix_common_api.py
+++ nix_common_api.py
@@ -17,7 +17,7 @@
 import textops
 
 # Get the standard library
-libc = ctypes.CDLL(ctypes.util.find_library("c"))
+libc = ctypes.CDLL("/system/lib/libc.so")
 
 # Functions
 _strerror = libc.strerror

Congrats, now you can run python repy.py restrictions.that_you_have your_script.repy!

Donating resources

Although installing Seattle through the install scripts doesn't work in all aspects right now, you can still donate resources by manually starting the node manager.

  1. If you didn't patch nix_common_api.py already, do it now, according to the patch above.
  2. Decide whom to donate your resources to. If you want to donate to the general public, proceed to the next step. To make sure you and your developer friends have access to the device, create a  customized installer ( how to) including everyone's public user keys. If you already have the Seattle files on your Android device, just overwrite the vesselinfo file with the version found in the customized installer.
  3. Check if runonce.py from the Seattle archive you extracted already includes the line import tempfile. Else grab a current version  (>=r4407) from SVN that doesn't use a hardcoded temp directory.
  4. Run python seattleinstaller.py. You might want to increase the percentage of resources donated using e.g. --percent 50. On our phone, 10 percent of resources mean even allpairsping needs to much RAM to run. The installer will claim it's installing on a Nokia N800/900 (due to it recognizing an ARM6 processor), and won't be able to configure Seattle for autostart.
  5. You might want to run python softwareupdater.py & now. Note that it will overwrite all your precious patched files, and I'm not quite sure how to find out that it has finished before you reapply the patches.
  6. Run python nmmain.py. It will take a while to register at the advertisement server.
  7. If you downloaded a customized installer that has your user key in the vesselinfo file, you can try to access your device using seash now.

Although the node manager is not registered to automatically start when the device boots, it can be run manually now. The software updater isn't started automatically either. It might be a good idea to run it from time to time to make sure you benefit from the latest improvements. Don't forget to apply the patches afterwards.


Attachments