5. more on app development

54
5. More on app development Some other mobile development systems MIDP Java – Maemo – Android – iPhone Windows Mobile – OpenMoko Commonly used implementation techniques • Summary

Upload: ponce

Post on 08-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

5. More on app development. Some other mobile development systems MIDP Java Maemo Android iPhone Windows Mobile OpenMoko Commonly used implementation techniques Summary. Mobile Java (MIDP in particular). Most importantly an add-on to proprietary phone OS based systems - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 2: 5. More on app development

Mobile Java (MIDP in particular)

• Most importantly an add-on to proprietary phone OS based systems– Huge device space that is already deployed– No need to modify the already existing prorietary

platform but simple wrapping is enough!

• Disclaimer: Full Java software stacks exist;– RIM & Blackberry– JavaFX Mobile (earlier SavaJe)– (Google Android --- at least kind of!)

Page 3: 5. More on app development

Building Mobile Java Infrastructure

Hosting operating system- Access to hardware

Page 4: 5. More on app development

Building Mobile Java Infrastructure

KVM MobileHotSpot VM

Standard-featuredVM

Simplified facilitiesReduced memory footprint

Standard-featured Java VMReduced memory footprint

Hosting operating system- Access to hardware

Page 5: 5. More on app development

Building Mobile Java Infrastructure

KVM MobileHotSpot VM

Standard-featuredVM

CLDC CDC

Connected Limited Device Configuration- No floating point support (v.1.0)- Simplified security scheme- No user-defined class loaders- No finalize, thread groups, reflection, or JNI- Also other simplifications

Connected Device Configuration- Standard facilities

Hosting operating system- Access to hardware

Page 6: 5. More on app development

Building Mobile Java Infrastructure

KVM MobileHotSpot VM

Standard-featuredVM

CLDC CDC

MIDP IMP

Foundation profile

Personal basis profile

Personal profile

Application development facilities

Hosting operating system- Access to hardware

Page 7: 5. More on app development

Midlet (MIDP)

Paused

Active

DestroyedstartApp pauseApp

constructor

destroyApp

destroyApp

Page 8: 5. More on app development

Development Process

MyApp.class

Development workstation

MyApp.java

javac

MyApp.class

preverifier

Target device(KVM runtime)

runtime verifier

interpreter

download

Page 9: 5. More on app development

Sample Midlet

Page 10: 5. More on app development

Midlet Implementation

• Extend class midlet• Implement methods

– Constructor– startApp– destroyapp– pauseapp

• Usually some way of interaction for the user required as well– E.g. CommandListener interface

Page 11: 5. More on app development

Behavioruser start

Appcommand

Actiondisplay

StatementgiveInfo

pickStatement

Page 12: 5. More on app development

Code...import javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class PersonalityTest extends MIDlet implements CommandListener { private Command positive, negative, exitCommand; /** Yes, No, Exit */ private TextBox tb; private int nth, count = 0; /** Counter for statement and answer pair. */ private String Questions[] = /** Questions */ { "The weapon of the brave is in his heart.", "A man is a lion for his own cause.", "Courage leads to the stars, fear toward death.", "Faced with crisis, the man of character falls back upon himself.", "It is not the oath that makes us believe the man, but the man the oath.", "Whoever is careless with the truth in small matters cannot "+ "be trusted with the important matters.", "No great thing is created suddenly." }; private int Qlen = Questions.length;

Page 13: 5. More on app development

Code… public PersonalityTest() { exitCommand = new Command("EXIT", Command.EXIT, 1); negative = new Command("NO", Command.CANCEL, 2); positive = new Command("YES", Command.OK, 2); } protected void startApp() { pickStatement(); } public void commandAction(Command c, Displayable d) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } else { if (c == positive) { count++; } else {count--;} } pickStatement(); }

Page 14: 5. More on app development

Code… protected void destroyApp(boolean u) {} protected void pauseApp() {}

private void pickStatement() { if (nth == Qlen) { giveInfo(); } else { displayStatement(Questions[nth]); nth = nth + 1; } } private void displayStatement(String statement) { tb = new TextBox("Statement Selection", statement, 256, 0);

tb.addCommand(positive); tb.addCommand(negative); tb.setCommandListener(this);

Display.getDisplay(this).setCurrent(tb); }

Page 15: 5. More on app development

