1 / 28

Android OS

Android OS . 100060010 許 軒 中 100060017 李紀萱 100060025 鄧國盛. Outline. Overview of Android OS Multiprogramming and Multitasking Scheduling employed Threading supported Programming languages and IDEs supported . 100060010 許軒中 100060017 李紀萱 100060025 鄧國盛. java. C.

acton
Télécharger la présentation

Android OS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android OS 100060010 許軒中 100060017 李紀萱 100060025 鄧國盛

  2. Outline • Overview of Android OS • Multiprogramming and Multitasking • Scheduling employed • Threading supported • Programming languages and IDEs supported 100060010許軒中 100060017李紀萱 100060025鄧國盛

  3. java C Android Architecture 100060010許軒中 100060017李紀萱 100060025鄧國盛

  4. The applications are at the topmost layer of the Android stack. An average user of the Android device would mostly interact with this layer (for basic functions, such as making phone calls, accessing the Web browser etc.) Android Architecture(Cont) Application framework includes the programs that manage the phone's basic functions. Think of the application framework as a set of basic tools with which a developer can build much more complex tool. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  5. Android Architecture(Cont) Dalvik VM Dalvik VM Dalvik VM Dalvik VM app app app app app app • Core libraries (Java) • These are different from Java SE and Java ME libraries. However these libraries provides most of the functionalities defined in the Java SE libraries. • DalvikVM • It is a type of JVM used in android devices to run apps and is optimized for low processing power and low memory environments. Dalvik VM is Register based and each application runs on its own Dalvik VM, that is, It has been designed to allow multiple VM instances to run at once • Operates on DEX files. .java .class package .dex compile .apk convert 100060010許軒中 100060017李紀萱 100060025鄧國盛

  6. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  7. Android Architecture(Cont) Libraries (C/C++) Android’s native libraries carry a set of instructions to guide the device in handling different types of data. These libraries are written in c or c++ language and are specific for a particular hardware. Kernel The basic layer is the Linux kernel. The whole Android OS is built on top of the Linux 2.6 Kernel with some further architectural changes made by Google.  It is this Linux that interacts with the hardware and contains all the essential hardware drivers. It also  acts as an abstraction layer between the hardware and other software layers. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  8. Anatomy of an Android Application Application components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior. Activities Services Content Providers Broadcast receivers 100060010許軒中 100060017李紀萱 100060025鄧國盛

  9. Activities An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture. Activity 1 Activity 2 Activity 3 Show list of new emails Compose emails Reading emails Email Application 100060010許軒中 100060017李紀萱 100060025鄧國盛

  10. A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. Example: Playing music in the background Services A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information.  Content Providers A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use.  Broadcast receivers 100060010許軒中 100060017李紀萱 100060025鄧國盛

  11. A unique aspect Any application can start another application’s component. Photo Editing Application Camera Application Android OS Component 1 Component 1 Intent Component 2 Component 2 Component 3 Component 3 100060010許軒中 100060017李紀萱 100060025鄧國盛

  12. Multitasking The Android system tries to maintain an application process for as long as possible……. but eventually needs to remove old processes to reclaim memory for new or more important processes. To determine which processes to keep and which to kill, the system places each process into an "importance hierarchy" based on the components running in the process and the state of those components. Importance Foreground Process Visible Process Service Process Background Process Empty Process 100060010許軒中 100060017李紀萱 100060025鄧國盛

  13. Foreground Process It hosts an Activity that the user is interacting with. It hosts a Service that's bound to the activity that the user is interacting with. It hosts a BroadcastReceiver that's executing its onReceive() method. Visible Process Visible Process A process that doesn't have any foreground components, but still can affect what the user sees on screen.  It hosts a Service that's bound to a visible (or foreground) activity. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  14. Service Process Service Process They are generally doing things that the user cares about (such as playing music in the background or downloading data on the network), Background Process Background Process A process holding an activity that's not currently visible to the user Empty Process A process that doesn't hold any active application components. The only reason to keep this kind of process alive is for caching purposes, to improve startup time the next time a component needs to run in it. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  15. When deciding which processes to kill, the Android system weighs their relative importance to the user. For example, it more readily shuts down a process hosting activities that are no longer visible on screen, compared to a process hosting visible activities. The decision whether to terminate a process, therefore, depends on the state of the components running in that process. If a user later returns to an application that's been killed, Android preserves the "all applications are running all of the time" experience by keeping track of the parts of the application the user is aware of (the Activities), and re-starting them with information about the last state they were seen in. Android's process management can be seen as a form of swap space: application processes represent a certain amount of in-use memory; when memory is low, some processes can be killed (swapped out); when those processes are needed again, they can be re-started from their last saved state (swapped in). 100060010許軒中 100060017李紀萱 100060025鄧國盛

  16. Scheduling Since Android is based on the Linux kernel, it shares many aspects with Linux, including how processes and threads are scheduled. • The Linux kernel uses the CFS, or the Completely Fair Scheduler which picks out the next process dynamically based on vruntime values and “nice values” 100060010許軒中 100060017李紀萱 100060025鄧國盛

  17. CFS Scheduler Scheduler Latency - the period in which all run queue tasks are scheduled at least once. Now consider a case where two threads share the CPU, one with niceness 0 and the other with niceness 5. CFS assigns these niceness levels the weights of 1024 and 335 respectively. The time that the threads get is therefore proportional to 1024/(1024+335) and 335/(1024+335). The thread with niceness 0 will receive approximately 75ms out of each 100ms and the thread with niceness 5 will receive approximately 25ms out of each 100ms Thread 1 Nice Value 0 Weight 1024 Thread 2 Nice Value 5 Weight 335 1024/(1024+335) 335/(1024+335 100060010許軒中 100060017李紀萱 100060025鄧國盛

  18. Vruntime To pick out the next process to run, Linux picks the process with the lowestvruntime (virtual run time) Thread 1 Nice Value 0 Weight 1024 Vruntime += 1 Run for 1 ns Thread 2 Nice Value 5 Weight 335 Vruntime += 3 Run for 1 ns 100060010許軒中 100060017李紀萱 100060025鄧國盛

  19. Time Slice Given to each process = sched_latency * (process_weight / all weights) Vruntime added to each process = Actual Runtime / (process_weight) Vrun time = sched_latency / all weights The CPU thinks that each process was given the same run time! However as we can see, processes with higher priorities (lower nice values) actually get larger time slices to run! 100060010許軒中 100060017李紀萱 100060025鄧國盛

  20. 100060010許軒中 100060017李紀萱 100060025鄧國盛

  21. But……. Imagine if we had 10 background threads and 1 foreground thread. Are nice levels enough to guarantee that the response time of our foreground thread is unaffected? Background Cgroup Default/Foreground Cgroup 5% of all CPU cycles 95% of all CPU cycles 100060010許軒中 100060017李紀萱 100060025鄧國盛

  22. Linux CFS Nice Values Hard on the CPU Nicer to the CPU THREAD_PRIORITY_DEFAULT THREAD_PRIORITY_LOWEST THREAD_PRIORITY_URGENT_AUDIO Default Cgroup – 95% Background Cgroup – 5% 100060010許軒中 100060017李紀萱 100060025鄧國盛

  23. Threading in Android When an Android application is first started, the runtime system creates a single thread in which all application components will run by default. This thread is generally referred to as the main thread.  100060010許軒中 100060017李紀萱 100060025鄧國盛

  24. Android also supports java.lang.thread. There are basically two main ways of having a Thread execute application code. • Create a new class that extends Thread and override • its run() method. • MyThreadt = new MyThread(); • t.start(); • public class MyThreadextends Thread{ • @Override • public void run() { • super.run(); • }//run • }//class 100060010許軒中 100060017李紀萱 100060025鄧國盛

  25. Create a new Runnable instance passing to it a Thread object. • Runnable myRunnable1 = new MyRunnableClass(); • Thread t1 = new Thread(myRunnable1); • t1.start(); • public class MyRunnableClassimplements Runnable { • @Override • public void run() { • }//run • }//class 100060010許軒中 100060017李紀萱 100060025鄧國盛

  26. Programming Language Android development is java-based (most of the times), because a large portion of Java libraries is supported in Android along with the Android libraries. Java.lang Java.math Javax.sql Javax.xml.parsers Java.text Java.security http://developer.android.com/reference/packages.html 100060010許軒中 100060017李紀萱 100060025鄧國盛

  27. Android SDK 100060010許軒中 100060017李紀萱 100060025鄧國盛

  28. Android SDK 100060010許軒中 100060017李紀萱 100060025鄧國盛

More Related