[MUSIC PLAYING]
JONATHAN HURWITZ: Thanks for coming, everyone.
So today, I'm going to be talking
about managing Bluetooth companion devices,
and I need a clicker.
So OK, so today, this is a lot harder
than it actually has to be.
So I'm going to talk to some of the pain points we have today,
and I actually stole an example from my friend, Tim,
who recently bought a smartwatch this weekend.
So we're going to walk through actually the steps he went
through with his companion app.
And I'm not going to call out the brand--
you know who you are if you're in the room.
So Tim got this new smartwatch, and he
wouldn't stop talking about all the exciting use
case he wanted to do, step tracking, calorie counting,
and he was really excited to read his sleep graphs.
And if you notice, all of these things
require the companion app as the interface to look at the graphs
and look at the long-term data because the watch has
a finite amount of storage, but servers have a larger amount
of finite storage.
So he unboxed it, and he downloaded the app.
And here's all the things he had to go through to set this up.
So the first thing is the app will tell
him make sure your watch is on.
Make sure it's nearby.
And we're going to start scanning for it.
And for the app to actually do this,
it needs to initiate a BLE scan to find the device.
So BLE and Wi-Fi scans can actually
compromise a user's location.
And we gate them behind a fine location permission
as of Android Q. The way in which a BLE scan can compromise
location is by either a device name, a unique string that
might be in an advertising packet, or by the MAC address.
So the app will have to actually request the location permission
from Tim.
I've called this out with a red arrow
because this is very confusing for users.
They don't understand why BLE and Wi-Fi equals location.
To them, location equals GPS.
And so this is bad for everyone because if they
decline that permission request, you don't get to do your scan.
You can't connect your device, and you get a pissed off user
who says, your device sucks, and we suck
at making operating systems.
So finally, we're at the point where Tim has actually
accepted it begrudgingly, and his app can do that BLE scan.
So it finds the watch, and he presses and taps and connects.
So this took five steps to do something
that should be a lot simpler.
So we're going to take this and turn it into this.
And so the way we do that is by actually
pushing a lot of the hard effort into the Android system.
And so what your app will do is it will essentially request
the Android system do the scan.
And then the system will present the results
to the user in a list that you can filter
by specifying a scan filter.
And then the user will tap that, and that single scan result
is passed back to the app, not the full list.
The beauty of this is you don't have
to request location permission.
In addition, in the next version of Android,
we're going to introduce the ability for this
to do scans, even if the global location toggle in settings
is off.
If you manage your own scans right now,
you can't do a scan if the global location toggle was off,
and that is not going to change for you in the next version
of Android, so use this.
And as I mentioned before, with our current Bluetooth API,
you can actually already specify a scan filter in Bluetooth--
at least scanner.startscan.
There's an option for that.
With this, you can do the same thing.
So if you really want to just find one device
and you don't want the user to look at a list,
you can instead pop a dialog where the user will just
be able to press Connect.
And it will find your exact device
based on your scan filter.
So few more benefits for you--
you can get a certain set of special powers
by specifying these in your manifest-- the ability to run
in the background, ability to do data in the background.
And it makes your life easier when it comes to notifications.
All of this is online in terms of documentation.
So I'm zooming through this, but you'll
be able to look at it after.
So here's an example of what it looks like.
This is an example from Wear OS.
You can see on the third screen is
that list I was talking about.
This is the case where the developer has not
specified a scan filter.
So if there were more devices when
I made this example in the room, you'd
see more things than just this generic smartwatch.
But what'll happen is the user will tap on that result
will be returned to the app.
It's up to the app what they want to do with that.
So you can do nothing, or you can pair and connect
to the device.
And in this case, we've gone through that flow.
And so you can check out a ping sample on the left, an API
example on the right.
Both of these sets of documentation
are going to get a lot better in the next few weeks.
So check today but please come back and check again.
We're going to make the example a little bit easier to read,
possibly add a few more.
So thank you so much.
[APPLAUSE]
[MUSIC PLAYING]