blob: d62478b27638985aa55b2c0bb0a3ff830cd787bf [file] [log] [blame]
Ed Coyne7464ac92017-06-08 12:26:48 -07001/*
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
32using namespace android;
33using android::base::ReadFileToString;
34
35// Create a typedef for readability.
36typedef android::BootAnimation::Animation Animation;
37
38namespace {
39
40class BootActionAnimationCallbacks : public android::BootAnimation::Callbacks {public:
41 void init(const Vector<Animation::Part>&) override {
Ed Coyne428ed512017-08-14 15:10:06 -070042 std::string library_path("/oem/lib/");
Ed Coyne7464ac92017-06-08 12:26:48 -070043
Ed Coyne428ed512017-08-14 15:10:06 -070044 // This value is optionally provided by the user and will be written to
45 // /oem/oem.prop.
46 char property[PROP_VALUE_MAX] = {0};
47 if (property_get("ro.oem.bootactions.lib", property, "") < 1) {
48 ALOGI("No bootaction specified");
49 return;
50 }
51 library_path += property;
52
53 mBootAction = new BootAction();
54 if (!mBootAction->init(library_path)) {
55 mBootAction = NULL;
56 }
Ed Coyne7464ac92017-06-08 12:26:48 -070057 };
58
59 void playPart(int partNumber, const Animation::Part&, int playNumber) override {
60 if (mBootAction != nullptr) {
61 mBootAction->startPart(partNumber, playNumber);
62 }
63 };
64
65 void shutdown() override {
66 if (mBootAction != nullptr) {
67 mBootAction->shutdown();
68 // Give it two seconds to shut down.
69 sleep(2);
70 mBootAction = nullptr;
71 }
72 };
73
74private:
75 sp<BootAction> mBootAction = nullptr;
76};
77
78} // namespace
79
80int main() {
81 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
82
83 if (bootAnimationDisabled()) {
84 ALOGI("boot animation disabled");
85 return 0;
86 }
87
88 waitForSurfaceFlinger();
89
90 sp<ProcessState> proc(ProcessState::self());
91 ProcessState::self()->startThreadPool();
92
93 sp<BootAnimation> boot = new BootAnimation(new BootActionAnimationCallbacks());
94
95 IPCThreadState::self()->joinThreadPool();
96 return 0;
97}