Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than...

37
Douglas C. Schmidt [email protected] www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA Android Services & Local IPC: The Activator Pattern (Part 1)

Transcript of Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than...

Page 1: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Douglas C. Schmidt [email protected]

www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science Institute for Software Integrated Systems

Vanderbilt University

Nashville, Tennessee, USA

Android Services & Local IPC: The Activator Pattern (Part 1)

Page 2: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

2

• Understand the Activator pattern

Learning Objectives in this Part of the Module

www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf

Page 3: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

3

Context

• Resource constrained & highly dynamic environments • Random-access memory (RAM)

is a valuable resource in any software environment

Challenge: Minimizing Resource Utilization

Small Memory Device

Page 4: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

4

Context

• Resource constrained & highly dynamic environments • Random-access memory (RAM)

is a valuable resource in any software environment

• It's even more valuable on a mobile OS like Android where physical memory is often constrained

Challenge: Minimizing Resource Utilization

Small Memory Device

Page 5: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

5

Small Memory Device

Problem • It‘s not feasible to have all App

Service implementations running all the time since this ties up end- system resources unnecessarily

Challenge: Processing a Long-Running Action

developer.android.com/training/articles/memory.html has more info

Page 6: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

6

Challenge: Processing a Long-Running Action Solution • Apply the Activator pattern

to activate & deactivate Android Services automatically • If your app needs a Service

to perform work in the background, don’t keep it running unless it's actively performing a job

ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 7: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

7

Challenge: Processing a Long-Running Action Solution • Apply the Activator pattern

to activate & deactivate Android Services automatically • If your app needs a Service

to perform work in the background, don’t keep it running unless it's actively performing a job

• Be careful to never leak your Service by failing to stop it when its work is done

developer.android.com/training/articles/memory.html#Services has more info

ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 8: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

8

Activator POSA4 Design Pattern Intent • Activator automates scalable on-demand activation & deactivation of

service execution contexts to run services accessed by many clients without consuming excessive resources

www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf has more info

Page 9: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

9

Applicability • When services in a system should only consume resources when they

are accessed actively by clients

Activator POSA4 Design Pattern

Page 10: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

10

Applicability • When services in a system should only consume resources when they

are accessed actively by clients • When clients should be shielded from where services are located, how

they are deployed onto hosts or processes, & how their lifecycle is managed

Activator POSA4 Design Pattern

Page 11: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

11

Structure & Participants

Activity

Activator POSA4 Design Pattern

Page 12: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

12

Structure & Participants

Intent

Activator POSA4 Design Pattern

Page 13: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

13

Structure & Participants

Context

Activator POSA4 Design Pattern

Page 14: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

14

Structure & Participants

Activity Manager Service

Activator POSA4 Design Pattern

Page 15: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

15

Structure & Participants ServiceMap

Activator POSA4 Design Pattern

Page 16: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

16

Structure & Participants

Linux Process

Activator POSA4 Design Pattern

Page 17: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

17

Structure & Participants

IntentService

Activator POSA4 Design Pattern

Page 18: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

18

Dynamics

Activator POSA4 Design Pattern The Client uses the Activator

to get service access

Page 19: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

19

Dynamics

When incoming requests arrive, the Activator looks up whether a target object is already active & if the object is

not running it activates the Service Execution Context

Activator POSA4 Design Pattern

Page 20: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

20

Dynamics

Activator POSA4 Design Pattern

An Activator can activate & passivate a Service running in a server after each

method call, each transaction, etc

Page 21: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

21

Dynamics

Activator POSA4 Design Pattern The Activation Table stores associations between services &

their physical location

Page 22: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

22

Dynamics

Activator POSA4 Design Pattern

A Service implements a specific type of functionality that it provides to clients

Page 23: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

23

ActivityManagerService

ServiceMap

Consequences + More effective resource

utilization • Servers can be spawned

“on-demand,” thereby minimizing resource utilization until clients actually require them

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

Activator POSA4 Design Pattern

mServicesByNamePerUser

