Google Android adventures Entry: CPS and Activities Date: Thu Jan 7 15:43:57 CET 2010 The android application model is designed to limit memory usage. One of the main components visible to the application programmer is the ``swapping out'' of activities. Whenver an application looses focus its onPause() method is called. At this time, all Activity state needs to be saved in a Bundle: it might happen that the process running the VM hosting the Activity gets killed by the low memory killer in case memory is needed elsewhere. If you combine this with the highly a-synchronous nature of the android API, an application written in CPS becomes attractive. The main question is: how to represent tree / graph structures as an Intent? Entry: Building native applications Date: Fri Jan 29 12:48:40 CET 2010 The simplest approach is to add a new application to the main build tree, by adding a directory that contains an Android.mk file in the style of: # See examples: # system/core/sh/Android.mk # system/core/cpio/Android.mk LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ program.c LOCAL_MODULE:= program include $(BUILD_EXECUTABLE) To see what the build actially does, run this: $ make showcommands program target thumb C: program <= program/program.c prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -I system/core/include -I hardware/libhardware/include -I hardware/libhardware_legacy/include -I hardware/ril/include -I dalvik/libnativehelper/include -I frameworks/base/include -I frameworks/base/opengl/include -I external/skia/include -I out/target/product/generic/obj/include -I bionic/libc/arch-arm/include -I bionic/libc/include -I bionic/libstdc++/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -I bionic/libm/include -I bionic/libm/include/arch/arm -I bionic/libthread_db/include -I program -I out/target/product/generic/obj/EXECUTABLES/program_intermediates -I out/target/product/generic/obj/SHARED_LIBRARIES/libwebcore_intermediates -c -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/AndroidConfig.h -I system/core/include/arch/linux-arm/ -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Werror=return-type -DSK_RELEASE -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -MD -o out/target/product/generic/obj/EXECUTABLES/program_intermediates/program.o program/program.c target Executable: program (out/target/product/generic/obj/EXECUTABLES/program_intermediates/LINKED/program) prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/generic/obj/EXECUTABLES/program_intermediates/LINKED/program -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -lc -lstdc++ -lm out/target/product/generic/obj/lib/crtbegin_dynamic.o out/target/product/generic/obj/EXECUTABLES/program_intermediates/program.o -Wl,--no-undefined /usr/people/beschout.nba/sw/android-google/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a out/target/product/generic/obj/lib/crtend_android.o target Non-prelinked: program (out/target/product/generic/symbols/system/bin/program) out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/program_intermediates/LINKED/program out/target/product/generic/symbols/system/bin/program target Strip: program (out/target/product/generic/obj/EXECUTABLES/program_intermediates/program) out/host/linux-x86/bin/soslim --strip --shady --quiet out/target/product/generic/symbols/system/bin/program --outfile out/target/product/generic/obj/EXECUTABLES/program_intermediates/program Install: out/target/product/generic/system/bin/program out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/program_intermediates/program out/target/product/generic/system/bin/program From this we can distill a Makefile: # This is a small hack to use commands snarfed from the main android # system build to compile native applications. # # To obtain commands: # # - create a symbolic link: ln -s mtsa-watchdog $(ANDROID_SRC) # - make showcommands mtsa-watchdog # - observe commands, and replace .c and .o with parameters to create templates ANDROID_SRC := ~/sw_local/android-google HERE := $(shell pwd) # The commands below simply replace the .o .c and application files # with parameters $(1) $(2) and use the $(call ...) construct to # substitute. # Note: all targets need to use absolute paths. I.e. to manually build targets use: # # make `pwd`/watchdog.o # <1:in> <2:out> android_compile = prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -I system/core/include -I hardware/libhardware/include -I hardware/libhardware_legacy/include -I hardware/ril/include -I dalvik/libnativehelper/include -I frameworks/base/include -I frameworks/base/opengl/include -I external/skia/include -I out/target/product/generic/obj/include -I bionic/libc/arch-arm/include -I bionic/libc/include -I bionic/libstdc++/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -I bionic/libm/include -I bionic/libm/include/arch/arm -I bionic/libthread_db/include -I program -I out/target/product/generic/obj/EXECUTABLES/program_intermediates -I out/target/product/generic/obj/SHARED_LIBRARIES/libwebcore_intermediates -c -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/AndroidConfig.h -I system/core/include/arch/linux-arm/ -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Werror=return-type -DSK_RELEASE -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -MD -o $(2) $(1) # <1:in> <2:out> android_link = prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o $(2) -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -lc -lstdc++ -lm out/target/product/generic/obj/lib/crtbegin_dynamic.o $(1) -Wl,--no-undefined /usr/people/beschout.nba/sw/android-google/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a out/target/product/generic/obj/lib/crtend_android.o %.o: %.c cd $(ANDROID_SRC) ; $(call android_compile,$<,$@) %.x: %.o cd $(ANDROID_SRC) ; $(call android_link,$<,$@) .PHONY: all clean TARGETS := $(HERE)/program.x all: $(TARGETS) clean: rm -rf *.o *~ *.d $(TARGETS)