sistemi di elettronica digitale, sez - alessandra...

52
Sistemi di Elettronica Digitale, Sez.7 Alessandra Flammini [email protected] Ufficio 24 Dip. Ingegneria dell’Informazione 030-3715627 Lunedì 16:30-18:30 Sistemi di elettronica digitale, A. Flammini, AA2017-2018

Upload: hoangmien

Post on 29-Apr-2018

216 views

Category:

Documents


3 download

TRANSCRIPT

Sistemi di Elettronica Digitale, Sez.7

Alessandra [email protected]

Ufficio 24 Dip. Ingegneria dell’Informazione030-3715627 Lunedì 16:30-18:30

Sistemi di elettronica digitale, A. Flammini, AA2017-2018

Smartphones, Android, Sensory

Systems

Sistemi di elettronica digitale, A. Flammini, AA2017-2018

3

FROM Mobile Phones to Smartphones

• First mobile phone 1983, camera phones late ‘90, OS late ’90

• Proprietary formats emerged to better take advantage of hardware capabilities:

• Palm OS (became Garnet OS)• RIM Blackberry OS• Java Micro Edition• Symbian OS (Sony Ericsson, Motorola, Samsung)• Windows Phone (Nokia)• iPhone iOS

• Major players now: • iOS• Android• Windows Phone (abandoned)

Sistemi di Elettronica Digitale, A. Flammini

4

History of Mobile Hardware

Sistemi di Elettronica Digitale, A. Flammini

5

History of Mobile Hardware

Sistemi di Elettronica Digitale, A. Flammini

6

History of Mobile Hardware

Sistemi di Elettronica Digitale, A. Flammini

7

INSIDE A SMARTPHONE

Samsung Galaxy S4: few big devices (cameras and other components on different boards)

Sistemi di Elettronica Digitale, A. Flammini

INSIDE A SMARTPHONE: open source projects

8Sistemi di Elettronica Digitale, A. Flammini

Not successfull, abandoned 2009

INSIDE A SMARTPHONE: Sensors

9Sistemi di Elettronica Digitale, A. Flammini

Accelerometer within the smartphone can be used to detect• human activities – walking, running, dancing or posture• vehicles collisions or vibrations• The Smartphone includes gyroscopes (orientation –yaw, pitch, roll- and their variation) and magnetometers (the strength of earth’s magnetic field)

Proximity sensor, touchscreen• during a call, if the phone is close (in touch) to the ear, the touchscreen is disabled. The touchscreen can be considered as another sensor (same for NFC)

Microphones• is a sensor for word and/or noise detection and identification, but also a sensor for acoustic pollution measurement, a sensor for traffic measurement, weapon shot detection, and so on

Cameras, luxmeter, temperature• A smartphone includes two cameras with sometimes a luxmeter for automatic flash management. The camera can be used as a heart rate detection. New possible cameras for pulsiossimeter or glucose detection

GPS, WiFi, BLE, Software sensors (e.g. fingerprint)

OPERATIVE SYSTEMS (OS)

Why a Smartphone needs an OS?• To execute several programs and applications• To manage memory and communication interfaces• To manage its HW and its SW

10Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Evolution

11Sistemi di Elettronica Digitale, A. Flammini

ANDROID: History

12Sistemi di Elettronica Digitale, A. Flammini

• 2008: T-Mobile G1 announced– SDK 1.0 released– Google sponsors first Android Developer Challenge– Android Open Source Project (Apache license)– Android Dev Phone 1 released

• 2009: New SDK release– Cupcake (SDK 1.5)

• Softkeyboard with autocomplete feature• Auto-rotation option

– Donut (SDK 1.6)• New camera features• Search features improved (Quick/Voice)

– Éclair (SDK 2.0/2.0.1/2.1)• New camera features• Multiple accounts

ANDROID: History

13Sistemi di Elettronica Digitale, A. Flammini

• 2010: Nexus One released to the public– Froyo (SDK 2.2)

• Expandable memory• USB tethering

– Gingerbread (SDK 2.3)• UI update• NFC

• 2011: New SDK release– Honeycomb (SDK 3.0/3.1/3.2) for tablets only

