Home | History | Annotate | Download | only in bootanimation
      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 #include "BootAnimationUtil.h"
     18 
     19 #include <inttypes.h>
     20 
     21 #include <binder/IServiceManager.h>
     22 #include <cutils/properties.h>
     23 #include <utils/Log.h>
     24 #include <utils/SystemClock.h>
     25 
     26 namespace android {
     27 
     28 bool bootAnimationDisabled() {
     29     char value[PROPERTY_VALUE_MAX];
     30     property_get("debug.sf.nobootanimation", value, "0");
     31     if (atoi(value) > 0) {
     32         return true;
     33     }
     34 
     35     property_get("ro.boot.quiescent", value, "0");
     36     return atoi(value) > 0;
     37 }
     38 
     39 void waitForSurfaceFlinger() {
     40     // TODO: replace this with better waiting logic in future, b/35253872
     41     int64_t waitStartTime = elapsedRealtime();
     42     sp<IServiceManager> sm = defaultServiceManager();
     43     const String16 name("SurfaceFlinger");
     44     const int SERVICE_WAIT_SLEEP_MS = 100;
     45     const int LOG_PER_RETRIES = 10;
     46     int retry = 0;
     47     while (sm->checkService(name) == nullptr) {
     48         retry++;
     49         if ((retry % LOG_PER_RETRIES) == 0) {
     50             ALOGW("Waiting for SurfaceFlinger, waited for %" PRId64 " ms",
     51                   elapsedRealtime() - waitStartTime);
     52         }
     53         usleep(SERVICE_WAIT_SLEEP_MS * 1000);
     54     };
     55     int64_t totalWaited = elapsedRealtime() - waitStartTime;
     56     if (totalWaited > SERVICE_WAIT_SLEEP_MS) {
     57         ALOGI("Waiting for SurfaceFlinger took %" PRId64 " ms", totalWaited);
     58     }
     59 }
     60 
     61 }  // namespace android
     62