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

Commit 6713edc5 authored by Massimo Carli's avatar Massimo Carli
Browse files

Fix possible NPE in TransparentPolicy

Even if the NPE would require TransparentPolicy#isRunning()
to be false which is not possible if also
`mTransparentPolicyState.mFirstOpaqueActivity` is null,
we use Optional.ofNullable() to prevent problems in case
the isRunning() method is mocked in tests.

Also remove unused methods.

Flag: EXEMPT small fix
Fix: 352868162
Test: atest WmTests:TransparentPolicyTest

Change-Id: Idbefec0e7290507f0b40347b2809d9dca40cf94b
parent a2c91d2f
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -162,10 +162,6 @@ class TransparentPolicy {
        mTransparentPolicyState.clearInheritedCompatDisplayInsets();
    }

    TransparentPolicyState getTransparentPolicyState() {
        return mTransparentPolicyState;
    }

    /**
     * In case of translucent activities, it consumes the {@link ActivityRecord} of the first opaque
     * activity beneath using the given consumer and returns {@code true}.
@@ -176,7 +172,7 @@ class TransparentPolicy {

    @NonNull
    Optional<ActivityRecord> getFirstOpaqueActivity() {
        return isRunning() ? Optional.of(mTransparentPolicyState.mFirstOpaqueActivity)
        return isRunning() ? Optional.ofNullable(mTransparentPolicyState.mFirstOpaqueActivity)
                : Optional.empty();
    }

@@ -216,10 +212,6 @@ class TransparentPolicy {
                SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
    }

    private void inheritConfiguration(ActivityRecord firstOpaque) {
        mTransparentPolicyState.inheritFromOpaque(firstOpaque);
    }

    /**
     * Encapsulate the state for the current translucent activity when the transparent policy
     * has started.