• New UI tablet oriented• Multi-core processor supporting

– Ice Cream Sandwich (SDK 4.0/4.0.1/4.0.2/4.0.3)• WIFI direct• Changes to the UI• Face unlock

• 2012: – Ice Cream Sandwich (SDK 4.0.4)

• Stability improvement

– Jelly Bean (SDK 4.1)• Google Now

ANDROID: History

14Sistemi di Elettronica Digitale, A. Flammini

2013:

Kit Kat (SDK 4.4)

NFC capabilities through Host

Card Emulation

Wireless printing support

Storage access framework, new framework

2014:

Lollipop (SDK 5)

Android RunTime (ART) with ahead-on-time (AOT) compilation

64-bit CPU

2015:

Marshmellow (SDK 6)

USB OTG, Access point for 5GHz

Fingerprint recognition, new functionalities for Power management

ANDROID: History

15Sistemi di Elettronica Digitale, A. Flammini

2016:

Nougat (SDK 7)

New graphic functionalities

Dual window (multi-window for tablet)

Auto-update

2017:

Oreo (SDK 8)

Floating windows

Text autofill

Notification dots

Power and memory management

NOTE: Android Wear for SmartWatch

ANDROID: History

16Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Current releases distribution

17Sistemi di Elettronica Digitale, A. Flammini

ANDROID is growing fast- More than 50% of smartphone market- More than 70% of tablet market- Not only smartphone and tablet

- Smart watch- Smart TV- IoT

18

ANDROID: main differences with IOS

Different device size (more HW manufactors)

Expandable memory

USB connection

External HW easier to product

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: ARCHITECTURE

Android is:• an OS (Linux kernel) for HW interface• A Library set to be used in APPs• A Java Virtual Machine for APPs porting and executing (all Apps are written in Java language)• A framework for APPs development• An Applications containers- general Apps (Phone)- specific Apps (FB)

Application: a Java-based program for ANDROID

19Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Linux Kernel

Android Linux Kernel has

differentiated from Linux

Kernel

From 2.6 ver to 3.8

Basic SO services

Abstraction between

hardware and software

Security

Memory management

Process management

20Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Libraries

Run in system background

Use C/C++ language

Four types of libraries

Bionic Libc, system C libraries

Function libraries, supporting multimedia, web browser, SQlite

Native servers

Hardware Abstraction Libraries

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Core Libraries

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language

Core APIs for Java language provide a powerful, yet simple and familiar development platform

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Dalvik Virtual Machine

Android custom implementation virtual machine

Provides application portability and runtime consistency

Runs optimized file format (.dex) and Dalvik bytecode

Java .class / .jar files converted to .dex at build time

Designed for embedded environment

Supports multiple virtual machine processes per device

Each process an instance of the DVM

Highly CPU-optimized bytecode interpreter

Efficiently Using runtime memory

The Dalvik VM relies on the Linux kernel for underlying functionality (threading and low-level memory management)

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Application Framework

Simplify the reuse of components

Applications can publish their capabilities and any other application may then make use of those capabilities

Applications is a set of services and systems, include

Views system, content providers, resources manager and so on

Frameworks

Activity Manager

Notification Manager

Resource Manager

Content Providers

Views

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Applications

Contain a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, …

All yours Apps will belong to this layer

All applications are written in Java programming language

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: SDK

Software Development Kit (SDK) enables developers to

create applications for the Android platform

Sample projects source code

Custom virtual machine

Development tools:

Dalvik Debug Monitor Service (DDMS)

Android Debug Bridge (ADB)

Android Emulator

SDK emulator: allows to develop and test apps on PC

without a physical device (simulate the mobile)

SDK download link:

http://developer.android.com/sdk/index.html

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Emulator

Virtual mobile device on PC

Allows to develop and test apps on PC without a physical device (simulate interrupt)

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Traditional vs APP programming

Only one APP at a time (“multitasking”)

Only one window →Simplified UI (User Interface)

Limited system access (“sandboxing”)

Limited resources and memory

Instant APP opening and closing: application should start and quit instantaneously.

