We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Android 5.0 internals and our inferiority complex

00:00

Formal Metadata

Title
Android 5.0 internals and our inferiority complex
Title of Series
Number of Parts
46
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
As an Android developers we use various frameworks and libraries provided by Google and others. Sometimes they are just a pure magic (say hi to Jake Wharton and his ActionBarShelock!) and sometimes… Well, if we make an effort to grap the source code and go through it, we realise there is no magic there. During my presentation, I will go deep into Lollipop’s new JobScheduler API. See what’s really there, how it’s advertised, and try to assess how big is the gap between us and guys at Google. Should we have any inferiority complex or could we write this code ourselves?
18
Software developerMortality rateControl flowPresentation of a groupInternetworkingCartesian coordinate systemComplex (psychology)GoogolLevel (video gaming)Square numberMultiplication signLecture/ConferenceMeeting/Interview
Presentation of a groupPresentation of a groupWikiSquare numberSoftware developerInstance (computer science)Complex (psychology)Level (video gaming)Web pageRight angleLecture/Conference
Presentation of a groupGoogolWebsiteTwitterBitCodeLecture/ConferenceMeeting/Interview
InformationGoogolCodeOpen sourceGoogolSoftware developerCASE <Informatik>Computing platformInstance (computer science)Process (computing)Computer virusRight anglePhysical lawMereologyGroup actionForm (programming)Computer animationLecture/Conference
Stack (abstract data type)Android (robot)PressureAndroid (robot)PressureVideoconferencingInstance (computer science)Stack (abstract data type)Power (physics)outputBlogSoftware developerLibrary (computing)Staff (military)Multiplication signEmailFamilyRight anglePresentation of a groupMeeting/Interview
PressureAndroid (robot)CodeLibrary (computing)Presentation of a groupRevision controlPhysical lawType theoryMathematicsFamilyRight angleSoftware developerComputer animationLecture/ConferenceMeeting/Interview
View (database)MultiplicationAndroid (robot)ExplosionWeb pageLevel (video gaming)Element (mathematics)Software development kitSocial classCore dumpLemma (mathematics)Salem, IllinoisPrice indexSoftware developerComputer hardwareScheduling (computing)Web 2.0MiniDiscNP-hardView (database)Descriptive statisticsData storage deviceInformation securityBitMathematicsInheritance (object-oriented programming)Range (statistics)Software developerMereologyTraffic reportingAndroid (robot)NumberElectronic mailing listProcess (computing)Error messageComputing platformDifferent (Kate Ryan album)Right angleComputer animationLecture/Conference
Range (statistics)Equals signBoolean algebraMathematicsRange (statistics)Android (robot)Level (video gaming)Line (geometry)CodeJava appletNumberGoogolProjective planeProcess (computing)Computer animationLecture/Conference
RSA (algorithm)Bit error rateComputing platformSoftware developerBlogProjective planeMaterialization (paranormal)Task (computing)Film editingWeb 2.0InternetworkingCartesian coordinate systemLevel (video gaming)System callTelecommunicationInstance (computer science)Software developerComputing platformLibrary (computing)GoogolComplex (psychology)Right anglePlotterComputer virusVideo gameDigital photographyMeeting/InterviewComputer animationLecture/Conference
Run time (program lifecycle phase)RandomizationInternetworkingProcess (computing)MereologyScheduling (computing)Projective planeComputing platformCodePattern languageSystem callSoftware developerArithmetic meanMultiplication signLecture/Conference
Task (computing)Data typeInformationBuildingNumberSynchronizationMultiplication signTask (computing)Physical systemService (economics)Server (computing)Process (computing)DatabaseCartesian coordinate systemSoftwareIntegerBefehlsprozessorPower (physics)Scheduling (computing)Connectivity (graph theory)Table (information)ArmDressing (medical)NeuroinformatikData managementContrast (vision)Point (geometry)Particle systemQuicksortUniform resource locatorNetzwerkverwaltungConstraint (mathematics)Speech synthesisComputer animation
Task (computing)Bit error rateRepetitionMechanism designMobile appObject (grammar)Set (mathematics)Software developerPhysical systemTask (computing)Transport Layer SecurityService (economics)Android (robot)BuildingDrop (liquid)Process (computing)GoogolArchaeological field surveyScheduling (computing)Computer animationLecture/Conference
Scheduling (computing)Content (media)Android (robot)Service (economics)View (database)Information securityView (database)State of matterService (economics)Physical systemScheduling (computing)Process (computing)Drop (liquid)MereologyNetwork topologyGroup actionPoint (geometry)Core dumpAndroid (robot)Web 2.0Lecture/Conference
WritingPhysical systemProcess (computing)Task (computing)Computer fileBootingScheduling (computing)Traffic reportingSoftware developerSet (mathematics)Right angleComputer animation
Multiplication signCartesian coordinate systemPhysical systemGame controllerSoftware developerCodeProcess (computing)Computing platformState of matterScheduling (computing)Task (computing)MereologySystem callNormal (geometry)Computer fileLecture/Conference
Context awarenessMultiplication signBroadcasting (networking)Game controllerConnectivity (graph theory)Computing platformTask (computing)CodeSoftwareArrow of timeEvent horizonRow (database)Computer iconInstance (computer science)Computer animation
Digital filterGroup actionContext awarenessString (computer science)Equals signCodeGame controllerPhysical systemFlagConnected spaceBroadcasting (networking)Installable File SystemSystem callProcess (computing)Row (database)Computer animation
Physical systemService (economics)Library (computing)Revision controlInternetworkingScheduling (computing)Process (computing)CodeCASE <Informatik>Cartesian coordinate systemDifferent (Kate Ryan album)Physical systemService (economics)Centralizer and normalizerData managementGroup actionGame controllerCompact spaceRight angleFacebookSoftware developerArchaeological field surveyArithmetic meanTraffic reportingXMLComputer animationLecture/Conference
Physical systemScheduling (computing)InformationScalable Coherent InterfaceComputer networkCompact spaceProcess (computing)Cartesian coordinate systemRevision controlService (economics)Physical systemScheduling (computing)Different (Kate Ryan album)QuicksortMachine visionGoogolDiagramProgram flowchart
Maxima and minimaScheduling (computing)Computing platformFlow separationRevision controlSoftwareProcess (computing)NetzwerkverwaltungGoogolGroup actionMessage passingRight angleMereologyTask (computing)Constraint (mathematics)Point cloudDifferent (Kate Ryan album)Asynchronous Transfer ModeCASE <Informatik>Drop (liquid)Logical constantFood energyBeat (acoustics)Lecture/ConferenceComputer animation
MereologyGoogolScheduling (computing)Revision controlSlide ruleSimilarity (geometry)Process (computing)Service (economics)SoftwareGame controllerLecture/Conference
Asynchronous Transfer ModeGame controllerAsynchronous Transfer ModeCodeGoogolScheduling (computing)Process (computing)MereologyPhysical systemComplex (psychology)Multiplication signFrequencyRight anglePoint (geometry)WeightComputer animationLecture/Conference
Computer networkAsynchronous Transfer ModeAsynchronous Transfer ModeFrequencyMultiplication signTable (information)Physical systemProcess (computing)Perspective (visual)Form (programming)Meeting/Interview
Task (computing)Computer networkAsynchronous Transfer ModeGoogolPhysical systemBitMultiplication signVideoconferencingPhysical systemGame controllerState of matterMereologyTask (computing)Process (computing)International Date LineRight angleScheduling (computing)Meeting/InterviewComputer animationLecture/Conference
RepetitionAutomatic differentiationService (economics)Theory of relativityGroup actionInternetworkingGoogolDegree (graph theory)Lecture/ConferenceMeeting/Interview
Core dumpBoom (sailing)Modal logicComputer-generated imageryEuler anglesInterior (topology)Convex hullLink (knot theory)Different (Kate Ryan album)Right angleOcean currentBitResultantGreatest elementGoogolPower (physics)Product (business)XML
Pointer (computer programming)Normed vector spaceGoogolMaizeMobile WebDuality (mathematics)Exact sequenceLibrary (computing)Queue (abstract data type)FreewarePower (physics)Different (Kate Ryan album)Right angleGoogolSheaf (mathematics)Musical ensembleService (economics)XMLComputer animation
VideoconferencingGoogolBlock (periodic table)Software developerBoss CorporationMetropolitan area networkStatement (computer science)Meeting/Interview
Statement (computer science)TrailAlgorithmState of matterInternational Date LineCodeAlgorithmArrow of timeAutomatic differentiationSystem callRight angleGoogolGame controllerLecture/Conference
TouchscreenElectronic visual displayAlgorithmGroup actionString (computer science)Equals signContext awarenessPhysical systemInternational Date LineState of matterElectronic visual displayScheduling (computing)Process (computing)AlgorithmCuboidMultiplication signBitPower (physics)Game controllerInstallable File SystemBroadcasting (networking)Arrow of timeTouchscreenCodeRight angleLevel (video gaming)Presentation of a groupAsynchronous Transfer ModeDisk read-and-write headGoogolComputer animationLecture/Conference
Group actionEquals signString (computer science)Context awarenessQuicksortTouchscreenMultiplication signGroup actionInternational Date LineAsynchronous Transfer ModeSlide ruleComputer animation
AlgorithmDivisorAndroid (robot)Electronic visual displayMultiplication signPerspective (visual)DivisorRight angleLine (geometry)CASE <Informatik>International Date LineGame controllerTouchscreenAlgorithmAndroid (robot)Basis <Mathematik>Video gameFamilyComputer animationLecture/Conference
RhombusPower (physics)AverageGoogolState of matterLecture/Conference
AlgorithmScheduling (computing)DatabaseInformationProcess (computing)Arithmetic meanAsynchronous Transfer ModeQuery language2 (number)Multiplication signNumberAverageStability theoryRandomizationLecture/Conference
NP-hardSpacetimeComplex (psychology)CASE <Informatik>Java appletRandom number generationPartition (number theory)Android (robot)CodeSoftware developerSource codeSoftware frameworkFile systemSheaf (mathematics)Core dumpFamilyProjective planePhysical systemComputer virusLecture/ConferenceMeeting/Interview
Markup languageCodeAndroid (robot)Level (video gaming)MassObservational studyLecture/Conference
Transcript: English(auto-generated)
Guten tag, pardon my German. Hello, I'm Alek. I work at Applause in Warsaw. We have a workshop in Berlin. So if you are interested in talking with us about our work for Applause
or application quality because this is what we are working at Applause. Please catch us after my presentation during the coffee breaks. So you already know that I'm Alek and I go by Palotas Plus on the internet.
My presentation is about inferiority complex, about mind complex and also about the gap between us, mortal developers and rockstar developers from Square or Google. I will try to find the answer, is the gap big or maybe we are at their level. I also learned that the inferiority complex could be also called impositor syndrome
and actually there is a wiki page about that. So if you are curious what's the impositor syndrome or the inferiority complex actually is, go to the wiki and see that. The story about the presentation is that I made a presentation a year ago
during DroidCon in Krakow about what's new in Lollipop. Back then it was a presentation about new APIs in the Lollipop and there are I guess better suited guys to do that. For instance Wojtek is sitting there from Google. So to learn what's new in Lollipop or the new release
which is I think called Macadamia Nut Cake, right? It's official name, MNC Macadamia Nut Cake. Of course Wojtek won't tell you that but that's the new name. So back then my presentation was about new APIs and what not but as always the devil is in the detail and I learned from the guy Alenkov.
He goes by Captain Petko on the Twitter. I learned that it's also very interesting to see how the API works from the other side under the hood. So back then I made the presentation about new APIs. Then I thought that maybe I will look how they work, how the guys from Google wrote the code. So this presentation here will be a bit technical later on
and hopefully you will find some motivation as well and at the end we will find the answer. Are we all rockstar developers or not? I will start with the disclaimer. Disclaimer is very important because first of all the disclaimer started with a joke but at the end I was approached by a guy from Google who said that
thanks to the disclaimer he understood that I'm not smart that is making fun of other developers not showing his own code. I'm just commenting Google code because it's written in Java, because it's open source and because I'm working with Android platform and there is no pun intended here.
I'm not making fun of Google developers because I don't have anything against Google. I make living thanks to their technologies. I don't want to diminish their achievements and say anything bad about their developers and at the end it's not like I was recruited by Google. I send them my CV and they turn me down. So there is no bad blood between me and the Google, right? So first of all how I got my inferiority complex.
So I attended various conferences. In this case actually it was Apple conference but I read a lot and I see that other developers are creating lots of new stuff. For instance iOS 8 gave us 4000 of new APIs.
So in a year they created lots of new stuff and I in a year closed like maybe 20 tickets in JIRA. So I'm not so a potent developer. So I always thought they are better developers than me. Creating more stuff, writing more blog posts, creating videos or creating new libraries. So I was reading about that.
I was seeing that there are lots of very new and powerful interesting stuff like material design, Bluetooth stacks and I thought that shit I'm not a rock star, right? Of course there is also very strong pressure from the Android weekly. Every week we receive an email, right?
Like 10 new blog posts, 20 new libraries. And sometimes even you see that your own friends are creating those awesome libraries and you are not making. So for me it was like oh shit I'm not so a rock star. So I thought that maybe I would do something about that. So instead of creating libraries I started making presentations. So it's one of the solutions.
Another one is take a look at the code and you will see if it's not that hard. So let's go to the lollipop because it's in the title of the presentation. But it of course applies to other versions of Android, right? Let's start and look at the changes in the lollipop. Some changes and try to compare ourselves if it's in our range, right?
If it's possible for us to create such changes. Material design, huge thing. I think you have to be a rock star developer to create material design, right? Web view updated via Play Store. You have to be Google to do that because it's a part of the platform for sure. Also it's quite a technical challenge.
Also quite interesting. Full disk description. So it's super hard. You have to be security geek to understand all this stuff. Mood to stuff, it's also a huge change. Android to work to be honest. It's a very funny thing but I don't know the details. For sure there is also very new and important I would say API job scheduler.
And you will see in a bit that it's not that hard. Also a part of lollipop, right? If you go through all the changes, you can see that there is a list of API difference. There's a report in the Android documentation. There are lots of new packages there. The list goes on and on.
And one random change there. It is a range, new package. Basically a range of two numbers like 4 and 10. And if you look at the package there, you can see that it's not that complicated. Just two numbers, you can check if a third number is within that range.
You can check if two ranges overlap and there are like 10 more methods there. And if you look at the code, it's like this. It's like four lines of Java which is basically super easy to understand. And while I was reading the changes in Android lollipop, I was going through the code. And when I saw that, I thought, okay, it's not that hard.
It's something that I can make. I can write this code and if it ends up in Android lollipop, then it means that I'm at the level of guys from Google. So, of course, there are also the projects. Another thing that is very important for Google
and it's very easy to have this impositor syndrome because of this project. Why? Because the projects are in the Google materials on the web, in the blog post. Also, they are quite interesting. For instance, in Jelly Bean, the project butter was about making your UI smoother.
Huge task, I guess. Other projects like with KitKat or even something Google called project fees or the telecom thing. There was also a project called Volta. We'll talk about that project here. But I think that it's important to say that when somebody asks you, what are you doing?
Very often developers are like this. I'm creating a new method. I just wrote a method. Nothing very important. I think that very smart is you call it a project, maybe even put it on GitHub. If you call something a project, we are proud of that. There is no reason for us to create.
If you create a library just for ourselves, call it a project. Call it a project Volta, for instance. Put it on the internet and then this is not that hard. This is a way to cure your infurities complex. Let's get back to the project Volta. Project Volta, huge task.
The idea of project Volta is to improve the battery life of the various levels. At the platform level, at the developer level. At developer level, it means new APIs for us developers. Even at user level, there is, I think, battery saver. And some tools for user to see what application is using more power. And when the telephone will die, right? There is this chart showing how much juice is left in your device.
Also, as part of this project, at the platform level, you have the art runtimes. Huge project. Not something random guy from the internet can create. There is also a job scheduler. We'll talk about that in a minute. Also, battery saver. Job scheduler API. So, once again, I was reading the code, trying to compare myself.
And found this job scheduler API, which is actually in Java. So, all the code is on the internet. It's in Java, so I understand that. And I can read the code and make a few comments about that. And also, what's fun, the job scheduler API is a part of very important project Volta.
So, for me, it was like, if I understand the job scheduler. If I can say that I could write this job scheduler, then maybe it means that I'm a custom developer, right? So, let's look at the job scheduler API. But before we look at the job scheduler API, we need to understand what was it for, right? It's for a task.
So, we have an application and a task. It's wise for the task to be not user facing. So, a task that's doing something in the background. The same task is also, it's not given that the task will run at some particular point in time. So, the task should be like, doesn't, you know,
the time of execution shouldn't matter for the task. And at the end, it's not a requirement, but the task could be like a resource-sensitive CPU power or something like that. So, we have our task, right? Background task. Let's say, syncing data from the server and storing it in local database on the device. In the old way, to run a task in the background,
we can use sync adapter for that, or we can go with other managers, set alarm, let's say, do the sync every three hours, right? But when the alarm goes off, we have to make sure using, let's say, network manager, if we have the network to connect to the server and get the data, right? So, let's say, we also don't want to do some heavy computing,
so then it's wise to make sure that the charger is connected, right? So, with the old way, we have to go through all the managers, and it's quite inconvenient because we have to set the alarm. If there is no network, we have to reset the alarm and check in 15 minutes, say, if the network is available in 15 minutes or not,
and it's not so easy. So, that's why it's the JobScheduler API. With JobScheduler API, we have our task, which is basically an ID, an integer. We have service component, which basically is a service in our application. So, when the time comes to execute the task,
system will walk up our application, start the service, and say, service, please do the task number four. We also can set some constraints. So, for instance, we can say that we need an unmetered network for our task, unmetered network that will be Wi-Fi. We also can say that we require charging. So, basically, this is API of JobScheduler,
a task that is a task, a set of constraints, and at the end, we create a JobInfo object. So, we have our own app with a task. Then, thanks to the JobBuilder, we create a JobInfo object. So, we converted the task to the JobInfo, and then we have to schedule the task
and send it to the JobScheduler. So, let's see how it works under the hood. First of all, what is the JobScheduler? JobScheduler is a special beast. It's a system service. Of course, it's another reason why it's only available, the whole mechanism of system services only for Google.
I mean, for guys who are creating their own Android builds. So, it's not easy for us developers to create a system service. So, JobScheduler is a system service. Thanks to that, it has some extra privileges. Let's see now what other services are available, system services. So, we have battery service.
This is a guy who can tell us what's the state of the battery, if the battery is charging or not. Another system service is a web view update service, which is super interesting and important from the security point of view. But also, he's a guy who's listening for the action package replaced intent.
So, JobScheduler system service, part of the core Android system. That's why it's only for Lollipop and works for Lollipop and this new release, Macadamia and Nugget Cake. So, we have our job. We send the job to the JobScheduler, right? What happens next? First of all, the task can be persisted between the reboots of the device.
It wasn't true with the old approach. If we send an alarm and then restart the device, the alarm is not set again when the device bots upright. We have to use the onboard completed intent for that.
So, with JobScheduler, we have our task converted into the job and then send it to the JobScheduler. What happens there? We can ask system to persist our jobs and the whole process of persisting a job is as easy as to write something into XML file. There is really no rocket science there and the only thing that is not in our reach
is that the folder is in the data system folder. So, only available for platform developers. I mean, for application that are running with certain privileges. So, not for our own application. But the code is super simple. Just write the job into XML file. Okay, so we have our job registered with the JobScheduler.
So, how the JobScheduler knows that it's time to run our task. So, the JobScheduler has so-called controllers. There are four of them. They are reporting the current state of the system. There is a network battery time and one magical controller.
So, the controller is a code that reports the JobScheduler where it's time to perform our task. Is it complicated or not? Could be, but it's not. For instance, the battery controller is basically, as we follow the red arrow on the top, basically it's a broadcast receiver.
Broadcast receiver is a common component that each of us can write, right? It doesn't require any extra privileges. So, battery controller is basically a broadcast receiver that on receive, so when time comes, gets a signal from the platform and what happens? Well, the battery controller just registers for a bunch of intents
which are publicly available intents like on battery low, on battery okay, connected, disconnected. And when the system is broadcasting the intent, the on receive method kicks in. On the next slide, I think, yeah. On the next slide, the battery controller is doing this dance with a bunch of ifs.
It's a very simple code when the battery controller is checking if the battery is low. If the battery is low, then it's setting the battery health flag to false. If the battery is okay, it's sending the flag to true. There is, of course, some code is removed here, but it's mostly common in debug stuff.
The code is as simple as this. So, the battery controller basically a broadcast receiver with a bunch of ifs inside, simply code. What's very interesting, Google gave us a job scheduler only for lollipop and up and the random guy from the internet created a compact version of the library.
It was also, for me, a strong signal that maybe there is no magic there. Maybe the code is quite obvious if a random guy from the internet created this. Of course, we know that there was a library called ActionBarSherlock. It was also created by a random guy from the internet. In that case, it was Jake Wharton. The library wasn't trivial at all. In this case, I must say the library is well done.
It works like on new devices. The library is using the native API and the older devices, I mean, lesser than lollipop, it's mimicking the behavior of a job scheduler. What does it mean for us developers? It means that we can write an application using this API
and doesn't be afraid to publish the application or have to rewrite the code. Okay, job scheduler for lollipop and up and for all the devices, let's create something based on alarm manager. Thanks to one guy from the internet and the fact that the code is quite simple,
we have this compact version and let's see what's the difference. This is job scheduler from the lollipop. So we have the central thing, job scheduler service in the middle. It's a system service. There are controllers on your right that are reporting to the job scheduler and there are three applications. In this case, we have Google Plus app,
Facebook and let's say eBay applications. They are registering scheduling jobs to the system service. This is a big picture of job scheduler in the action. How does the compact version works? Very simple. Like I said, the only thing that the guy couldn't recreate was the job scheduler being a system service.
So basically, each application has his own job scheduler service. It basically means that the whole stuff is, let's say, not as good in the performance as the Google version because each job scheduler requires more RAM
because it's running in separate application. There is no common basket of all jobs, right? So this is the difference between compact version, sorry, the version from lollipop and the compact version. The stuff in the middle because it wasn't in the reach of the guy not working for Google and having a chance to work with the platform.
But Google fixed that, not by making a separate version of job scheduler. They fixed that by doing something called GCM Network Manager, which is something super new from the Google IO and basically it's part of Google Cloud Messaging version 3.
How it works? It's not connected to the sending messages, to the Cloud Messaging platform. In this way, it's not meant to send messages to the devices. It's a tool to register.
In the case of GCM, it's called Task. In a job scheduler, there were jobs. Here we have tasks. If we compare the constraints we can set on the left are tasks, on the right are tasks from GCM on the left, on the right are jobs from job scheduler. If we compare the constraints we can use, the only difference is here that we cannot use this idle mode.
We'll talk about the idle mode in a bit. The rest is very similar. I guess that Google created this because the job scheduler API is not easy to use because it's only for Lollipop. So I guess that the usage is very low and the guys from Google decided that let's do the thing in GCM.
What's important here, the GCM is part of Google Play Services. So it's available also on devices per Lollipop, right? This is another version that you can use. This is a slide about this. There are similarities here. This is a tool we can use to use job scheduler API
on other devices than with Lollipop. But let's get back to the job scheduler. I think that this is the most interesting part because, as you remember, there were four controllers. There are four controllers available for us. Battery network, battery network, charging.
Four controllers, this is the fourth one, right? And this is the last controller that cured my inferiority complex. We'll see how the code works. But before we see how the code works, let's see what guys from Google will tell us about this mode, idle mode.
The next thing we'll introduce is idle mode. So this is, as it sounds like, a period of time for which the system is determined that the phone is not being used. And it's not likely to be used any time soon. So just to take an example, if you set up a job that required idle mode and also charging,
this would probably be executed sometime at night when the user is sleeping and the phone is plugged into the wall on their bedside table next to them. And from a battery perspective, you can't do much better than that. You can hammer the CPU, you can do whatever you want. The user isn't around to see any of this stuff. And when they wake up in the morning,
the battery is at 100% because it was plugged in all night. We've also consolidated a bunch of... Okay, so have you noticed that the guy on the left was laughing a bit at the end? No? Anyways, I can skip that. This is the idle mode, the fourth controller. System knows that the phone is not being used and it's not likely to be used any time soon.
That's the quote from the video. My question is, does it create such an algorithm or not? The phone is not being used and it's not likely to be used any time soon. The phone, like in your pockets or in your bags, or this one here, how to tell that it's not being used?
This part is quite easy, right? And it's not likely to be used any time soon. Also, there is an example from the same video. If we ask the job scheduler, setting, creating the job or the task from the new API, and creating the job, we say that we want the idle state and charging. From the video, it was said that it most probably will happen at night
when the phone is next to your bed. Not easy, right? So let's say, before we go to the details, let's make one digression here. So with the Google, there is no one Google, right? There are many Googles because of their business and ads.
They can target each of us differently, right? They understand my behavior on the Internet, so I see different ads than you guys. They also understand many different things if it goes to the, let's say, money and ad-related business. Search, ad-related, I search for Cristiano Ronaldo
that was said that was dumped by his current back-then girlfriend, Irina Shaikh, I think. So on the left, a bit different result than on the right. Pictures are higher in the search results on the left, lower in the right, even if it's just one search result.
Also at the bottom, there are some, let's say, follow-up searches suggestions that are a bit different. Another product, when all the power of Google is visible, also in the search, I searched for Nexus 6, and the first is an ad for a shop that's nearby the place I live, so it's only for me, right?
It makes sense only for me. Another thing, it's also paid service. Google Play Music, there is a recommended for you section, right, with different kinds of music. So for me, it's Eric Clapton that's good. So if it goes to money, Google is very good about,
you know, making it targeted on each of us, right? So we're almost in the details. So we know that there is strong marketing of their technologies, and to be honest, as developers, we should be thankful for that because we have lots of videos, DevBytes videos, we can learn about their technologies,
they are blog posts, they are very active also on Google+. There are some bold statements there in those videos, so it's quite funny, and if we see all those videos and those bold statements, we can think that there is a gap, big gap between us, you know, mortal developers and those rock stars from Google,
and at the end, it is proven that Google is capable of doing really huge things, right? Let's say that with their ads business. So let's say how it works that the last controller, so-called idle state algorithm, or maybe idle state algorithm. First of all, let me explain the quotes here.
So the quotes are actually not mine, they are in the code. If you follow the red arrow, quote is in the comment, and the quote was written by a guy from Google, so I can imagine that the guy was writing the code, and for him it was like, it's idle, it's not idle, it's idle.
But let's go and see if it's possible for the code to detect that the phone is not likely to be used and is lying next to my bed. So the idle state algorithm created, available in the job scheduler works like this. When the display turns off, just like in my phone,
this timer is set for 71 minutes, plus minus 5 minutes. 71 minutes. It's defined the code, 71 minutes. Then, if the alarm goes off, we check. If the screen is still off, so the screen was off for 71 minutes, a bit more maybe, then we are in the idle state.
If the screen is on, it means we are not in the idle state. So for me, if I press the power button, just to see the time, and turn off the display, the device is no longer in the idle mode, but of course, it's in the idle mode, because I'm having a presentation. So I can imagine that if Google has my calendar, right,
and I have a presentation, so I guess they could use that in the algorithm, right? Are they using that? Not really. Let's see if I'm joking or not. No. So the code goes like this. The idle controller is the same as the battery controller. So basically, it's just a broadcast receiver.
As required by broadcast receiver, there is an onReceive method. Inside this method, there is a bunch of ifs. They are checking if the screen goes off, basically by receiving the intent that the screen was turned off or the drink was started. So if the screen was turned off, they start an alarm, right? The red arrow here.
Next slide. This is a way to get out of the, sorry, to break the timer, right? So if the screen is turned on, they cancel the alarm so that the timer won't go off and they won't enable the idle mode. And the last thing here is, of course,
when we receive after 71 minutes more or less the action trigger idle intent, we turn on the idle mode. So to look at this from the different perspective, time is not a factor in this case. I mean, time is a factor because we have those 71 minutes,
but there is no way to say that it will happen at night. So it's not like at night, right? Next, sensors are not being used. So it's hard to tell that the device will be lying next to my bed, right? Of course, there is something which is new, Android Does. I guess I pronounced it correctly or not.
There is another tool by Google to help with battery life. Maybe it's using sensor, but idle controller from Lollipop is not using. The only factor in the whole algorithm is the screen. Is it turned off or not? And what's, let's say, funny here is it's not tuned per user basis.
I have a wear and my wear was like, let's move around for 10 days and now we learn how you exercise throughout the day, basically move throughout the day and try to find the amount of steps you are making on average so I can see if you are above or below the average. So with the wear, they are learning about my behavior.
With the idle state, there is no such thing. There is this random 71 minutes here. So there will be a Q&A session at the end, but I was asked about the 71 minutes, if it's just random 71 minutes. I can imagine that it can be random 71 minutes
because somebody thought that it's random 71 minutes or maybe here is the whole power of Google. They are getting data from our devices. They made a query on their big database of data and they come up with the 71 minutes thing. So here, maybe in this 71 minutes is the whole magic of the whole algorithm,
but then in the quote it was like idle. So the guy who was writing the quote, he didn't have, I think, the information about 71 minutes because maybe there will be a comment. Now let's set it for 71 minutes because we have seen that it's the average of something. There is no clue in the quote or the comment messages,
so maybe here is the answer. So my takeaway is for you, one more thing about, sorry, for the 71 minutes, with the job scheduler API, there is something called stable charging mode. So the stable charging mode, if you can imagine, it's when you connect your phone to the charger.
If the charger is connected for more than two minutes, it means that your phone is in the stable charging mode. For me it's also like let's set some random timer and call it stable charging. It doesn't mean that it will be charging for the next ten minutes, right? It only means that it's charging for two minutes.
So this random two minutes, not a minute and a half or two minutes and ten seconds, this two minutes and this 71 minutes here, for me it's just a random number set in the code. At the end, my takeaway for you guys is as follows. Don't be afraid to look at the code.
If you go to the developer Android com, the get sources section, you will see that you need lots of space on your device to download. If you're using a Mac, you need a special partition because a Mac file system is not case sensitive, right? So you may have a feeling that it's hard to get the sources,
but it's not that hard. You don't need like ten gigabits of space. You can go to the GitHub and you can download each packet separately and the whole framework, the whole Java of Android framework is like 20 megabits, something like that. So don't be afraid to look there. There is no rocket science there. By looking at the code, you can cure yourself from various complexes.
Another thing is don't be afraid to write code. Don't be afraid to call something a project, to put it on the GitHub, even if it's a crappy code, just like our code from the markup session, which I know doesn't work with Android 5.0 and up. It's only for Lollipop.
It's awful C code there, but I'm not afraid to put code on the GitHub and to receive some even random comments from a stranger that it works or not. Anyways, write code, put it online, don't be afraid. And at the end, thanks a lot for DroidCon Berlin for inviting me and you guys here
and for you for attending my talk. Last question because there are always questions and maybe I will start with the questions. My question is, is it true that all of you know Kotlin? Because there is a Kotlin session on stage one. Okay, okay. So thank a lot for attending my talk
and not the Kotlin session.