\subsection{Hardware Abstraction Layer}

\begin{frame}
  \frametitle{Whole Android Stack}
  \begin{center}
    \includegraphics[height=0.85\textheight]{slides/android-native-layer-hal/android-stack-hal.pdf}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Hardware Abstraction Layers}
  \begin{itemize}
  \item Usually, the kernel already provides a HAL for user space
  \item However, from Google's point of view, this HAL is not sufficient and
    suffers some restrictions, mostly:
    \begin{itemize}
    \item Depending on the subsystem used in the kernel, the user space
      interface differs
    \item All the code in the kernel must be GPL-licensed
    \end{itemize}
  \item Google implemented its HAL with dynamically loaded user space libraries
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Library naming}
  \begin{itemize}
  \item It follows the same naming scheme as for init: the generic
    implementation is called \code{libfoo.so} and the hardware-specific
    one \code{libfoo.hardware.so}
  \item The name of the hardware is looked up with the following properties:
    \begin{itemize}
    \item \code{ro.hardware}
    \item \code{ro.product.board}
    \item \code{ro.board.platform}
    \item \code{ro.arch}
    \end{itemize}
  \item The libraries are then searched for in the directories:
    \begin{itemize}
    \item \code{/vendor/lib/hw}
    \item \code{/system/lib/hw}
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Various layers}
  \begin{itemize}
  \item Audio (\code{libaudio.so}) configuration, mixing, noise
    cancellation, etc.
    \begin{itemize}
    \item \code{hardware/libhardware/include/audio.h}
    \end{itemize}
  \item Graphics (\code{gralloc.so}, \code{hwcomposer.so},
    \code{libhgl.so}) handles graphic memory buffer allocations,
    OpenGL implementation, etc.
    \begin{itemize}
    \item \code{libhgl.so} should be provided by your vendor
    \item \code{hardware/libhardware/include/gralloc.h}
    \item \code{hardware/libhardware/include/hwcomposer.h}
    \end{itemize}
  \item Camera (\code{libcamera.so}) handles the camera functions:
    autofocus, take a picture, etc.
    \begin{itemize}
      \item \code{hardware/libhardware/include/camera{2,3}.h}
    \end{itemize}
  \item GPS (\code{libgps.so}) configuration, data acquisition
    \begin{itemize}
    \item \code{hardware/libhardware/include/hardware/gps.h}
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Various layers}
  \begin{itemize}
  \item Lights (\code{liblights.so}) Backlight and LEDs management
    \begin{itemize}
    \item \code{hardware/libhardware/include/lights.h}
    \end{itemize}
  \item Sensors (\code{libsensors.so}) handles the various sensors on
    the device: Accelerometer, Proximity Sensor, etc.
    \begin{itemize}
    \item \code{hardware/libhardware/include/sensors.h}
    \end{itemize}
  \item Radio Interface (\code{libril-vendor-version.so}) manages all
    communication between the baseband and \code{rild}
    \begin{itemize}
    \item You can set the name of the library with the \code{rild.lib} and
      \code{rild.libargs} properties to find the library
    \item \code{hardware/ril/include/telephony/ril.h}
    \end{itemize}
  \item Bluetooth (\code{libbluetooth.so}) Discovery and communication
    with Bluetooth devices
    \begin{itemize}
    \item \code{hardware/libhardware/include/bluetooth.h}
    \end{itemize}
  \item NFC (\code{libnfc.so}) Discover NFC devices, communicate
    with it, etc.
    \begin{itemize}
    \item \code{hardware/libhardware/include/nfc.h}
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Example: rild}
  \begin{center}
    \includegraphics[height=0.8\textheight]{slides/android-native-layer-hal/rild-architecture.pdf}
  \end{center}
\end{frame}