APP has her own lifecycle….

Code must apply to many kind of devices

Sistemi di Elettronica Digitale, A. Flammini

APP design first of all! Then code programming

ANDROID: APP Basic Components

An APP is made of:

Activities (Programs and related User Interface)

Services (Activities without User Interface, in background)

Intents (Messages among Activities)

Content providers

Standard interface for sharing data among Applications

Broadcast receivers

Receive notification from Android system

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: APP Basic Components

Activity:

Single screen of application, only “on screen” activity is in running state

Single App many Activities which can exchange data

Activities have a event-driven life-cycle

Activities is composed by graphic components

UI is built using a hierarchy of ViewandViewGroupobjects

View are usually UI widgets (e.g. textfield, button)

ViewGroup are invisible view containers that define how the child views are laid out (grid or list)

Android provides an XML vocabulary that corresponds to ViewandViewGroup so you can define your UI in XML using a hierarchy of UI elements

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: Widgets

Text View

Button

Toggle Button

Check Box

Radio Button

Checked Text View

Progressing Bar

Seek Bar

Quick Contact Badge

Radio Group

Rate Bar

Sistemi di Elettronica Digitale, A. Flammini

ANDROID: DESIGN

32Sistemi di Elettronica Digitale, A. Flammini

The Holy Bible URL: http://developer.android.com

• Be flexible• Optimize Layouts• Assets for all

ANDROID: NAV DESIGN

33Sistemi di Elettronica Digitale, A. Flammini

Up Vs Back

ANDROID: INTERACTION DESIGN

34Sistemi di Elettronica Digitale, A. Flammini

• Information widgets

• Collection widgets

• Control widgets

• Hybrid widgets

You can imagine them as "at-a-glance" views of an app's most important data and functionalitythat is accessible right from the user's home screen.

ANDROID: MORE DESIGN

35Sistemi di Elettronica Digitale, A. Flammini

Swipe views allow the user to efficiently move from item to item using a simple gestureand thereby make browsing and consuming data a more fluent experience.

ANDROID: FULL SCREEN DESIGN

36Sistemi di Elettronica Digitale, A. Flammini

Some content is best experienced full screen, like videos, games, image galleries, books, and slides in a presentation. Users can be engaged more deeply with content in full screen by minimizing visual distraction from app controls and protecting users from escaping the app accidentally.

ANDROID: CONFIRMATION DESIGN

37Sistemi di Elettronica Digitale, A. Flammini

ANDROID APP BASIC: MANIFEST FILES

38Sistemi di Elettronica Digitale, A. Flammini

The manifest file provides essential information about your app to the Android system, which the system must have before it can run any of the app's code.

• It names the Java package for the application. The package name serves as a uniqueidentifier for the application.

• It describes the components of the application, which include the activities, services, broadcast receivers, and content providers that compose the application. It also namesthe classes that implement each of the components and publishes their capabilities, such as the Intent messages that they can handle. These declarations inform the Androidsystem of the components and the conditions in which they can be launched.

• It determines the processes that host the application components.• It declares the permissions that the application must have in order to access protected

parts of the API and interact with other applications. It also declares the permissionsthat others are required to have in order to interact with the application's components.

• It lists the Instrumentation classes that provide profiling and other information as the application runs. These declarations are present in the manifest only while the application is being developed and are removed before the application is published.

• It declares the minimum level of the Android API that the application requires.• It lists the libraries that the application must be linked against.

ANDROID APP BASIC: Layout before

39Sistemi di Elettronica Digitale, A. Flammini

ANDROID APP BASIC: Layout after (var.1)

40Sistemi di Elettronica Digitale, A. Flammini

ANDROID APP BASIC: Layout after (var.2)

41Sistemi di Elettronica Digitale, A. Flammini

See tutorial for APP development in http://developer.android.com

ANDROID APP BASIC: COMPONENTS

42Sistemi di Elettronica Digitale, A. Flammini

ACTIVITIESAn activity is the entry point for interacting with the user. It represents a single screen with a user interface.

SERVICESA service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons.

