Profile

Cover photo
Dianne Hackborn
Works at Google (Android)
Attended Oregon State University
Lives in California
29,992 followers|3,655,449 views
AboutPostsPhotosVideos

Stream

Dianne Hackborn

Shared publicly  - 
 
Yay, pineapple guava season has started! First ones on the ground, ready to eat. :)
46
Theo Franzén's profile photoRay Ryan's profile photoDianne Hackborn's profile photokhalid hussain's profile photo
9 comments
 
Wow Amazing 
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
Best boss battle music ever?
4
Jeff Bottaro's profile photo
 
Bullfight music for the clinically depressed. I love it.
Add a comment...

Dianne Hackborn

Shared publicly  - 
19
2
Mike Wolfson's profile photo
 
Agreed, so great!  Thanks for sharing.
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
Ah it's been a while since I listened to this stuff. So good!
8
1
yogesh gohel's profile photo
 
Owow
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
For Android developers, I'd like to especially point out this I/O video as one to watch. It covers some of the significant changes we have been making to platform behavior to improve battery life, changes which impact all apps.

We did a lot of the outreach to apps back in Marshmallow when doze was first introduces (since it is a rare case where it impacts all apps, not just ones that target a new platform version); however, with doze light in N, it is even more important that apps follow those recommendations so they continue to work correctly. We had to make the initial doze behavior in Marshmallow fairly conservative to mitigate its impact on existing apps... but now that we've had it out there and worked with developers to update their apps, we can start tightening the screws down. :)

The presentation also gives a preview of some significant behavior changes we plan on making to the platform in a future release, related to broadcast receivers and services. This is I think the largest application model change we have ever made to the platform, so it is well worth taking a look at it now so you can prepare for when it hits. Unlike doze, we plan (at least for now) on this being something that doesn't apply to existing apps, only apps that target the newer platform version. (And many changes you make today to have your app compatible with these future restrictions will also have a positive impact for our users on current devices!)
177
62
Ian Lake's profile photoStephen Charman's profile photoDianne Hackborn's profile photoGreg S's profile photo
22 comments
Greg S
 
Even in regular light I rarely move the brightness up from the minimum. In direct sunlight of course it needs to be high. But indoor electric lights the screen on every Nexus phone has been more than bright enough the minimum setting.

On the occasions when my screen is mostly off the phone lasts nearly forever. That happens with my spare phone when I'm traveling. It basically ends up being a podcast player and I only have to charge it every 2 or 3 days.

My main phone needs to be charged at least once midday to make it through the day and sometimes twice. And the power consumption reported is always much higher for the screen than the rest of the consumers put together.

The latter part sounds relevant and interesting. Sounds like a worthwhile engineering problem to tackle. 
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
Very good video on optimizing apk size. One thing worth mentioning that I have started to see as an anti-pattern is compressing the resource table in the apk. Don't do that! :)

When aapt generates the resource table file in your apk it always stores it uncompressed, and this is very deliberate: on the device the system can then just directly mmap that file from the apk; however, if that file has been compressed then, each time the resources are loaded, they need to be decompressed in to a local RAM allocation for the entire size of the file. Using mmap is significantly more efficient, since it only needs to load in to RAM the parts of the resource table that are actually used (think about all the different languages you may have, for example, when only one of them is going to be used), can share this mapping across all processes using the file, and the system can even page out parts of the file it doesn't currently need.

Compressing the resource table also helps other things much less than you may think. For example, when the play store is delivering an apk to a device, it is also compressing the entire apk that it transferred -- so you still get the full benefit of compression when considering the network traffic needed. In fact, an uncompressed resource table may be even better when delivering updates to the apk, since the play store will better be able to generate a delta update between the old and new resource table.

So the only place a compressed resource table really helps is in at-rest storage on disk. But this comes at a significant cost of much more RAM used at runtime, and this cost can hit you all over the place: if you have multiple processes, each process will need to load its own copy, and other application processes (such as the launcher or share dialog or notification UI) will need to decompress into its own RAM the entire resource table whenever it needs to load resources from your application. Ouch!

Let the system mmap that file. :)
101
10
Greg S's profile photo
Greg S
+
5
6
5
 
