OSGi on
Google Android
using Apache Felix
Marcel Offermans
Karl Pauls




       luminis
Who are we?




                                      luminis
              image © 2008 Google Earth
Who are we?




• Karl Pauls


                                       luminis
               image © 2008 Google Earth
Who are we?




• Karl Pauls
• Marcel Offermans
                                             luminis
                     ...
Who are we?




• Karl Pauls
• Marcel Offermans
                                             luminis
                     ...
Who are we?



                          Arnhem




• Karl Pauls
• Marcel Offermans
                                      ...
Who are we?



                          Arnhem                 Enschede




• Karl Pauls
• Marcel Offermans
             ...
Agenda

• Android
 •   Introduction and architecture

 •   Hello world demo

• OSGi
 •   Introduction

 •   Framework and ...
Agenda

• Android
 •   Introduction and architecture

 •   Hello world demo

• OSGi
 •   Introduction

 •   Framework and ...
Android




• First SDK release: november 2007
• Android Developer Challenge, $10M prize money
• Current SDK (M5 RC15): ma...
Android



• Device Architecture
• Dalvik Virtual Machine
• From source to deployment
• Anatomy of an application
• Applic...
This image is
Architecture   rather low-res,
               so perhaps draw
               it again...




               ...
Dalvik Virtual Machine



• interpreter-only, register based virtual machine
• optimized to run multiple VM instances
• ex...
From source to deployment


       .java           .class         .jar        .dex          .apk
               javac     ...
Anatomy


• activity, a single screen
• intent, describes what the application wants done
• intent filter, describes inten...
Anatomy Example



                    intent                        intent      intent
activity   intent             acti...
Life cycle

• Application life cycle is not controlled by the
  application itself

• Android maintains an “importancy hie...
Life cycle (Activity)




                        luminis
Hello world demo!




• Create an application with an activity in Eclipse
• Set “hello world” text
• Create a breakpoint
•...
Agenda

• Android
 •   Introduction and architecture

 •   Hello world demo

• OSGi
 •   Introduction

 •   Framework and ...
OSGi history

• Started as an embedded platform for the “home
  gateway”

• Originally under the JCP as JSR-8 (1999)
• OSG...
OSGi today


OSGi technology is the dynamic module system
for Java™
OSGi technology is Universal Middleware.
OSGi technolo...
OSGi Alliance

• Expert Groups:
 •   core platform (CPEG)

 •   mobile (MEG)

 •   vehicle (VEG)

 •   enterprise (EEG)

 ...
OSGi specification




      !"#$%"&'($)&%*+,-./'0                                          !"#$%"&'($)&%*+,-./'0
      1/...
OSGi Framework Layering


SERVICE MODEL   L3 - Provides a publish/find/bind service
                model to decouple bund...
Module Layer (1/3)


• Unit of deployment
  is the bundle i.e., a JAR

• Separate class loader
  per bundle
  •   Class lo...
Module Layer (1/3)
                                                                                                       ...
Module Layer (2/3)

• Multi-version support
  •   i.e., side-by-side versions

• Explicit code boundaries and dependencies...
Module Layer (3/3)

• Sophisticated class space consistency model
  •   Ensures code constraints are not violated

• Packa...
Life-cycle Layer



• Managed life cycle
  •   States for each bundle;

• Allows updates of existing bundles.
  •   Dynami...
Life-cycle Layer
                                                                                                Life-cycl...
Service Layer

• OSGi framework
 promotes service
 oriented interaction
 pattern among
 bundles
              Service
    ...
Service Layer
                                                                                       Service

• OSGi frame...
Security

• Optional Security Layer based on
  Java permissions

• Infrastructure to define, deploy, and
  manage fine-gra...
Shameless plug:



 if you want to know more about security in
        OSGi, come to our talk about
  Building Secure OSGi...
Leveraging standard services

• Specification:
  •   OSGi compendium – catalog of standard service
      descriptions

• I...
OSGi compendium




                  !"#$%"&'($)&%*+,-./'0
                  "&'($)&%1/02&34$50
                  67&%!"#...
OSGi compendium
    User Admin         Initial Provisioning        Wire Admin
                 Log                    Devi...
Agenda

• Android
 •   Introduction and architecture

 •   Hello world demo

• OSGi
 •   Introduction

 •   Framework and ...
Why OSGi and Android?

           Models are different

         Java VM         Dalvik VM               Dalvik VM

      ...
Benefits of each model

         Java VM
         invoke
   App             App   Dalvik VM               Dalvik VM




  ...
