osgi on google android using apache felix · osgi on google android using apache felix marcel...

49
luminis OSGi on Google Android using Apache Felix Marcel Offermans Karl Pauls

Upload: vunguyet

Post on 25-May-2018

232 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi on

Google Android

using Apache Felix

Marcel Offermans

Karl Pauls

Page 2: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

image © 2008 Google Earth

Page 3: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

• Karl Pauls

image © 2008 Google Earth

Page 4: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

• Karl Pauls

• Marcel Offermans

image © 2008 Google Earth

Page 5: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

• Karl Pauls

• Marcel Offermans

image © 2008 Google Earth

Page 6: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

• Karl Pauls

• Marcel Offermans

Arnhem

image © 2008 Google Earth

Page 7: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

Who are we?

• Karl Pauls

• Marcel Offermans

EnschedeArnhem

image © 2008 Google Earth

Page 8: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 9: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 10: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Android

• First SDK release: november 2007

• Android Developer Challenge, $10M prize money

• Current SDK (M5 RC15): march 2008

• Phones: second half of 2008?

Page 11: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Android

• Device Architecture

• Dalvik Virtual Machine

• From source to deployment

• Anatomy of an application

• Application life cycles

Page 12: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

ArchitectureThis image is rather low-res, so perhaps draw it again...

Page 13: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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 ;)

Page 14: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

From source to deployment

• 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

.java .class .jar .dex .apk

javac jar dx aapt

Page 15: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 16: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Anatomy Example

activity intent activityintent

filterintent

service

intent

filter

intent

receiver

Page 17: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 18: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Life cycle (Activity)

Page 19: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Hello world demo!

• Create an application with an activity in Eclipse

• Set “hello world” text

• Create a breakpoint

• Deploy and debug the application

Page 20: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 21: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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)

Page 22: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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.

Page 23: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi Alliance

• Expert Groups:

• core platform (CPEG)

• mobile (MEG)

• vehicle (VEG)

• enterprise (EEG)

• residential (REG)

• Working Groups:

• marketing

• requirements

Page 24: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi specification

������������� ���������������������������������� ��

���� ���������������� ������!""#

OSGi Alliance

Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'

Signatu re Not Verified

�������������� ������������� ���� ����������� ��

���� ��������������� ������!""#

OSGi Alliance

Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:45:47 + 01'00'

Signatur e Not Verified

Page 25: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi Framework Layering

SERVICE MODEL

MODULE

LIFECYCLE

Execution

Environment

L3 - 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. bundles) that use classes from each

other in a controlled way according to

system and bundle constraints

L0 - OSGi Minimum Execution Environment

CDC/Foundation

JavaSE

Page 26: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 27: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Module

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

Page 28: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 29: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

• Allows for tight coupling when requiredModule

Page 30: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Life-cycle Layer

• Managed life cycle

• States for each bundle;

• Allows updates of existing bundles.

• Dynamically install, start, update, and uninstall

Module

Page 31: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Life-cycle Layer

• Managed life cycle

• States for each bundle;

• Allows updates of existing bundles.

• Dynamically install, start, update, and uninstall

Life-cycle

Life-cycle

start

end

installedinstall

startingstart

stopping stop

activeresolved

uninstalled

uninstall

Module

Page 32: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Service Layer

• OSGi framework

promotes service

oriented interaction

pattern among

bundles

Service

Provider

Service

Requester

Service

Registry

interact

publish find

Life-cycle

Module

Page 33: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Service Layer

• OSGi framework

promotes service

oriented interaction

pattern among

bundles

Service

Service

Log Database

Bundle Bundle Bundle

publish useuse

publish

Bundle

Prefs

publishuse

Service

Provider

Service

Requester

Service

Registry

interact

publish find

Life-cycle

Module

Page 34: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Security

• Optional Security Layer based on

Java permissions

• Infrastructure to define, deploy, and

manage fine-grained application

permissions

• Code authenticated by location or

signer

• Well defined API to manage

permissions

• PermissionAdmin

• ConditionalPermissionAdmin

Security

Module

Life-cycle

Secu ty

Service

Page 35: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Shameless plug:

if you want to know more about security in OSGi, come to our talk about

Building Secure OSGi Applications

Page 36: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 37: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi compendium

������������� ���������������������������������� ��

���� ���������������� ������!""#

OSGi Alliance

Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'

Signatu re Not Verified

Page 38: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

OSGi compendium

Log

HTTP

Device Access

Configuration AdminPreferences

Metatype

Wire AdminUser Admin

IO Connector

Initial Provisioning

UPnP™ Device

Declarative Services

Event AdminService Tracker

XML Parser

Position

Measurement and State

Execution Environment Spec

������������� ���������������������������������� ��

���� ���������������� ������!""#

OSGi Alliance

Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'

Signatu re Not Verified

Page 39: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 40: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Why OSGi and Android?

Models are different

OSGi

Java VM

App

Dalvik VM

AppApp App

Dalvik VM

App

Dalvik VM

App

Android

Page 41: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Benefits of each model

AndroidOSGi

Java VM

App Appinvoke

Java VM

App App

lib lib lib

Dalvik VM

App

Dalvik VM

App

Dalvik VM

App

crash

Page 42: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 43: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

Page 44: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

...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

Page 45: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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

ttt

Page 46: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Architecture

shape bundleshape bundle

shape bundle

host bundle

apache felix application

...osgi...

...android...

...android.felix

ApacheFelix

onCreate(Bundle b)

onDestroy()

onStart()

onStop()

Activity

...

...android.felix.view

ViewFactory

create(Context c) : View

...android.servicebased.host

...android.servicebased.host.service

SimpleShape

draw(Canvas c, int x, int y)

Activator

...

DefaultShape

create(Context c) : View

ShapeComponent

getShape() : SimpleShape

getX() : int

getY() : int

BundleActivator

start(BundleContext c)

stop(BundleContext c)

ServiceTrackerCustomizer

addingService(ServiceReference r) : o

modifiedService(ServiceReference r, Object o)

removedService(ServiceReference r, Object o)

shape bundleshape bundleshape bundh...android.servicebased.circle

Activator

...

Page 47: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Live demo!

• Deploying Felix to the Phone Emulator

• Installing the first bundle, the host application

• Adding and removing plugins: square, circle and

triangle

Page 48: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

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: [email protected]

Marcel Offermans: [email protected]

Page 49: OSGi on Google Android using Apache Felix · OSGi on Google Android using Apache Felix Marcel Offermans ... based on the components and their state: ... Building Secure OSGi Applications

luminis

Questions?!

? & !