Programming Mobile Services for Android Handheld Systems: Concurrency

Course page: https://class.coursera.org/posaconcurrency-001
By Dr. Douglas C. Schmidt, Université Vanderbilt

Section 0

MOOC Introduction

MOOC Organization and Topics

Concurrency Motivations

  • To simplify Program Structure
  • To increase performances (renderscript ?)
  • Improve Responsiveness

Concurrency Challenges

  • Accidental complexities
    • using low level API:

* error-prone

  	* type casts
  	* quasi-typed thread handles
  	* non-portable
  * How to debug ?
  * Heisenbug: debugger changing execution sequence and times
  * Need Static/dynamic analysis to detect race conditions.
* Inherent complexities:
	* synchronization
	* scheduling
	* deadlock

Overview of Patterns and Frameworks

  • Patterns provide guide and architecture
  • Frameworks overview:

* inversion of control (owns the app event loop)

	* provide integrated domain specific structures
	* semi-complete applications
* Android frameworks:
	* Hammer framework
* Gang of four:
  * Template method
  * Strategy method
  * Factory method
  

Week 1

Overview of Android Layers

  • Android provides layered stack for mobile devices.
    • more flexible system.
    • Layers:
      1. Hardware (CPU, storage, wifi, sensors, etc)
      2. Variant of Linux OS (power management)
      3. Middleware infrastructure
        1. Hardware abstraction layer
        2. Java runtime environment
          1. Optimized Jva virtual machine (Dalvik or ART)
          2. subset of core java libraries
        3. C/C++ libraries
      4. Middleware frameworks
        1. GUI
        2. Telephonu
        3. Camera
        4. Multimedia
      5. Packaged apps.
  • Overview of the android linux kernel
    • Provides:
      • Virtual memory
      • Processes
      • Thread management
      • network and inter process communitation stack
      • device drivers (touch screen, USB, bluetooth)
      • android specific optimization
    • cf. Binder (IPC) Driver
    • Shared memory driver
    • Power management (⇒ wakelocks)
    • Low memory killer (oom_handling)
  • Overview of the android Hardware Abstraction Layer
    • runs in user space
    • defines the interface that the hardware drivers should implement
    • Separate concerns:
      • android platform logic / hardware
    • User space because:
      • radio interface was not standardized.
      • intellectual properties: no GPL needed for user space.
  • Overview of the Android Runtime: Java virtual machine
    • support concurrent execution of java apps
    • Virtual machine:
      • managed runtime platform
      • created/destroyed with process (cf. “zygote”)
      • Android app runs on its own process with its VM.
      • Not using standard Java VM, instead Dalvik VM.
      • Dalvik is a “register machine”
      • Dalvik being replaced by ART.
      • ART uses “ahead-of-time” compiler + better garbage collection.
      • VMs implement java's concurrency features.
  • Overview of the Android Runtime: Core Java Libraries
  • Core java classes: java.*, javax.* (some missing!)
  • Threads in process can communicate with shared objects or message passing.
  • Threads in different processes will use IPC for communication.
  • Each thread as specific info & common process shared info.
  • Overview of the Android Runtime:
    • android.*
    • Concurrency frameworks:
      • Handlers, Messages and Runnables (HaMeR)
      • AsyncTask: (cf. executeOnExecutioner)
    • Services framework
  • Overview of the Android Native C/C++ Libraries:
    • JNI
    • Android NDK: write C++ apps/perform additional optimization.
  • Overview of the Android Application Framework: