Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Network Layer; Location Management

Similar presentations


Presentation on theme: "Android Network Layer; Location Management"— Presentation transcript:

1 Android Network Layer; Location Management
Y. Richard Yang 3/2/2011

2 Admin Assignment 3 Schedule project meetings

3 Recap: Android Software Framework
Components Activity and view Service Broadcast receiver Data providers Resources and manifest Intent as a component glue Non-blocking/zippy processing Thread, Handler, AsyncTask, IntentService Notification

4 Recap: Accessing Data in Cloud
A typical setting is that a device accesses data in the cloud Two design points poll Tx more expensive than Rx 5 min frequency: ~144 mAh / day push

5 Solution: Push Google Contacts, Calendar, Gmail, etc., use push sync
A single persistent connection from device to Google Android Cloud to Device Messaging (C2DM) to make it a public service

6 C2DM Overview Uses existing connection for Google services
Your servers send lightweight “data” messages to apps Tell app new data available Intent broadcast wakes up app App supplies UI, e.g., Notification, if/as necessary

7 C2DM Flow Enabling cloud to device messaging Per message
App (on device) registers with Google, gets registration ID App sends registration ID to its App Server Per message App Server sends (authenticated) message to Google Google sends message to device Disabling cloud to device messaging App can unregister ID, e.g., when user no longer wants push

8 C2DM

9 Android Code: Registration to C2DM
// Use the Intent API to get a registration ID // Registration ID is compartmentalized per app/device Intent regIntent = new Intent(“com.google.android.c2dm.intent.REGISTER”); // Identify your app regIntent.putExtra(“app”, PendingIntent.getBroadcast(this, 0, new Intent(), 0); // Identify role account server will use to send regIntent.putExtra(“sender”, OfSender); // Start the registration process startService(regIntent);

10 Receiving Registration ID
// Registration ID received via an Intent public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (“…REGISTRATION”.equals(action)) { handleRegistration(context, intent); } } private void handleRegistration(Context context, Intent intent){ String id = intent.getExtra(“registration_id”); if ((intent.getExtra(“error”) != null) { // Registration failed. Try again later, with backoff. } else if (id != null) { // Send the registration ID to the app’s server. // Be sure to do this in a separate thread.

11 Receiving Registration ID
App receives the ID as an Intent com.google.android.c2dm.intent.REGISTRATION App should send this ID to its server Service may issue new registration ID at any time App will receive REGISTRATION Intent broadcast App must update server with new ID

12 Android Data Storage Model
Storage methods Shared preference Built-in SQLite database Java file system using InputFileStream and OutputFileStream

13 Shared Preference A per-application key-value store
SharedPreference prefs = getSharedPreferences(“myDataStorage”); Editor mEditor = prefs.edit(); mEditor.putString(“username”, “myid”); mEditor.putString(“password”, “mySecret”); mEditor.commit(); SharedPreference prefs = getSharedPreferences(“myDataStorage”); String u = prefs.getString(“username”, null); String p = prefs.getString(“password”, null);

14 Content Provider Each provider can expose its data as a simple table on a database model Each content provider exposes a public URI that uniquely identifies its data set: android.provider.Contacts.Phones.CONTENT_URI android.provider.Contacts.Photos.CONTENT_URI android.provider.CallLog.Calls.CONTENT_URI android.provider.Calendar.CONTENT_URI

