Перевод с английского
<<  Apple на wwdc 2012 Open Access Free-Open Software, Open Data, Creative Commons Wikipedia: Commonalities and Distinctions  >>
Mobile Software Development Framework: Android IPC; Intro to Mobile
Mobile Software Development Framework: Android IPC; Intro to Mobile
Outline
Outline
Admin
Admin
Recap: Event Handler Execution
Recap: Event Handler Execution
Recap: Background/UI Contention
Recap: Background/UI Contention
Recap: Android Handler
Recap: Android Handler
Recap: Fixing LoadingScreen
Recap: Fixing LoadingScreen
Recap: Inter-Process Communications (IPC)
Recap: Inter-Process Communications (IPC)
Activity
Activity
Recap: Intent Data Structure
Recap: Intent Data Structure
Explicit Intent
Explicit Intent
Declare Activity in Manifest
Declare Activity in Manifest
Intent Resolution: Explicit Intent
Intent Resolution: Explicit Intent
StartActivity for Result: Caller
StartActivity for Result: Caller
StartActivity for Result: Called
StartActivity for Result: Called
StartActivity for Result: Callee
StartActivity for Result: Callee
StartActivity for Result: Caller
StartActivity for Result: Caller
Explicit Intent: Start Service
Explicit Intent: Start Service
Discussion
Discussion
Outline
Outline
Intent Resolution: Implicit Intent
Intent Resolution: Implicit Intent
Implicit Intents
Implicit Intents
Implicit Intents
Implicit Intents
Intent Filter
Intent Filter
Intent Filter: Example
Intent Filter: Example
Implicit Start Activity
Implicit Start Activity
A Design Template: Provider
A Design Template: Provider
A Design Template: Provider
A Design Template: Provider
A Design Template: Invoker
A Design Template: Invoker
Outline
Outline
Content Provider
Content Provider
Content Provider and Intent
Content Provider and Intent
Content Consumer
Content Consumer
Outline
Outline
Broadcast Intents
Broadcast Intents
Intent and Broadcast: Sender
Intent and Broadcast: Sender
Intent and Broadcast: Receiver
Intent and Broadcast: Receiver
Intent, Broadcast, Receiver, Notification
Intent, Broadcast, Receiver, Notification
Intent, Broadcast, Receiver, Notification
Intent, Broadcast, Receiver, Notification
Discussion: Downside of Implicit Intent
Discussion: Downside of Implicit Intent
Real Example App: iMDb
Real Example App: iMDb
Example App
Example App
Vulnerability: Eavedropping
Vulnerability: Eavedropping
Vulnerability: Spoofing
Vulnerability: Spoofing
Vulnerability: Man-in-the-Middle
Vulnerability: Man-in-the-Middle
Vulnerability: Spoofing
Vulnerability: Spoofing
Vulnerability: Permission re-Delegation
Vulnerability: Permission re-Delegation
Permission System
Permission System
Permission Redelegation
Permission Redelegation
Permission Redelegation: Reality Check
Permission Redelegation: Reality Check
More Examples of Attack
More Examples of Attack
More Info on IPC
More Info on IPC
Progress So Far
Progress So Far
Accessing Data in the Cloud
Accessing Data in the Cloud
Progress So Far
Progress So Far
Solution 1: Polling
Solution 1: Polling
Impact of Polling on Battery
Impact of Polling on Battery
Solution 2: Push Notification
Solution 2: Push Notification
Push Service
Push Service

Презентация на тему: «На зоопарк фон». Автор: Yang Richard Yang. Файл: «На зоопарк фон.ppt». Размер zip-архива: 1170 КБ.

На зоопарк фон

содержание презентации «На зоопарк фон.ppt»
СлайдТекст
1 Mobile Software Development Framework: Android IPC; Intro to Mobile

Mobile Software Development Framework: Android IPC; Intro to Mobile

Push Notification

10/16/2012 Y. Richard Yang

1

2 Outline

Outline

Admin Android Inter-process communications Mobile push notification

2

3 Admin

Admin

Schedule for the rest of semester

3

4 Recap: Event Handler Execution

Recap: Event Handler Execution

Event handler (EH) executed by the main/UI thread’s Looper Slow EH blocks event processing Guidelines Notify user Incremental update Short/non-blocking handler, real processing offloaded to other thread

4

5 Recap: Background/UI Contention

Recap: Background/UI Contention

Conflict with UI thread

public class LoadingScreen extends Activity implements Runnable { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading); // start a new thread to load Thread thread = new Thread(this); thread.start(); } public void run(){ longRunningTask(); setContentView(R.layout.main); } … }

5

6 Recap: Android Handler

Recap: Android Handler

Background thread sends msg through handler to UI thread, who processes the msg

