Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Anton Minashkin] Random Musings on the Android...

[Anton Minashkin] Random Musings on the Android Things

Presentation from GDG DevFest Ukraine 2017 - the biggest community-driven Google tech conference in the CEE.

Learn more at: https://devfest.gdg.org.ua

Google Developers Group Lviv

October 13, 2017
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Technology

Transcript

  1. #dfua Behavior Changes • UI • One application • Core

    application packages • Support for Google services
  2. #dfua Behavior Changes • UI • One application • Core

    application packages • Support for Google services
  3. #dfua UI • same UI toolkit • application window occupies

    the full real estate of the display • no system status bar or navigation buttons • display is not required
  4. #dfua Behavior Changes • UI • One application • Core

    application packages • Support for Google services
  5. #dfua One application • one app with Home activity •

    Home activity will be launched automatically on boot • must contain both CATEGORY_DEFAULT and IOT_LAUNCHER intent filters
  6. #dfua Behavior Changes • UI • One application • Core

    application packages • Support for Google services
  7. #dfua Core application packages • Standart suite of System Apps

    is not included • Avoid using common intents • Avoid using next content providers:
  8. #dfua Behavior Changes • UI • One application • Core

    application packages • Support for Google services
  9. #dfua Support for Google services General rule: APIs that require

    user input or authentication credentials aren't available to apps
  10. #dfua User-Space Drivers User drivers are components registered from within

    apps that extend existing Android framework services.
  11. #dfua User-Space Drivers They allow any application to inject hardware

    events into the framework that other apps can process using the standard Android APIs.
  12. #dfua Device Driver Types: GPS The GPS user driver allows

    your app to publish updates to the device's physical location through the Android location services.
  13. #dfua Device Driver Types: GPS The framework only supports a

    single source for GPS location data. You cannot register multiple GPS drivers.
  14. #dfua Device Driver Types: GPS ... // Create a new

    driver implementation mDriver = new GpsDriver(); // Register with the framework UserDriverManager manager = UserDriverManager.getManager(); manager.registerGpsDriver(mDriver); ...
  15. #dfua Device Driver Types: GPS public void handleLocationUpdate(String rawGpsData) {

    // Convert raw data into a location object Location location = parseLocationFromString(rawGpsData); // Send the location update to the framework mDriver.reportLocation(location); }
  16. #dfua Device Driver Types: GPS public void handleLocationUpdate(String rawGpsData) {

    // Convert raw data into a location object Location location = parseLocationFromString(rawGpsData); // Send the location update to the framework mDriver.reportLocation(location); }
  17. #dfua Device Driver Types: HID Input user drivers provide an

    interface for apps to inject events into Android's input pipeline
  18. #dfua Device Driver Types: HID • 30+ input sources •

    deliver events to Foreground Activity
  19. #dfua Device Driver Types: HID // Create a new driver

    instance mDriver = InputDriver.builder(InputDevice.SOURCE_CLASS_BUTTON) .setName(DRIVER_NAME) .setVersion(DRIVER_VERSION) .setKeys(new int[] {KEY_CODE}) .build();
  20. #dfua Device Driver Types: HID // Register with the framework

    UserDriverManager manager = UserDriverManager.getManager(); manager.registerInputDriver(mDriver);
  21. #dfua Device Driver Types: HID // A state change has

    occurred private void triggerEvent(boolean pressed) { ... KeyEvent[] events = ... if (!mDriver.emit(events)) { Log.w(TAG, "Unable to emit key event"); } }
  22. #dfua Device Driver Types: HID // A state change has

    occurred private void triggerEvent(boolean pressed) { ... KeyEvent[] events = ... if (!mDriver.emit(events)) { Log.w(TAG, "Unable to emit key event"); } } synchronously | all or nothing
  23. #dfua Device Driver Types: Sensors • ~30 Sensor types •

    ...and custom types as well • supports Sensors with sleeping mode
  24. #dfua Device Driver Types: Sensors The data from these sensors

    is delivered through the same SensorManager APIs as the built-in Android sensors
  25. #dfua Device Driver Types: Sensors The framework polls your driver

    periodically when listeners are registered for sensor updates
  26. #dfua Device Driver Types: Sensors UserSensorDriver mDriver = new UserSensorDriver()

    { ... @Override public UserSensorReading read() { ... return new UserSensorReading(new float[]{...}); } };
  27. #dfua Device Driver Types: Sensors UserSensorDriver mDriver = new UserSensorDriver()

    { ... // Called by the framework to toggle low power modes @Override public void setEnabled(boolean enabled) { if (enabled) { // Exit low power mode } else { // Enter low power mode } } };
  28. #dfua Device Driver Types: Sensors UserSensor accelerometer = UserSensor.builder() .setName("GroveAccelerometer")

    .setVendor("Seeed") .setType(Sensor.TYPE_ACCELEROMETER) .setDriver(mDriver) .build();
  29. #dfua Device Driver Types: Sensors UserDriverManager manager = UserDriverManager.getManager(); //

    Create a new driver implementation mAccelerometer = ...; // Register the new driver with the framework manager.registerSensor(mAccelerometer);
  30. #dfua Device Driver Types: Sensors FUN FACT: ServiceManager contains a

    lot of different constants, including: • GRAVITY_DEATH_STAR_I (3.5303614E-7) • GRAVITY_THE_ISLAND (4.815162) • LIGHT_FULLMOON/NO_MOON/CLOUDY
  31. #dfua Device Driver Types: Sensors FUN FACT: ServiceManager contains a

    lot of different constants, including: • GRAVITY_DEATH_STAR_I (3.5303614E-7) • GRAVITY_THE_ISLAND (4.815162) • LIGHT_FULLMOON/NO_MOON/CLOUDY
  32. #dfua Device Driver Types: Sensors FUN FACT: ServiceManager contains a

    lot of different constants, including: • GRAVITY_DEATH_STAR_I (3.5303614E-7) • GRAVITY_THE_ISLAND (4.815162) • LIGHT_FULLMOON/NO_MOON/CLOUDY
  33. #dfua Device Driver Types Using audio drivers, your apps can

    register new audio input/output devices
  34. #dfua Device Driver Types public class PlaybackDriver extends AudioOutputDriver {

    @Override public void onStandbyChanged(boolean inStandby) { ... } @Override public int write(ByteBuffer buffer, int count) { ... } }
  35. #dfua Device Driver Types public class PlaybackDriver extends AudioOutputDriver {

    @Override public void onStandbyChanged(boolean inStandby) { ... } @Override public int write(ByteBuffer buffer, int count) { ... } }
  36. #dfua Device Driver Types public class PlaybackDriver extends AudioOutputDriver {

    @Override public void onStandbyChanged(boolean inStandby) { ... } @Override public int write(ByteBuffer buffer, int count) { ... } }
  37. #dfua Connectivity | Peripheral I/O • General Purpose Input/Output (GPIO)

    • Pulse Width Modulation (PWM) • Serial Communication (I2C/SPI/UART)
  38. #dfua Connectivity | Peripheral I/O • General Purpose Input/Output (GPIO)

    • Pulse Width Modulation (PWM) • Serial Communication (I2C/SPI/UART)
  39. #dfua GPIO GPIO pins provide a programmable interface to read

    the state of a binary input device or control the on/off state of a binary output device.
  40. #dfua GPIO ... private Gpio mGpio; @Override protected void onCreate(Bundle

    savedInstanceState) { ... PeripheralManagerService manager = new PeripheralManagerService(); mGpio = manager.openGpio(GPIO_NAME); ... }
  41. #dfua GPIO @Override protected void onDestroy() { ... if (mGpio

    != null) { mGpio.close(); mGpio = null; } ... }
  42. #dfua GPIO ... // Initialize the pin as a high

    output gpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_HIGH); // Low voltage is considered active gpio.setActiveType(Gpio.ACTIVE_LOW); ... // Toggle the value to be LOW gpio.setValue(true); ...
  43. #dfua GPIO ... // Initialize the pin as a high

    output gpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_HIGH); // Low voltage is considered active gpio.setActiveType(Gpio.ACTIVE_LOW); ... // Toggle the value to be LOW gpio.setValue(true); ...
  44. #dfua Connectivity | Peripheral I/O • General Purpose Input/Output (GPIO)

    • Pulse Width Modulation (PWM) • Serial Communication (I2C/SPI/UART)
  45. #dfua PWM PWM is a common method used to apply

    a proportional control signal to an external device using a digital output pin.
  46. #dfua PWM • The frequency (Hz) - how often the

    output pulse repeats. • The period is the time each cycle takes. • The duty cycle (%) describes the width of the pulse within that frequency window.
  47. #dfua PWM Most PWM hardware has to toggle at least

    once per cycle, so even duty values of 0% and 100% will have a small transition at the beginning of each cycle.
  48. #dfua PWM public void initializePwm(Pwm pwm) throws IOException { pwm.setPwmFrequencyHz(120);

    pwm.setPwmDutyCycle(25); // Enable the PWM signal pwm.setEnabled(true); }
  49. #dfua Connectivity | Peripheral I/O • General Purpose Input/Output (GPIO)

    • Pulse Width Modulation (PWM) • Serial Communication (I2C/SPI/UART)
  50. #dfua Serial Communication The Inter-Integrated Circuit (IIC or I2C) bus

    connects simple peripheral devices with small data payloads (e.g. sensors).
  51. #dfua Serial Communication Serial Peripheral Interface (SPI) devices are typically

    found where fast data transfer rates are required (e.g. Graphical displays)
  52. #dfua Serial Communication Complex peripheral devices such as GPS modules,

    LCD displays, and XBee radios typically use Universal Asynchronous Receiver Transmitter (UART) ports (often simply called serial ports) to communicate.
  53. #dfua Advanced stuff: Cloud Cloud IoT Core is a fully

    managed service that allows you to easily and securely connect, manage, and ingest data from millions of globally dispersed devices
  54. #dfua Protocol bridge The protocol bridge provides connection endpoints for

    protocols with automatic load balancing for all device connections
  55. #dfua Protocol bridge The protocol bridge has native support for

    secure connection over industry standard protocols such as MQTT, HTTP
  56. #dfua Protocol bridge The protocol bridge publishes all device telemetry

    to Cloud Pub/Sub, which can then be consumed by downstream analytic systems.
  57. #dfua Cloud: Other features • Fully managed and scalable •

    Role-level access control • Device deployment at scale
  58. #dfua Cloud: Other features • Fully managed and scalable •

    Role-level access control • Device deployment at scale
  59. #dfua Worth to mention Notifications are not supported. Avoid calling

    the NotificationManager APIs in your apps. (Because there is no status bar)
  60. #dfua Worth to mention Dangerous permissions are granted on the

    next device reboot and do not require run time checks
  61. #dfua Worth to mention No ANR anymore! You can do

    computation on a Main Thread (but probably you shouldn’t)
  62. #dfua Summary • Good for quick prototyping • Java/Kotlin >

    C/C++ • Still not production ready • Much fun • So experience