operating system and architectureapm/cmsw/docs/02basic.pdf · android operating system and...

20
Operating System and Architecture Android

Upload: trinhnhi

Post on 03-Jul-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Operating System

and

Architecture

Android

Page 2: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Android

❖Operating System and development system from

Google and Open Handset Alliance since 2008

• At the lower level is based on the Linux kernel and in a

higher level is based on a Java virtual machine

• Several versions in quick succession

▪1.0, 1.1, 1.5 (cupcake), 1.6 (donut), 2.0, 2.1 (éclair), 2.2 (froyo),

2.3 (gingerbread), 3.0-2 (honeycomb) (tablets), 4.0 (ice cream

sandwich), 4.1-3 (jelly beans), 4.4 (kitkat), 5.0-1 (lollipop), 6.0

(marshmallow), 7.0-1 (nougat), 8.0-1 (oreo), 9.0 (pie)

• Supports a high hardware variability

• Integrates a sensor collection (gps, accelerometer,

compass, gyroscope …)

• High graphics and sound quality

▪Screen densities of 120, 160, 240, 320 and 480 dpi and higher

▪Resolutions from 240x320 to 1600x2520 pixels (4K 2160x3840)

Android 2

Page 3: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Screens

Android 3

Low Med TV High Xhigh XXhigh

Small 0.3%

Normal 0.8% 0.3% 26.1% 39.9% 24.2%

Large 2.2% 1.4% 0.4% 1.2% 0.5%

Xlarge 1.7% 0.6% 0.4%

from 3.0” to 4.5”

120 dpi

from 4.5” to 7.0”

< 3.0”

160 dpi 240 dpi 320 dpi

from 7.0” to 10.0”

Aug. 2018

213 dpi 480 dpi

Actual screen resolutions:

from 240x320 pixels

to (4K = 2160x3840)

Page 4: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Framework based in reuse and extension patterns

❖ Optimized virtual machine (Dalvik VM) → ART

❖ Integrates a browser (based on WebKit) → Blink

❖ 2D and 3D graphics (OpenGL ES 1.1, 2.0) → 3.2

❖ Local relational data base based on SQLite

❖ Several standard multimedia formats supported

(MPEG4, H.264, MP3, AAC, JPG, PNG, GIF, …)

❖ Comms in GSM, 3G/4G, WiFi, Bluetooth and NFC

❖ Camera, GPS, compass and accelerometer

❖ Application development uses Java or Kotlin

Android 4

Main features

Page 5: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Versions in usePlatform API Level Distribution

Android 2.3.3-7 10 0.2%

Android 4.0.3-4 15 0.3%

Android 4.1-3 16-18 3.6%

Android 4.4 19 9.1%

Android 5.0-1 21-22 20.4%

Android 6.0 23 23.5%

Android 7.0-1 24-25 30.8%

Android 8.0-1 26-27 12.1%

Aug-2018

Android 5

Android 6.0 Marshmallow

Android 7.0 Nougat

Android 8.0 Oreo

Android 9.0 Pie

Page 6: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Architecture

Android 6

Android OS Layers

and Components

C/C++ native compiled

code

OS

Java code

Java virtual machine

Java libraries

JIT and AOT compilers

Page 7: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Linux kernel• Low level OS services (memory and process management,

communications and network, files) and hardware access (peripheral and sensor drivers)

❖Native libraries•Written in C/C++ and compiled to the processor native

instructions▪Surface management, 2D and 3D graphics, multimedia codecs,

DBMS SQL, Web engine

▪Wrapped in Java

▪ It is possible to develop and install new native libraries using the NDK (Native Development Kit)

❖ Android runtime• Java virtual machine optimized for small devices and

processors (Dalvik VM)

• Java base library (with some superposition with Java SE and Java ME)

Android 7

Operating system components (1)

Page 8: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Application Framework

•High level library, in Java, suitable to the creation of

user Android applications (Android API); also the

higher level Android management services (Java)

▪Activity manager – controls the application lifetime and

navigation between ‘screens’

▪Content manager – control shared data between applications

providing a standard format and access

▪Resource manager – Management of non-code specifications

and assets in applications

▪Location manager – Android device position determination

(the device knows always its position in the world using GPS

Wi-Fi or GSM receptors)

▪Notification manager – External event management like

messages, to-do’s, alerts, etc

Android 8

Operating system components (2)

Page 9: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Applications (Apps)

•Programs that control the full screen to interact with

the user

▪An Android device contains some pre-defined applications

which are mandatory:

▪ Home

▪ Launcher

▪ Phone dialer

▪ Calendar and Email

▪ Contacts

▪ Web browser

▪ Play Store

❖Widgets

•Operate only on a small rectangular portion of the

screen, inside the Home applicationAndroid 9

The Android system

Page 10: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Built from Java source code, Resources and

Assets

Android 10

Building Applications

.java 01001

10010

01110

.class

.xml

01001

10010

01110

01001

10010

01110

.dex

01001

10010

01110

.apk

javacdex

aapk

device

install

run

assets

resources

sources

Page 11: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ The Android applications can contain several independent

components

• Activities, Services, Broadcast Receivers and Content Providers

