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

Commit ac5636e6 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

HostStubGen: Fix minor bug

In some cases, filter classes need to use [outermostFilter]
to refer to policies on other items.

Bug: 292141694
Test: run-all-tests.sh
Change-Id: I6f2796fb44e7f70e9f64f77107b2046c3733e0e2
parent a29375a5
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ package com.android.hoststubgen.filters
 * Base class for an [OutputFilter] that uses another filter as a fallback.
 */
abstract class DelegatingFilter(
        // fallback shouldn't be used by subclasses, so make it private.
        // fallback shouldn't be used by subclasses directly, so make it private.
        // They should instead be calling into `super` or `outermostFilter`.
        private val fallback: OutputFilter
) : OutputFilter() {
@@ -27,11 +27,21 @@ abstract class DelegatingFilter(
        fallback.outermostFilter = this
    }

    /**
     * Returns the outermost filter in a filter chain.
     *
     * When methods in a subclass needs to refer to a policy on an item (class, fields, methods)
     * that are not the "subject" item -- e.g.
     * in [ClassWidePolicyPropagatingFilter.getPolicyForField], when it checks the
     * class policy -- [outermostFilter] must be used, rather than the super's method.
     * The former will always return the correct policy, but the later won't consult outer
     * filters than the current filter.
     */
    override var outermostFilter: OutputFilter = this
        get() = field
        set(value) {
            field = value
            // Propagate the inner filters.
            // Propagate to the inner filters.
            fallback.outermostFilter = value
        }

+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ class ImplicitOutputFilter(
        val fallback = super.getPolicyForField(className, fieldName)

        val cn = classes.getClass(className)
        val classPolicy = super.getPolicyForClass(className)
        val classPolicy = outermostFilter.getPolicyForClass(className)

        log.d("Class ${cn.name} Class policy: $classPolicy")
        if (classPolicy.policy.needsInImpl) {