Confirmed users, Bureaucrats and Sysops emeriti
882
edits
Joel Reymont (talk | contribs) |
|||
(7 intermediate revisions by one other user not shown) | |||
Line 30: | Line 30: | ||
Chris has a [http://chrislord.net/files/fosdem-09-slides.odp presentation] that explains the headless branch a bit and [http://chrislord.net/blog/Software/building-moblin-web-browser.enlighten instructions on how to build it]. | Chris has a [http://chrislord.net/files/fosdem-09-slides.odp presentation] that explains the headless branch a bit and [http://chrislord.net/blog/Software/building-moblin-web-browser.enlighten instructions on how to build it]. | ||
--- | |||
There's an [https://bugzilla.mozilla.org/show_bug.cgi?id=446591 existing bug] that deals with headless UI. | |||
= Previous statuses = | = Previous statuses = | ||
= Android Notes = | = Android Notes = | ||
== Can Android run a completely native app? == | |||
According to [http://sites.google.com/site/io/anatomy--physiology-of-an-android Anatomy and physiology] and [http://developer.android.com/guide/topics/fundamentals.html Android Fundamentals], each Android process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications. | |||
Android processes (Java VMs) communicate with the Home App and various system services via the [http://en.wikipedia.org/wiki/OpenBinder Binder IPC] described using [http://developer.android.com/guide/developing/tools/aidl.html Android Interface Definition Language (AIDL)]. | |||
The ''Home Application'' (Launcher) is the app that displays the Android desktop and allows the [http:///Volumes/android/mydroid/frameworks/base/core/java/android/app/LauncherActivity.java launching of other apps] by clicking on their icons. | |||
An ''activity'' presents a visual user interface for one focused endeavor the user can undertake. For example, an activity might present a list of menu items users can choose from or it might display photographs along with their captions. A text messaging application might have one activity that shows a list of contacts to send messages to, a second activity to write the message to the chosen contact, and other activities to review old messages or change settings. | |||
A ''task'' is a group of related activities. May include activities from other apps, running in other processes, e.g. map viewer. A task has an activity stack. | |||
Any given activity | |||
* Has a content view that is created using a layout resource. | |||
* Can be floating or embedded inside another activity. | |||
* Has a pause callback invoked when the user is leaving the activity. | |||
* Is visible when it's at the top of the stack for the current task. | |||
* Is paused when there's another activity on top of it but remains visible. It has lost focus but remains completely alive and attached to the window manager but can be killed in low memory conditions. | |||
* Is stopped when it's completely obscured by another activity. The window is hidden and activity will be killed when memory is needed elsewhere. | |||
* Has a finish callback that may be called when the activity is being evicted from memory. | |||
* Generates a thumbnail of the activity via a callback that's called before pausing. | |||
* Receives trackball and key events via callbacks. | |||
When an app icon is clicked, the Home app uses the package manager to retrive app info and package it into an [http:///Volumes/android/mydroid/frameworks/base/core/java/android/content/Intent.java intent], an asynchronous message with information necessary to start a given activity. The Home app then uses startActivity, a method of Context to launch the activity. [http:///Volumes/android/mydroid/frameworks/base/core/java/android/content/Context.java Context is an abstract class] whose implementation is provided by the Android system. | |||
The launch request is sent via the Binder IPC to the [http:///Volumes/android/mydroid/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java Activity Manager Service] which uses the [http:///Volumes/android/mydroid/frameworks/base/core/java/android/os/Process.java Process] class to start an [http:///Volumes/android/mydroid/frameworks/base/core/java/android/app/ActivityThread.java Activity Thread] in a new instance of the Dalvik Java VM via the [http:///Volumes/android/mydroid//Volumes/android/mydroid/system/core/libcutils/zygote.c Zygote]. | |||
The mechanism above assumes Java is used to implement activities. For example, the first non-option argument to Zygote should be a class name in the system class path. Also, [http://developer.android.com/guide/developing/tools/aidl.html aidl command-line tool] only generates Java code for Binder IPCs. | |||
While I'm confident that I could write a native application that plugs into the Android event stream as well as the activity, window, etc. managers, doing so would require adding C++ code generation to the ''aidl tool'' and implementing the portion of the Android Java SDK that deals with the activity life cycle. | |||
Still, it will not be possible to launch a native app from the Home app due to the Java assumptions in the core launching mechanism, so a Java shim will be required. There may be a great deal of flexibility in running a completely native app since, for example, OpenGL ES is not required and the screen (surface) buffer can be written to directly. | |||
Another alternative is to let the Java shim handle act as an invisible ''activity'' that uses the NDK to pass events to native code running in a shared library. OpenGL ES will be required in the latter case to write to a pre-configured screen context. | |||
To summarize... | |||
The Android activity and application launching mechanism assumes Java. Apps run in separate processes (and Java VMs) and talk to system services via the Binder IPC. | |||
There's no C++ code generation from the AIDL that describes the IPC so we'll need to write that. We'll also need to write a whole bunch of other C++ code that covers the portion of the Android Java SDK that deals with the application life cycle to be able to suspend, resume, stop and generally be a good citizen of the Android desktop (Home application). | |||
We won't be able to launch a native app right from the Android desktop so a Java shim will be needed. If we go the long route and talk to system services using Binder IPC, then we won't need OpenGL ES and will be able to write directly to the screen buffer (surface). If we make our Java shim a proper Android activity that feeds all kinds of events to our shared library using the NDK (JNI), then we'll be required to use OpenGL ES to write to a pre-configured context as well as potentially implement calls back to Java from our native libraries. | |||
I volunteer to write the C++ from AIDL code generator, as well as re-implement necessary portions of the Android Java SDK in C++. Many a C++ programmer will thank us for that and announcing a Mozilla Android C++ SDK may actually force Google's hand and make them release something official. | |||
Going the officially sanctioned way and using a proper Java activity shim with the NDK will positively be easier initially but may turn out to be a pain down the road what with OpenGL ES and all the data flying back and forth between Java and native code. | |||
== Sample external application Makefile == | |||
Here's how you can build your own native apps without being shoehorned into the Android SDK build structure. I got this by massaging the output of ''make showcommands''. | |||
<pre> | |||
SDK := /Volumes/android/mydroid | |||
TOOLCHAIN := $(SDK)/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1 | |||
ABILIB := $(TOOLCHAIN)/lib/gcc/arm-eabi/4.2.1/ | |||
BIN := $(TOOLCHAIN)/bin | |||
C++ := $(BIN)/arm-eabi-g++ | |||
CC := $(BIN)/arm-eabi-gcc | |||
INCLUDE := \ | |||
-I$(SDK)/system/core/include \ | |||
-I$(SDK)/hardware/libhardware/include \ | |||
-I$(SDK)/hardware/libhardware_legacy/include \ | |||
-I$(SDK)/hardware/ril/include \ | |||
-I$(SDK)/dalvik/libnativehelper/include \ | |||
-I$(SDK)/frameworks/base/include \ | |||
-I$(SDK)/frameworks/base/opengl/include \ | |||
-I$(SDK)/external/skia/include \ | |||
-I$(SDK)/out/target/product/generic/obj/include \ | |||
-I$(SDK)/bionic/libc/arch-arm/include \ | |||
-I$(SDK)/bionic/libc/include \ | |||
-I$(SDK)/bionic/libstdc++/include \ | |||
-I$(SDK)/bionic/libc/kernel/common \ | |||
-I$(SDK)/bionic/libc/kernel/arch-arm \ | |||
-I$(SDK)/bionic/libm/include \ | |||
-I$(SDK)/bionic/libm/include/arch/arm \ | |||
-I$(SDK)/bionic/libthread_db/include \ | |||
-I$(SDK)/frameworks/base/cmds/demo \ | |||
-I$(SDK)/system/core/include/arch/linux-arm \ | |||
-include $(SDK)/system/core/include/arch/linux-arm/AndroidConfig.h \ | |||
$(NULL) | |||
CFLAGS = \ | |||
-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ -DANDROID \ | |||
-DSK_RELEASE -DNDEBUG -UDEBUG \ | |||
-mthumb -mthumb-interwork -msoft-float -march=armv5te -mtune=xscale \ | |||
-fpic -fno-exceptions -ffunction-sections -funwind-tables -fstack-protector \ | |||
-fno-short-enums -fmessage-length=0 -finline-functions -fno-inline-functions-called-once \ | |||
-fgcse-after-reload -frerun-cse-after-loop -frename-registers -fvisibility-inlines-hidden \ | |||
-fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -fno-rtti \ | |||
-W -Wall -Wno-multichar -Wno-unused -Werror=return-type -Wstrict-aliasing=2 \ | |||
-Wnon-virtual-dtor -Werror=return-type \ | |||
-MD -Os -g \ | |||
$(NULL) | |||
LIBDIR := $(SDK)/out/target/product/generic/obj/lib | |||
LIBS := -lui -llog -lutils -lc -lstdc++ -lm $(LIBDIR)/crtbegin_dynamic.o | |||
LDFLAGS := \ | |||
-nostdlib -Bdynamic -Wl,--no-undefined -Wl,-T,$(SDK)/build/core/armelf.x \ | |||
-Wl,-dynamic-linker,$(SDK)/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc \ | |||
-L$(LIBDIR) -Wl,-rpath-link=$(LIBDIR) \ | |||
$(NULL) | |||
all: demo | |||
demo: surfaceflinger.o demo.o | |||
$(C++) $(LDFLAGS) -o demo $(LIBS) surfaceflinger.o demo.o \ | |||
$(ABILIB)/interwork/libgcc.a $(LIBDIR)/crtend_android.o | |||
surfaceflinger.o: | |||
$(C++) $(INCLUDE) -c $(CFLAGS) surfaceflinger.cpp | |||
demo.o: | |||
$(CC) $(INCLUDE) -c $(CFLAGS) demo.c | |||
clean: | |||
rm -f demo *.o | |||
</pre> | |||
== Introduction to the Android Window System == | |||
[http://people.debian.org.tw/%7Eolv/surfaceflinger/surfaceflinger.pdf Slides] and [http://people.debian.org.tw/%7Eolv/surfaceflinger/demo.tar.gz demo code]. | |||
== Building and running the OpenGL ES NDK example == | == Building and running the OpenGL ES NDK example == | ||
Line 85: | Line 216: | ||
</pre> | </pre> | ||
Now, | Now, let's build the debug release of project | ||
<pre> | <pre> | ||
Line 268: | Line 399: | ||
== Vlad's Android Notes == | == Vlad's Android Notes == | ||
Can be found [ | Can be found [[User:VladVukicevic/Android_Notes|here]]. | ||
''Italic text'' |