Code… private void giveInfo() { if (count > 1) { tb = new TextBox("PersonalityTest", "You seem to be an overly positive

person.", 50, 0); } else if (count < -1) { tb = new TextBox("Personalitytest", "You appear as a gravely negative

person.", 50, 0); } else { tb = new TextBox("Personalitytest", "You seem to have difficulties in being

in line with yourself.", 80, 0); } tb.addCommand(exitCommand); tb.setCommandListener(this); Display.getDisplay(this).setCurrent(tb); }} // class PersonalityTest

Page 16: 5. More on app development

JAD/Midlet suite manifest

MIDlet-1: PersonalityTest, PersonalityTest.png, PersonalityTest

MIDlet-Name: PersonalityTest

MIDlet-Vendor: Unknown

MIDlet-Version: 1.0

MicroEdition-Configuration: CLDC-1.0

MicroEdition-Profile: MIDP-2.0

Page 17: 5. More on app development

MIDlet execution environment

JAR File

MIDlet 1 MIDlet 2getResorceAsStream()non-class access

including JAR manifest

RMS

RMS1

RMS2

getResorceAsStream()non-class access

including JAR manifest(Appl. descriptor file)

Page 18: 5. More on app development

MIDlet execution environment• Classes and native code that implement CLDC and

MIDP – Only shared name space for all MIDlet suites in early

versions– Later systems introduce more advanced facilities

• Classes within MIDlet suite’s JAR file• All non-class files in the MIDlet’s suite’s JAR file

– Icons, images, JAR manifest– Accessible with java.lang.Class.getResourceAsStream

• Contents of Application Descriptor File– Accessible with java.lang.Class.getResourceAsStream

• Separate name space for RMS record stores

Page 19: 5. More on app development

MIDP 1.0 libraries and interfaces• UI

– Different device specific wrapping for widgets• Canvas: Low-level interface; control for programmer• Screen: Device specific widgets; control for the widgets and library;

navigation, scrolling etc. built in– Different screen capabilities (e.g. screen, color, ...)

– Different input mechanisms (keyboard, touch screen, ...)

• Networking interface– Originally http focused, no link to final implementation-level

protocol; later improved considerably

• Persistence– RMS, record management system

• Reflects a simple, record-oriented database• Records interfaced with byte arrays

Page 20: 5. More on app development

UI class hierarchy (MIDP 1.0)Display

Displayable

0..1

Screen

Canvas Alert

List

TextBox

Form

Item

StringItem

ImageItem

TextField

DateField

Gauge

ChoiceGroup

0..1

Page 21: 5. More on app development

Other screen-related issues• Game API (MIDP 2.0)

– Sprites, layering, etc.– Enables native implementation

• GUI enhancements– Builds on MIDP 1.0 LCDUI– Custom items, layout control, graphical enhancements...– Backward compatibility

• Further enhancements provided in later JSRs for e.g. – Multimedia– 3D

Page 22: 5. More on app development

Networking Interface• Originally http focused (MIDP 1.0) with multiple carriers (e.g. TCP/IP,

WAP, i-Mode)

• Numerous networking extensions and improvements– HTTPS, SSL– Serial port– Sockets– Server Sockets– Datagrams– Network push feature

• Network initiated MIDlet launch

• OTA (over the air) applications– Installation

• Verify integrity, certificates, requested permissions

– Invocation• Permissions

– Originally extension, later required

Page 23: 5. More on app development

Persistence• Based on Record Management

System– Records contained by record stores

• RMS sharing obeys MIDlet suite principle– Same name can be used for different

RMS record stores in different MIDlet suites

– Later relaxed

• Programmer (or device manufacturer) handles mutual exclusion

– listRecordStores, openRecordStore, getName, getSize, addRecord, deleteRecord,...

– DataInputStream, DataOutputstream, ByteArrayInputStream, ByteArrayOutputStream

RecordStore

RecordId = 1

RecordId = 7

RecordId = 3

Page 24: 5. More on app development

Other services

• Timers

class myTask extends TimerTask { public void run() { ... }}myTimer = new Timer();myTask = new myTask();myTimer.schedule(myTask, 100, 1000);

• Access to resource files (getResourceAsStream)

• System properties (java.lang.System.GetProperty)– microedition.platform (name of the device)– microedition.encoding (character encoding) – microedition.configuration (used configuration and its version)– microedition.profiles (used profile and its version)– microedition.locale (language and country)

Page 25: 5. More on app development

• JSR-120: Wireless Messaging API– Short Message Service (SMS)– Unstructured Supplementary Service Data (USSD)– Cell Broadcast Service (CBS)

• JSR-135: Mobile Media API– Straightforward access and control of basic audio and multimedia

resources and files

• JSR-172: J2MET Web Services Specification– Infrastructure for basic XML processing capabilities– Reuse of web service concepts when designing J2ME clients for

enterprise services– Provides APIs and conventions for programming J2ME clients of

enterprise services– Programming model for J2ME client communication with web

services, consistent with that for other Java clients such as J2SE.

Further interfaces

Page 26: 5. More on app development

Further interfaces• JSR-177: Security and Trust Services for J2MET

– Necessary step for a device to become trusted, i.e., to provide security mechanisms to support a wide variety of application-based services, such as access to corporate network,mobile commerce, and digital rights management

– Model and a set of APIs that enable applications running on a J2ME device to communicate with a smartcard

• JSR-179: Location API for J2MET– Optional package that enables developers to write mobile, location-

based applications for J2ME devices

• JSR-180: Session Initiation Protocol (SIP) for J2MET– Session Initiation Protocol (SIP) is used to establish and manage

multimedia IP sessions– General SIP API for J2ME devices based on the SIP protocol

defined by IETF and 3GPP, and targeting resource constrained platforms.

Page 27: 5. More on app development

• JSR-184: Mobile 3D Graphics for J2MET– Lightweight, interactive 3D graphics API, which sits

alongside J2ME and MIDP as an optional package. – API targeted at devices that typically have very little

processing power and memory, and no hardware support for 3D graphics or floating point math

• JSR-190: Event Tracking API for J2MET– Optional package that standardizes the tracking of

application events in a mobile device– Submission of these event records to an event-tracking

server via a standard protocol

• JSR-195: Information Module Profile– Like MIDP but no screen or keyboard

Further interfaces

Page 28: 5. More on app development

Some fundamental specifications• JSR-68: J2MET Platform Specification

– Defines the"ground rules" for the J2ME platform architecture and J2MEstandardization activities.

– Formalizes the fundamental concepts behind J2ME, such as the notions of a configuration and profile

– Defines how new J2ME APIs can be formed, e.g., by subsetting existingAPIs from Java 2 Platform, Standard Edition

• JSR-185: JavaT Technology for Wireless Industry– Defines how various technologies associated with MIDP work

together to form a complete handset solution for the wireless services industry

– Which optional packages fit with which profiles? How an end-to-end solution for interoperable Java applications will work? How the migration of applications can occur and to which profiles as the devices become more capable?

Page 29: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 30: 5. More on app development

Maemo

• Nokia Internet Tablet• Based on Debian Linux

distribution and package management

• Development environment based on Scratchbox virtualization system

• Pretty much everything can be programmatically accessed

• C, C++, Python, JavaScript

Page 31: 5. More on app development

Maemo application: The Concept(http://maemo.org/development/training/maemo_technology_overview_content/ )

Page 32: 5. More on app development

Maemo application: The codeint main(int argc, char** argv) {

ApplicationState aState = {}; osso_context_t* ctx = NULL;

gtk_init(&argc, &argv); // Initialization begins aState.program = HILDON_PROGRAM(hildon_program_get_instance()); aState.window = HILDON_WINDOW(hildon_window_new()); hildon_program_add_window(aState.program, HILDON_WINDOW(aState.window)); ctx = osso_initialize(..... /* parameters omitted */ ); … // Event handler definitions g_signal_connect(G_OBJECT(aState.window), "key_press_event",

G_CALLBACK(cbKeyPressed), &aState); … gtk_main(); // Event processing

osso_deinitialize(ctx); // Shutdown return EXIT_SUCCESS; }

Page 33: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 34: 5. More on app development

Android

• Originally Google, later Open Handset Alliance

• Open source – No licence or distribution payments• Beta SDK 11/ 2007, 1.0 SDK 09/2008

– SDK includes emulator, debugging tools, on-device debugging

• T-Mobile G1– 10/2008 (USA ja UK)– Europe early 2009

• Several manufacturers aim at launcing Android phones during 2009– Motorola, Lenovo, Sony Ericsson, Samsung

Page 35: 5. More on app development

Android – Technology

• Built on top of Linux– Drivers, processes and memory management, security,

networking,power management– Libraries such as SQLite, WebKit, OpenGL

• Dalvik VM– Abstract view to the hardware– Development done using Java, not a Java VM– Runs Dalvik executables which are obtained based on Java

bytecodes

• Possible to bypass VM and use C/C++– Requires information on targer device– Not officially supported

Page 36: 5. More on app development

Android – Application development

• All applications are equal– Can be replaced by 3rd party apps– Same APIs are available for all programs (calls, SMS, WLAN, GPS,

camera, sensors, …)– Inter-application communication– Application can request making a call and the system seeks the

corresponding service

• Any app can offer services and use services offered by others

• Background execution allowed– (Unlike in Standard Java MIDP 2.0)– Programs cannot control their own life cycles– VM can interfere with the execution of the VM by suspending and

resuming them; apps must be designed to be compatible with this

Page 37: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 38: 5. More on app development

iPhone(http://developer.apple.com/iphone/gettingstarted/docs/iphoneosoverview.action)

• Mac OS X based system; origins trace to Mach kernel old Unix implementations

• Objective C for programming– Low level interfaces commonly

based on C; more advanced interfaces (e.g. Multimedia) mixture of C and Objective C

• Explicit redesign to support phone UI– Touch events– Not application centric

Page 39: 5. More on app development

Technology layers• Core OS and Core Services layers: fundamental interfaces for

iPhone OS– File access, low-level data types, Bonjour services, network sockets,

SQLite, access to POSIX threads and UNIX sockets, etc.• Media layer:

– 2D and 3D drawing, audio, video, OpenGL ES, Quartz, and Core Audio, Core Animation

• Cocoa Touch layer:– Fundamental infrastructure used by applications, object-oriented

support for collections, file management, network operations, access to the user’s contact and photo information and to the accelerometers and other hardware features of the device.

– UIKit framework provides the visual infrastructure for your application, including classes for windows, views, controls, and the controllers that manage those objects

• The starting point for any new project is the Cocoa Touch layer, and the UIKit framework in particular.

Page 40: 5. More on app development

Objective C Code(http://developer.apple.com/iphone/gettingstarted/docs/creatingiphoneapps.action)

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int retVal = UIApplicationMain(argc, argv, nil, nil);

[pool release];

return retVal;

}

Page 41: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 42: 5. More on app development

Windows Mobile

• .NET Compact Framework– Based on .NET environment – Common Language Runtime (CLR)– MicroSoft Intermediate Language (MSIL)

• Just-In-Time compilation from MSIL to binary when used

• Tools somewhat similar than in general with .NET development– Small differences in programming perspective (UI,

performance, resources, etc…)

Page 43: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 44: 5. More on app development

OpenMoko(www.openmoko.org)

• An open source project dedicated to delivering mobile phones software stack– Linux, etc. What could be expected based on Maemo and

Android

• Currently selling the Neo FreeRunnerphone to advanced users and will start selling it to the general public as soon as the software is more developed

• In general, seems comparable to Maemo, except that geared towards implementation of a phone, not Internet tablet

Page 45: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 46: 5. More on app development

Improving portability with VM

• Possibility to implement the same system on top of different infrastructure– Same environment can be used in both development and

execution environment

• Some tedious and error-prone tasks can be allocated to the virtual machine instead of the programmer– Memory management in particular– Support for recovering from errors

• Simplifies the implementation of security features– There already is a central element that is responsible for

executing applications

Page 47: 5. More on app development

Unifying stimuli with event-based programming

service caller

serviceprovider

eventevent observers

event source

Traditional service call Event-based operations

Page 48: 5. More on app development

Benefits

• Commonly used technique in UI programming

• Serialization of operations triggered to the execution; events can be handled one by one

• Simplified model of execution – No need to define the order of execution in user programs; it is

enough to generate an event

• Simplified introduction of new event generators• Simplified introduction of new event observers• Long-lasting operations form a problem

– Commonly initiate a new event that continues processing after a while

• Introduces additional complexity in the form of a state machine

Page 49: 5. More on app development

Separating device specific parts using MVC pattern

Model

View Controller

Reusable across differentuser interfaces, devices,

input media, etc.

Reusable in similar devices

The model should gather all common aspects.In practise, many systems force commonalities to views and controllers.

Page 50: 5. More on app development

Model-View-Controller, MVCObserver

update()

Controller

initialize(Model,View)handleEvent()update()

View

initialize(Model)makeController()activate()display()update()

Model

attach(Observer)detach(Observer)notify()getData()service()

*update()

attach()getdata()

attach() service()

Page 51: 5. More on app development

MVC Execution

Controller Model View

handle-Event

servicenotify

updatedisplay

getData

updategetData

Page 52: 5. More on app development

Interfacing

• Access to device specific resources vs. access to a sandbox– Security considerations unavoidable

• Access to device specific widgets vs.access to a generic canvas on top of which can be rendered– All apps similar in a device vs.

App similar in all devices

• Managed code for applications vs.using native applications

Page 53: 5. More on app development

5. More on app development

• Some other mobile development systems– MIDP Java– Maemo– Android– iPhone– Windows Mobile– OpenMoko

• Commonly used implementation techniques• Summary

Page 54: 5. More on app development

Conclusions

• Numerous approaches to programming mobile devices exist

• Commonalities– Virtual machines to unify the development

approach in several different configurations– Event-based programming for user input– Separating UI specifics using MVC– Auxiliaries packaged in installation packages