\subchapter{Write an application with the SDK}{Learn the basic concepts of
the Android SDK and how to use them}

After this lab, you will be able to:
\begin{itemize}
  \item Write an Android application
  \item Integrate an application in the Android build system
\end{itemize}

\section{Write the application}

Go to the \code{/home/<user/felabs/android/app} directory.

You will find the basics for the \code{MissileControl} app. This app is incomplete,
parts of some activities are missing. However the UI part is
already done, so create the code to launch the activity with the given
layout and the needed hooks defined in the layout description. These
hooks implement the behavior of every button: move the
launcher, fire, etc.  Every button should be self-explanatory, except
for the USB/Emulation switch, which switches between USB mode (which
uses the USBBackend you developed) and Emulation mode (which uses the
\code{DummyBackend} class for debugging).

The whole application now uses 3 layers to work, the application itself, which
is a perfectly standard Android application, relying on Java $\rightarrow$ C
bindings integrated in the Android framework, which in turn relies on libusb
that we included in the system libraries.

We can't have a real USB missile launcher for participant,
so the \code{DummyBackend} class is provided to test that your application and the
changes to the framework are functional.

You can still switch back-ends with the switch button in the application.

\section{Integrate the application}

Once again, write down the \code{Android.mk} file to build the application in the
Android image, and set the dependencies on the JNI libs so that the app
is compiled and runs properly.

When you test your application, you will find that it 
crashes because it doesn't find the \code{.jar} file containing the Java
bindings to libusb, while you used them successfully with
Dalvik. This is because Android's security model refuses to load
untrusted jar files. However, you can make Android accept a jar file
by adding an xml file similar to \code{AndroidManifest.xml} into
the \code{/system/etc/permissions/} folder. There are several examples
of such a file in this folder, so adapt one to our case. After
rebuilding, it should work fine.

Once you have completed this lab, you can ask your instructor to
give you a URL where Free Electrons' solution is available, and compare
it with what you implemented.

\section{Going Further}

We have used direct bindings and calls to use our library. However, we
have seen that with Android, we tend to use services in that case, for
security reasons, as well as to keep a consistent state across the
system. If you have any time left, implement a new service that will
be used by your application and replace the direct function calls.
