\subsection{Wakelocks}
\begin{frame}
  \frametitle{Power management basics}
  \begin{itemize}
  \item Every CPU has a few states of power consumption, from being
    almost completely off, to working at full capacity.
  \item These different states are used by the Linux kernel to save
    power when the system is run
  \item For example, when the lid is closed on a laptop, it goes into
    ``suspend'', which is the most power conservative mode of a
    device, where almost nothing but the RAM is kept awake
  \item While this is a good strategy for a laptop, it is not
    necessarily good for mobile devices
  \item For example, you don't want your music to be turned off when
    the screen is
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Wakelocks}
  \begin{itemize}
  \item Android's answer to these power management constraints is wakelocks
  \item One of the most famous Android changes, because of the
    flame wars it spawned
  \item The main idea is instead of letting the user deciding of when
    the devices needs to go to sleep, the kernel is set to suspend as
    soon and as often as possible. 
  \item In the same time, Android allows applications and kernel
    drivers to voluntarily prevent the system from going to suspend,
    keeping it awake (thus the name wakelock)
  \item This implies to write the applications and drivers to use the
    wakelock API.
    \begin{itemize}
    \item Applications do so through the abstraction provided by the
      API
    \item Drivers must do it themselves, which prevents to directly
      submit them to the vanilla kernel
    \end{itemize}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Wakelocks API}
  \begin{itemize}
  \item Kernel Space API
\begin{minted}[fontsize=\footnotesize]{c}
#include <linux/wakelock.h>
void wake_lock_init(struct wakelock *lock,
                    int type,
                    const char *name);
void wake_lock(struct wake_lock *lock);
void wake_unlock(struct wake_lock *lock);
void wake_lock_timeout(struct wake_lock *lock, long timeout);
void wake_lock_destroy(struct wake_lock *lock);
\end{minted}
  \item User-Space API
\begin{minted}[fontsize=\footnotesize]{console}
$ echo foobar > /sys/power/wake_lock
$ echo foobar > /sys/power/wake_unlock
\end{minted}
\end{itemize}
\end{frame}