Services in Android

• Must be declared in AndroidManifest.xml
• Can be started and stopped:
  Context.startService and Co...
Getting Felix to run...

• First step, getting the framework to run
  •   Apache Felix is very portable, so we just dex’ed...
...others soon followed

• At EclipseCon 2008, Santa Clara:
  •   Neil Bartlett and BJ Hargrave, ported both Equinox and
 ...
A dynamic application


• Apache Felix framework
  •   embeds an activity to hook into;

  •   embeds file install bundle ...
Architecture
                                                                                                             ...
Live demo!




• Deploying Felix to the Phone Emulator
• Installing the first bundle, the host application
• Adding and re...
Links

• Slides, docs and code:
  http://opensource.luminis.net/

• Android SDK:
  http://code.google.com/android/

• Open...
Questions?!




      ?&!
              luminis
Upcoming SlideShare
Loading in …5
×

luminis

1,775 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,775
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

luminis

  1. 1. OSGi on Google Android using Apache Felix Marcel Offermans Karl Pauls luminis
  2. 2. Who are we? luminis image © 2008 Google Earth
  3. 3. Who are we? • Karl Pauls luminis image © 2008 Google Earth
  4. 4. Who are we? • Karl Pauls • Marcel Offermans luminis image © 2008 Google Earth
  5. 5. Who are we? • Karl Pauls • Marcel Offermans luminis image © 2008 Google Earth
  6. 6. Who are we? Arnhem • Karl Pauls • Marcel Offermans luminis image © 2008 Google Earth
  7. 7. Who are we? Arnhem Enschede • Karl Pauls • Marcel Offermans luminis image © 2008 Google Earth
  8. 8. Agenda • Android • Introduction and architecture • Hello world demo • OSGi • Introduction • Framework and compendium • Apache Felix on Google Android • Getting it to run • Creating a dynamic application: paint program luminis
  9. 9. Agenda • Android • Introduction and architecture • Hello world demo • OSGi • Introduction • Framework and compendium • Apache Felix on Google Android • Getting it to run • Creating a dynamic application: paint program luminis
  10. 10. Android • First SDK release: november 2007 • Android Developer Challenge, $10M prize money • Current SDK (M5 RC15): march 2008 • Phones: second half of 2008? luminis
  11. 11. Android • Device Architecture • Dalvik Virtual Machine • From source to deployment • Anatomy of an application • Application life cycles luminis
  12. 12. This image is Architecture rather low-res, so perhaps draw it again... luminis
  13. 13. Dalvik Virtual Machine • interpreter-only, register based virtual machine • optimized to run multiple VM instances • executes files in .dex format • runs on posix-compliant operating systems • looks like Java ;) luminis
  14. 14. From source to deployment .java .class .jar .dex .apk javac jar dx aapt • Eclipse Plugin: Android Development Tools • compiles and packages automatically • allows you to launch and debug in the emulator • Command line: activityCreator.py • generates project structure • Ant build.xml file, optionally IntelliJ project files luminis
  15. 15. Anatomy • activity, a single screen • intent, describes what the application wants done • intent filter, describes intents that can be handled • intent receiver, non UI code that reacts to intent • service, background process with API • content provider, for shared data access luminis
  16. 16. Anatomy Example intent intent intent activity intent activity intent filter filter receiver service luminis
  17. 17. Life cycle • Application life cycle is not controlled by the application itself • Android maintains an “importancy hierarchy” based on the components and their state: • foreground process • visible process • service process • background process • empty process luminis
  18. 18. Life cycle (Activity) luminis
  19. 19. Hello world demo! • Create an application with an activity in Eclipse • Set “hello world” text • Create a breakpoint • Deploy and debug the application luminis
  20. 20. Agenda • Android • Introduction and architecture • Hello world demo • OSGi • Introduction • Framework and compendium • Apache Felix on Google Android • Getting it to run • Creating a dynamic application: paint program luminis
  21. 21. OSGi history • Started as an embedded platform for the “home gateway” • Originally under the JCP as JSR-8 (1999) • OSGi alliance, consists of a large number of big companies, with the following mission: • Maintaining and publicizing the OSGi specification. • Certifying implementations. • Organising events. • Current version: OSGi Release 4.1 (JSR-291) luminis
  22. 22. OSGi today OSGi technology is the dynamic module system for Java™ OSGi technology is Universal Middleware. OSGi technology provides a service-oriented, component- based environment for developers and offers standardized ways to manage the software lifecycle. These capabilities greatly increase the value of a wide range of computers and devices that use the Java™ platform. luminis
  23. 23. OSGi Alliance • Expert Groups: • core platform (CPEG) • mobile (MEG) • vehicle (VEG) • enterprise (EEG) • residential (REG) • Working Groups: • marketing • requirements luminis
  24. 24. OSGi specification !"#$%"&'($)&%*+,-./'0 !"#$%"&'($)&%*+,-./'0 1/'&%"2&)$.$),-$/3 "&'($)&%1/02&34$50 45&%!"#$%6++$,3)& 67&%!"#$%8++$,3)& 7&+&,8&%9:%;&'8$/3%9<= 9&+&,:&%;<%=&':$/3%;>? 62'$+%>??@ 82'$+%@AAB Digitally signed by Digitally OSGi OSGi Alliance DN: cn=OSGi Alliance, c=US Date: signed by 2007.02.22 OSGi OSGi Alliance DN: cn=OSGi Alliance, c=US Signatu Alliance 14:44:10 + 01'00' re Not Alliance Date: Verified 2007.02.22 Signatur 14:45:47 + e Not 01'00' Verified luminis
  25. 25. OSGi Framework Layering SERVICE MODEL L3 - Provides a publish/find/bind service model to decouple bundles L2 - Manages the life cycle of a bundle in LIFECYCLE a framework without requiring the vm to be restarted L1 - Creates the concept of a module (aka. bundles) that use classes from each MODULE other in a controlled way according to system and bundle constraints Execution L0 - OSGi Minimum Execution Environment Environment CDC/Foundation JavaSE luminis
  26. 26. Module Layer (1/3) • Unit of deployment is the bundle i.e., a JAR • Separate class loader per bundle • Class loader graph • Independent namespaces • Class sharing at the Java package level luminis
  27. 27. Module Layer (1/3) Module Bundle Bundle Bundle Bundle imports exports imports • Unit of deployment exports exports exports org.apache.utils 1.0 org.apache.db 1.4 is the bundle i.e., a JAR org.apache.log 2.3 org.apache.utils 1.1 • Separate class loader per bundle • Class loader graph • Independent namespaces • Class sharing at the Java package level Module luminis
  28. 28. Module Layer (2/3) • Multi-version support • i.e., side-by-side versions • Explicit code boundaries and dependencies • i.e., package imports and exports • Support for various sharing policies • i.e., arbitrary version range support • Arbitrary export/import attributes • Influence package selection Module luminis
  29. 29. Module Layer (3/3) • Sophisticated class space consistency model • Ensures code constraints are not violated • Package filtering for fine-grained class visibility • Exporters may include/exclude specific classes from exported package • Bundle fragments • A single logical module in multiple physical bundles • Bundle dependencies Module • Allows for tight coupling when required luminis
  30. 30. Life-cycle Layer • Managed life cycle • States for each bundle; • Allows updates of existing bundles. • Dynamically install, start, update, and uninstall Module luminis
  31. 31. Life-cycle Layer Life-cycle install installed start start starting resolved active • Managed life cycle end uninstall stopping stop uninstalled • States for each bundle; • Allows updates of existing bundles. • Dynamically install, start, update, and uninstall Life-cycle Module luminis
  32. 32. Service Layer • OSGi framework promotes service oriented interaction pattern among bundles Service Registry publish find Life-cycle Service Service Provider Requester Module interact luminis
  33. 33. Service Layer Service • OSGi framework Log Database Prefs promotes service use publish publish publish use oriented interaction use Bundle Bundle Bundle Bundle pattern among bundles Service Registry publish find Service Life-cycle Service Service Provider Requester Module interact luminis
  34. 34. Security • Optional Security Layer based on Java permissions • Infrastructure to define, deploy, and manage fine-grained application permissions • Code authenticated by location or Security signer Service • Well defined API to manage Life-cycle permissions • PermissionAdmin Module • ConditionalPermissionAdmin luminis
  35. 35. Shameless plug: if you want to know more about security in OSGi, come to our talk about Building Secure OSGi Applications luminis
  36. 36. Leveraging standard services • Specification: • OSGi compendium – catalog of standard service descriptions • Implementations: • OBR repository at bundles.osgi.org – over 1400 bundles, implement compendium and other services • Maven repository and third party OBR’s • More and more projects are made OSGi compatible, for example: • Apache Commons OSGi luminis
  37. 37. OSGi compendium !"#$%"&'($)&%*+,-./'0 "&'($)&%1/02&34$50 67&%!"#$%8++$,3)& 9&+&,:&%;<%=&':$/3%;>? 82'$+%@AAB Digitally signed by OSGi OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 Signatu Alliance 14:44:10 + 01'00' re Not Verified luminis
  38. 38. OSGi compendium User Admin Initial Provisioning Wire Admin Log Device Access XML Parser Measurement and State Preferences UPnP™ Device Configuration Admin Position Metatype Event Admin Service Tracker !"#$%"&'($)&%*+,-./'0 "&'($)&%1/02&34$50 67&%!"#$%8++$,3)& HTTP 9&+&,:&%;<%=&':$/3%;>? 82'$+%@AAB IO Connector Execution Environment Spec Digitally signed by OSGi OSGi Alliance DN: cn=OSGi Alliance, c=US Declarative Services Date: 2007.02.22 Signatu Alliance 14:44:10 + 01'00' re Not Verified luminis
  39. 39. Agenda • Android • Introduction and architecture • Hello world demo • OSGi • Introduction • Framework and compendium • Apache Felix on Google Android • Getting it to run • Creating a dynamic application: paint program luminis
  40. 40. Why OSGi and Android? Models are different Java VM Dalvik VM Dalvik VM App App App App Dalvik VM App App OSGi Android luminis
  41. 41. Benefits of each model Java VM invoke App App Dalvik VM Dalvik VM cr as App App h Java VM App App Dalvik VM App lib lib lib OSGi Android luminis
  42. 42. Services in Android • Must be declared in AndroidManifest.xml • Can be started and stopped: Context.startService and Context.stopService() • You can bind to a service if you want to talk to it • Services can run in remote processes, in which case there is an Android IDL compiler to generate stubs • handles primitives, some collections and Parcelable’s by value • handles other AIDL interfaces by reference luminis
  43. 43. Getting Felix to run... • First step, getting the framework to run • Apache Felix is very portable, so we just dex’ed it • found a couple of issues, fixed in release 1.0.3 • Second step, dynamically loading bundles • the hard part was finding a way to load classes • found undocumented internal class • Google, we need an official API for this! • For more details: http://blog.luminis.nl/roller/luminis/entry/osgi_on_google_android_using luminis
  44. 44. ...others soon followed • At EclipseCon 2008, Santa Clara: • Neil Bartlett and BJ Hargrave, ported both Equinox and Concierge to Android • Slides at: https://eclipsecon.greenmeetingsystems.com/attachments/download/390 • ProSyst announced: • A port of their mBedded Server: http://www.adon-line.de/kunden/prosystBlog/?p=24 • Knopflerfish • We talked to Eric Wistrand and Christer Larsson of MakeWave but they have no plans yet luminis
  45. 45. A dynamic application • Apache Felix framework • embeds an activity to hook into; • embeds file install bundle for easy deployment. • Host bundle that provides a canvas and a toolbar • Shape bundles that add new shapes • Based on example from Apache Felix website: http://felix.apache.org/site/apache-felix-application-demonstration.html luminis
  46. 46. Architecture host bundle ...android.servicebased.host apache felix application ShapeComponent ...android... ...android.felix.view getShape() : SimpleShape getX() : int Activity ViewFactory getY() : int ... create(Context c) : View DefaultShape create(Context c) : View ...android.felix Activator ...osgi... ... ApacheFelix onCreate(Bundle b) BundleActivator ...android.servicebased.host.service onDestroy() start(BundleContext c) onStart() stop(BundleContext c) SimpleShape onStop() ServiceTrackerCustomizer draw(Canvas c, int x, int y) addingService(ServiceReference r) : o modifiedService(ServiceReference r, Object o) removedService(ServiceReference r, Object o) shape bundle shape bundle shape bundle ...android.servicebased.circle Activator ... luminis
  47. 47. Live demo! • Deploying Felix to the Phone Emulator • Installing the first bundle, the host application • Adding and removing plugins: square, circle and triangle luminis
  48. 48. Links • Slides, docs and code: http://opensource.luminis.net/ • Android SDK: http://code.google.com/android/ • Open Handset Alliance: http://www.openhandsetalliance.com/ • Apache Felix and OSGi: http://felix.apache.org/ http://www.osgi.org/ • Karl Pauls: karl.pauls@luminis.nl Marcel Offermans: marcel.offermans@luminis.nl luminis
  49. 49. Questions?! ?&! luminis

×