apache felix on androidsarchive.apachecon.com/c/aceu2009/sessions/materials...l1 - creates the...
TRANSCRIPT
![Page 1: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/1.jpg)
Apache Felix on Androids
Marcel OffermansChristian van Spaandonk
1
![Page 2: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/2.jpg)
Agenda• Introduction to Google Android• Demo: Hello world• The OSGi framework• Combining Android and OSGi• Getting Felix to run• Application design and deployment• Demo: modular desktop application• Demo: context awareness
2
![Page 3: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/3.jpg)
Android• Device Architecture• Dalvik Virtual Machine• From Source to Deployment• Anatomy of an Application• Application life cycle
3
![Page 4: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/4.jpg)
Architecture
4
![Page 5: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/5.jpg)
Dalvik Virtual Machine• interpreter only, register based• optimized to run multiple instances• executes files in .dex format• runs on posix-compliant OS• looks, feels and smells like Java ;)
5
![Page 6: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/6.jpg)
From Source to Deployment
• Eclipse Plugin: Android Dev Tools– compiles and packages automatically– launch and debug in emulator or phone
• Command line: activityCreator.py– generates project structure– Ant build.xml file– IntelliJ project files
6
.java .class .jar .dex .apk
javac jar dx aapt
![Page 7: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/7.jpg)
Anatomy
• activity, a single screen• intent, describes what you want done• intent filter, describes intents that can
be handled• intent receiver, UI that reacts to intent• service, background process with API• content provider, for shared data
access
7
![Page 8: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/8.jpg)
Anatomy Example
8
activity intent activityintent
filterintent
service
intent
filter
intent
receiver
![Page 9: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/9.jpg)
Life Cycle• is not controlled by the application• android maintains “importance
hierarchy” based on:– foreground process– visible proces– service proces– background proces– empty proces
9
![Page 10: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/10.jpg)
Life Cycle (Activity)
10
![Page 11: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/11.jpg)
Demo: hello world• Create an application with an Activity in
Eclipse• Set the “hello world” text• Create a breakpoint• Deploy and debug the application
11
![Page 12: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/12.jpg)
OSGi Framework LayeringL3 - Provides a publish/find/bind service model to decouple bundles
L2 - Manages the life cycle of a bundle in a framework without requiring the vm to be restarted
L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other in a controlled way
L0 - well defined profiles that define the environment in which bundles can work, ie:* CDC/Foundation* JavaSE-6* Android-1.0
SERVICE MODEL
MODULE
LIFE-CYCLE
ExecutionEnvironment
12
![Page 13: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/13.jpg)
Module Layer• Unit of deployment
is the bundle• Separate class
loader per bundle• Class sharing at the package level• Packages are versioned, multiple
versions concurrently supported• Framework handles the
consistency
13
ModuleBundle Bundle Bundle
org.apache.utils 1.0
org.apache.utils 1.1org.apache.log 2.3
org.apache.db 1.4
Bundle
exports
imports
exports
imports
exports
exports
Module
![Page 14: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/14.jpg)
Life-cycle Layer• Managed life cycle
for each bundle• Bundles can be:
– added, – updated and – removed
14
Life-cycle
Module
Life-cycle
start
end
installedinstall
startingstart
stopping stop
activeresolved
uninstalled
uninstall
![Page 15: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/15.jpg)
Service Layer• Preferred way for
bundles to interact• Service registry
can even be distributed in OSGi R4.2
15
Service Provider
Service Requester
Service Registry
interact
publish find Service
Life-cycle
Module
Service
Log Database
Bundle Bundle Bundle
publish useuse
publish
Bundle
Prefs
publish
use
![Page 16: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/16.jpg)
Side step: interaction styles
16
Bundle
Component invoking a
service
Bundle
Componentproviding a
servicemethod call
MyService
Bundle
EventAdmin implementation
Bundle
Component listening for
events
EventAdminBundle
Component publishing an
event(a)synch event
EventHandler
![Page 17: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/17.jpg)
Security Concepts Overview• Codebased security of the Java
Security Model– uses Protection Domains– stack walk based Permission Check– signed bundles
• PA and CPA provide management infrastructure
• IF all conditions match THEN apply permissions
17
Security
Module
Life-cycle
Service
![Page 18: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/18.jpg)
OSGi and Android
18
OSGi
Java VM
App
Dalvik VM
AppApp App
Dalvik VM
App
Dalvik VM
App
Android
![Page 19: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/19.jpg)
Benefits of each model
19
AndroidOSGi
Java VM
App Appinvoke
Java VM
App App
lib lib lib
Dalvik VM
App
Dalvik VM
App
Dalvik VM
App
crash
![Page 20: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/20.jpg)
Why combine them?• Using and enforcing a modular design• Build applications faster through re-use
of existing OSGi components• Applications tailored for the user, only
give him what he wants/needs• Dynamic loading and unloading, you do
not always need all application components
20
![Page 21: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/21.jpg)
Android Services• declared in AndroidManifest.xml• can be started and stopped:
Context.startService(), .stopService()• you can bind to it to use it• services run in remote processes, IDL
compiler generates stubs– primitives, collections, Parcelable’s by
value– other AIDL interfaces by reference
21
![Page 22: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/22.jpg)
Getting Felix to run• Initial efforts by Karl Pauls and me• Felix is portable, so we just dex’ed it• since 1.0.3 we are Android aware
– found a way to dynamically load classes– relies on an undocumented class
• Google, we need an API for:– dynamic class loading– dynamic security policies
22
![Page 23: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/23.jpg)
Deploying on a dev phone• Some manual preparation is necessary• Phone is configured so apps cannot
dynamically load classes• Fixed by:
– becoming root– chmod 777 /data/dalvik-cache
23
![Page 24: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/24.jpg)
Side step: other frameworks• EclipseCon 2008, Santa Clara:
– Neil Bartlett and BJ Hargrave ported both Equinox and Concierge to Android
• ProSyst:– ported their embedded server
• Knopflerfish:– no plans as far as we know
24
![Page 25: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/25.jpg)
Application design• Basis of the application is an Activity,
exposed through ActivityService
• Felix looks for a ViewFactory to create its main view
• Security is declared here
25
public interface ActivityService { public Activity getActivity(); public Object lookupSystemService(String name);}
public interface ViewFactory { public View create(Context context);}
![Page 26: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/26.jpg)
Management Agent• Responsible for installation and update• Communicates with a provisioning
server• Can be used to:
– centrally manage and deploy components– allow a “store” like or context aware
interface to select components client side• We embed the management agent as
part of the application
26
![Page 27: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/27.jpg)
Topology• Client: on the laptop• Server: far, far away on the net• Phone: using 3G/GPRS
27
provisioning server
Android Application
management agent
network
component repository
client
![Page 28: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/28.jpg)
Side step: Deployment Admin• streams deployment packages• packages get installed transactionally• supports fix packages with deltas• can install arbitrary file types• types handled by resource processors
28
source target
Package for target A version 4com
ponent Y
1.2
com
ponent X
1.0
configura
tion
A1
com
ponent Z
2.0
configura
tion
D3
![Page 29: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/29.jpg)
Desktop Application• Desktop component
(ViewFactory) shows a button bar at the top
• Applications plug in, show their UI below the button bar, register interface:
29
view
buttonbar
C A1 A2
public interface DesktopApplication { public static final String NAME = "name"; public ImageView getImageView(Context context); public View getView(Context context); }
![Page 30: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/30.jpg)
Demo: dynamic deployment• Bundles for:
– desktop, button bar and plugin mechanism– weather, a simple weather application– maps, a mockup mapping application
• Deploy and use applications• Undeploy applications
30
![Page 31: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/31.jpg)
Context Aware Extension• Combines the centrally managed model
with a local one• Phone can enable/disable certain
components based on certain logic by talking to the ArtifactHandler service
31
public interface ArtifactHandler { public List<Artifact> listComponents() throws IOException; public void add(String name) throws IOException; public void remove(String name) throws IOException;}
![Page 32: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/32.jpg)
Demo: context awareness• Same application as before• Weather bundle is context aware:
– only gets installed when your home WiFi network can be found
• Show deployment and undeployment without user intervention
32
![Page 33: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/33.jpg)
Wrapping it up• learned how to deploy and debug
Android application
• seen how we can use OSGi and a management agent to deploy stuff
• seen some live demos
33
![Page 34: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/34.jpg)
Links• Apache Felix
– http://felix.apache.org/• Google Android
– http://developer.android.com/• Sample code
– https://opensource.luminis.net/confluence/display/SITE/Apache+Felix+on+Androids
•
34
![Page 35: Apache Felix on Androidsarchive.apachecon.com/c/aceu2009/sessions/materials...L1 - Creates the concept of a module (aka. bundle) that both isolate and share classes from each other](https://reader034.vdocuments.net/reader034/viewer/2022042305/5ed11d64a4cd0f7e1411eb76/html5/thumbnails/35.jpg)
Q & A
35
??? !
! !