47
Business Cards Application for Android Final presentation Prepared By: Eyal Segal Koren Shoval Advisor: Nathaniel Azuelos

Business Cards Application for Android Final presentation Prepared By: Eyal Segal Koren Shoval Advisor: Nathaniel Azuelos

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Business Cards Application for Android

Final presentationPrepared By:Eyal SegalKoren Shoval

Advisor:Nathaniel Azuelos

Presentation Overview• Project Goals• About the Application• Working Environment• Android SDK

– About Android• Framework

– Class Diagrams• Business card application

– Edit• Use Cases & Class Diagrams

– Browse• Use Cases & Class Diagrams

– Bluetooth & Encryption• Use Cases, Sequence Diagrams & Class Diagrams

• Memory considerations• UI Demo

Project Goals• Create an application for managing business cards

– Learn and use Android API– Build a graphical user interface

• Examine data exchange on mobile devices– Communication via Bluetooth– Considering encryption & authentication

About the Application• Design your own business cards

– Use your own pictures as backgrounds– Customize fonts, colors and layout

• Browse, search and organize your business cards collection– Two browsing styles– Manage custom folders

• Share your business cards with your colleagues using bluetooth– Supports secured transmission

Working Environment• Operating system

– Windows Vista x86• Development tools

– Eclipse IDE for java– Android SDK– Android emulators– Eclipse memory analyzer

• Android devices– HTC desire, HTC magic

• Android 2.2 (Froyo)

Application block diagram

Android SDK

Business card application

• Our code is based on 3 layers

Framework

About Android

• Operating System for mobile devices– Open source– Developed by Google

• Uses a modified version of the Linux kernel• Allows developers to write code in Java language

– Android API– We are using API level 8 (version 2.2)

Application block diagram

Android SDK

Business card application

• Our code is based on 3 layers

Framework

FrameworkApplication block diagram

Framework

• Reusable code components• Implements non-standard Android abilities &

functionality– Based on Android SDK

Utilities

Graphics

Animations

Watchdog

Logger

User interface

Gallery view

Explorer view

Misc. dialogs

Color picker

Device picker

Services

Background service

Storage

Notifications

Preferences

Bluetooth

Encryption

Misc. views

Fonts & Resources

Swipe

Enable & visualize logging. Used mainly by bluetooth service.

Used for accepting Incoming bluetooth messages and processing application requests inthe background.

Runs independently from the application.

Threads for accepting, sending and receiving messages via bluetoothwith or without encryption

Manange and extends android notifications.Used by background service to alert user about new events

Class Diagrams

• Background Service

• Storage Service

• Notification Service

Background Service - Class Diagramclass localserv ice

BroadcastReceiver

BootCompletedReceiv er

+ onReceive(Context, Intent) : void

Service

LocalServ ice

+ getService() : LocalService+ start(Context) : void+ stop(Context) : void+ RegisterMessageTypeFor(String, RegisterationBlock) : void+ getRegistredBlockFor(String) : RegisterationBlock+ onBind(Intent) : IBinder+ onStartCommand(Intent, int, int) : int+ onCreate() : void+ onDestroy() : void

RegisterationBlock

+ AnswerActivityClass: Class<?>+ BlockType: EnumBlockType

+ getAnswerActivityBlock(Class<?>) : RegisterationBlock+ getRunnableBlock(Class<?>) : RegisterationBlock

«interface»

RegisterationBlock::IRunnableBlock

+ handleMessage(MessageBlock) : void

«enumeration»RegisterationBlock::

EnumBlockType

«enum» AnswerActivity Runnable

Bluetooth Package

Notification Serv ice

+BlockType

Start()

new Sender() new Listener()

getRegistrationBlock()

«use»

Storage Service - Class Diagramclass storage

ImageStorage

+ ImageStorage(Context)+ getBitmap(int) : Bitmap+ getDrawable(int) : BitmapDrawable+ unpackBitmap(byte[]) : Bitmap+ packBitmap(Bitmap) : byte[]+ asDrawable(Bitmap) : BitmapDrawable

InternalStorageAdapter

+ InternalStorageAdapter(Context, String)

«interface»

IStorageAdapter

