7 Contains common code for all projects on Android to bootstrap LibreOffice. In
8 addition it is a home to LibreOfficeKit (LOK - see libreofficekit/README) JNI
11 LOAndroid3 (in experimental)
12 ****************************
14 LibreOffice Android application - the code is based on Fennec (Firefox for Android).
15 It uses OpenGL ES 2 for rendering of the document tiles which are gathered from
16 LibreOffice using LOK. The application contains the LibreOffice core in one shared
17 library: liblo-native-code.so, which is bundled together with the application.
19 Architecture and Threading
20 **************************
22 The application implements editing support using 4 threads:
23 1. The Android UI thread, we can't perform anything here that would take a considerable
25 2. An OpenGL thread which contains the OpenGL context and is responsible for drawing
26 all layers (including tiles) to the screen.
27 3. A thread (LOKitThread), that performs LibreOfficeKit calls, which may take more time
28 to complete. In addition it also receives events from the soffice thread (see below)
29 when the callback emits an event. Events are stored in a blocking queue (thread
30 processes events in FCFS order, goes to sleep when no more event is available and
31 awakens when there are events in queue again).
32 4. A native thread created by LibreOfficeKit (we call it the soffice thread), where
33 LibreOffice itself runs. It receives calls from LOKitThread, and may emit callback
39 LOKitThread (org.libreoffice.LOKitThread) communicates with LO via JNI (this can
40 be done only for one thread) and processes events (defined in org.libreoffice.LOEvent)
46 LibreOfficeMainActivity (org.libreoffice.LibreOfficeMainActivity) is the entry point
47 of the application - everything starts up and tears down from here (onCreate, onResume,
48 onPause, onStart, onStop, onDestroy).
53 From here on one of the most interesting pieces are the classes around document view,
54 which includes listening to touch events, recalculating the viewport, tiled handling
55 and rendering the layers to the document.
57 Viewport - the viewport is the currently visible part of the document. It is defined
58 by view rectangle and zoom.
60 Layers - document view is rendered using many layers. Such layers are: document
61 background, scroll handles, and also the document tiles.
66 - LayerView (org.mozilla.gecko.gfx.LayerView) is the document view of the application.
67 It uses the SurfaceView (android.view.SurfaceView) as the main surface to draw on
70 - GLController (org.mozilla.gecko.gfx.GLController) - holder of the OpenGL context.
72 - RenderControllerThread (org.mozilla.gecko.gfx.RenderControllerThread) executes the
73 rendering requests through LayerRenderer.
75 - LayerRenderer (org.mozilla.gecko.gfx.LayerRenderer) renders all the layers.
77 - GeckoLayerClient (org.mozilla.gecko.gfx.GeckoLayerClient) is the middle man of the
78 application, which connects all the bits together. It is the document view layer
79 holder so the any management (including tiled rendering) usually go through this
80 class. It listens to draw requests and viewport changes from PanZoomController
83 Touch events, scrolling and zooming
84 -----------------------------------
86 The main class that handles the touch event, scrolling and zooming is JavaPanZoomController
87 org.mozilla.gecko.gfx.JavaPanZoomController (implementation of PanZoomController interface).
88 When the user performs a touch action, the document view needs to change, which means the
89 viewport changes. JavaPanZoomController changes the viewport and signals the change through
90 PanZoomTarget (org.mozilla.gecko.gfx.PanZoomTarget).
95 Tiled rendering is a technique that splits the document to bitmaps of same size (typically
96 256x256) which are fetched on demand.
98 In the application the ComposedTileLayer (org.mozilla.gecko.gfx.ComposedTileLayer) is the
99 layer responsible for tracking and managing the tiles. Tiles are in this case also layers
100 (sub layers?) implemented in SubTile (org.mozilla.gecko.gfx.SubTile), where each one is
101 responsible for one tile bitmap (actually OpenGL texture once it has been uploaded).
103 When the viewport changes, the request for tile rechecking is send to LOKitThread (see
104 LOKitThread#tileReevaluationRequest), where the tiles are rechecked, add and removed if
107 CompositeTileLayer is actually an abstract class, which has two implementations. One is
108 DynamicTileLayer (org.mozilla.gecko.gfx.DynamicTileLayer), which is used for main tile
109 view of the document, and FixedZoomTileLayer (org.mozilla.gecko.gfx.FixedZoomTileLayer),
110 which just renders the tiles at a fixed zoom level. This is then used as a background
111 low resolution layer.
116 Tile can change in LibreOffice when user changes the content (adds, removes text or changes
117 the properties). In this case, an invalidation rectangle is signaled from LibreOffice, which
118 includes a rectangle that needs to be invalidated. In this case LOKitThread gets this request
119 via callback, and rechecks all tiles if they need to be invalidated. For more details see
120 LOKitThread#tileInvalidation).
125 For editing there are 2 coarse tasks that the LibreOffice app must do:
126 1. send input events to LibreOffice core (keyboard, touch and mouse)
127 2. listen to messages (provided via callback) from LibreOffice core and react accordingly
129 In most cases when an input event happens and is send to the LO core, then a message from
130 LO core follows. For example: when the user writes to the keyboard, key event is sent and
131 a invalidation request from LO core follows. When user touches an image, a mouse event is
132 sent, and a "new graphic selection" message from LO core follows.
134 All keyboard and touch events are send to LOKitThread as LOEvents. In LOKitThread they are
135 processed and send to LibreOffice core. The touch events originate in JavaPanZoomController,
136 the keyboard events in LOKitInputConnectionHandler (org.libreoffice.LOKitInputConnectionHandler),
137 however there are other parts too - depending on the need.
139 InvalidationHandler (org.libreoffice.InvalidationHandler) is the class that is responsible
140 to process messages from LibreOffice core and to track the state.
145 Overlay elements like cursor and selections aren't drawn by the LO core, instead the core
146 only provides data (cursor position, selection rectangles) and the app needs to draw them.
147 DocumentOverlay (org.libreoffice.overlay.DocumentOverlay) and DocumentOverlayView
148 (org.libreoffice.overlay.DocumentOverlayView) are the classes that provide the overlay over
149 the document, where selections and the cursor is drawn.
151 Emulator and debugging notes
152 ****************************
154 For instructions on how to build for Android, see README.cross.
156 * Getting something running
158 Attach your device, so 'adb devices' shows it. Then run:
160 cd android/experimental/LOAndroid3
164 and if all goes well, you should have some nice debug output to enjoy when you
169 Create an AVD in the android UI, don't even try to get the data partition size
170 right in the GUI, that is doomed to producing an AVD that doesn't work.
171 Instead start it from the console:
173 LD_LIBRARY_PATH=$(pwd)/lib emulator-arm -avd <Name> -partition-size 500
175 where <Name> is the literal name of the AVD that you entered.
177 [ In order to have proper acceleration, you need the 32-bit libGL.so:
179 sudo zypper in Mesa-libGL-devel-32bit
181 and run emulator-arm after the installation. ]
183 Then you can run ant/adb as described above.
185 After a while of this loop you might find that you have lost a lot of
186 space on your emulator's or device's /data volume. You can do:
188 adb shell stop; adb shell start
192 First of all, you need to configure the build with --enable-debug or
193 --enable-dbgutil. You may want to provide --enable-selective-debuginfo too,
194 like --enable-selective-debuginfo="sw/" or so, in order to fit into the memory
197 Building with all symbols is also possible but the linking is currently
198 slow (around 10 to 15 minutes) and you need lots of memory (around 16GB + some
201 You also want to avoid --with-android-package-name (or when you use
202 that, you must set it to "org.libreoffice"), otherwise ndk-gdb will complain:
204 ERROR: Could not extract package's data directory. Are you sure that
205 your installed application is debuggable?
207 When you have all this, install the .apk to the device, and:
209 cd android/experimental/LOAndroid3
210 <android-ndk-r10d>/ndk-gdb --adb=<android-sdk-linux>/platform-tools/adb --start
212 Pretty printers aren't loaded automatically due to the single shared
213 object, but you can still load them manually. E.g. to have a pretty-printer for
214 rtl::OString, you need:
216 (gdb) python sys.path.insert(0, "/master/solenv/gdb")
217 (gdb) source /master/instdir/program/libuno_sal.so.3-gdb.py
219 * Debugging the Java part
221 At the moment the code is not organized in a way that would make Eclipse or
222 Android Studio happy as-is, so the quickest way is to use the jdb command-line
223 debugger. Steps to use it:
225 1) Find out the JDWP ID of a debuggable application:
229 From the list of currently active JDWP processes, the last number is the just
230 started debuggable application.
232 2) Forward the remote JDWP port/process ID to a local port:
234 adb forward tcp:7777 jdwp:31739
236 3) Connect to the running application:
238 jdb -sourcepath src/java/ -attach localhost:7777
240 Assuming that you're already in the LOAndroid3 directory in your shell.
242 * Debugging the missing services
244 Android library only include essential services that are compiled for
245 LibreOffice in order to reduce the size of the apk. When developing,
246 some services might become useful and we should add those services
247 to the combined library.
249 In order to identify missing services, we need to be able to receive
250 SAL_INFO from cppuhelper/source/shlib.cxx in logcat and therefore identify
251 what services are missing. To do so, you may want add the following
252 when configuring the build.
254 --enable-selective-debuginfo="cppuhelper/ sal/"
256 Which services are combined in the android lib is determined by
258 solenv/bin/native-code.py
260 * Common Errors / Gotchas
262 lo_dlneeds: Could not read ELF header of /data/data/org.libreoffice...libfoo.so
263 This (most likely) means that the install quietly failed, and that
264 the file is truncated; check it out with adb shell ls -l /data/data/....
268 All Android apps are basically Java programs. They run "in" a Dalvik
269 (or on Android 5 or newer - ART) virtual machine. Yes, you can also
270 have apps where all *your* code is native code, written in a compiled
271 language like C or C++. But also such apps are actually started
272 by system-provided Java bootstrapping code (NativeActivity) running
275 Such a native app (or actually, "activity") is not built as a
276 executable program, but as a shared object. The Java NativeActivity
277 bootstrapper loads that shared object with dlopen.
279 Anyway, our current "experimental" apps are not based on NativeActivity.
280 They have normal Java code for the activity, and just call out to a single,
281 app-specific native library (called liblo-native-code.so) to do all the