6

7 Recap: Fixing LoadingScreen

Recap: Fixing LoadingScreen

Conflict with UI thread

Conflict with UI thread

Conflict with UI thread

public class LoadingScreen extends Activity implements Runnable { private Handler mHandler = new Handler(); // UI handler @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading); // start a new thread to load Thread thread = new Thread(this); thread.start(); } public void run(){ longTask(); mHandler.post(mSetFinalViewTask); } private Runnable mSetFinalViewTask = new Runnable() { public void run() { setContentView(R.layout.main); } }; }

7

8 Recap: Inter-Process Communications (IPC)

Recap: Inter-Process Communications (IPC)

Objective: reuse existing data and services among Android components

8

9 Activity

Activity

Component

Service

Component

Broadcast Receiver

Component

Recap: Inter-Process Communications (IPC)

startActivity()

startActivityForResult()

startService()

bindService()

broadcastIntent()

9

10 Recap: Intent Data Structure

Recap: Intent Data Structure

Primary pieces of info in an Intent Action: The general action to be performed ACTION_VIEW, ACTION_DIAL, ACTION_EDIT, … Your own definition of strings Data: a URI tel:123 content://contacts/people/1 http://zoo.cs.yale.edu/classes/cs434 hotel://name/Omni_New_Haven Other attributes Category Type (MIME type) Component (class name) Extras (key-value store)

scheme

path

host

10

11 Explicit Intent

Explicit Intent

class: MapActivity

Map App

Yelp

To: MapActivity.class

Only the specified activity receives this message

http://developer.android.com/training/basics/firstapp/starting-activity.html

11

12 Declare Activity in Manifest

Declare Activity in Manifest

Make sure AndroidManifest.xml announces activities that can be started

See IntentController

Shown in Launcher

Announce class

<application android:icon="@drawable/icon” android:label="@string/app_name" > <activity android:name=".IntentController” android:label="IntentController" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TipCal" android:label="TipCal" > </activity>

12

13 Intent Resolution: Explicit Intent

Intent Resolution: Explicit Intent

Context

class name

start activity

public class IntentController extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.intentcontroller); // launch tip cal button Button tipBtn = (Button) findViewById(R.id.tipButton); tipBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent tipIntent = new Intent(IntentController.this, TipCal.class); startActivity(tipIntent); } });

13

14 StartActivity for Result: Caller

StartActivity for Result: Caller