Can you send this link to the engineers at Google? I've actually had to start uninstalling updates and disabling Google apps because I don't have enough storage on my older devices and the biggest apps by a huge margin are sheets, slides, docs, drive, calendar, play books, play movies, games, news, etc. They're one and sometimes two orders of magnitude larger than the apps I use most.
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
Have a look at this Kickstarter being done by a friend of mine, who I have worked with on and off over many years and is a pretty awesome engineer. It looks like they are doing some pretty cool things, if you are in to this kind of game.
Lead a squad of genetically enhanced super-spies to save the world in this turn-based tactical squad RPG.
11
1
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
I will be participating in this!
 
Upcoming AMA with Android engineering team, July 19 @12pm PT * /r/androiddev

The Android engineering team will participate in its first ever AMA on /r/androiddev this Tuesday, July 19 from 12-2pm PT.

This will be your chance to ask us any and every technical question related to the development of the Android platform -- from the APIs and SDK to specific features. Please note that we want to keep the conversation focused strictly on the engineering of the platform.

https://goo.gl/8bRZKN
5 comments on original post
99
8
John Bump's profile photoMarty Ballard's profile photo
2 comments
 
I'll be lurking on the thread, hoping to gain some knowledge!
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
I very much enjoyed the new Ghostbusters. I didn't find the basic story as interesting as the original one (which I think is both for the better and worse), but it was pretty continually entertaining with a lot of great jokes.

This is also the first time I have gone out to see a recent movie at an actual movie theater in I-don't-know-how-long, solely due to all the nasty negative stuff being said about it. So good job on that!
48
Christopher Tate's profile photoDianne Hackborn's profile photoJason Sams's profile photo
13 comments
 
I think it's facing two negative issues.  It's the only movie that comes to mind really triggered both.  Either one could generate some negativity but combined I really think pushed it over the tipping point where it snowballed.
Actually looking for the 538 link I realized they ran two articles on this, not just one.  The older and I think better article was here. http://fivethirtyeight.com/features/men-are-sabotaging-the-online-reviews-of-tv-shows-aimed-at-women/
Add a comment...

Dianne Hackborn

Shared publicly  - 
27
4
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
"How should I design my Android application? What kind of MVC pattern should I use? What should I use for an event bus?"

We often see questions from developers that are asking from the Android platform engineers about the kinds of design patterns and architectures they use in their apps. But the answer, maybe surprisingly, is we often don't have a strong opinion or really an opinion at all.

(Edit to clarify: when I write "we" here I am talking about the Android platform team. I am not speaking for all of Google or Android developer relations. There are lots of good suggestions and opinions inside and outside of Google about how to write apps, and I am not intending to dismiss those.)

Should you use MVC? Or MVP? Or MVVM? I have no idea. Heck, I only know about MVC from school and had to do a Google search to find other options to put here.

This may be surprising, because Android could feel like it has strong opinions on how apps should be written. With its Java language APIs and fairly high-level concepts, it can look like a typical application framework that is there to say how applications should be doing their work. But for the most part, it is not.

It is probably better to call the core Android APIs a "system framework." For the most part, the platform APIs we provide are there to define how an application interacts with the operating system; but for anything going on purely within the app, these APIs are often just not relevant.

That said, the Android APIs can often look different (or higher level) from what one typically expects in an operating system, which may easily lead to confusion about how they should be used.

For an example of this, let's consider how an operating system defines "how to run an app." In a classic system, this is basically the contract it has with an application about when it should run:

int main(...) {
// My app goes here!
}

So the operating system starts the app, calls its main() function, and the app goes off and runs and does what it wants until it decides it is done. And clearly it is not saying anything here about what the app should be doing or how it should be designed within that main function -- it's a pretty pure blank slate.

In Android, however, we explicitly decided we were not going to have a main() function, because we needed to give the platform more control over how an app runs. In particular, we wanted to build a system where the user never needed to think about starting and stopping apps, but rather the system took care of this for them... so the system had to have some more information about what is going on inside of each app, and be able to launch apps in various well-defined ways whenever it is needed even if it currently isn't running.

To accomplish this, we decomposed the typical main entry point of an app into a few different types of interactions the system can have with it. And these are the Activity, BroadcastReceiver, Service, and ContentProvider APIs that Android developers quickly become familiar with.

