blob: 2a3d3766ab38a14bb8e617d580651163f45e486d [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
David Pursellbe09c952017-10-10 14:43:04 -070019#include <base/files/file_util.h>
Ed Coyne7464ac92017-06-08 12:26:48 -070020#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"
David Pursell54a8fe42017-09-29 16:05:26 -070031#include "BootParameters.h"
Ed Coyne7464ac92017-06-08 12:26:48 -070032
33using namespace android;
Ed Coyne7464ac92017-06-08 12:26:48 -070034
35// Create a typedef for readability.
36typedef android::BootAnimation::Animation Animation;
37
38namespace {
39
David Pursellbe09c952017-10-10 14:43:04 -070040constexpr const char* kDefaultLibName = "libbootaction.so";
41
David Pursell54a8fe42017-09-29 16:05:26 -070042class BootActionAnimationCallbacks : public android::BootAnimation::Callbacks {
43public:
44 BootActionAnimationCallbacks(std::unique_ptr<BootParameters> bootParameters)
45 : mBootParameters(std::move(bootParameters)) {}
46
Ed Coyne7464ac92017-06-08 12:26:48 -070047 void init(const Vector<Animation::Part>&) override {
Ed Coyne428ed512017-08-14 15:10:06 -070048 std::string library_path("/oem/lib/");
Ed Coyne7464ac92017-06-08 12:26:48 -070049
Ed Coyne428ed512017-08-14 15:10:06 -070050 // This value is optionally provided by the user and will be written to
51 // /oem/oem.prop.
52 char property[PROP_VALUE_MAX] = {0};
David Pursellbe09c952017-10-10 14:43:04 -070053 property_get("ro.oem.bootactions.lib", property, kDefaultLibName);
54 library_path += property;
55
56 if (!::base::PathExists(::base::FilePath(library_path))) {
57 ALOGI("Skipping boot actions: %s does not exist", library_path.c_str());
Ed Coyne428ed512017-08-14 15:10:06 -070058 return;
59 }
Ed Coyne428ed512017-08-14 15:10:06 -070060
61 mBootAction = new BootAction();
Mickey Keeley47d2c022018-04-30 11:39:30 -070062 if (!mBootAction->init(library_path, mBootParameters)) {
Ed Coyne428ed512017-08-14 15:10:06 -070063 mBootAction = NULL;
64 }
Ed Coyne7464ac92017-06-08 12:26:48 -070065 };
66
67 void playPart(int partNumber, const Animation::Part&, int playNumber) override {
68 if (mBootAction != nullptr) {
69 mBootAction->startPart(partNumber, playNumber);
70 }
71 };
72
73 void shutdown() override {
74 if (mBootAction != nullptr) {
Ed Coyneaa599b92017-09-26 13:19:04 -070075 // If we have a bootaction we want to wait until we are actually
76 // told to shut down. If the animation exits early keep the action
77 // running.
78 char value[PROPERTY_VALUE_MAX] = {0};
79 for (int exitRequested = 0; exitRequested == 0; ) {
80 property_get("service.bootanim.exit", value, "0");
81 exitRequested = atoi(value);
82
83 // Poll value at 10hz.
84 if (exitRequested == 0) {
85 usleep(100000);
86 }
87 }
88
Ed Coyne7464ac92017-06-08 12:26:48 -070089 mBootAction->shutdown();
90 // Give it two seconds to shut down.
91 sleep(2);
92 mBootAction = nullptr;
93 }
94 };
95
96private:
David Pursell54a8fe42017-09-29 16:05:26 -070097 std::unique_ptr<BootParameters> mBootParameters;
Ed Coyne7464ac92017-06-08 12:26:48 -070098 sp<BootAction> mBootAction = nullptr;
99};
100
101} // namespace
102
103int main() {
104 setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
105
David Pursell54a8fe42017-09-29 16:05:26 -0700106 // Clear our params for next boot no matter what.
107 std::unique_ptr<BootParameters> bootParameters(new BootParameters());
Braden Kell6dd64f32017-09-25 17:30:28 -0700108
Ed Coyne7464ac92017-06-08 12:26:48 -0700109 if (bootAnimationDisabled()) {
110 ALOGI("boot animation disabled");
111 return 0;
112 }
113
114 waitForSurfaceFlinger();
115
116 sp<ProcessState> proc(ProcessState::self());
117 ProcessState::self()->startThreadPool();
118
Mickey Keeley47d2c022018-04-30 11:39:30 -0700119 bool isSilentBoot = bootParameters->isSilentBoot();
120 sp<BootActionAnimationCallbacks> callbacks =
121 new BootActionAnimationCallbacks(std::move(bootParameters));
122
123 // On silent boot, animations aren't displayed.
124 if (isSilentBoot) {
125 callbacks->init({});
126 } else {
127 sp<BootAnimation> boot = new BootAnimation(callbacks);
128 }
Ed Coyne7464ac92017-06-08 12:26:48 -0700129
130 IPCThreadState::self()->joinThreadPool();
131 return 0;
132}