mServicesByIntentPerUser

Page 24: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

24

Consequences + More effective resource

utilization + Coarse-grained concurrency

• By spawning server processes to run on multi-core/CPU computers

Activator POSA4 Design Pattern ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 25: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

25

Consequences + More effective resource

utilization + Coarse-grained concurrency + Modularity, testability, &

reusability • Application modularity &

reusability is improved by decoupling server implementations from the manner in which the servers are activated

Activator POSA4 Design Pattern ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 26: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

26

Consequences – Lack of determinism &

ordering dependencies • Hard to determine or

analyze the behavior of an app until its components are activated at runtime

Activator POSA4 Design Pattern ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 27: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

27

Consequences – Lack of determinism &

ordering dependencies – Reduced security & reliability

• An application that uses Activator may be less secure or reliable than an equivalent statically- configured application

Activator POSA4 Design Pattern ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 28: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

28

Consequences – Lack of determinism &

ordering dependencies – Reduced security & reliability – Increased run-time overhead &

infrastructure complexity • By adding levels of abstraction

& indirection when activating & executing components

Activator POSA4 Design Pattern ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 29: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

29

Known Uses • UNIX Inetd “super server”

• Internal services are fixed at static link time • e.g., ECHO & DAYTIME

Activator POSA4 Design Pattern

Internal service

Internal service

Internal service

Page 30: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

30

Known Uses • UNIX Inetd “super server”

• Internal services are fixed at static link time

• External services can be dynamically reconfigured • e.g., FTP, TELNET, & HTTP

Activator POSA4 Design Pattern

Internal service

Internal service

Internal service

See en.wikipedia.org/wiki/Inetd for more on Inetd

Page 31: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

31

Known Uses • UNIX Inetd “super server” • CORBA Implementation Repository

Activator POSA4 Design Pattern

ImR (ringil:5000) Client

ringil:4500 plane.exe airplane_poa server.exe poa_name ringil:5500 iiop://ringil:5000/poa_name/object_name

Server (ringil:5500)

1. some_request

4. LOCATION_FORWARD

2. ping 3. is_running

6. some_response

5. some_request

2.1 start

iiop://ringil:5500/poa_name/object_name

Page 32: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

32

Known Uses • UNIX Inetd “super server” • CORBA Implementation Repository • Android ActivityManagerService

Activator POSA4 Design Pattern

ActivityManagerService

ServiceMap bindService()

Client 1

mServicesByNamePerUser

mServicesByIntentPerUser

Page 33: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

33

Known Uses • UNIX Inetd “super server” • CORBA Implementation Repository • Android ActivityManagerService

Activator POSA4 Design Pattern

ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

mServicesByNamePerUser

mServicesByIntentPerUser

Page 34: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

34

Known Uses • UNIX Inetd “super server” • CORBA Implementation Repository • Android ActivityManagerService

Activator POSA4 Design Pattern

ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 35: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

35

Known Uses • UNIX Inetd “super server” • CORBA Implementation Repository • Android ActivityManagerService

Activator POSA4 Design Pattern

ActivityManagerService

ServiceMap

Service

bindService()

Process.start()

Client 1

2

3

4 someMethodCall()

mServicesByNamePerUser

mServicesByIntentPerUser

Page 36: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

36

Summary

• Activator frees clients from the responsibility of (re)activating the resources they use • It appears to them as if all resources were always (virtually) available

Page 37: Android Services & Local IPC: The Activator Pattern …Activator may be less secure or reliable than an equivalent statically- configured application Activator POSA4 Design Pattern

Android Services & Local IPC Douglas C. Schmidt

37

Summary

www.dre.vanderbilt.edu/~schmidt/PDF/Activator.pdf has more info

• Activator frees clients from the responsibility of (re)activating the resources they use

• Activator also ensures that (re)activating a resource incurs minimal overhead because it maintains information about how to optimize this process • e.g., an activator could reload the resource’s persistent state & reacquire

the needed computing resources in parallel, thereby speeding resource initialization