Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73dea90a authored by Wei Sheng Shih's avatar Wei Sheng Shih Committed by Automerger Merge Worker
Browse files

Merge "Return default value safely without throw out exception." into sc-dev am: 7ab80ae7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14891911

Change-Id: Ic104f998626774e52363d102c87296bc6dc4b40f
parents 7a4403a0 7ab80ae7
Loading
Loading
Loading
Loading
+30 −13
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.List;
import java.util.function.Consumer;
import java.util.function.Consumer;
import java.util.function.IntSupplier;
import java.util.function.IntSupplier;
import java.util.function.Supplier;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;


/**
/**
 * Util class to create the view for a splash screen content.
 * Util class to create the view for a splash screen content.
@@ -207,6 +208,15 @@ public class SplashscreenContentDrawer {
                .build();
                .build();
    }
    }


    private static <T> T safeReturnAttrDefault(UnaryOperator<T> getMethod, T def) {
        try {
            return getMethod.apply(def);
        } catch (RuntimeException e) {
            Slog.w(TAG, "Get attribute fail, return default: " + e.getMessage());
            return def;
        }
    }

    /**
    /**
     * Get the {@link SplashScreenWindowAttrs} from {@code context} and fill them into
     * Get the {@link SplashScreenWindowAttrs} from {@code context} and fill them into
     * {@code attrs}.
     * {@code attrs}.
@@ -215,16 +225,18 @@ public class SplashscreenContentDrawer {
        final TypedArray typedArray = context.obtainStyledAttributes(
        final TypedArray typedArray = context.obtainStyledAttributes(
                com.android.internal.R.styleable.Window);
                com.android.internal.R.styleable.Window);
        attrs.mWindowBgResId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
        attrs.mWindowBgResId = typedArray.getResourceId(R.styleable.Window_windowBackground, 0);
        attrs.mWindowBgColor = typedArray.getColor(
        attrs.mWindowBgColor = safeReturnAttrDefault((def) -> typedArray.getColor(
                R.styleable.Window_windowSplashScreenBackground, Color.TRANSPARENT);
                R.styleable.Window_windowSplashScreenBackground, def),
        attrs.mReplaceIcon = typedArray.getDrawable(
                Color.TRANSPARENT);
                R.styleable.Window_windowSplashScreenAnimatedIcon);
        attrs.mReplaceIcon = safeReturnAttrDefault((def) -> typedArray.getDrawable(
        attrs.mAnimationDuration = typedArray.getInt(
                R.styleable.Window_windowSplashScreenAnimatedIcon), null);
                R.styleable.Window_windowSplashScreenAnimationDuration, 0);
        attrs.mAnimationDuration = safeReturnAttrDefault((def) -> typedArray.getInt(
        attrs.mBrandingImage = typedArray.getDrawable(
                R.styleable.Window_windowSplashScreenAnimationDuration, def), 0);
                R.styleable.Window_windowSplashScreenBrandingImage);
        attrs.mBrandingImage = safeReturnAttrDefault((def) -> typedArray.getDrawable(
        attrs.mIconBgColor = typedArray.getColor(
                R.styleable.Window_windowSplashScreenBrandingImage), null);
                R.styleable.Window_windowSplashScreenIconBackgroundColor, Color.TRANSPARENT);
        attrs.mIconBgColor = safeReturnAttrDefault((def) -> typedArray.getColor(
                R.styleable.Window_windowSplashScreenIconBackgroundColor, def),
                Color.TRANSPARENT);
        typedArray.recycle();
        typedArray.recycle();
        if (DEBUG) {
        if (DEBUG) {
            Slog.d(TAG, "window attributes color: "
            Slog.d(TAG, "window attributes color: "
@@ -476,10 +488,15 @@ public class SplashscreenContentDrawer {
                    drawable = layerDrawable.getDrawable(0);
                    drawable = layerDrawable.getDrawable(0);
                }
                }
            }
            }
            if (drawable == null) {
                mColorChecker = new SingleColorTester(
                        (ColorDrawable) createDefaultBackgroundDrawable());
            } else {
                mColorChecker = drawable instanceof ColorDrawable
                mColorChecker = drawable instanceof ColorDrawable
                        ? new SingleColorTester((ColorDrawable) drawable)
                        ? new SingleColorTester((ColorDrawable) drawable)
                        : new ComplexDrawableTester(drawable, filterTransparent);
                        : new ComplexDrawableTester(drawable, filterTransparent);
            }
            }
        }


        public float nonTransparentRatio() {
        public float nonTransparentRatio() {
            return mColorChecker.nonTransparentRatio();
            return mColorChecker.nonTransparentRatio();