These classes may look like they are telling you how the internals of your app should work, but they are not! In fact, they are all about how your app needs to interact with the system (and how the system can coordinate its interaction with other apps). As long as that interaction with the system happens, we don't really care what goes on inside of the app.

To illustrate, let's briefly look at these different APIs and what they really mean to the Android system.

Activity

This is the entry into an application for interacting with the user. From the system's perspective, the key interactions it provides with the app are:

• Keep track of what the user currently cares about (what is on screen) to ensure the process hosting that is kept running.
• Know that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around.
• Help the application deal with the situation where its process is killed so the user can return to activities with their previous state restored.
• Provide a way for applications to implement user flows between each other, coordinated by the system. (The most classic example here being share.)

What we don't care about:

Once we have gotten in to this entry-point to your UI, we really don't care how you organize the flow inside. Make it all one activity with manual changes to its views, use fragments (a convenience framework we provide) or some other framework, or split it into additional internal activities. Or do all three as needed. As long as you are following the high-level contact of activity (it launches in the proper state, and saves/restores in the current state), it doesn't matter to the system.

BroadcastReceiver

This is a mechanism for the system to deliver events to the application that may be outside of a regular user flow. Most importantly, because this is another well-defined entry into the app, the system can deliver broadcasts to apps even if they aren't currently running. So, for example, an app can schedule an alarm to post a notification to tell the user about an upcoming event... and by delivering that alarm to a BroadcastReceiver of the app, there is no need for the app to remain running until the alarm goes off.

What we don't care about:

Dispatching events within an app is an entirely different thing. Whether you use some event bus framework, implement your own callback system, whatever... there is no reason to use the system's broadcasting mechanism, since you aren't dispatching events across apps. (In fact there is good reason not to -- there is a lot of unnecessary overhead and many potential security issues if using a global broadcast mechanism for the internal implementation of an app.) We do provide the LocalBroadcastManager convenience class that implements a purely in-process intent dispatching system with a similar API to the system's APIs, if you happen to like them. But again, there is no reason to use that over something else for things going on purely within your app.

Service

A general-purpose entry point for keeping an app running in the background for all kinds of reasons. There are actually two very distinct semantics services tell the system about how to manage an app:

Started services are simply telling the system to, for some reason, "keep me running until I say I am done." This could be to sync some data in the background or play music even after the user leaves the app. Those also represent two different types of started services that modify how the system handles them:

• Music playback is something the user is directly aware of, so the app tells the system this by saying it wants to be foreground with a notification to tell the user about it; in this case the system knows that it should try really hard to keep that service's process running, because the user will be unhappy if it goes away.

• A regular background service is not something the user is directly aware as running, so the system has more freedom in managing its process. It may allow it to be killed (and then restarting the service sometime later) if it needs RAM for things that are of more immediate concern to the user.

Bound services are running because some other app (or the system) has said that it wants to make use of the service. This is basically the service providing an API to another process. The system thus knows there is a dependency between these processes, so if process A is bound to a service in process B, it knows that it needs to keep process B (and its service) running for A. Further, if process A is something the user cares about, than it also knows to treat process B as something the user also cares about.

Because of their flexibility (for better or worse), services have turned out to be a really useful building block for all kinds of higher-level system concepts. Live wallpapers, notification listeners, screen savers, input methods, accessibility services, and many other core system features are all built as services that applications implement and the system binds to when they should be running.

What we don't care about:

Android doesn't care about things going on within your app that don't have any impact on how it should manage your process, so there is no reason to use services in these cases. For example, if you want to start some background operation to download data for your UI, you should not use a service for this -- it is actually important to not be telling the system to keep your process running while doing this, because it really doesn't need to be and the system would be better off having more freedom in managing it with other things the user is doing.

If you just make a simple background thread (or whatever non-service mechanism you want) to do the downloading, you will get the semantics you want: while the user is in your UI, the system will keep your process running for that, so the download will never be interrupted. When they leave your UI, your process will still be kept around (cached) and able to continue downloading, as long as its RAM isn't needed elsewhere.