❖ Components

• Activities

▪ Contain a portion of the user interface (full screen or window)

▪ Execute a well defined task inside the application

▪ One application can contain one or more activities

▪ Are independent but can be invoked by others

▪ Are subclasses of the android.app.Activity class

▪ Are usually composed by a hierarchy of Views

▪ One activity must be the starting activity of an applicationAndroid 11

Application components (1)

Page 12: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Other components•Services▪Don’t have user interface

▪Can execute in background for an indeterminate period

▪ It’s possible to establish a connection with the service and communicate through a well defined programming interface

•Broadcast receivers▪Can receive and react to notifications originated in the

system or other applications

▪Applications can initiate a notification ‘broadcast’

•Content providers▪Make available to other applications a data collection

maintained by this application

▪Define an interface to access, add and update the supported data types

Android 12

Application components (2)

Page 13: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Application planning

Android 13

Activity Diagram

Sketch andWireframe

Navigation

Page 14: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

Activity Launching

Android Applications 14

Android Launcher

Activity

Other Activity

Intent

Intent

action.MAINcategory.LAUNCHER

startActivity()Back button

Page 15: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Activities and Services

•Are activated through an Intent

• Intents identify the component or specify actions for

activities and services

▪Explicit intents contain the class name of the destination

▪ Implicit intents can specify an action, a category, data (in the

form of an uri) and possibly extra information

▪ Android will try to find a matching component capable of

executing the action in the data (or data type) specified

▪When activities and services are declared in the manifest they

can specify ‘intent-filters’ describing their accepting intents

Android 15

Component activation (1)

Inside an activity, when we need to navigate to other activity of the same

application, we normally use an explicit intent:

Intent otherActivity = new Intent(thisActivity, OtherActivity.class);

thisActivity.startActivity(otherActivity);

Page 16: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Broadcast receivers

• Intents for activating broadcast receivers identify a

‘message’ to be delivered to matching receivers

▪The ‘message’ is specified using an action, category, data and

extra info (put together in an intent object)

▪ It is sent by a call to sendBroadcast(Intent)

▪A broadcast receiver that has been installed matching the

intent (with a compatible intent-filter) will be then activated

(runs its onReceive(Context, Intent) method)

Android 16

Component activation (2)

Page 17: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Content providers

•When declared in the manifest they must have an

‘authority’ (which is a kind of provider name)

•Also they must recognize a name for its data

collection

•Usually they support CRUD operations on that

collection

•They are activated through a ContentResolver object

▪ Obtained by getContentResolver() method from an activity

▪ ContentResolvers have operations (methods) like: query,

insert, update and delete

▪ These methods require a Uri identifying the provider and data

collection following the format

▪ content://<authority>/<data collection>[/<item>]

Android 17

Component activation (3)

Page 18: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖ Component invocation mechanism

•For Activities (UI), Services (background), Broadcast

Receivers (notifications)

•All the intents have a name (action) and can have

more data associated (uri, category, extra info)

▪ They can be also explicit with a class name (inside an app)

•An intent is a class in the Android API

•There are many pre-defined intents in the Android API

Android 18

Intents

Intent intent = new Intent(Intent.ACTION_DIAL);startActivity(intent);

Matches the Android activity (in the

Dialer application) that allows the

user to make a phone call, declared

in an <intent-filter> that can handle

this action

Intent intent = new Intent(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:555-555-5555"));startActivity(intent);

Example 1:

Example 2:

Matches the activity that makes a phone call

from a number

Page 19: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Intents can transport data between components

•The Data field can be used for any type of an Uri

▪The calling component uses the method setData(Uri data),

while the new component can read it with Uri getData()

•The Extra field is used for arbitrary data types

▪ It is a Bundle – set of (name, value) pairs organized as an hash

table

▪ The value can be a String, simple type, or an array

▪ Can also be any Serializable or Parcelable (more efficient) object

▪ The values are inserted with some PutExtra(String name, ... value)

method and retrieved with ... get...Extra(String name)

Android 19

Intents data

IntentActivity Activity

creates

fills with

data

starts

retrieves

the data

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

...

Intent intent = getIntent();

String fName = intent.getStringExtra("firstName");

String lName = intent.getStringExtra("lastName");

}

Page 20: Operating System and Architectureapm/CMSW/docs/02Basic.pdf · Android Operating System and development system from ... Android 6.0 Marshmallow Android 7.0 Nougat ... (memory and process

❖Specially invoked activities can return data

• Invocation using startActivityForResult(...)

▪Besides the intent, it has a requestCode (int) as a parameter

▪ The new activity should create a result Intent, fill it with the result data,

and call setResult(), passing this intent, before finishing

▪ The original activity can retrieve this intent and get the data

Android 20

Getting result data

...

Intent resultIntent = new Intent();

resultIntent.putExtra("some_key", "String data");

setResult(Activity.RESULT_OK, resultIntent);

finish();

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

switch(requestCode) {

case (MY_CHILD_ACTIVITY) : {

if (resultCode == Activity.RESULT_OK)

String returnValue = data.getStringExtra("some_key");

break;

}

}

}

Intent

Intent

startActivityForResult()

onActivityResult()