How Android Starts an App

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

Services. Application component No user interface Two main uses Performing background processing Supporting remote method execution.
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
Android Application Model (3)
Remote Method Invocation
Implementing Remote Procedure Calls Authors: Andrew D. Birrell and Bruce Jay Nelson Xerox Palo Alto Research Center Presenter: Jim Santmyer Thanks to:
Java RMI Project and Android Architecture
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
Grid Computing, B. Wilkinson, 20043b.1 Web Services Part II.
P2P communication Using the GTalk Service API. Introduction Peer-to-Peer communication highly used in mobile devices. Very efficient to when certain factors.
CSE 486/586 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
CS 153 Design of Operating Systems Spring 2015 Lecture 23: Inter-Process Communication (IPC) and Remote Procedure Call (RPC)
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Remote Procedure Calls CS587x Lecture Department of Computer Science Iowa State University.
Eric Tryon Brian Clark Christopher McKeowen. System Architecture The architecture can be broken down to three different basic layers Stub/skeleton layer.
Remote Procedure Call Andy Wang Operating Systems COP 4610 / CGS 5765.
Mark Stanovich Operating Systems COP Primitives to Build Distributed Applications send and receive Used to synchronize cooperating processes running.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Introduction to Android Programming
Remote Procedure Calls
Android Application -Architecture.
Concurrency in Android
More Security and Programming Language Work on SmartPhones
Android Content Providers & SQLite
Mobile Applications (Android Programming)
Security and Programming Language Work on SmartPhones
Distributed Computing
Karthik Dantu and Steve Ko
CSE 486/586 Distributed Systems Remote Procedure Call
Behavioral Design Patterns
Remote Method Invocation
MAD.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Activities and Intents
Android Mobile Application Development
Processes Overview: Process Concept Process Scheduling
Extending Java RMI for Dynamic Reconfiguration
Threads CSSE 332 Operating Systems Rose-Hulman Institute of Technology
The Component System … a bit further
Processes The most important processes used in Web-based systems and their internal organization.
CMPE419 Mobile Application Development
Knowledge Byte In this section, you will learn about:
Programming Models for Distributed Application
Android Programming Lecture 9
Lecture 23 Polymorphism Richard Gesick.
DISTRIBUTED COMPUTING
MSIS 670 Object-Oriented Software Engineering
Sarah Diesburg Operating Systems COP 4610
Application Development A Tutorial Driven Course
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
Remote Procedure Call Hank Levy 1.
Chapter 14 Abstract Classes and Interfaces
Operating Systems: A Modern Perspective, Chapter 6
Android Developer Fundamentals V2 Lesson 5
CS510 Operating System Foundations
Remote Procedure Call Hank Levy 1.
CSE 153 Design of Operating Systems Winter 2019
CMPE419 Mobile Application Development
15. Proxy SE2811 Software Component Design
Remote Procedure Call Hank Levy 1.
Advanced Operating Systems (CS 202) Operating System Structure
CIS 470 Mobile App Development
Presentation transcript:

How Android Starts an App Karthik Dantu and Steve Ko

Administrivia Show us your build! Which file did you modify to change the build id? Assignment3 is due next week.

Today: How Android Starts an App Why? A good example to start with in order to understand the source (I think) Getting deeper with the source Not quite straightforward to understand Goal: giving you enough pointers so you can navigate the source yourself.

Things You Need to Know Android Programming Model Launcher is implemented with this model. Android IPC mechanisms ActivityManager uses IPC mechanisms. Zygote

Android Programming Model No main() Four main components: Activity, Service, ContentProvider, BroadcastReceiver You need to implement at least one of them to write an Android app. Event-driven

Example - Activity

Example - Activity

Android IPC Mechanisms Android relies heavily on IPC mechanisms. This goes with the event-driven programming model. Three main mechanisms Intent Binder Looper-Handler

Intent You can think of it as a message or a command. Main fields Action (e.g., ACTION_VIEW) and Data Many system events are communicated as intents. E.g., ACTION_BATTERY_CHANGED, ACTION_POWER_CONNECTED, etc. A reasonable strategy for code navigation Locate where the switch-case code is for different actions

Binder The main IPC mechanism on Android Binder enables method calls across process boundaries. Caller side: A proxy and marshalling code Callee side: A stub and unmarshalling code Two ways to use it. Automatic proxy & stub generation (.aidl) Manual proxy & stub implementation

Binder with .aidl .aidl defines the interface. Naming convention: I*.aidl. E.g., IPackageManager.aidl The stub compiler generates I*.java E.g., IPackageManager.java This is part of the build process, i.e., you will not find I*.java file in the source (unless you’ve compiled already, then it’s under out/). It contains I*.Stub abstract class E.g., abstract class IPackageManager.Stub

Binder with .aidl A Stub class should be extended. This is the actual implementation for IPC calls. E.g., class PackageManagerService extends IPackageManager.Stub Callers can use the interface to make IPC calls. Callers can import classes in I*.java and use Stub.asInterface() when making IPC calls. E.g., IPackageManager.Stub.asInterface() returns an object for making IPC calls.

Binder with .aidl A reasonable strategy for code navigation If you encounter a call using an object returned from .asInterface() call, it’s a Binder call. Don’t worry about marshalling/unmarshalling code, e.g., onTransact(). Find the class that extends the Stub class. (Use croot;jgrep)

Binder without .aidl Manual implementation of the interface, marshalling/unmarshalling, and methods. E.g., IActivityManager.java defines the interface for accessing ActivityManager. abstract class ActivityManagerNative implements IActivityManager and has the marshalling/unmarshalling code. There’s a class that extends ActivityManagerNative and provide the actual callee-side implementation.

Binder without .aidl A reasonable strategy for code navigation Manual implementation typically follows the ActivityManager example. Interface file  abstract class  extended class E.g., startActivity() goes through this flow of classes.

Looper-Handler Looper is a per-thread message loop. Looper.prepare() Looper.loop() A Handler is shared by two threads to send/receive messages. Looper-Hanlder is used in the app control process to handle various messages.

Zygote C++ (e.g., app_main.cpp) and Java (e,g., ZygoteInit.java) Starts at boot. ZygoteInit.java manages a domain socket and listens to incoming VM creation requests. This uses ZygoteConnection.java. Main flow Forks a new VM instance. Loads the class that has the process’s main(). Calls the main().

Code Flow for App Start Launcher sends an intent to start an activity. startActivity() is a Binder call to ActivityManager. ActivityManager sends a process fork request. This request uses a socket to Zygote. Zygote forks a new VM instance that loads ActivityThread. ActivityThread has the real main() for an app.

Code Flow for App Start ActivityThread calls the app’s onCreate() ActivityThread notifies ActivityManager. ActivityManager makes a Binder call to ActivityThread to start the app (i.e., call onStart()).

Code Navigation Let’s see the code!