1627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian/*
2627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * Copyright (C) 2007 The Android Open Source Project
3627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian *
4627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * you may not use this file except in compliance with the License.
6627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * You may obtain a copy of the License at
7627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian *
8627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian *
10627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * See the License for the specific language governing permissions and
14627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian * limitations under the License.
15627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian */
16627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
17627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian#define LOG_TAG "BootAnimation"
18627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
19721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park#include <stdint.h>
20721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park#include <inttypes.h>
21721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park
22ac31a3b8b09aba1c5ebc73f0cf65cac2210aa6b7Mathias Agopian#include <binder/IPCThreadState.h>
23ac31a3b8b09aba1c5ebc73f0cf65cac2210aa6b7Mathias Agopian#include <binder/ProcessState.h>
24ac31a3b8b09aba1c5ebc73f0cf65cac2210aa6b7Mathias Agopian#include <binder/IServiceManager.h>
251610486d371b867c0a842ede38e64774c18ba5d9Yabin Cui#include <cutils/properties.h>
261610486d371b867c0a842ede38e64774c18ba5d9Yabin Cui#include <sys/resource.h>
27627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian#include <utils/Log.h>
28721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park#include <utils/SystemClock.h>
29627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian#include <utils/threads.h>
30627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
31627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian#include "BootAnimation.h"
32627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
33627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopianusing namespace android;
34627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
35627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian// ---------------------------------------------------------------------------
36627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
37cfedceb8c180a2e176154d461659e0c3569dc931Andreas Gampeint main()
38627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian{
39627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian    setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
40627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
41de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian    char value[PROPERTY_VALUE_MAX];
42de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian    property_get("debug.sf.nobootanimation", value, "0");
43de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian    int noBootAnimation = atoi(value);
44a8d2c6457fe339acaae256510afbe63e39147d62Dmitri Plotnikov    if (!noBootAnimation) {
45a8d2c6457fe339acaae256510afbe63e39147d62Dmitri Plotnikov        property_get("ro.boot.quiescent", value, "0");
46a8d2c6457fe339acaae256510afbe63e39147d62Dmitri Plotnikov        noBootAnimation = atoi(value);
47a8d2c6457fe339acaae256510afbe63e39147d62Dmitri Plotnikov    }
486215d3ff4b5dfa52a5d8b9a42e343051f31066a5Steve Block    ALOGI_IF(noBootAnimation,  "boot animation disabled");
49de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian    if (!noBootAnimation) {
50de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian
51de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian        sp<ProcessState> proc(ProcessState::self());
52de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian        ProcessState::self()->startThreadPool();
53de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian
54721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        // TODO: replace this with better waiting logic in future, b/35253872
55721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        int64_t waitStartTime = elapsedRealtime();
56721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        sp<IServiceManager> sm = defaultServiceManager();
57721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        const String16 name("SurfaceFlinger");
58721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        const int SERVICE_WAIT_SLEEP_MS = 100;
59721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        const int LOG_PER_RETRIES = 10;
60721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        int retry = 0;
61721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        while (sm->checkService(name) == nullptr) {
62721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park            retry++;
63721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park            if ((retry % LOG_PER_RETRIES) == 0) {
64721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park                ALOGW("Waiting for SurfaceFlinger, waited for %" PRId64 " ms",
65721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park                      elapsedRealtime() - waitStartTime);
66721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park            }
67721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park            usleep(SERVICE_WAIT_SLEEP_MS * 1000);
68721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        };
69721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        int64_t totalWaited = elapsedRealtime() - waitStartTime;
70721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        if (totalWaited > SERVICE_WAIT_SLEEP_MS) {
71721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park            ALOGI("Waiting for SurfaceFlinger took %" PRId64 " ms", totalWaited);
72721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park        }
73721c9dc1253db9a713063674d196d57b83536d6aKeun-young Park
74de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian        // create the boot animation object
75de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian        sp<BootAnimation> boot = new BootAnimation();
76627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian
77de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian        IPCThreadState::self()->joinThreadPool();
78de36313b0b80c019c2784edd9d41f6761fe80685Mathias Agopian    }
79627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian    return 0;
80627e7b50be41e4fdee758a1bfad3a55de56b4e27Mathias Agopian}
81