Apache Felix on Androids

      Marcel Offermans
   Christian van Spaandonk




                             1
Agenda
•   Introduction to Google Android
•   Demo: Hello world
•   The OSGi framework
•   Combining Android and OSGi
•   ...
Android
•   Device Architecture
•   Dalvik Virtual Machine
•   From Source to Deployment
•   Anatomy of an Application
•  ...
Architecture




               4
Dalvik Virtual Machine
•   interpreter only, register based
•   optimized to run multiple instances
•   executes files in ...
From Source to Deployment
  .java           .class         .jar        .dex          .apk
          javac            jar  ...
Anatomy
• activity, a single screen
• intent, describes what you want done
• intent filter, describes intents that can
  b...
Anatomy Example


                    intent                        intent         intent
activity   intent             ac...
Life Cycle
• is not controlled by the application
• android maintains “importance
  hierarchy” based on:
  – foreground pr...
Life Cycle   (Activity)




                    10
Demo: hello world
• Create an application with an Activity in
  Eclipse
• Set the “hello world” text
• Create a breakpoint...
OSGi Framework Layering
                L3 - Provides a publish/find/bind service
SERVICE MODEL   model to decouple bundle...
Module Layer
                                                                                              Module
        ...
Life-cycle Layer
                                                                                      Life-cycle
        ...
Service Layer
                                                                                            Service



• Pre...
Side step: interaction styles
                  Bundle                         Bundle
                                 MyS...
Security Concepts Overview
• Codebased security of the Java
  Security Model
  – uses Protection Domains
  – stack walk ba...
OSGi and Android

      Java VM         Dalvik VM               Dalvik VM

                        App                    ...
Benefits of each model
      Java VM
      invoke
App             App   Dalvik VM               Dalvik VM




            ...
Why combine them?
• Using and enforcing a modular design
• Build applications faster through re-use
  of existing OSGi com...
Android Services
• declared in AndroidManifest.xml
• can be started and stopped:
  Context.startService(), .stopService()
...
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...
Deploying on a dev phone
• Some manual preparation is necessary
• Phone is configured so apps cannot
  dynamically load cl...
Side step: other frameworks
• EclipseCon 2008, Santa Clara:
  – Neil Bartlett and BJ Hargrave ported both
    Equinox and ...
Application design
• Basis of the application is an Activity,
  exposed through ActivityService
       public interface Ac...
Management Agent
• Responsible for installation and update
• Communicates with a provisioning
  server
• Can be used to:
 ...
Topology
• Client: on the laptop
• Server: far, far away on the net
• Phone: using 3G/GPRS

                              ...
Side step: Deployment Admin
•   streams deployment packages
•   packages get installed transactionally
•   supports fix pa...
Desktop Application
• Desktop component                                 C   A1    A2
                                     ...
Demo: dynamic deployment
• Bundles for:
  – desktop, button bar and plugin mechanism
  – weather, a simple weather applica...
Context Aware Extension
• Combines the centrally managed model
  with a local one
• Phone can enable/disable certain
  com...
Demo: context awareness
• Same application as before
• Weather bundle is context aware:
  – only gets installed when your ...
Wrapping it up
• learned how to deploy and debug
  Android application

• seen how we can use OSGi and a
  management agen...
Links
• Apache Felix
    – http://felix.apache.org/
• Google Android
    – http://developer.android.com/
• Sample code
   ...
Q&A


? ?   !
                   !
?         !
              35
Upcoming SlideShare
Loading in...5
×

Apache Felix on Androids

1,495

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,495
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Apache Felix on Androids

  1. 1. Apache Felix on Androids Marcel Offermans Christian van Spaandonk 1
  2. 2. 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
  3. 3. Android • Device Architecture • Dalvik Virtual Machine • From Source to Deployment • Anatomy of an Application • Application life cycle 3
  4. 4. Architecture 4
  5. 5. 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
  6. 6. From Source to Deployment .java .class .jar .dex .apk javac jar dx aapt • 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
  7. 7. 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
  8. 8. Anatomy Example intent intent intent activity intent activity intent filter filter receiver service 8
  9. 9. 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
  10. 10. Life Cycle (Activity) 10
  11. 11. 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
  12. 12. OSGi Framework Layering L3 - Provides a publish/find/bind service SERVICE MODEL model to decouple bundles L2 - Manages the life cycle of a bundle in a LIFE-CYCLE framework without requiring the vm to be restarted L1 - Creates the concept of a module (aka. MODULE bundle) that both isolate and share classes from each other in a controlled way Execution L0 - well defined profiles that define the environment in which bundles can work, ie: Environment * CDC/Foundation * JavaSE-6 * Android-1.0 12
  13. 13. Module Layer Module Bundle Bundle Bundle Bundle • Unit of deployment exports imports exports exports imports exports is the bundle org.apache.utils 1.0 org.apache.db 1.4 org.apache.log 2.3 org.apache.utils 1.1 • Separate class loader per bundle • Class sharing at the package level • Packages are versioned, multiple versions concurrently supported • Framework handles the consistency Module 13
  14. 14. Life-cycle Layer Life-cycle install installed • Managed life cycle start resolved start starting active for each bundle end uninstall stopping stop uninstalled • Bundles can be: – added, – updated and – removed Life-cycle Module 14
  15. 15. Service Layer Service • Preferred way for Log Database use publish Prefs publish bundles to interact publish use use Bundle Bundle Bundle Bundle • Service registry can even be distributed in OSGi R4.2 Service publish Registry find Service Life-cycle Service Service Provider interact Requester Module 15
  16. 16. Side step: interaction styles Bundle Bundle MyService Component Component invoking a providing a service service method call Bundle Bundle Bundle EventAdmin EventHandler Component Component EventAdmin publishing an listening for implementation event events (a)synch event 16
  17. 17. Security Concepts Overview • Codebased security of the Java Security Model – uses Protection Domains – stack walk based Permission Check – signed bundles Security • PA and CPA provide Service management infrastructure Life-cycle • IF all conditions match THEN apply permissions Module 17
  18. 18. OSGi and Android Java VM Dalvik VM Dalvik VM App App App App Dalvik VM App App OSGi Android 18
  19. 19. Benefits of each model Java VM invoke App App Dalvik VM Dalvik VM cr a App App sh Java VM App App Dalvik VM App lib lib lib OSGi Android 19
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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
  24. 24. 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
  25. 25. Application design • Basis of the application is an Activity, exposed through ActivityService public interface ActivityService { public Activity getActivity(); public Object lookupSystemService(String name); } • Felix looks for a ViewFactory to create its main view public interface ViewFactory { public View create(Context context); } • Security is declared here 25
  26. 26. 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
  27. 27. Topology • Client: on the laptop • Server: far, far away on the net • Phone: using 3G/GPRS Android Application provisioning management network server agent client component repository 27
  28. 28. 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 Package for target A version 4 component X component Y component Z configuration configuration source target 1.0 1.2 2.0 D3 A1 28
  29. 29. Desktop Application • Desktop component C A1 A2 buttonbar (ViewFactory) shows a view button bar at the top • Applications plug in, show their UI below the button bar, register interface: public interface DesktopApplication { public static final String NAME = "name"; public ImageView getImageView(Context context); public View getView(Context context); } 29
  30. 30. 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
  31. 31. 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 public interface ArtifactHandler { public List<Artifact> listComponents() throws IOException; public void add(String name) throws IOException; public void remove(String name) throws IOException; } 31
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. Q&A ? ? ! ! ? ! 35
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×