Overview of Android Layers (Part 1)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
ok so now we're going to focus on what will become the next part of the course so we're basically done with the overview of Java portion so you now have way more than enough information of course to complete the programming assignment one and two you will also hopefully have learned enough about Java so as we get into the bulk of the course or we do a lot more interesting discussion of real examples you'll be able to follow along with the Java features we're going to use the next part of the course which is really the bulk of the you know or it's the beginning of the bulk of the course starts to cover the Android development environment and runtime environment now Android is a massive humanoid thing and so the first part of the discussions will give you a gestalt view of what's going on with the Android and then we'll start zooming in probably starting next week with the specific things you'll have to be responsible for to write assignment number three which is going to involve Android programming but for right now these are just concepts you have to understand so the purpose of this is to acquaint you with the key layers in the Android architecture and it's also a good time to give a pitch for what we call full stack development so many people in our field sadly are only aware of their you know one layer that they work on this is particularly true for people who don't get a Vanderbilt education they they go off to some other place where they you know don't get the benefit of a deeper understanding what happens at many different points along the the stack we're gonna cover everything comprehensively by the time you're done as an undergrad or a grad student this will give you an overview of the stacks of the Android software environment but be aware that much of what I'm going to talk about here is also applicable elsewhere as well you can find other information about this stuff here at this link we're also going to be spending some time talking about concurrency and communication because those are really the most in my mind the most interesting parts of modern systems trying to understand how to take advantage of multi-core platforms take advantage of networking that's really where the money is that's really where the excitement is so that's we're going to emphasize here all right so the first thing to remember is that Android is a layered environment so what does that mean it basically means that we don't try to solve all the problems in one fell swoop but instead we break things up into levels of abstraction and each level or layer as its called has a set of things it does well and in many cases it does those things in a very standardized way so when you understand some of the layers here you'll not only still understand how Android works but you'll also understand how most other operating systems and higher level software middleware etc behaves today as well so Android provides a layered stack for mobile devices and at the very very bottom of course are all the hardware things so I have my trusty Android smartphone which has a bunch of sensors in it like an accelerometer and GPS and it has bluetooth and it has Wi-Fi it has connectors for USB power and other kinds of devices it's got a bunch of different multi-core processor type things in it for doing general computation for doing DSP radio kinds of stuff for calls and so on and so forth so there's a whole pile of hardware in these ever more powerful and life companion like devices we're not going to talk about any of that well we are going to start talking about though are the software parts and at the very bottom of the software stack but of course on top of the hardware is the operating system and you'll see that Android provides a variant of Linux although it's been heavily customized for the world of mobile devices some of the things that it adds we'll talk about later things like high-performance inter-process communication sophisticated power management are important because of the way in which people use these things as phones not just mobile computers there's also a pile of things that we call the the middleware infrastructure middleware and you can look at middleware and a lot of different ways the easiest way is to look at middlewares being the layers of software that sit on top of the operating systems but underneath the underlying applications so in this particular case there's a bunch of different things in the middle R infrastructure there's nothing called the hardware abstraction layer which we'll talk about and a little bit more detail in a second the hardware abstraction layer basically tries to provide standard interfaces for otherwise inconsistent hardware devices you find in modern smartphones like cameras and radios and those kinds of things which you have not historically found in more traditional desktop or even laptop environments there's a java runtime environment which has a couple of layers it has a virtual machine layer which provides you an instruction a managed hosting environment for running Java bytecode there's also a subset of the core Java libraries so some of the things we've been talking about like collections for example and then there's also a set of native C and C++ libraries that do all kinds of interesting things in fact a lot of the actual heavy lifting in Android is actually done in C and C++ and we'll talk a little bit later about why that is you might think to yourself why do they do that why do they have this heavy c and c++ layer in an environment that's program largely in Java and we'll talk more about that then there's also a whole pile of middleware frameworks which are things that nestled on top of the infrastructure so this is the infrastructure middleware these are the application framework layers of the middleware and this is all the kind of stuff that's getting closer to what you're probably experiencing more as a user so the graphical user interface services for handling the telephony modes cameras and other multimedia devices so you know video video play out various kinds of multimedia frameworks obviously music iTunes like stuff and then all kinds of other things we'll talk about later and also how do you actually deliver applications to people that's that's the part where there's a market for for developers and then the final thing that comes with an Android distribution are so-called packaged applications and these are the apps right this is stuff like browsers and email and calendar and contacts and all that kind of good stuff and Android ships with about two dozen or so open-source applications that come out of the box sometimes vendors will add more stuff on top of the ones that come from Google but oftentimes the also keep the Google ones there as well now there's also non packaged applications that people sometimes bundle like Google Maps or Gmail or so on or YouTube and so on but those are typically not available and open source form although if you really want to hurt yourself you can go to the trouble of decompiling the bytecode classes to try to see what those things look like anybody ever try to do that anybody take a look and decompiled maps or Gmail or anything to see what the source code looks like well if you ever want to amuse yourself you should do it because they are very careful and they shroud the code so before they release the code in bytecode form the engineers at Google run their programs through a an obfuscator and it replaces all the nice long you know user friendly names that were taught in school to write to make code easy to understand with like a B C sites are completely off you skates the code so you have absolutely no idea what that code does and they do that because that's sort of their intellectual property and they don't want people to just steal it all right so that's basically a really quick fast you know two minute tour through the layers and Android we will now go and talk about each of these layers in a little bit more detail well first start by talking about the Android Linux kernel and so you can find out more this wiki pedia link about Android Linux a lot of what's in Android Linux is also in Linux so let's take a quick tour through that now you know it's a little it's a little premature to get heavy into operating system course details that's cs2 81 and so I don't expect you guys to be experts at all the stuff we're about to cover but I want you to at least have a passing familiarity with some of these concepts because they're pretty important and they are at the heart of everything we do with computing these days so some of the things you find in Linux and Android Linux are core abstractions for managing the hardware devices hardware resources in a modern operating environment so the key things we're going to talk about we're going to talk about virtual memory processes and threats so virtual memory is basically a way of giving application developers the they have a lot more memory than there is physical memory on the device most devices even with today's absurdly bloated amounts of memory like a you know 8 gig or 4 gig of ram you can still pack a lot more stuff with all the different things that have to run then there is physical memory so there's something called virtual memory and virtual memory basically does two things it allows the illusion that you have much more memory on your device and you really have because it uses backing store which is slower less expensive memory in order to store things when it they're not actually being actively accessed by the processor so that's one thing virtual memory does and the second thing that virtual memory does is it allows you to physically isolate memory in one application from memory in another application so that you can't accidentally read or write to the memory that you don't have access to and the main motivation of course is security because you don't want people tampering with things that they shouldn't have access to but also just robustness you don't want scribbling over parts of memory address space and then corrupting the state of the program so that's what virtual memory is all about and you can find out more about it here when you take the OS course you learn more about it the second thing and this is actually not unrelated to virtual memory that are important in operating systems are things called processes so a process is basically a unit of resource allocation and protection and different permissions different resources different memory segments and so on can be shielded from each other by allocating them in separate processes so a process is basically something that you can create or spawn as an application developer or assistant developer and in fact when you run an app in the Android environment it runs in the context of a process now those things have been around for you know 40 50 years at this point and you can learn more about them here more fine-grain then the process is something called the thread and a process can have one or more threads and a thread is basically it a unit of computation or a way of executing streams of an structions in the context of a process and one process can actually have multiple threads and we'll see lots of examples later about this works let's see and these threads are then mapped to run on the underlying processing cores this is the this is a metaphor for a core right we have multi-core I'm not making any statements about whether Apple has good cores or not but they do provide a good metaphor so those are some things that you'll find in Android Linux if this is what you'd find in Linux this is what you find in Android Linux you'll also find upon a protocol stacks which are used to access the outside world of course everybody wants to go and be on Facebook or Twitter or do you know browse the internet whatever you want to do you need to use you need to use the Internet protocols there's internet protocol stacks that are they're very sophisticated and then there's also something called a device driver framework so anybody can maybe think of any of the kinds of devices that you might want to connect to your your smartphone so headphones yeah great example headphones when plug your headphones in other devices which are not so obvious but are really important of course would be the touch screen driver the thing that manages the touch screen that's obviously something that's a device and speakers the microphone you know the radio there's all kinds of crazy things that are going to be accessible through the operating system and this thing called the drive device driver framework gives ways of accessing those either a character at a time or a chunk of bytes at a time so chunk of bytes at a time would be things like flash memory or various other kinds of you know a solid-state drives character devices would be things like network interfaces you have to read a character at a time alright so those are just common things again this is not an OS class but you've you've got like the first month of an OS class in 30 seconds right the other sort of things that Android provides are Android specific enhancements to the operating system so for example they have a really cool driver that handles community between processes because one of the important things you do a lot in Android is talk between different processes to get things done you have system processes and you have application user processes and application developers who can write processes and they have to communicate back and forth and there's a bunch of services that are provided for you by the underlying system services that Android provides us on so to make this all work well and efficiently they have something called the binder driver and it's basically an inter process communication mechanism for sending data back and forth between the different processes yeah so a driver driver is just a bunch of systems software that knows how to control hardware devices so if you have a touchscreen on your computer right I mean obviously you have a let me touch screen hold on your smartphone or you have a network you know you have a transceiver you have a like a Wi-Fi piece of hardware or you've got Bluetooth right the hardware that is the actual physical hardware then it has a thing called a device driver which is a piece of software that runs in the context of the operating system to talk to that piece of hardware and it's very low level and nasty and horrible and you should be very happy it's not 1972 or something because that's the kind of thing we'd be doing in this course if we were learning about that stuff because that's what they did back then um so there's ways of communicating between high-performance inter-process communication there's ways of sharing memory between address spaces which is another way of trying to optimize communication so you don't have to copy the data you can put it in shared memory and pass pointers or references to that memory back and forth there's some really cool support for power management that allows the applications or system services to control whether the device is able to sleep or not as a general rule of thumb you usually want the device to be able to sleep when it's not being used in fact on most of these things you know if you don't use it for about 15 seconds it blanks the screen right because screen draws a lot of power but does every once in a while you want something that will actually keep keep going even when you don't want the device to shut down like when someone does a phone call right you know while you're talking on the phone yeah if you haven't touched the computer for a while or the interface you don't want the thing to shut down so there's things called way clocks and that's part of the power management features that Android has and there are all kinds of ways of trying to control how power is managed big big issue in modern mobile computing is trying to deal with power issues another interesting thing they call the the low memory killer it sounds kind of sinister on it sounds like you want to have you know CSI low power killer right something like that and what it does is when memory starts to be running low on your device it goes around and it finds applications that it deems to be doing unimportant things and it euthanizes them that's right it's very heartless right it to shut stuff down on when we talk more about androids life cycle model you'll learn why this is important all right so those are some of the kernel level things again you don't have to be an expert on this you just have to sort of know that there are kernel level things that are important and roughly what they do the next thing we're gonna talk about is the hardware abstraction layer or the how does anybody know what this is that's Hal right and Hal 9000 I told you about and I tell you this this is a good little piece of trivia to know if you want to if you want to impress your especially your parents people your parents generation because they probably watch this so if you go and watch 2001 Space Odyssey which is where Hal is from then you'll find out that how is basically IBM plus plus right so they incremented every letter right pretty cool so that's that's like science fiction geek trivia now this is like this is just geek trivia okay so if you you know what Windows and T is Windows NT is the operating system technology that underlies Windows and it was developed by a guy named Dave Cutler who prior to coming to Microsoft had been the chief architect of VMs at Dec and so when he went to Microsoft he invented Windows NT which was VMs plus plus so that's that's like stats serious geek trivia right this this will make you a big hit it like getting comic-con or something like that but if you're at CES then you'll know some like really cool trivia there so that's the hardware abstraction layer history the hardware abstraction layer and Android is there to separate out some concerns for example it separates out and raise a platform logic the software that androids platform provides up to the applications from the hardware as well as from the operating system and so it basic this is really weird it provides a user space library written in C and C++ for accessing devices that live in the operating system kernel which seems odd because usually devices that live in the operating system kernel are actually accessed by a operating system kernel level drivers that live in kernel space whereas what we find in the how is actually living in user space and we'll talk about why that is in a second yeah what's the kernel a kernel is the what's everything we just talked about so so everything we just talked about with Android what what were some things we just talked about with Android drivers network protocol stack processes threads virtual memory binder driver and low memory killer those are all things that run in the OS kernel and that's typically a protected address space that has special access to regions of memory and instructions that the hardware can run and so it's the part that make sure it's the part for example that make sure that you don't have one application accessing information it shouldn't have access to because has the wrong permissions so the kernel is kind of like a it's like a traffic cop that keeps track of information flowing around inside it of an operating environment so everything we just talked about all that other stuff was in the in the OS kernel so the hardware abstraction layer basically provides an interface to the hardware drivers and they put it in user space for some interesting reasons part of the reasons were technical so a lot of the devices that you find a lot of the hardware that you find in a mobile phone or not the kind of thing people up to this point had ever expected to find in a Linux environment so for example a Linux environment that you would have for your desktop or laptop probably doesn't have a radio in it right because you don't making phone calls with it might have y5 it doesn't have a cellular radio likewise there's various kinds of things you know cameras and other kind of stuff you probably don't have a really high-resolution megapixel camera in your laptop whereas you probably do on your smartphone so there's a bunch of interfaces that are not actually part of the standard Linux kernel they wanted to have people have a standard interface to that were not provided the standard interface in the traditional kernel interfaces but that's actually just the cover story the real reason was that the Linux environment requires people who provide operating system drivers to release them in open source form because of the way that they license kernel modules in Linux because of the use of the GNU Public License the variant of the GNU public license that used for Linux is very very liberal in the sense that everybody has to have access to everything free as in freedom as Richard Stallman likes to say so as a consequence if they had put all this stuff into the OS kernel drivers then everybody who was a manufacturer of Android devices would have had to have released all their source code for their touchscreen drivers and all kind of his stuff in open-source form and a lot of people aren't comfortable doing that because that's their competitive advantage that's how they differentiate themselves that's how you know LG separates themselves some Samsung separates themselves from Motorola separates themselves from hob way or whoever and so they were uncomfortable with that so by having the user level drivers of having the drivers be put in user level for the hardware abstraction layer allowed them to circumvent the overly liberal licensing model overly liberalism quotes of course that are therein in janu it's a little beyond the scope of this class to talk about open source licensing models but at some point when you get if you go further along in computer science and you get to the upper division CS 297 course it's a seminar course that's kind of a projects course where we talk about a lot of broadening topics and one of the topics we'll cover there is open source which is kind of cool licensing issues are a big deal there all right next topic this is actually some recap so I'll go through this very quickly is Java Virtual Machine so there's a runtime environment that has a virtual machine you probably recall from the first day or so of class we talked about a virtual machine being a hosted environment for executing bytecode in a managed way and so in in Android like in most virtual machines the unit of the execution and creation of bytecode containers is the process which we just talked about which is part of the kernel and the virtual machine environment abstracts away a lot of the details of the underlying hardware so you'd have to know or care that you're running on one processor or one in one chipset or another in Android applications typically run in their own process inside their own VM instance so if you're the Android browser application for example then your browser is going to run on top of a bunch of other things that are out of the box part of the Android environment what's interesting about Android and this this triggered years worth of expensive litigation between Oracle and Google is that while they use Java to write the bulk of the applications in android they don't actually use the java virtual machine TM as the underlying virtual machine instead they write their own virtual machine called dalvik dalvik is a charming little village in Iceland which is where the guy who wrote the original virtual machine was from so he called it dalvik and it's a little different from a standard java virtual machine I don't have time to go into all the nuances if you take a look there's a bunch of cool videos you can learn about the internals of dalvik to see how it compares and contrasts I will not hold you responsible for that there's programs that will take Java classes and turn them into Android specific bytecode formats so they can run on in Android environment there's also a cool thing called a just-in-time compiler Just In Time compiler will take a look at the code as its executing and see what parts of the bytecode is run frequently and then it will decide automatically to compile that into binary form and be able to execute it natively yeah Oh what so the question is what prevents you from turning Java code into to a binary well in fact that's what's called the Android runtime which is the new virtual machine format that dalvik that Google is moving towards which you can learn about if you watch this video and what they have this is what you're actually talking about they have something that they call and ahead of time compiler so instead of a just-in-time compiler yeah that'd arch as its called Android runtime has ahead of time compiler which tries as much as the Java semantics allow which is the kicker to try to convert the Java source code into binary although there are certain semantics of Java having to do with verification of certain things and late binding and so on well you can't entirely compile it all away at compile time but you can get pretty close so they have this thing called ahead of time compiler you can read more about all that stuff here and they also have better garbage collection as well the last couple seconds here the virtual machines whether it's dalvik or art or whatever they implement all the concurrent programming language features that they support in Java and we'll cover more of those as we get a little further all in the course okay so at this point a couple things we are not going to have a quiz on Wednesday because we just didn't cover enough stuff so this stuff that we cover here will cover our next quiz which would be a week from Wednesday and
Info
Channel: Douglas Schmidt
Views: 24,103
Rating: 4.9224806 out of 5
Keywords: Android (Operating System)
Id: Thl_0ycg-i8
Channel Id: undefined
Length: 26min 24sec (1584 seconds)
Published: Mon Jan 26 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.