15 Intent and Content Provider
private void pickContact() {     // Create an intent to "pick" a contact, as defined by the content provider URI     Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);     startActivityForResult(intent, PICK_CONTACT_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {     // If the request went well (OK) and the request was PICK_CONTACT_REQUEST     if (resultCode == Activity.RESULT_OK && requestCode == PICK_CONTACT_REQUEST) {         // Perform a query to the contact's content provider for the contact's name         Cursor cursor = getContentResolver().query(data.getData(),         new String[] {Contacts.DISPLAY_NAME}, null, null, null);         if (cursor.moveToFirst()) { // True if the cursor is not empty             int columnIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME);             String name = cursor.getString(columnIndex);             // Do something with the selected contact's name...         }     } }

16 Andriod

17 Android Debug Dalvik Debugging Monitoring Service (DDMS) Android tools
Eclipse: Window -> Open Perspective -> Other -> DDMS Android tools Android debug bridge (adb) LogCat Hierarchical viewr TraceView

18 References Online development guide Book resources
Book resources “The Android Developer’s Cookbook” “Professional Android 2 Application Development”, by Reto Meier, from Yale Internet Resource

19 Recap: Wireless Link Layer
The basic services of the link layer framing, link reliability, etc link access: interference, quality of service (and fairness) control Guided by network layer transmit to which neighbor at what quality B A S E F H J D C G I K M N L

20 Network Layer Services
Transport packets from source to dest Network layer protocol in host and router Basic functions: Control plane compute routing from sources to destinations Data plane: forwarding move packets from input interface to appropriate output interface(s) B A S1 E D2 S2 J D1 C G I K M N L

21 Network Layer: API API (provided to upper layer)
transmit( info, src, dest, …); A key decision in network layer design is how to represent destinations? we refer to how applications specify destinations as the addressing scheme the supported addressing scheme(s) can have profound impacts on usability, flexibility, and scalability

22 Discussion: How to Specify a Destination?
B A S E F H J D C G I K M N L

23 Two Basic Approaches for Identifying Destinations
Locators Encode locations on network topology Identifiers (ID) independent of network topology A E D C B F

24 Addressing Scheme: Sensornet Example
Destination: message to a sensor (e.g., who detected fire) <ID = D> // id. <Lat= ; Long= > // loc <temperature = highest> // prop. B A S E D F J C G I K M N L

25 Addressing Scheme: Printer
How may we specify the destination as the color printer on the 2nd floor of AKW Internet domain name: lw2c.cs.yale.edu Internet protocol (IP) address: [building = AKW; floor=2; entity = printer; quality = color]

26 Addressing Scheme: Telephone
Very first scheme: connection by operators to business ID or locator?

27 Addressing Scheme: Telephone
The telephone numbering scheme: invented in 1888 by Almon Strowger, an undertaker: “No longer will my competitor steal all my business just because his wife is a BELL operator.”

28 Addressing Scheme: Telephone
E.164: Maximum 15 digits Hierarchical addressing scheme: country code + national destination (area) code (optional) + subscriber number e.g., Why hierarchical addressing scheme? uniquely determines the switch upon which the telephone is attached to B A S E D F J C G I K M N L

29 Summary Evolution of telephone addressing scheme
Identifier (business type) Identifier (person) Locator (hierarchical phone #) Nowadays: identifier (person again w/ mobile phones)

30 Internet Addressing Scheme
Also a hierarchical locator addressing scheme IP address: 32-bit identifier for an interface An IP address is associated with an interface %/sbin/ifconfig -a = 223 1 3 2

31 IP Addressing Hierarchical scheme:
Hierarchical scheme: network part (high order bits) host part (low order bits) What’s a network? (from IP address perspective) device interfaces with same network part of IP address link layer can reach each other

32 Why Hierarchy? The hierarchy is important for the scalability of Internet routing The routing system handles only the number of networks 350,679 networks on Mar ; 818 mil hosts in Jan. 2011)

33 Routing in IP/Telephone Networks
Represent network as a graph Determine a path to each destination on the graph Q: what does a node in the graph represent? A E D C B F 2 1 3 5

34 Key Problems Location management Dynamic routing
F Key Problems Location management E.g., due to user mobility (roaming) Dynamic routing E.g., due to node mobility/wireless connectivity, link connectivity/quality can be highly dynamic Interference management


Download ppt "Android Network Layer; Location Management"

Similar presentations


Ads by Google