Home | History | Annotate | Download | only in bootanimation
      1 /*
      2  * Copyright (C) 2007 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 "BootAnimation"
     18 
     19 #include <stdint.h>
     20 #include <inttypes.h>
     21 
     22 #include <binder/IPCThreadState.h>
     23 #include <binder/ProcessState.h>
     24 #include <binder/IServiceManager.h>
     25 #include <cutils/properties.h>
     26 #include <sys/resource.h>
     27 #include <utils/Log.h>
     28 #include <utils/SystemClock.h>
     29 #include <utils/threads.h>
     30 
     31 #include "BootAnimation.h"
     32 
     33 using namespace android;
     34 
     35 // ---------------------------------------------------------------------------
     36 
     37 int main()
     38 {
     39     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY);
     40 
     41     char value[PROPERTY_VALUE_MAX];
     42     property_get("debug.sf.nobootanimation", value, "0");
     43     int noBootAnimation = atoi(value);
     44     if (!noBootAnimation) {
     45         property_get("ro.boot.quiescent", value, "0");
     46         noBootAnimation = atoi(value);
     47     }
     48     ALOGI_IF(noBootAnimation,  "boot animation disabled");
     49     if (!noBootAnimation) {
     50 
     51         sp<ProcessState> proc(ProcessState::self());
     52         ProcessState::self()->startThreadPool();
     53 
     54         // TODO: replace this with better waiting logic in future, b/35253872
     55         int64_t waitStartTime = elapsedRealtime();
     56         sp<IServiceManager> sm = defaultServiceManager();
     57         const String16 name("SurfaceFlinger");
     58         const int SERVICE_WAIT_SLEEP_MS = 100;
     59         const int LOG_PER_RETRIES = 10;
     60         int retry = 0;
     61         while (sm->checkService(name) == nullptr) {
     62             retry++;
     63             if ((retry % LOG_PER_RETRIES) == 0) {
     64                 ALOGW("Waiting for SurfaceFlinger, waited for %" PRId64 " ms",
     65                       elapsedRealtime() - waitStartTime);
     66             }
     67             usleep(SERVICE_WAIT_SLEEP_MS * 1000);
     68         };
     69         int64_t totalWaited = elapsedRealtime() - waitStartTime;
     70         if (totalWaited > SERVICE_WAIT_SLEEP_MS) {
     71             ALOGI("Waiting for SurfaceFlinger took %" PRId64 " ms", totalWaited);
     72         }
     73 
     74         // create the boot animation object
     75         sp<BootAnimation> boot = new BootAnimation();
     76 
     77         IPCThreadState::self()->joinThreadPool();
     78     }
     79     return 0;
     80 }
     81