instructor: mazhar hussain · instructor: mazhar hussain. previous lecture ... v. 2.0)...
TRANSCRIPT
PROGRAMMING WITH ANDROID:
SYSTEM ARCHITECTURE
&
MOBILE IP
Instructor: Mazhar Hussain
PREVIOUS LECTURE
•Desktop and Service side Programming
•Software design concerns
2
3
OUTLINE
Android Components: Content Providers
Android Components: Services
Android Components: Intents
Android Components: Activities
Android Dalvik Java Virtual Machine
Android Architecture: An Overview
Android Application Distribution and Markets
4
ANDROID … WHAT?Android is a Linux-based
platform for mobile devices …
Operating System
Middleware
Applications
Software Development Kit (SDK)
Which kind of mobile devices … (examples)
SMARTPHONES TABLETS EREADERS ANDROID TV GOOGLE GLASSES
?
5
ANDROID … WHEN?
Google buys Android from the Android
Inch
Open Handset Alliance (OHA) created for
open standards for mobile devices. Partners of
OHA: Google, Motorola, Samsung, Vodafone, T-
Mobile, etc
Android 1.0 Released
The first Android smartphone: G1 HTC-Dream
Android 1.1 Released
Android 1.5 (CupCake) Released
2005
2006
2007
2008
2009
Time
6
ANDROID … WHEN? Android 1.6 (Donut) Released
Android 2.0 (Eclair) Released
Android 2.2 (Froyo) Released
Android 2.3 (Gingerbread) Released
Android 3.0 (Honeycomb) Released
(First version for devices with larger screens such as tablets)
Android 4.0 (Ice-Cream Sandwich)
Released. (It merges the 3.x tab centric design and the
v2.x phone based design into a single version.)
2008
2009
2010
2011
2012
Time
7
ANDROID … WHEN? Android 4.2 (Jelly Bean) Released
Gesture Mode for Accessibility
Improved browser performance
Easy data-sharing through NFC
Improved camera and face recognition
functionalities
…
API Level 17 (Android 4.2):
Daydream: screensaver customization API
Support to multi-user environments
Nested fragments for UI improvements
…
2012
2013
Time
KEY LIME PIE
8
ANDROID … WHEN?
http://developer.android.com/about/dashboards/index.html http://www.appbrain.com/stats/android-market-
app-categories
ANDROID DISTRIBUTIONS ANDROID APPLICATIONS
x
9
ANDROID … WHEN?
ANDROID VERSION
HISTORY AND POPULARITY
(2009-2013)
http://en.wikipedia.org/wiki/Android_version_history
2.3.x
2.2.x1.6-2.0
4.x
10
THE ANDROID ARCHITECTURE
} Stack
Architect
ure
Open Source
Architecture
(Apache/MIT License
v. 2.0)
Business-friendly
License
11
THE ANDROID ARCHITECTURE
Built on top of
Linux kernel
(v. 2.6-3.0)
Advantages:
Portability (i.e.
easy to compile on
different harwdare
architectures)
Security (e.g.
secure multi-process
environment)
Power
Management
12
THE ANDROID ARCHITECTURE Native
Libraries (C/C++ code)
Graphics (Surface
Manager)
Multimedia (Media
Framework)
Database DBMS (SQLite)
Font
Management (FreeType)
WebKit
C libraries (Bionic)
….
13
THE ANDROID ARCHITECTUREApplication
Libraries(Core Components of
Android)
Activity
Manager
Packet Manager
Telephony
Manager
Location
Manager
Contents
Provider
Notification
Manager
….
14
THE ANDROID ARCHITECTURE
Applications(Written in Java code)
Android Play
Store
Entertainment
Productivity
Personalization
Education
Geo-
communication
….
15
THE ANDROID ARCHITECTURE
Dalvik
Virtual
Machine (VM)
Novel Java
Virtual Machine
implementation (not
using the Oracle
JVM)
Open License
(Oracle JVM is not
open!)
Optimized for
memory-constrained
devices
Faster than
16
DALVIK JAVA VIRTUAL MACHINE (JVM)Java
Source
Code
Java Byte
Code
Java
Virtual
Machine
(JVM)
Java
Source
Code
Java Byte
Code
Dalvik
Byte
Code
Dalvik
Virtual
Machine
(VM)
Java
Compiler
Java
Compiler
Dex
CompilerStack-based
byte-code
Register-based
byte-code
Java Standard Edition
17
ANDROID APPLICATIONS DESIGN
GUI Definition
Events Management
Application Data
Management
Background Operations
User Notifications
APPLICATION DESIGN:
18
ANDROID APPLICATIONS DESIGN
Activities
Intents
Services
Content Providers
Broadcast Receivers
APPLICATION COMPONENTS
19
ANDROID COMPONENTS: ACTIVITIES
An Activity corresponds to a
single screen of the
Application.
An Application can be composed of
multiples screens (Activities).
The Home Activity is shown
when the user launches an
application.
Different activities can exhange
information one with each other.
Hello World!
Android
HelloWorld
Button1
20
ANDROID COMPONENTS: ACTIVITIES
Each activity is composed by a list of graphics
components.
Some of these components (also called Views)
can interact with the user by handling events
(e.g. Buttons).
Two ways to build the graphic interface:
Example:
Button button=new Button (this);TextView text= new TextView();text.setText(“Hello world”);
PROGRAMMATIC APPROACH
21
ANDROID COMPONENTS: ACTIVITIES
Each activity is composed by a list of graphics
components.
Some of these components (also called Views)
can interact with the user by handling events
(e.g. Buttons).
Two ways to build the graphic interface:
Example:
< TextView android.text=@string/hello”android:textcolor=@color/blue android:layout_width=“fill_parent”android:layout_height=“wrap_content” />< Button android.id=“@+id/Button01”android:textcolor=“@color/blue”android:layout_width=“fill_parent”android:layout_height=“wrap_content” />
DECLARATIVE APPROACH
22
- Build the application
layout through XML files(like HTML)
- Define two different XML
layouts for two different
devices
- At runtime, Android
detects the current device
configuration and loads
the appropriate resources
for the application
- No need to recompile!
- Just add a new XML file
if you need to support a
EXAMPLE
Device 1HIGH screen pixel density
Device 2LOW screen pixel density
XML Layout FileDevice 1
XML Layout FileDevice 2
Java App Code
ANDROID COMPONENTS: ACTIVITIES
23
ANDROID COMPONENTS: ACTIVITIES
Android applications typically use both the
approaches!DECLARATIVE
APPROACH
PROGRAMMATIC APPROACH
Define the Application
layouts and resources
used by the Application
(e.g. labels).
Manages the events, and
handles the interaction
with the user.
XML Code
Java Code
24
ANDROID COMPONENTS: ACTIVITIES
Views can generate events (caused by
human interactions) that must be managed by
the Android-developer.
public void onClick(View arg0) {if (arg0 == Button) {
// Manage Button events}
}
ESEMPIO
Bu
tton
TextE
dit
25
ANDROID COMPONENTS: ACTIVITIES
The Activity Manager is
responsible for creating,
destroying, managing activities.
Activities can be on different
states: starting, running,
stopped, destroyed, paused.
Only one activity can be on the
running state at a time.
Activities are organized on a
stack, and have an event-
driven life cycle (details later …)
26
ANDROID COMPONENTS: ACTIVITIES
Main difference between Android-programming and
Java (Oracle) -programming:
Mobile devices have constrained resource
capabilities!
Activity lifetime depends on users’ choice (i.e.
change of visibility) as well as on system
contraints (i.e. memory shortage).
Developer must implement lifecycle methods to
account for state changes of each Activity …
27
ANDROID COMPONENTS: ACTIVITIES
public class MyApp extends Activity {
public void onCreate() { ... }
public void onPause() { ... }
public void onStop() { ... }
public void onDestroy(){ ... }
….
}
Called when the Activity
is created the first time.
Called when the Activity
is partially visible.
Called when the Activity
is no longer visible.
Called when the Activity
is dismissed.
28
ANDROID COMPONENTS: INTENTS Intents: asynchronous messages to activate
core Android components (e.g. Activities).
Explicit Intent The component (e.g.
Activity1) specifies the destination of the intent
(e.g. Activity 2).
LOGIN
PASSWO
RD
Logi
n
marco
**********
Welcome Marco!
Login Intent
Activity1
Activity2
29
ANDROID COMPONENTS: INTENTS Intents: asynchronous messages to activate
core Android components (e.g. Activities).
Implicit Intent The component (e.g.
Activity1) specifies the type of the intent (e.g.
“View a video”).
View
Implicit Intent
Activity1
Activity2
Activity2
Multiple choices
might be available
to the user! } Intent-
Filters
30
ANDROID COMPONENTS: SERVICES Services: like Activities, but run in
background and do not provide an user
interface.
Used for non-interactive tasks (e.g.
networking).
Service life-time composed of 3 states:Startin
g
Destroy
ed
Runnin
g
(on background)
onCreate()
onStart()onDestroy()
31
ANDROID COMPONENTS: CONTENT PROVIDERS
Each Android application has its own
private set of data (managed through files or
through SQLite database).
Content Providers: Standard interface
to access and share data among different
applications.
DB
APP
insert
()update()
delete
()query
()
Conte
nt
Provid
er e.g. Photo
Gallery
32
ANDROID COMPONENTS: BROADCAST RECEIVERS
Publish/Subscrib
e paradigm
Broadcast
Receivers: An
application can
be signaled of
external
events.
Notification
types: Call
incoming, SMS
delivery, Wifi
33
ANDROID COMPONENTS: BROADCAST RECEIVERS
class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {
String s = new StringBuilder();
wifiList = mainWifi.getScanResults();
for(int i = 0; i < wifiList.size(); i++){
s.append(new Integer(i+1).toString() + ".");
s.append((wifiList.get(i)).toString());
s.append("\\n");
}
mainText.setText(sb);
}
BROADCAST RECEIVER example
34
ANDROID COMPONENTS: BROADCAST RECEIVERS
public class WifiTester extends Activity {
WifiManager mainWifi;
WifiReceiver receiverWifi;
List<ScanResult> wifiList;
public void onCreate(Bundle savedInstanceState)
{
…
mainWifi = (WifiManager)
getSystemService(Context.WIFI_SERVICE);
receiverWifi = new WifiReceiver();
registerReceiver(receiverWifi, new
IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE
_ACTION));
mainWifi.startScan();
}
BROADCAST RECEIVER example
35
ANDROID COMPONENTS: SYSTEM API
Using the components described so far, Android
applications can then leverage the system API …
Telephony Manager data access (call, SMS, etc)
Sensor management (GPS, accelerometer, etc)
Network connectivity (Wifi, bluetooth, NFC, etc)
Web surfing (HTTP client, WebView, etc)
Storage management (files, SQLite db, etc)
….
SOME EXAMPLEs …
36
ANDROID COMPONENTS: GOOGLE API
… or easily interface with other Google
services:
37
Each Android application is
contained on a single APK file.
Java Byte-code (compiled for
Dalvik JVM)
Resources (e.g. images. videos,
XML layout files)
Libraries (optimal native C/C++
code)
APK
FIL
E
XM
L
File
s
C
Android Application Distribution
38
ANDROID APPLICATION DISTRIBUTION
Each application must be
signed through a key
before being distributed.
Applications can be
distributed via Web or
via Stores.
Android Play Store:
application store run by
Google … but several
other application stores
are available (they are
just normal applications).
39
ANDROID APPLICATION SECURITY
Android applications run with a distinct
system identity (Linux user ID and group
ID), in an isolated way.
Applications must explicitly share
resources and data. They do this by
declaring the permissions they need for
additional capabilities.
Applications statically declare the permissions
they require.
User must give his/her consensus during the
installation.
<uses-permission android:name=“android.permission.IACCESS_FINE_LOCATION" />
<uses-permission android:name=“android.permission.INTERNET" />
ANDROIDMANIFEST.XML
MOBILE NETWORKING THROUGHMOBILE IP
TRULY MOBILE NETWORKING
Provide confident access to the Internet
anytime, anywhere
Reconnection occurs automatically and
noninteractively
Mobility transparent to applications and
higher level protocols such as TCP
TODAY’S INTERNET PROTOCOL
Packets are routed to destinations based on
IP address
APPLY TO MOBILE NETWORKING
APPLY TO MOBILE NETWORKING
128.143.77.84
X
MOBILE IP APPROACH
Mobile IP uses two IP addresses:
Home address: The IP address assigned to the
mobile node, making it logically appear attached to its
home network.
Care-of address: An IP address at the mobile node's
current point of attachment to the Internet, when the
mobile node is not attached to the home network.
MOBILE NETWORK TERMINOLOGY (1)
Home network: The network at which the mobile node
seems reachable, to the rest of the Internet, by virtue of its
assigned IP address.
Foreign network: The network to which the mobile
node is attached when it is not attached to its home
network, and on which the care-of address is reachable
from the rest of the Internet.
MOBILE NETWORK TERMINOLOGY (2)
Home agent: A router on the home network that
effectively causes the mobile node to be reachable at its
home address even when the mobile node is not attached
to its home network.
Foreign agent: A router on the foreign network that can
assist the mobile node in receiving datagrams delivered to
the care-of address.
HOW MOBILE IP WORKS
128.143.77.84
HA
HOW MOBILE IP WORKS
128.143.77.84
HA
FA
Register
Discovery
Discovering the care-of address
Registering the care-of address
Tunneling to the care-of address
AGENT DISCOVERY PROTOCOL
Extends ICMP Router Discovery protocol
ICMP Router Discovery Protocol enables hosts attached
to multicast or broadcast networks to discover the IP
addresses of their neighboring routers.
Agent advertisements: The mobile agent broadcast
agent advertisements at regular intervals.
Agent solicitation: The mobile node broadcast or
multicast a solicitation that will be answered by any
foreign agent or home agent that receives it.
ADVERTISEMENT MESSAGE FORMATS
ICMP Router Advertisement Agent Advertisement extension
Type: 16
R: register required
B: busy
H: home agent
F: foreign agent
M: minimum encapsulation
G: GRE encapsulation
V: Van Jacobson header compression
ADVERTISEMENT MESSAGE FORMATS
ICMP Router Advertisement Prefix Length extension
Type: 19
Prefix Length:network number of the corresponding Router Address listed in the ICMP Router Advertisement portion of the message.
MOBILE NODE MOVE DETECTIONLifetime based
The mobile node record the Lifetime of advertisement message. If it fails to receive another advertisement from the same agent until the the Lifetime expires, it considers to find a new agent.
Network prefixes based
The Prefix-length extension is used to determine if the newly received advertisement is in the same subnet as the mobile node’s current care-of-
address.
REGISTRATION
MH: mobile host; FA: Foreign Agent; HA: Home Address
Exchange of Registration Request and Registration
Reply messages: UDP using well-known port 434
FOREIGN AGENT CONSIDERATION Each foreign agent must be configured with a care
of address
For each pending or current registration, the foreign
agent maintains a visitor list entry containing:
Link-layer source address of the mobile node
The mobile node’s Home Address
The Home Agent address
The identification field
The requested registration Lifetime
The remaining Lifetime of the pending or current
registration
SECURITY CONSIDERATIONS IN REGISTRATION
Danger: Registration Request works remotely to the
home agent to affect the home agent's routing table
Security:
Authentication: Home agents and mobile nodes perform
authentication using MD5 algorithm and key size of 128
bits.
Replay Protection: The Identification field is used to verify
that a registration message has been freshly generated.
timestamp , random number
TUNNELING TO THE CARE OF ADDRESS
CHANGES WITH IP VERSION 6
Route Optimization
When it knows the mobile node's current care-of
address, a correspondent node can deliver packets
directly to the mobile node's home address without
any assistance from the home agent
Security
Strong authentication and encryption features are
included in IP V6
PROBLEMS FACING MOBILE IP
Security issues
Routing inefficiency
Triangle routing
Ingress filtering
User perceptions of reliability
Competition from other protocols
REFERENCE
"Mobile Networking through Mobile IP," C.
Perkins, IEEE Internet Computing, Vol. 2, No. 1,
1998.
"Mobile IP ," C. Perkins, IEEE Communications
Magazine, Vol. 35, No. 5, 1997.
QUESTIONS/COMMENTS?
61