CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
 data/data-storage.html#pref data/data-storage.html#pref 
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
1 Internet Networking Spring 2004 Tutorial 13 LSNAT - Load Sharing NAT (RFC 2391)
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android.
1 Spring Semester 2007, Dept. of Computer Science, Technion Internet Networking recitation #12 LSNAT - Load Sharing NAT (RFC 2391)
Service Broker Lesson 11. Skills Matrix Service Broker Service Broker, provides a solution to common problems with message delivery and consistency that.
Data Persistence in Android
Mobile Application Development with ANDROID Tejas Lagvankar UMBC 29 April 2009.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
01. Introduction to Android Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea
Lec 04 Content Providers Adapters CursorLoaders Advanced Debugging.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Mobile Application Development using Android Lecture 2.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
Data Storage: Part 2 (File System). Internal Storage versus External Storage Internal storage − for private data –By default, files saved to the internal.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Nilesh Singh Local Data Storage option Android provides several options for you to save persistent application data. - Shared preferences - Creation.
© 2006 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Filtering Traffic Using Access Control Lists Introducing Routing and Switching.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
Security, NATs and Firewalls Ingate Systems. Basics of SIP Security.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
DKU-MUST Mobile ICT Education Center 10. Activity and Intent.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
© 2006 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Filtering Traffic Using Access Control Lists Introducing Routing and Switching.
When you run a scenario, the Vusers on each host machine use the host’s IP address. You can define multiple IP addresses on a host machine to emulate a.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
Technische Universität München Services, IPC and RPC Gökhan Yilmaz, Benedikt Brück.
1 Network Communications A Brief Introduction. 2 Network Communications.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
1. 2 The Address Book app provides convenient access to contact information that’s stored in a SQLite database on the device. You can: scroll through.
Content Providers.
Android Application -Architecture.
Content provider.
Android Content Providers & SQLite
Data Storage: Part 2 (File System)
CS371m - Mobile Computing Persistence.
Android Application Data Storage 1.
Mobile Software Development for Android - I397
Lecture 7: Service Topics: Services, Playing Media.
Instructor: Mazhar Hussain
Lecture 7: Android Services
Android Mobile Application Development
Content Providers.
Introduction to Networking
Introducing To Networking
* Essential Network Security Book Slides.
Application Development A Tutorial Driven Course
Lecture 7: Service Topics: Services, Broadcast Receiver, Playing Media.
Android Development Tools
CIS 470 Mobile App Development
Presentation transcript:

CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation

CSE 486/586, Spring 2012 Android Emulator Networking Note: this is my (Steve’s) best guess; actual details might be different. But it should be good enough for your understanding. Each emulator instance is attached to a virtual router. The virtual router runs on top of the host (probably as an application). The virtual router forwards connections originated from its emulator instance. However, the virtual router acts as a firewall; it blocks all connection attempts going into its emulator instance from somewhere else. 2

CSE 486/586, Spring 2012 Android Emulator Networking What if we want to allow others (in general) to connect to an app running inside an emulator instance? –Android provides redirection as a solution. 3 emu0 App connect() VR0 Host emu1 App connect() VR1 emu2 App connect() VR2

CSE 486/586, Spring 2012 Android Emulator Networking Redirection Basics –In order to allow connection attempts going into the emulator instance, we need to set up redirection from the virtual router to its emulator instance. –Since everything happens on top of the host, the only way to enable any kind of networking is to borrow the host’s IP and ports. –Redirection forces the virtual router to listen on a host port and forward all traffic coming to the host port to the emulator instance. Process –Pick a host port to borrow (that others will use to connect to) –Set up redirection from that host port to the emulator port that the app is listening on –E.g., redir add tcp: : »Meaning, forward all traffic from the host port to the emulator port 4

CSE 486/586, Spring 2012 Android Emulator Networking On emu0: redir add tcp:10000: emu0 App VR0 Host VR0 starts listening on & forwards all traffic to emu0’s App may or may not listen on 8080 (not required for redirection)

CSE 486/586, Spring 2012 Android Emulator Networking On emu0: redir add tcp:10000: emu0 App VR0 Host VR0 starts listening on & forwards all traffic to emu0’s App may or may not listen on 8080 (not required for redirection) For any connect() attempt to (either from outside or from an app running on the host), it will succeed.

CSE 486/586, Spring 2012 Android Emulator Networking On emu0: redir add tcp:10000: emu0 App VR0 Host VR0 starts listening on & forwards all traffic to emu0’s App may or may not listen on 8080 (not required for redirection) For any connect() attempt to (either from outside or from an app running on the host), it will succeed. This (port 8080) is not visible to anyone outside of VR0. All others can only see port This is why you can use the same server port number in your app.

CSE 486/586, Spring 2012 Android Emulator Networking On emu0: redir add tcp:10000:8080 On emu1: redir add tcp:20000: emu0 App VR0 Host emu1 App VR Since we’re borrowing the host’s port numbers, this has to be different from VR0’s port number.

CSE 486/586, Spring 2012 Android Emulator Networking Now all connect() should be to : E.g., connect() to :10000 will be forwarded to emu0: emu0 App VR0 Host emu1 App VR

CSE 486/586, Spring 2012 Android Emulator Networking IP Addresses –A virtual router assigns an IP address to its emulator instance ( ) and to the host ( ) from a private IP range ( /8). –It assigns an IP address to the host mainly for convenience (I think…). In the previous example, if emu1 wants to talk to emu0, it can use: –connect() to :10000 Effectively, we are identifying different emulators using host port numbers we’re borrowing instead of their IP:port pairs. 10