Likewise for connecting different parts of your app together, there is no reason to bind to a service that is running in the same process as the one binding to it. Doing so is not actively harmful -- the system just sees a dependency from the process to itself so doesn't try to keep it around any more than usual -- but it is a bunch of unnecessary work for both you and the system. Instead, you can just use singletons or other normal in-process patterns for connecting pieces of your app together.

ContentProvider

Finally, the ContentProvider is a fairly specialized facility for publishing data from an app to other places. People generally think of them as an abstraction on a database, because there is a lot of API and support built in to them for that common case... but from the system design perspective, that isn't their point.

What these are to the system is an entry-point into an app for publishing named data items, identified by a URI scheme. Thus an app can decide how it wants to map the data it contains to a URI namespace, handing out those URIs to other entities which can in turn use them to access the data. There are a few particular things this allows the system to do in managing an app:

• Handing out a URI doesn't require the app remain running, so these can go all over the place with the owning app being dead. Only at the point where someone tells the system, "hey give me the data for this URI" does it need to make sure the app owning that data is running, so it can ask the app to retrieve and return the data.

• These URIs also provide an important fine-grained security model. For example, an application can place the URI for an image it has on the clipboard, but leave its content provider locked up so nobody can freely access it. When another app pulls that URI off the clipboard, the system can give it a temporary "URI permission grant" so that it is allowed to access the data only behind that URI, but nothing else in the app.

What we don't care about:

It doesn't really matter how you implement the data management behind a content provider; if you don't need structured data in a SQLite database, don't use SQLite. For example, the FileProvider helper class is an easy way to make raw files in your app available through a content provider.

Also, if you are not publishing data from your app for others to use, there is no need to use a content provider at all. It is true, because of the various helpers built around content providers, this can be an easy way to put data in a SQLite database and use it to populate UI elements like a ListView. But if any of this stuff makes what you are trying to do more difficult, then feel free to not use it and instead use a more appropriate data model for your app.
895
281
Alex Bonel's profile photoŁukasz Byjoś's profile photo张小贤's profile photoDanke Xie's profile photo
69 comments
 
I personally don't think MVC, MVP and MVVM make much difference in writing good Android apps. Since they got hot recently, I did a quick research and what I found is MVP and MVVM are more relevant for web-based apps. For Android, they just say Android does not even follow the basic MVC pattern because things like CursorAdapter mix the View and the Model. For this reason, I doubt those fancy design/architectural patterns are quite practical for Android development. Common sense may suffice. I don't think Android makes it hard to write maintainable and extensible apps.
Add a comment...

Dianne Hackborn

Shared publicly  - 
 
Good to know!
 
Secure those bits!

The Android security team has been hard at work building new tools to help developers protect user data in transit.  :)  Yesterday Alex posted about two great features that shipped last year in M:

https://security.googleblog.com/2016/04/protecting-against-unintentional.html

I'm particularly proud of the strategy I came up with to help detect any plaintext traffic leaving an app using a complex pile of iptables rules.  It's super easy to enable detection in your app with just one method call to this new StrictMode API:

https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder.html#detectCleartextNetwork()

And here's the guts of where the iptables rules are generated using the powerful u32 module to do "shallow" packet inspection, both IPv4/v6 and TCP/UDP are supported:

https://android.googlesource.com/platform/system/netd/+/master/server/StrictController.cpp

Since it does bit banging to sniff out the explicit SSL 3.1 (TLS 1.0) signature, I don't recommend shipping it enabled in production, as that version number might increment in the future.
6 comments on original post
79
14
Ian Lake's profile photo
 
Great to see how it works under the covers! I talked about it in our recent StrictMode video (https://www.youtube.com/watch?v=BxTfwT7mkB4&t=91) and blog post (https://medium.com/google-developers/strictmode-for-runtime-analysis-on-android-f8d0a2c5667e)
Add a comment...
Story
Tagline
Google (Android Framework)
Education
  • Oregon State University
    Computer Science, 1989 - 1996
Basic Information
Gender
Female
Relationship
Married
Work
Occupation
Write code and manage people who write code.
Employment
  • Google (Android)
    Android Framework Engineer, 2005 - present
  • PalmSource
  • Be Inc.
  • Lucent Technologies / AT&T
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
California
Previously
Naperville, IL - Corvallis, OR - Meridian, ID