+ getPath() : String+ read(String, String) : Object+ write(Serializable, String, String) : void+ delete(String, String) : void+ getItems(String, Filter) : String[]+ getFile(String, String) : File+ readBitmap(String, String) : Bitmap+ writeBitmap(Bitmap, String, String) : void+ createFolder(String, String) : void+ deleteFolder(String, String) : void+ moveFolder(String, String, String, String) : void+ move(String, String, String, String) : void+ setDefaultFolders(String[]) : void

IStorageAdapter::Filter

+ Directories: Filter = new Filter(Enum... {readOnly}+ Files: Filter = new Filter(Enum... {readOnly}+ All: Filter = new Filter(Enum... {readOnly}

+ setIncludeVirtual() : Filter+ equals(Object) : boolean+ includeVirtual() : boolean

«enumeration»IStorageAdapter::Filter::EnumFilter

«enum» Directories Files All

NullStorageAdapter

+ NullStorageAdapter(String)+ read(String, String) : Object+ write(Serializable, String, String) : void+ delete(String, String) : void+ getItems(String, Filter) : String[]+ getFile(String, String) : File+ readBitmap(String, String) : Bitmap+ writeBitmap(Bitmap, String, String) : void

SdCardStorageAdapter

+ SdCardStorageAdapter(String)+ isWriteable() : boolean+ isReadable() : boolean

StorageAdapter

+ StorageAdapter(String)+ getPath() : String+ read(String, String) : Object+ write(Serializable, String, String) : void+ delete(String, String) : void+ move(String, String, String, String) : void+ getItems(String, Filter) : String[]+ getFile(String, String) : File+ readBitmap(String, String) : Bitmap+ writeBitmap(Bitmap, String, String) : void+ createFolder(String, String) : void+ deleteFolder(String, String) : void+ moveFolder(String, String, String, String) : void+ combinePath(String, String) : String+ makeSureExists(String) : void+ setDefaultFolders(String[]) : void

StorageAdapterFactory

+ getAdapter(Context, String, StorageType, boolean) : IStorageAdapter

«enumeration»StorageAdapterFactory::

StorageType

«enum» Internal SdCard

StorageCache

+ StorageCache(IStorageAdapter)+ getPath() : String+ read(String, String) : Object+ write(Serializable, String, String) : void+ delete(String, String) : void+ move(String, String, String, String) : void+ getItems(String, Filter) : String[]+ readBitmap(String, String) : Bitmap+ writeBitmap(Bitmap, String, String) : void+ getFile(String, String) : File+ createFolder(String, String) : void+ deleteFolder(String, String) : void+ moveFolder(String, String, String, String) : void+ setDefaultFolders(String[]) : void

StorageServ ice

+ start(Context, String) : void+ getAdapter(String) : IStorageAdapter+ setAdapter(String, String, boolean) : IStorageAdapter+ setAdapter(String, IStorageAdapter) : void+ combinePath(String, String) : String+ getImageStorage() : ImageStorage+ getTemporaryStorage() : TemporaryStorage

TemporaryStorage

+ TemporaryStorage(Context)+ read(String) : Object+ remove(String) : void+ cache(Serializable) : String

~m_adapter

+All

+Files+Directories

«use»

«use»

Notification Service - Class Diagram

class localserv ice

«interface»

INotificationCallback

+ onActivityResult(Intent) : void

«interface»

INotificationService

+ getNotificator(String, String) : INotificator+ getNotificator() : INotificator+ getProgressBarNotificator(String) : ProgressBarNotificator+ notify(int, Notification) : void+ notify(int, String, String) : void+ notify(int, String, String, Class<?>, Bundle, INotificationCallback) : void+ getLocalNotificator() : INotificator+ cancel(int) : void

«interface»

INotificator

+ notify(String, String, Class<?>, Bundle, INotificationCallback) : void+ notify(String, Class<?>, Bundle, INotificationCallback) : void+ notify(String, String) : void+ notify(String) : void+ cancel() : void+ setTitle(String) : void+ setDescription(String) : void

NotificationServ ice

+ getInstance() : INotificationService+ start(Context, String) : void+ stop() : void+ getLocalNotificator() : INotificator+ getNotificator(String, String) : INotificator+ getProgressBarNotificator(String) : ProgressBarNotificator+ getNotificator() : INotificator+ notify(int, String, String) : void+ notify(int, String, String, Class<?>, Bundle, INotificationCallback) : void+ notify(int, Notification) : void+ cancel(int) : void

Notificator

+ Notificator(INotificationService, int)+ Notificator(INotificationService, int, String, String)+ setTitle(String) : void+ setDescription(String) : void+ notify(String, String) : void+ notify(String) : void+ notify(String, String, Class<?>, Bundle, INotificationCallback) : void+ notify(String, Class<?>, Bundle, INotificationCallback) : void+ cancel() : void

ProgressBarNotificator

+ ProgressBarNotificator(Context, INotificationService, int, String)+ notify(int) : void+ cancel() : void

-m_service -m_service

-m_service

-m_notificator

«use»

Application block diagram

Android SDK

Business card application

Framework

• Our code is based on 3 layers

• Specific code for business cards logic– use cases– user interface – structures

Business cards app.Application block diagram

Business cards application

Utilities

Contacts

Business cards painter

User interface

Editor

Browse by tabs

Themes manager Browse by folders

Edit personal cards.Set personal information as well as setting background, fonts, colors and layout.

Send card via bluetooth

Business Card Models - Class Diagramclass themes

Serializable

BusinessCard

+ BusinessCard(boolean)+ BusinessCard(BusinessCard)+ getTag() : Object+ setTag(Object) : void+ isVirtual() : boolean+ isEditable() : boolean+ getFileName() : String+ setFileName(String) : void+ getPath() : String+ setPath(String) : void+ getItems() : List<BusinessCardItem>+ getBackgroundFilename() : String+ getBackground() : BitmapDrawable+ setBackground(String) : void+ setBackground(String, Bitmap) : void+ getFirstName() : String+ setItem(ItemType, String) : void+ getLastName() : String+ getFullName() : String+ getPhoneNumber() : String+ getEmail() : String+ toString() : String+ toSimpleString() : String+ addItem(BusinessCardItem) : void+ getItem(UUID) : BusinessCardItem+ removeItem(UUID) : void+ setItem(BusinessCardItem) : void+ setVirtual(boolean) : void+ setEditable(boolean) : void+ match(String) : boolean+ equals(Object) : boolean+ equals(BusinessCard) : boolean+ removeItems() : void

Serializable

BusinessCardBlock

+ BusinessCardBlock(BusinessCard)+ getBusinessCard() : BusinessCard

Serializable

BusinessCardItem

+ m_id: UUID = UUID.randomUUID() {readOnly}+ m_type: ItemType = ItemType.Text+ m_value: String = ""+ m_x: int = 50+ m_y: int = 50+ m_layout: BusinessCardItemLayout = new BusinessCar...+ m_visible: boolean = true

+ BusinessCardItem(ItemType, String)+ BusinessCardItem(ItemType, String, int, int)+ BusinessCardItem(ItemType, String, int, int, BusinessCardItemLayout, boolean)+ GetInputType() : int+ equals(Object) : boolean+ equals(BusinessCardItem) : boolean

Serializable

BusinessCardItemLayout

+ Default: BusinessCardItemLayout = new BusinessCar... {readOnly}+ m_font: FontItem+ m_textSize: FontSize = FontSize.Small+ m_textColor: int = Color.BLACK+ m_textStyleBold: boolean = false+ m_textStyleItalic: boolean = false+ m_textStyleUnderline: boolean = false

+ BusinessCardItemLayout()+ BusinessCardItemLayout(FontItem, FontSize, int, boolean, boolean, boolean)+ BusinessCardItemLayout(BusinessCardItemLayout)

BusinessCardPainter

+ getBusinessCardAsBitmap(BusinessCard) : Bitmap+ getBusinessCardAsBitmap(BusinessCard, int) : Bitmap+ paintBusinessCardItems(Canvas, BusinessCard, int) : void+ getScale(BusinessCard, int) : float+ getPaint(Paint, BusinessCardItemLayout, int) : void

Serializable

BusinessCardTheme

+ getName() : String+ create(Map<ItemType, String>) : BusinessCard+ apply(BusinessCard) : BusinessCard+ fromBusinessCard(String, BusinessCard) : BusinessCardTheme

ContactsUtils

+ initialize(Context) : void+ getContacts() : Map<String, BusinessCard>

«enumeration»ItemType

«enum» FirstName LastName Name Phone Address Email Company Fax Text Institute WorkPhone Description Profession Department Link

ThemesManager{leaf}

+ initialize(Context) : void+ getInstance() : ThemesManager+ getThemes() : List<String>+ getTheme(String) : BusinessCardTheme+ getDefaultTheme() : BusinessCardTheme+ save(BusinessCardTheme) : void+ isDefault(String) : boolean+ remove(String) : void

-m_defaultTheme

-m_instance

+m_layout

+m_type1..*

+Default

1..*

apply theme

«use»

Use cases

1. Editor1.1 Create card1.2 Edit card1.3 Create item layout1.4 Edit item layout1.5 Position item on a card1.6 Manage all items1.7 Create new theme from a card1.8 Apply a theme1.9 Set background from android gallery

Use cases1.1 Create

1.1.1 User starts card editor (from main)1.1.2 A card is generated using the default theme1.1.3 A popup screen opens and lets user edit item values1.1.4 User edits default items and clicks “save”1.1.5 The popup closes showing the editor surface.1.1.6 The user clicks on menu option “save as” and saves the card1.1.7 A save dialog opens and the user selects where to save the

card and its filename.1.1.8 Users clicks “ok” and the card is saved.

– Exceptions1.1.4 User clicks “cancel” or presses the back button in the popup

screen and the changes are ignored.1.1.8 User clicks “cancel” in save dialog

Use cases1.3 Create item layout

Starts at the editor surface1.3.1 User clicks on menu option “Add Item”1.3.2 Layout dialog opens with the item’s information1.3.3 User edits item’s text content1.3.5 User updates item’s type, style and color1.3.6 User clicks on “ok” button to save the changes1.3.7 Editor gets back the updated item, save the changes to the card and

updates the surface

– Exceptions1.3.7 User clicks “cancel” or presses the back button in the dialog

screen and the changes are ignored.

Use cases1.5 Position item on card

Starts at the editor surface1.5.1 User clicks on an item1.5.2 Editor surface shows edit, remove and drag buttons and a frame

around the item1.5.3 The user presses on the surface inside the frame or on the drag button and drags the item on the surface to its new

position1.5.4 The editor surface saves the changes to the card

– Exceptions1.5.2 User clicks outside of the item’s frame to cancel the item’s

selection.

Use cases1.8 Apply a theme

Starts at the editor surface1.8.1 User clicks on menu option “Set Theme”1.8.2 A themes gallery popup with the first theme applied to the card.1.8.3 User swipes left or right to iterate between themes,

each swipe alters the layout of the card according to the current

theme.1.8.4 User clicks on “Select theme” and the theme is set on the card1.8.5 Editor gets the result back from the themes gallery and set the

updates business card on the surface.– Exceptions

1.8.4 User clicks the back button and the changes are ignored.

Editor Activity - Class Diagram

Framework

Android SDK

Business card application

class editor

Activity

BusinessCardEditor

+ onCreate(Bundle) : void+ onCreateOptionsMenu(Menu) : boolean+ onMenuItemSelected(int, android.view.MenuItem) : boolean- saveTheme() : void- selectTheme() : void+ getWidth() : int+ getHeight() : int- selectBackground() : void- showEditItems() : void- saveBusinessCard() : void- makeToast(String) : void+ showItemToolbox(BusinessCardItem) : void# onActivityResult(int, int, Intent) : void+ getScreenWidth() : int+ getScreenHeight() : int

Activity

BusinessCardEditorItemsList

+ onCreate(Bundle) : void- setItemsView(LinearLayout, List<BusinessCardItem>) : void- saveItems() : void- addItemsToBusinessCard() : void# onSaveInstanceState(Bundle) : void# onRestoreInstanceState(Bundle) : void

Activity

BusinessCardEditorItemToolbox

+ onCreate(Bundle) : void- updateControls() : void- setSpinner(Spinner, Object) : void

View

BusinessCardEditorSurface

+ BusinessCardEditorSurface(BusinessCardEditor, BusinessCard)- getGridPaint() : Paint- getBoundingBoxPaint() : Paint- getTextPaint() : Paint# snapToAxis(int, int, int) : int# findSelected(int, int) : BusinessCardItem# onDraw(Canvas) : void+ setBackgroundDrawable(Drawable) : void+ toggleGridLines() : void+ setBusinessCard(BusinessCard) : void+ toggleSnapGridLines() : void

Activity

BusinessCardThemeSelector

# onCreate(Bundle) : void- setTheme() : void- deleteTheme() : void+ onTouchEvent(MotionEvent) : boolean+ onDoubleTap() : boolean+ onSwipe(int) : boolean+ onCreateOptionsMenu(Menu) : boolean+ onMenuOpened(int, Menu) : boolean+ onMenuItemSelected(int, MenuItem) : boolean

ItemsViewViewFactory

T

GalleryView

LinearLayout

HeaderView

+ HeaderView(Context)- initialize() : void+ setText(String) : void# getView() : View

«interface»

ISwipeListener

+ onSwipe(int) : boolean+ onDoubleTap() : boolean

OkCancelDialog

+ showDialog() : void

Sav eInputDialog

+ showDialog() : void

SimpleOnGestureListener

SwipeGestureDetectorListener

+ SwipeGestureDetectorListener(ISwipeListener)+ onFling(MotionEvent, MotionEvent, float, float) : boolean+ onDoubleTap(MotionEvent) : boolean

Dialog

UberColorPickerDialog

+ UberColorPickerDialog(Context, OnColorChangedListener, int)# onCreate(Bundle) : void

Android:View Android:Activ ity

«use»

«use»«use»

~m_listener

-m_themeHeader

• Specific code for business cards logic– use cases– user interface – structures

Business cards app.Application block diagram

Business cards application

Utilities

Contacts

Business cards painter

User interface

Editor

Browse by tabs

Themes manager Browse by folders

View & manage business cards.Send email, sms, call and more.Send cards via BT and edit personal cards.

View & managebusiness cards.Send email, sms, call and More. Send cards via BT and edit personal cards.

Send card via bluetooth

Use cases

2. Browse2.1 Browse for a card2.2 Search for a card2.3 Create folder2.4 Rename folder2.5 Delete folder2.6 Use business card (SMS, Call, Email, etc.)2.7 Move a card between folders

Use cases2.1 Browse for a card (tab activity)

2.1.1 User clicks on “browse” button at main2.1.2 Browse activity opens up to show the default search tab2.1.3 User selects the folder with the card by clicking the folder’s tab2.1.4 The tabs view updates the list of cards to

display the cards in the current folder2.1.5 User scrolls to the requested card

and clicks on the card to select it

Use cases2.3 Create folder (tab activity)

Starts at tabs view2.3.1 User clicks the “New…” tab or chooses menu option “Create folder”2.3.2 An input dialog pops up2.3.3 User inserts the new folder name and clicks “Ok” button2.3.4 The folder is created and appears as a tab

– Exceptions2.3.3 User clicks the back button or “Cancel” button and the folder is

not created. 2.3.3 User enters an existing name. The current tab is changed to the

existing tab, and no new folder is created2.3.3 User enters a forbidden name (“New…”, “Contacts”, “Search”).

No folder is created and the last used tab is active again

Use cases2.5 Delete folder (tab activity)

Starts at tabs view2.5.1 User selects a specific folder by clicking its tab2.5.2 User chooses menu option “Delete folder”2.5.3 A confirmation dialog pops up2.5.4 User clicks “Ok” button and the folder is deleted

– Exceptions2.5.4 User clicks the back button or “Cancel” button and the folder is not deleted.

Tabs Activity - Class Diagram

Framework

Android SDK

Business card application

class v iewer

ListViewOnItemClickListener

BusinessCardListView

+ BusinessCardListView(Context)+ onItemClick(AdapterView<?>, View, int, long) : void+ getSelected() : BusinessCard# getItems() : List<BusinessCard>+ notifyDataSetChanged() : void

BaseAdapterFilterable

BusinessCardsAdapter

+ BusinessCardsAdapter(BusinessCardListView)+ getFilter() : Filter+ getView(int, View, ViewGroup) : View# getImage(BusinessCard) : Bitmap+ getCount() : int+ getItem(int) : BusinessCard+ getItemId(int) : long+ notifyDataSetChanged() : void

TabActivity

TabsActiv ity

+ onCreate(Bundle) : void+ setCurrentTab(String) : void+ getCurrentTab() : String+ reload() : void- addTab(Class<?>, String, String, String, Drawable) : void# onDestroy() : void# onResume() : void

ViewBusinessCardsListViewTab

+ onCreate(Bundle) : void

ViewBusinessCardsSearchTab

# onStart() : void+ onCreate(Bundle) : void# createBusinessCards(String) : List<BusinessCard>

Activity

ViewBusinessCardsTabBase

+ onCreate(Bundle) : void# getListView() : ListView# find(String, String) : BusinessCard# getBusinessCards() : List<BusinessCard># createBusinessCards(String) : List<BusinessCard>+ onCreateOptionsMenu(android.view.Menu) : boolean+ onMenuOpened(int, Menu) : boolean+ onMenuItemSelected(int, MenuItem) : boolean# onResume() : void- refresh() : void

Android:Activ ityAndroid:ListView

BusinessCardEditor

Activity

v iewer::BluetoothDev icePicker

# onCreate(Bundle) : void- send(int) : void# onStart() : void- setupBluetooth() : void- createDeviceInfo(BluetoothDevice, boolean)- discoverDevices() : void- stopDiscovery() : void- setStatus(String, String) : void# onDestroy() : void# onActivityResult(int, int, Intent) : void

#m_listView

-m_listView

«use»

«use»

• Specific code for business cards logic– use cases– user interface – structures

Business cards app.Application block diagram

Business cards application

Utilities

Contacts

Business cards painter

User interface

Editor

Browse by tabs

Themes manager Browse by folders

Send card via bluetooth

BluetoothVersion 2.1

• Bluetooth is a proprietary open wireless technology standard for exchanging data over short distances

• The Bluetooth specifications are developed and licensed by the Bluetooth Special Interest Group(SIG).– consists of more than 13,000 companies

• low power consumption• Maximum application throughput is 1.4Mbit/sec• Maximum distance of 100 meters (class 1)

BluetoothOn Android

• Bluetooth 2.1• Supported protocols

– SDP – Service discovery protocol• allows a device to discover services supported by other devices• Each service is identified by a Universally Unique Identifier(UUID)

– RFCOMM - Serial Port Emulation• provides a simple reliable data stream to the user, similar to TCP

• The Bluetooth APIs let applications:– Scan for other Bluetooth devices– Query the local Bluetooth adapter for paired Bluetooth devices– Establish RFCOMM channels/sockets– Connect to specified sockets on other devices– Transfer data to and from other devices

Use cases

3. Bluetooth3.1 Send business card via Bluetooth3.2 Receive a business card

Use cases3.1 Send business card via Bluetooth (1)

Starts at tabs view with a selected card3.1.1 User clicks on menu option "Send”

3.1.2 Device picker opens up with a list of paired devices3.1.3 User clicks on a device3.1.4 Connection is made with the device3.1.5 The card is sent to the remote device3.1.6 Application waits for a status response3.1.7 Application displays the status to the user

- Branch3.1.3b If the device is not in the known device list 3.1.3b.1 User clicks on “Scan for new devices”

3.1.3b.2 Application request device detection 3.1.3b.3 Each detected device is added to the list 3.1.3b.4 User clicks on a device 3.1.3b.5 Continue to step 3.1.4

Use cases3.1 Send business card via Bluetooth (2)- Branch (2)3.1.5b If encryption is enabled

3.1.5b.1 Application asks user for a password3.1.5b.2 User inserts an agreed upon password and clicks “ok”3.1.5b.3 Application starts the EKE protocol to agree on a secret key3.1.5b.4 Application sends an encrypted card using the key3.1.5b.5 Continue to step 3.1.6

- Exception3.1.1 If bluetooth is not enabled ask user to enable bluetoot

3.1.1.1 If user clicks “cancel” the operation is canceled and the application return to the browser view

3.1.4 Connection to remote device fails3.1.4.1 Display error message

3.1.5b.3 Authentication fails3.1.5b.3.1 Display error message and abort operation

3.1.6 Read timeout exception3.1.6.1 Display unknown response message

Use cases3.2 Receive a business card (1)

Service listens for an incoming connection3.2.1 A remote device a connection is accepted

3.2.2 Service forks the socket to a receive handler3.2.3 Receiver reads the data from the remote device3.2.4 Receiver notifies the user about an incoming card3.2.5 Receiver saves the card to the default “received” folder3.2.6 Receiver sends the status (Accepted, Refused, Failed) to the remote

device

- Branch (1)3.2.3b If the message is encrypted 3.2.3b.1 Receiver opens a password dialog 3.2.3b.2 User inserts a password and clicks on “ok” 3.2.3b.3 Receiver start the EKE protocol 3.2.3b.4 Receiver reads encrypted data from the remote device

Use cases3.2 Receive a business card (2)- Branch (2)

3.2.5b If the preference for “confirmation dialog” is checked 3.2.5b.1 Receiver open a save card dialog, showing the card 3.2.5b.2 User selects the location to save and clicks “ok” 3.2.5b.3 Receiver saves the card to that location 3.2.5b.4 Continue with step 3.2.6

- Exceptions3.2.1 If bluetooth is not enabled then nothing will happen3.2.3 Read timeout exception

3.2.3.1 Display error message3.2.3b.3 Authentication fails

3.2.3b.3.1 Display error message and abort operation

sd BusinessCard

Sending Thread

Receiving Thread

Device Picker

Listening Thread

BackgroundService

BackgroundService

Answer Activity

opt Encryption

Send card

New

New

Connect

Accept

New

Send(message type)

Send(card)

GetRunnableBlock(messageType)

New

Show() :Boolean

Send(status)

Send/Receive business card via bluetoothsequence diagram

If messageType = “Encrypted”setup encryption using EKE protocol

Receiver• The background service creating listening thread • Listener thread waits for incoming connectionsSender• User selects a card to send and a device to send to• The background service receives a request to send

a message and creates sending thread• The sending thread connects to the remote deviceReceiver• The listening thread accepts the connection and

creates a receiving thread• The receiving thread waits for an incoming

message (blocking)

Sender Receiver

sd BusinessCard

Sending Thread

Receiving Thread

Device Picker

Listening Thread

BackgroundService

BackgroundService

Answer Activity

opt Encryption

Send card

New

New

Connect

Accept

New

Send(message type)

Send(card)

GetRunnableBlock(messageType)

New

Show() :Boolean

Send(status)

Send/Receive business card via bluetoothsequence diagram – cont.

Sender• The sending thread sends the message typeSender & Receiver• if message type is “Encrypted” then EKE protocol is

startedReceiver• Wait for incoming messageSender • Send the message to the remote device• Wait for status messageReceiver• Receive message• Start registration block according to message type• Send status according to user answer

Sender Receiver

If messageType = “Encrypted”setup encryption using EKE protocol

EncryptionEKE – Encrypted Key Exchange

• A family of password authenticated key agreement methods

• Based on Diffie-Hellman protocol• Protected against

– Replay attack• resending client or server messages

– Dictionary attack• trying out “dictionary” like passwords

– Man in the middle attack• watch and understand the conversation between 2 users

– Session hijacking• connecting to a pre-authenticated session and

impersonate as one of the users

EncryptionOn Android

• Easy to extend using javax.crypto.cipher package– Decorators over input/output stream– Supported cipher providers (need to select 3 parameters)

– Algorithms: AES, DES, DES-EDE, RSA, PBE, etc.– Mode: None, CBC, CFB, ECB, OFB, PCBC– Padding: None, PKCS5, SSL3, OAEPwithMD5, etc.

• Authentication– Supports Key generators such as

– DH, AES, DES, HMacMD5, HMacSHA1, etc.

Encryption Algorithm EKE – Sequence diagram

sd Use Case Model

Client A Client B

k=g^ab(mod p)

w=f(password) w=f(password)k=g^ab(mod p)

Device Name, Ew(g^a mod p)

Ew(g^b mod p), Ek(challengeB)

Ek(challengeA,challengeB)

Ek(challengeA)

• Step 1 - Client A – Scrambles the password using function f

• w=f(password)– Sends name and DH public key

encrypted under w

• Step 2 – Client B– Scrambles the password using function f– Computes common DH key k

• K=g^ab mod p– Generates a random string – challenge B– Sends

• DH public key encrypted under w • challenge B encrypted under k

Encryption Algorithm EKE – Sequence diagram

sd Use Case Model

Client A Client B

k=g^ab(mod p)

w=f(password) w=f(password)k=g^ab(mod p)

Device Name, Ew(g^a mod p)

Ew(g^b mod p), Ek(challengeB)

Ek(challengeA,challengeB)

Ek(challengeA)

• Step 3 – Client A– Computes common DH key k– Generates a random string – challenge A– Decrypts challenge B – Encrypts and sends

challenge A || challenge B under k• This is the step where client A proves

that he knows the common key k

• Step 4 – Client B– Decrypts and extracts challenge A– Send challenge A encrypted under k

• This is the step where client B proves that he knows the common key k

EncryptionEKE – Cont.

• Protected against – Why?– Replay attack

• Using random challenges in both sides– Dictionary attack

• Hashing the password– Man in the middle attack

• Based on shared password (known only to both sides)– Session hijacking

• Using secret key to encrypt the entire session

Bluetooth & Encryption - Class Diagramclass crypto

ThreadIWatchDogListener

AbstractBluetoothThread

+ AbstractBluetoothThread(String)+ onTimeout() : void+ intToByteArray(int) : byte[]+ byteArrayToInt(byte[]) : int+ setProgress(int) : void+ getProgress() : int+ run() : void

«enumeration»AbstractBluetoothThread::

Status

«enum» Accepted Refused Failed Unknown

AbstractDHSecretKeyGenerator

+ AbstractDHSecretKeyGenerator(KeyPair)+ getPublicKey() : byte[]

AliceDHSecretKeyGenerator

+ AliceDHSecretKeyGenerator()+ getSecretKey(byte[]) : SecretKey

BluetoothClientThread

+ BluetoothClientThread(BluetoothSocket)

BluetoothSendThread

+ BluetoothSendThread(String, MessageBlock)+ connected() : void+ ensurePaired(BluetoothDevice, String) : void

BobDHSecretKeyGenerator

+ BobDHSecretKeyGenerator(byte[])+ getSecretKey() : SecretKey

Serializable

CacheMessageBlock

+ CacheMessageBlock(MessageBlock)+ getCachedMessage() : MessageBlock+ remove() : void

CipherGenerator

+ CipherGenerator(String)+ CipherGenerator(SecretKey)+ encrypt(MessageBlock) : MessageBlock+ isEncrypted(MessageBlock) : boolean+ decrypt(MessageBlock) : MessageBlock+ generateRandomChallenge() : String

Serializable

MessageBlock

+ MessageBlock(String, Serializable)+ getType() : String+ getData() : Serializable+ cache() : CacheMessageBlock+ isCached() : boolean+ uncache() : MessageBlock+ destroy() : void

Thread

BluetoothListenerThread

+ BluetoothListenerThread()+ run() : void+ cancel() : void

#m_cipher

«use»

Memory considerations

• Android limits memory usage to 16mb per application

• Using Eclipse memory analyzer & GC logs we traced the highest memory consumption in the code

• Based on the results we refactored several parts of the code to reduce memory usage• Reduce bitmap processing• Minimized cache usage• Reduced business card size• Used disk as cache instead of memory

UI Demo

Sources• Google’s Android Developers

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

• Wikipedia– Bluetooth, encryption

• Security in software applications - Course site– http://webcourse.cs.technion.ac.il/236350/Spring2010/en/ho_Lectures.html

• Java docs– http://java.sun.com/j2se/1.4.2/docs/api/

• More…