private void startGame() { Intent launchGame = new Intent(this, CoolGameA.class); // passing information to launched activity launchGame.putExtra("userName", userName); launchGame.putExtra("userScore", userScore); startActivityForResult(launchGame, PLAY_GAME); }

14

15 StartActivity for Result: Called

StartActivity for Result: Called

public class CoolGameA extends Activity { private TextView tv2; int previousScore, score; String user; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.game); tv2 = (TextView) findViewById(R.id.game_text); //Get the intent that started this activity to fetch passed info Intent i = getIntent(); //returns [] if not initialized by calling activity user = i.getStringExtra("userName"); //returns -1 if not initialized by calling activity previousScore = i.getIntExtra("userScore", -1); tv2.setText(user + ":" + previousScore); doSessionWithInput(user, previousScore);

15

16 StartActivity for Result: Callee

StartActivity for Result: Callee

//change values for an example of return score = previousScore - 41; //setup button listener Button startButton = (Button) findViewById(R.id.end_game); startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { //return information to calling activity Intent i = getIntent(); i.putExtra("returnScore", score); i.putExtra("returnName", user); setResult(RESULT_OK, i); finish(); } }); } }

16

17 StartActivity for Result: Caller

StartActivity for Result: Caller

private void startGame() { Intent launchGame = new Intent(this, CoolGameA.class); // passing information to launched activity launchGame.putExtra("userName", userName); launchGame.putExtra("userScore", userScore); startActivityForResult(launchGame, PLAY_GAME); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLAY_GAME && resultCode == RESULT_OK) { userName = data.getExtras().getString(”returnName"); userScore = data.getExtras().getInt(“returnScore"); // show it has changed tv.setText(userName + ":" + userScore); } super.onActivityResult(requestCode, resultCode, data); }

17

18 Explicit Intent: Start Service

Explicit Intent: Start Service

http://developer.android.com/guide/components/services.html

public class PlayMusicService extends Service { public void onCreate() { super.onCreate(); } public int onStartCommand(Intent intent, int flags, int startId) { play_music(); return 1; } private void play_music() { while (true) { play_music_note(currentIndex); currentIndex++; } } // end of play_music

18

19 Discussion

Discussion

Problem of explicit intent

19

20 Outline

Outline

Admin Android Inter-process communications Intent data structure Explicit intent Implicit intent

20

21 Intent Resolution: Implicit Intent

Intent Resolution: Implicit Intent

Intent does not specify exact class to run Info in the Intent used by the system to determine the best component, at run time, to handle the intent

21

22 Implicit Intents

Implicit Intents

Handles Action: VIEW

Browser A

Yelp

Implicit Intent Action: VIEW

22

23 Implicit Intents

Implicit Intents

Handles Action: VIEW

Browser A

Yelp

Handles Action: VIEW

Browser B

Implicit Intent Action: VIEW

23

24 Intent Filter

Intent Filter

http://developer.android.com/guide/topics/intents/intents-filters.html

Problem: how to know what an Activity/Service can handle? Solution: Activities/Services/Receivers declare what they can/want to receive in Intent filter

24

25 Intent Filter: Example

Intent Filter: Example

AndroidManifest.xml file for com.android.browser

String action = "android.intent.action.VIEW"; Uri data = Uri.parse("http://www.google.com"); Intent myIntent = new Intent(action, data); startActivity(myIntent);

<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <scheme android:name="http" /> <scheme android:name="https" /> <scheme android:name="file" /> </intent-filter>

25

26 Implicit Start Activity

Implicit Start Activity

See IntentController

action

data

public class IntentController extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.intentcontroller); // launch dial button Button dialBtn = (Button) findViewById(R.id.dialButton); dialBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String action = "android.intent.action.DIAL"; String phno = "tel:4326400"; Uri data = Uri.parse(phno); Intent dialIntent = new Intent(action, data); startActivity(tipIntent); } });

26

27 A Design Template: Provider

A Design Template: Provider

<activity android:name=".Booking" android:label=“Booking"> <intent-filter> <action android:name=“com.hotelapp.ACTION_BOOK" /> <data android:scheme=“hotel" android:host=“name”/> </intent-filter> </activity>

27

28 A Design Template: Provider

A Design Template: Provider

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = getIntent(); // why am I called String action = intent.getAction(); Uri data = intent.getdata(); String hotelName = data.getPath(); // do the booking setResult(RESULT_OK); finish(); }

28

29 A Design Template: Invoker

A Design Template: Invoker

String action = “com.hotelapp.ACTION_BOOK"; String hotel = “hotel://name/“ + selectedHotel; Uri data = Uri.parse(hotel); Intent bookingIntent = new Intent(action, data); startActivityForResults(bookingIntent, requestCode);

29

30 Outline

Outline

Admin Android Inter-process communications Intent data structure Explicit intent Implicit intent Content provider as target of intent

30

31 Content Provider

Content Provider

Enable uniformed API for sharing data across applications E.g., Address book, photo gallery Each provider can expose its data as a simple table on a database model Query, delete, update, and insert rows

31

32 Content Provider and Intent

Content Provider and Intent

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 A content consumer declares access requirement <uses-permission android:name="android.permission.READ_CONTACTS"/>

32

33 Content Consumer

Content Consumer

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... } } }

33

34 Outline

Outline

Admin Android Inter-process communications Intent data structure Explicit intent Implicit intent Content provider as target of intent Broadcast intent

34

35 Broadcast Intents

Broadcast Intents

Multiple components may be interested in an event/update e.g., system event such as an incoming phone call, battery level low, network cell changes receives notification by declaring a broadcast receiver

35

36 Intent and Broadcast: Sender

Intent and Broadcast: Sender

Example: IntentController

String action = "edu.yale.cs434.RUN"; Intent cs434BroadcastIntent = new Intent(action); cs434BroadcastIntent.putExtra("message", "Wake up."); sendBroadcast(cs434BroadcastIntent);

36

37 Intent and Broadcast: Receiver

Intent and Broadcast: Receiver

<uses-permission android:name="android.permission.READ_PHONE_STAT”> <receiver android:name="MyPhoneReceiver”> <intent-filter> <action android:name="android.intent.action.PHONE_STATE”> </action> </intent-filter> </receiver> <receiver android:name=".CS434BroadcastReceiver" android:enabled="true"> <intent-filter> <action android:name="edu.yale.cs434.RUN" /> </intent-filter> </receiver>

37

38 Intent, Broadcast, Receiver, Notification

Intent, Broadcast, Receiver, Notification

