Allow IO During boot process, BootActions.

NOTE: this is only compiled into products with PRODUCT_IOT=true.

Introduce BootActions that a developer can provide to manipulate IO
before the android framework comes up on boot.

We will look for a configuration file at /oem/app/etc/boot_action.conf and
expect it to tell us the name of a shared library. We will then fetch
this library from /oem/app/lib/${arch}/ and load it. We expect it to export
boot_action_init(), boot_action_shutdown(), and optionally
boot_action_start_part(int partNumber, int playNumber).

We will then call boot_action_init() during boot after PeripheralManager
is up and call boot_action_shutdown() when the android framework is up
and we are going to start loading APKs.

We will also call boot_action_start_part(*) when each part of the boot
animation is started, use this if you want to synchronize the boot
action and the boot animation.

Boot actions run in a restricted environment and in general can only
make calls to PeripheralManager.

Bug: 37992717
Test: Pushed to local imx7d to test boot actions, pushed to bullhead test that animation+sound still works.
Change-Id: I9e53a17567f8028ea84486d637e1d231ee1125e1
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index 3ebe7d6..56e131523 100644
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -93,22 +93,27 @@
         Font clockFont;
     };
 
-    // Callback will be called during initialization after we have loaded
-    // the animation and be provided with all parts in animation.
-    typedef std::function<void(const Vector<Animation::Part>& parts)> InitCallback;
+    // All callbacks will be called from this class's internal thread.
+    class Callbacks : public RefBase {
+    public:
+        // Will be called during initialization after we have loaded
+        // the animation and be provided with all parts in animation.
+        virtual void init(const Vector<Animation::Part>& /*parts*/) {}
 
-    // Callback will be called while animation is playing before each part is
-    // played. It will be provided with the part and play count for it.
-    // It will be provided with the partNumber for the part about to be played,
-    // as well as a reference to the part itself. It will also be provided with
-    // which play of that part is about to start, some parts are repeated
-    // multiple times.
-    typedef std::function<void(int partNumber, const Animation::Part& part, int playNumber)>
-            PlayPartCallback;
+        // Will be called while animation is playing before each part is
+        // played. It will be provided with the part and play count for it.
+        // It will be provided with the partNumber for the part about to be played,
+        // as well as a reference to the part itself. It will also be provided with
+        // which play of that part is about to start, some parts are repeated
+        // multiple times.
+        virtual void playPart(int /*partNumber*/, const Animation::Part& /*part*/,
+                              int /*playNumber*/) {}
 
-    // Callbacks may be null and will be called from this class's internal
-    // thread.
-    BootAnimation(InitCallback initCallback, PlayPartCallback partCallback);
+        // Will be called when animation is done and thread is shutting down.
+        virtual void shutdown() {}
+    };
+
+    BootAnimation(sp<Callbacks> callbacks);
 
     sp<SurfaceComposerClient> session() const;
 
@@ -170,8 +175,7 @@
     String8     mZipFileName;
     SortedVector<String8> mLoadedFiles;
     sp<TimeCheckThread> mTimeCheckThread = nullptr;
-    InitCallback mInitCallback = nullptr;
-    PlayPartCallback mPlayPartCallback = nullptr;
+    sp<Callbacks> mCallbacks;
 };
 
 // ---------------------------------------------------------------------------