Native LibrariesLecture 10
Operating Systems Practical
11 January 2017
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of thislicense, visit http://creativecommons.org/licenses/by/4.0/.
OSP Native libraries, Lecture 10 1/35
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 2/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 3/35
Bionic
I Custom C library
I Replacement for glibc
I Not POSIX compliantI Goals
I BSD licenseI Avoid GPL and LGPL in userspace
I Small sizeI glibc is very large
I High speedI Designed for low CPU frequencies
OSP Native libraries, Lecture 10 4/35
Bionic vs. glibc
I Bionic routines do not throw, pass and handle C++exceptions
I Support for exceptions adds a great overheadI Exceptions can be used internally in C++ code, if they do not
cross the libc routine
I No C++ Standard Template LibraryI Native code developers can use gnustl or stlport
I New pthread implementation
I No wchar_t and no support for LOCALE
OSP Native libraries, Lecture 10 5/35
Bionic vs. glibc
I A shared memory region is used for configurationI Also used by the applications through property_get() and
property_set()
I No openlog() or syslog()I __libc_android_log_print() used for logging
I Specific malloc implementationI A hash table used for tracking allocations to discover leaks
I No pty support
OSP Native libraries, Lecture 10 6/35
Bionic vs. glibc
I No AIO (aio_read(), aio_write())I No crypt()
I Includes MD5 and SHA1I Developers should use OpenSSL for crypto
I Android has its own account managementI Does not use /etc/passwd, no getpwent()I getpwnam() and getpwuid() wrappers that use Android ID
service
I getprotobyname() only prints ”FIX ME! implementgetprotobyname()”
I Bionic not finished
OSP Native libraries, Lecture 10 7/35
Bionic pthreads
I Mutexes, rwlocks, condvars implemented using kernel futexesI No pthread_cancel()
I Threads cannot kill other threads
I No pthread_atfork()
I Thread local storage (TLS) implementedI Max 64 keysI Id and errno reservedI Mapped at 0xffff0ff0 in the process (on ARM)
I pthread_attr_{set,get}inheritsched andpthread_attr_{set,get}scope not implemented
OSP Native libraries, Lecture 10 8/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 9/35
SQLite
I Developed for embedded systems
I Used by Android, Apple iOS, BlackberryI Low memory consumption
I Starts from 50 KB, reaches few hundred KB
I Ease of useI No configuration files or complex commands
I FreeI Released under public domainI Supported by Google, Adobe, MozillaI Active maintenance
OSP Native libraries, Lecture 10 10/35
SQLite
I Is serverlessI No processI Access database through libraryI No port configuration, no user adding, no access levels
I All data in a single fileI Indices, triggers, metadataI Journal file added
I Fewer datatypesI INTEGER, REAL, TEXT, BLOBI No datetime -> stringI No boolean -> 0 and 1I Blob not recommended on Android -> files in the file system
OSP Native libraries, Lecture 10 11/35
SQLite
I Does not use static typingI Type depends on the inserted valueI Not on the definition in CREATE TABLEI Create INTEGER column and insert TEXTI Manifest typing -> between static and dynamic typing
I No fixed column lengthI No limit to the inserted valueI Constraints in the code
I Database files are cross-platformI Pull file from device, use it on laptopI Open file with GUI toolsI Populate file on laptop, push on device
OSP Native libraries, Lecture 10 12/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 13/35
SSL
I Generated from OpenSSL external project
I Includes libcrypto and libssl librariesI Libcrypto implements cryptographic algorithms
I Symmetric ciphersI Public key cryptoI CertificatesI Authentication codes, hashes
I Libssl implements SSL/TLS for secure communications
I Cryptographic routines from libcrypto are used by libssl
OSP Native libraries, Lecture 10 14/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 15/35
WebKit
I Open source web browser engine
I BSD license but WebCore and JavaScriptCore under LGPL
I From 2013, WebKit is a trademark of Apple
I Contributors: Apple, Nokia, Google, Samsung, Adobe, Intel,etc.
I Ports: Safari, Chrome, Android, Blackberry, Tizen, etc.
I Originally forked from KHTML and KJS libraries from KDE
I Google forked WebCore (WebKit component) into Blink
OSP Native libraries, Lecture 10 16/35
WebKit
I Speed, power and versatility
I Support for new features in CSS3, HTML5 and JavaScriptI WebCore
I LGPL licenseI C++ basedI Layout, rendering, DOM library for HTML and SVGI Creates HTML visualizations based on DOM markup and CSS
I JavaScriptCoreI JavaScript engineI Derived from KJS library in KDE and PCRE regular expression
libraryI High performance interaction engine
OSP Native libraries, Lecture 10 17/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 18/35
Surface Manager
I a.k.a. Surface Flinger
I Part of System Server
I System-wide surface composer
I Handles surface rendering to frame buffer deviceI Combines 2D and 3D surfaces, surfaces from multiple apps
I Each app generates 1 or more surfacesI The Surface Flinger composes these surfacesI The result is stored in the Frame Buffer
OSP Native libraries, Lecture 10 19/35
Surface Manager
OSP Native libraries, Lecture 10 20/35
Surface Manager
I Surfaces passed as buffers using Binder IPC callsI Surface instances written to or restored from Parcels
I Use OpenGL ES or 2D hardware accelerator for thecomposition
I Double buffering using page flipI Front buffer (primary surface) and back bufferI Change primary surface pointer and back buffer pointerI Screen never flickers or displays artifacts
OSP Native libraries, Lecture 10 21/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 22/35
Audio Manager
I a.k.a. Audio Flinger
I Part of Media Server
I Manages the audio output devices
I Receives and combines multiple audio streams (tone, mediaplayer, games)
I Directs audio to various outputs (Headphones, Speaker)
OSP Native libraries, Lecture 10 23/35
Audio Manager
OSP Native libraries, Lecture 10 24/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 25/35
Media Framework
I Uses StageFright engine for audio/video recording andplayback
I Default software codecsI Implement your own hardware codec
I Using OpenMAX Integration Layer (IL)
I OpenMAX ILI Standardized way for Stagefright to recognize and use
hardware codecsI OpenMAX plugin - shared libraryI Implemented according to the standard
I Accessed through android.media API
OSP Native libraries, Lecture 10 26/35
Outline
Bionic
SQLite
SSL
WebKit
Surface Manager
Audio Manager
Media Framework
OpenGL ES
OSP Native libraries, Lecture 10 27/35
OpenGL ES
I Manage 2D and 3D graphics on embedded systems
I Interface between software and graphics acceleration hardware
I Low-level, lightweight API
I Subset of OpenGL
I Display complex 3D graphics on mobile
I Easy porting
OSP Native libraries, Lecture 10 28/35
OpenGL ES
I Industry standardI Open, vendor-neutral, multi-platformI Anyone can implement OpenGL ES based on the specification
I Small footprint, low power consumptionI Minimum data storage requirementsI Small binary
I Works with both hardware and software renderingI Calls to hardware, to software routines or combination of both
OSP Native libraries, Lecture 10 29/35
OpenGL ES 1.x vs. 2.0
I NDK includes both OpenGL ES 1.x and 2.0 libraries(eventually 3.0)
I Differ significantlyI Different Graphics Rendering Pipelines
I Processing stages taken by the graphics hardware to producegraphics
I Accepts object description (vertices, primitives, color values)
I 1.x fixed function pipelineI Input primitive, texture data, lightning
I 2.0 programmable pipelineI Write vertex and fragment shaders using the Shading
Language (GLSL)
OSP Native libraries, Lecture 10 30/35
OpenGL ES 1.x vs. 2.0
1.x 2.0Performance Fast 2D and 3D graphics Faster 2D and 3D graphics
Compatibility Almost all Android devi-ces
Many Android devices
Ease of coding Fixed pipeline with con-venient functions, easy touse for simple 3D apps
No built-in basic functions,more effort to use for simple3D apps
Graphics control Difficult or impossible tocreate some effects (fixedpipeline)
More direct control of thegraphics processing pipeline(programmable pipeline)
OSP Native libraries, Lecture 10 31/35
OpenGL ES in Android app
I Use OpenGL ES directly from Android app
I Create a view container
I Implement a GLSurfaceView and GLSurfaceView.Renderer
I GLSurfaceViewI View container for the graphicsI Draw and manipulate objects using OpenGL API
I GLSurfaceView.RendererI Controls what is drawn in the viewI Defines methods required for drawingI Attach it to the GLSurfaceView instanceI GLSurfaceView.setRenderer()
OSP Native libraries, Lecture 10 32/35
OpenGL ES in Android app
I Call OpenGL APII OpenGL ES 1.0/1.1 API
I android.opengl (static interface, better performance)I javax.microedition.khronos.opengles (standard
implementation)
I OpenGL ES 2.0 APII android.opengl.GLES20 (starting with Android 2.2, API
level 8)
I OpenGL ES 3.0 APII android.opengl.GLES30 (starting with Android 4.3, API
level 18)I Requires an implementation of the pipeline provided by the
manufacturerI Not all 4.3 devices support 3.0 API
I Declare version requirement in the manifestI <uses-feature android:glEsVersion="0x00020000"
android:required="true" />
OSP Native libraries, Lecture 10 33/35
Bibliography
I Karim Yaghmour, Embedded Android: Porting, Extending,and Customizing, Chapter 1
I http://codingrelic.geekhold.com/2008/11/
six-million-dollar-libc.html
I https:
//www.grokkingandroid.com/sqlite-in-android/
I http://trac.webkit.org/wiki
I https://androidteam.googlecode.com/files/
Anatomy-Physiology-of-an-Android.pdf
I http://developer.android.com/guide/topics/
graphics/opengl.html
OSP Native libraries, Lecture 10 34/35
Keywords
I Bionic
I SQLite
I SSL
I WebKit
I Surface Manager
I Audio Manager
I Media Framework
I OpenGL ES
OSP Native libraries, Lecture 10 35/35