public class CS434BroadcastReceiver extends BroadcastReceiver { public static final String CUSTOM_INTENT = "edu.yale.cs434.RUN"; // Display an alert that we've received a message. @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(CUSTOM_INTENT)) { String message = (String)intent.getExtras().get("message"); CharSequence text = "Got intent " + CUSTOM_INTENT + " with " + message; int duration = Toast.LENGTH_SHORT; Toast mToast = Toast.makeText(context, text, duration); mToast.show(); } // end of if } // end of onReceive }

38

39 Intent, Broadcast, Receiver, Notification

Intent, Broadcast, Receiver, Notification

public class MyPhoneReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { String state = extras.getString(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, "Incoming number: "+phoneNumber, Toast.LENGTH_LONG).show(); } // end of if } // end of if } // end of onReceive }

39

40 Discussion: Downside of Implicit Intent

Discussion: Downside of Implicit Intent

40

41 Real Example App: iMDb

Real Example App: iMDb

41

42 Example App

Example App

IMDb App

Handles Actions: willUpdateShowtimes, showtimesNoLocationError

Showtime Search

Results UI

Implicit Intent Action: willUpdateShowtimes

42

43 Vulnerability: Eavedropping

Vulnerability: Eavedropping

IMDb App

Eavesdropping App

Handles Action: willUpdateShowtimes, showtimesNoLocationError

Showtime Search

Malicious Receiver

Implicit Intent Action: willUpdateShowtimes

Sending Implicit Intents makes communication public

43

44 Vulnerability: Spoofing

Vulnerability: Spoofing

Malicious Injection App

IMDb App

Handles Action: willUpdateShowtimes, showtimesNoLocationError

Malicious Component

Results UI

Action: showtimesNoLocationError

Receiving Implicit Intents makes the component public

44

45 Vulnerability: Man-in-the-Middle

Vulnerability: Man-in-the-Middle

IMDb App

Man-in-the-Middle App

Handles Action: willUpdateShowtimes, showtimesNoLocation Error

Handles Action: willUpdateShowtimes, showtimesNoLocationError

Showtime Search

Results UI

Malicious Receiver

Action: willUpdateShowtimes

Action: showtimesNoLocation Error

45

46 Vulnerability: Spoofing

Vulnerability: Spoofing

46

47 Vulnerability: Permission re-Delegation

Vulnerability: Permission re-Delegation

Permission re-delegation occurs when an application without a permission gains additional privileges through another application

47

48 Permission System

Permission System

Malware

Deputy

toggleWifi()

toggleWifi()

Permission System

API

48

49 Permission Redelegation

Permission Redelegation

Malware

Malware

pressButton(0)

Deputy

toggleWifi()

Permission System

API

49

50 Permission Redelegation: Reality Check

Permission Redelegation: Reality Check

Analyzed manifests of 5 system applications Built attacks using 5 of the 16 system apps Found 15 attacks in the 5 applications

50

51 More Examples of Attack

More Examples of Attack

DeskClock: Start an internal service Tell it to infinitely vibrate with a WAKE_LOCK on Phone: Trigger the “phone call answered” message receiver Phone call will be silenced, vibrate cancelled More details see schedule page links

51

52 More Info on IPC

More Info on IPC

Intent is a high level abstraction For more details on implementation of Intent, see a set of slides on binder

52

53 Progress So Far

Progress So Far

Issue (responsiveness): slow UI is a sin Solution: event listener gives tasks to background thread(s) Issue: Background threads may need to update UI Solution: Handler/AsyncTask so that one thread can delegate tasks to to another thread Issue (composability): reusability is highly desired Solution: Intent

53

54 Accessing Data in the Cloud

Accessing Data in the Cloud

Challenge: How do you keep data on a device fresh?

54

55 Progress So Far

Progress So Far

Issue (responsiveness): slow UI is a sin Solution: event listener gives tasks to background thread(s) Issue: Background threads may need to update UI Solution: Handler/AsyncTask so that one thread can delegate tasks to to another thread Issue (composability): reusability is highly desired Solution: Intent

55

56 Solution 1: Polling

Solution 1: Polling

Simple to implement Device periodically asks server for new data/update Appropriate for content that changes constantly Stock Quotes, News Headlines Problems?

56

57 Impact of Polling on Battery

Impact of Polling on Battery

Baseline: ~5-8 mA Network: ~180-200 mA Tx more expensive than Rx Assume radio stays on for 10 sec. Energy per poll: ~0.50 mAh 5 min frequency: ~144 mAh / day Droid 2 total battery: 1400 mAh

Source: Android development team at Google

57

58 Solution 2: Push Notification

Solution 2: Push Notification

Design issue: Who to push to client device? Option 1: each app does it individually Option 2: a shared push service

58

59 Push Service

Push Service

A single persistent connection from device to a cloud push service provider Multiple application providers push to the service provider Service provider pushes to a device using the persistent connection Two examples Apple Push Notification Service (APNS) Google Cloud Messaging (GCM)

59

«На зоопарк фон»
http://900igr.net/prezentacija/anglijskij-jazyk/na-zoopark-fon-192818.html
cсылка на страницу
Урок

Английский язык

29 тем
Слайды