CSE 486/586, Spring 2012 Content Providers A content provider provides a table view of data. If you write a content provider, any client application with the permission can enter/read/update/delete data items in your content provider. A client application (that uses your content provider) uses ContentResolver to interact with your content provider. You need to extend ContentProvider and implement necessary methods. 11

CSE 486/586, Spring 2012 How a Client Interacts Table identification  URI (android.net.Uri) –E.g., content://user_dictionary/words Insert –public final Uri ContentResolver.insert (Uri url, ContentValues values) Update –public final int ContentResolver.update (Uri uri, ContentValues values, String where, String[] selectionArgs) Query –public final Cursor ContentResolver.query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) Delete –public final int ContentResolver.delete (Uri url, String where, String[] selectionArgs) 12

CSE 486/586, Spring 2012 How to Write a Content Provider 1.Declare in AndroidManifest.xml 2.Define a URI that client apps will use 3.Define permissions 4.Implement necessary methods in ContentProvider 5.When implementing ContentProvider, use either the Android file system or SQLite as the actual data storage. 13

CSE 486/586, Spring 2012 Declare in AndroidManifest.xml

CSE 486/586, Spring 2012 Defining a URI Typical format –content:// / –Authority: a global (Android-wide) name for the provider »E.g., edu.buffalo.cse.cse486.proj1.provider –Table name: the name of a table that the provider exposes »Note: a provider can expose more than one table. Should be added to AndroidManifest.xml –E.g., … 15

CSE 486/586, Spring 2012 Define Permissions Should define permissions (for others) in AndroidManifest.xml android:permission: Single provider-wide read/write permission. –E.g., … android:readPermission: Provider-wide read permission. android:writePermission: Provider-wide write permission. 16

CSE 486/586, Spring 2012 Necessary Methods query() –Retrieve data from your provider. insert() –Insert a new row into your provider. update() –Update existing rows in your provider. delete() –Delete rows from your provider. getType() –Return the MIME type corresponding to a content URI. onCreate() –Initialize your provider. The Android system calls this method immediately after it creates your provider. Notice that your provider is not created until a ContentResolver object tries to access it. These need to handle concurrent accesses (need to be thread-safe) 17

CSE 486/586, Spring 2012 Storage Options Internal storage: file system, private to the app External storage: file system, open to everybody SQLite: database, private to the app Read: storage.html storage.html 18

CSE 486/586, Spring 2012 Internal Storage Saving files directly on the device's internal storage. User uninstallation  files are removed. To create and write a private file to the internal storage: –Call openFileOutput() with the name of the file and the operating mode. This returns a FileOutputStream. –Write to the file with write(). –Close the stream with close(). E.g., String FILENAME = "hello_file"; String string = "hello world!”; FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(string.getBytes()); fos.close(); 19

CSE 486/586, Spring 2012 Internal Storage MODE_PRIVATE  create the file (or replace a file of the same name) and make it private to your application. Other modes available are: –MODE_APPEND, MODE_WORLD_READABLE, and MODE_WORLD_WRITEABLE. To read a file from internal storage: –Call openFileInput() and pass it the name of the file to read. This returns a FileInputStream. –Read bytes from the file with read(). –Then close the stream with close(). 20

CSE 486/586, Spring 2012 External Storage Shared "external storage” –E.g., a removable storage media (such as an SD card) or an internal (non-removable) storage. Files saved to the external storage are: –World-readable –Can be modified by the user when they enable USB mass storage to transfer files on a computer. Checking media availability –Before you do any work with the external storage, you should always call getExternalStorageState() to check whether the media is available. 21

CSE 486/586, Spring 2012 External Storage Accessing files on external storage (API Level 8 or greater) –Use getExternalFilesDir() to open a File that represents the external storage directory where you should save your files. –This method takes a type parameter that specifies the type of subdirectory you want, such as DIRECTORY_MUSIC and DIRECTORY_RINGTONES (pass null to receive the root of your application's file directory). This method will create the appropriate directory if necessary. –If the user uninstalls your application, this directory and all its contents will be deleted. 22

CSE 486/586, Spring 2012 External Storage Saving files that should be shared –For files not specific to your application and that should not be deleted when your application is uninstalled –Save them to one of the public directories on the external storage. –These directories lay at the root of the external storage, such as Music/, Pictures/, Ringtones/, and others. (API Level 8 or greater) –Use getExternalStoragePublicDirectory(), passing it the type of public directory you want, such as DIRECTORY_MUSIC, DIRECTORY_PICTURES, DIRECTORY_RINGTONES, or others. This method will create the appropriate directory if necessary. 23

CSE 486/586, Spring 2012 Services A service runs in the background with no UI for long- running operations. –Playing music, sending/receiving network messages, … –Subclass of android.app.Service Started service –A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. Bound service –A service is "bound" when an application component binds to it by calling bindService(). A bound service offers a client- server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC). 24

CSE 486/586, Spring 2012 How to Write a Service Declare in AndroidManifest.xml Implement necessary methods in Service 25

CSE 486/586, Spring 2012 Declare in AndroidManifest.xml

CSE 486/586, Spring 2012 Necessary Methods onStartCommand() –The system calls this method when another component, such as an activity, requests that the service be started, by calling startService(). onBind() –The system calls this method when another component wants to bind with the service (such as to perform RPC), by calling bindService(). onCreate() –The system calls this method when the service is first created, to perform one-time setup procedures (before it calls either onStartCommand() or onBind()). onDestroy() –The system calls this method when the service is no longer used and is being destroyed. 27

CSE 486/586, Spring 2012 Service Lifecycle 28