BROADCAST RECEIVERSA broadcast receiver is a component that enables the system to deliver events to the appoutside of a regular user flow, allowing the app to respond to system-wide broadcast announcements.

CONTENT PROVIDERSA content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that yourapp can access.

ANDROID APP BASIC: ACTIVITY LIFE CYCLE

Activities have a event-driven life-cycle (event -> callback)

Callback When

onCreate() App creation

onStart() Activity visible

onResume() after onStart

onRestart() after onStop

onPause()another Activity called

onStop() Activity invisible

onDestroy()Before Activity destruction

43Sistemi di Elettronica Digitale, A. Flammini

ANDROID APP BASIC: USER INTERFACE

44Sistemi di Elettronica Digitale, A. Flammini

The graphical user interface for an Android app is built using a hierarchy of View and ViewGroup objects.

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent">

<EditText android:id="@+id/edit_message"android:layout_width="wrap_content"android:layout_height="wrap_content"android:hint="@string/edit_message" />

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send" />

</LinearLayout>

ANDROID APP BASIC: CALL-BACK STRUCTURE

45Sistemi di Elettronica Digitale, A. Flammini

<Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/button_send"android:onClick="sendMessage" />

public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);

}

/** Called when the user clicks the Send button */public void sendMessage(View view) {

// Do something in response to button}

}

HOW ANDROID APPs MANAGE SENSORS

46Sistemi di Elettronica Digitale, A. Flammini

Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy, and are useful if you want to monitor three-dimensional devicemovement or positioning, or you want to monitor changes in the ambient environmentnear a device.

The Android platform supports three broad categories of sensors:• Motion sensors: these sensors measure acceleration forces and rotational forces along

three axes. This category includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.

• Environmental sensors: these sensors measure various environmental parameters, suchas ambient air temperature and pressure, illumination, and humidity. This categoryincludes barometers, photometers, and thermometers.

• Position sensors: these sensors measure the physical position of a device. This categoryincludes orientation sensors and magnetometers.

SENSOR CATEGORIES

47Sistemi di Elettronica Digitale, A. Flammini

HW based sensors

Physical component built into the device

The data is directly acquired measuring specific environmental properties

SW based sensors

Emulate a HW based sensor behavior

The data are derived from one or more HW based sensors

SENSOR CATEGORIES

48Sistemi di Elettronica Digitale, A. Flammini

SENSORS: Accelerometer

49Sistemi di Elettronica Digitale, A. Flammini

Typically usages

screen orientation

inclination for game input

vibrations measurements

SENSORS: GPS

50Sistemi di Elettronica Digitale, A. Flammini

Typically usages:

Location

Lateration/Triangulation of cell towers or wifinetworks (with database of known locations for towers and networks)

Location of associated cell tower or wifi network

Need connect to 3 satellites for 2D positioning, 4 satellites for 3D positioning

More visible satellites increase precision

Typical precision 20-50m

Maximum precision: 10m

SENSORS: Gyroscope

51Sistemi di Elettronica Digitale, A. Flammini

Usages:

Measurements of rate of rotation (angular speed)

3 values related to the axes

Pitch value (rotation around X axis)

Roll value (rotation around Y axis)

Yaw value (rotation around Z axis)

SENSOR FRAMEWORK

52Sistemi di Elettronica Digitale, A. Flammini

You can access these sensors and acquire raw sensor data by using the Android sensorframework. The sensor framework is part of the android.hardware package and includesthe following classes and interfaces:

• SensorManager: You can use this class to create an instance of the sensor service. Thisclass provides various methods for accessing and listing sensors, registering and unregistering sensor event listeners, and acquiring orientation information. This classalso provides several sensor constants that are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.

• Sensor: You can use this class to create an instance of a specific sensor. This classprovides various methods that let you determine a sensor's capabilities.

• SensorEvent: The system uses this class to create a sensor event object, which providesinformation about a sensor event. A sensor event object includes the followinginformation: the raw sensor data, the type of sensor that generated the event, the accuracy of the data, and the timestamp for the event.

• SensorEventListener: You can use this interface to create two callback methods thatreceive notifications (sensor events) when sensor values change or when sensoraccuracy changes.