Home | History | Annotate | Download | only in iot
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "IotBootAnimation"
     18 
     19 #include <android-base/file.h>
     20 #include <binder/IPCThreadState.h>
     21 #include <binder/IServiceManager.h>
     22 #include <binder/ProcessState.h>
     23 #include <cutils/properties.h>
     24 #include <sys/resource.h>
     25 #include <utils/Log.h>
     26 #include <utils/threads.h>
     27 #include <BootAnimation.h>
     28 
     29 #include "BootAction.h"
     30 #include "BootAnimationUtil.h"
     31 
     32 using namespace android;
     33 using android::base::ReadFileToString;
     34 
     35 // Create a typedef for readability.
     36 typedef android::BootAnimation::Animation Animation;
     37 
     38 namespace {
     39 
     40 class BootActionAnimationCallbacks : public android::BootAnimation::Callbacks {public:
     41     void init(const Vector<Animation::Part>&) override {
     42         // Create and initialize BootActions if we have a boot_action.conf.
     43         std::string bootActionConf;
     44         if (ReadFileToString("/oem/app/etc/boot_action.conf", &bootActionConf)) {
     45             mBootAction = new BootAction();
     46             if (!mBootAction->init("/oem/app/lib", bootActionConf)) {
     47                 mBootAction = NULL;
     48             }
     49         } else {
     50             ALOGI("No boot actions specified");
     51         }
     52 
     53     };
     54 
     55     void playPart(int partNumber, const Animation::Part&, int playNumber) override {
     56         if (mBootAction != nullptr) {
     57             mBootAction->startPart(partNumber, playNumber);
     58         }
     59     };
     60 
     61     void shutdown() override {
     62         if (mBootAction != nullptr) {
     63             mBootAction->shutdown();
     64             // Give it two seconds to shut down.
     65             sleep(2);
     66             mBootAction = nullptr;
     67         }
     68     };
     69 
     70 private:
     71     sp<BootAction> mBootAction = nullptr;
     72 };
     73 
     74 }  // namespace
     75 
     76 int main() {
     77     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
     78 
     79     if (bootAnimationDisabled()) {
     80         ALOGI("boot animation disabled");
     81         return 0;
     82     }
     83 
     84     waitForSurfaceFlinger();
     85 
     86     sp<ProcessState> proc(ProcessState::self());
     87     ProcessState::self()->startThreadPool();
     88 
     89     sp<BootAnimation> boot = new BootAnimation(new BootActionAnimationCallbacks());
     90 
     91     IPCThreadState::self()->joinThreadPool();
     92     return 0;
     93 }
     94