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

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

[Ravenwood] Support "partial allowlisting".

- Now, the policy file supports a new directive "allow-annotation",
which
allows annotations on a per-member bases, which allows to expose a method
with @RavenwoodKeep without allowing more annotations in the same class.

This feature could potentially replace the original "annotation
allowlist txt", but it doesn't do that yet. Specifically, even when a
class has an "allow-annotation", we still won't allow using a class-wide
annotations on it.

For now, using "allow-annotation" with a "field" or a "package" isn't
supported, only because there may not be a good use case anyway.
Mechanically, it's not too hard to support them.

Another issue is the original allowlist actually supports suffix matching
(in addition to prefix matching), which the policy file doesn't support
yet. Suffix matching isn't used yet, but we might use it for classes
like EventLogTags or aflag generated classes.

- Implementation wise, this new "allow-annotation" directive couldn't
be embedded in the current filter chain mechanism. So now we create
another, smaller filter chain just to store "allow-annotation".

- Also made some clean up:
    - Fixed run-test-manually.sh
    - Removed unused file, hoststubgen-test-policy-override.txt

Flag: EXEMPT host test change only
Bug: 379892071
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh -s
Test: Manual test: Add @RavenwoodKeep to random members of BroadcastReceiver
    and ensure it won't build.

Change-Id: I23563e7f5b1bd1de1f2b2fe6d0d260095e6a7e9e
parent e16b65da
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,8 @@ import com.android.internal.os.DebugStore;
 * <a href="{@docRoot}guide/components/broadcasts.html">Broadcasts</a> developer guide.</p></div>
 * <a href="{@docRoot}guide/components/broadcasts.html">Broadcasts</a> developer guide.</p></div>
 *
 *
 */
 */
@android.ravenwood.annotation.RavenwoodPartiallyAllowlisted
@android.ravenwood.annotation.RavenwoodKeepPartialClass
public abstract class BroadcastReceiver {
public abstract class BroadcastReceiver {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private PendingResult mPendingResult;
    private PendingResult mPendingResult;
@@ -361,6 +363,7 @@ public abstract class BroadcastReceiver {
        }
        }
    }
    }


    @android.ravenwood.annotation.RavenwoodKeep
    public BroadcastReceiver() {
    public BroadcastReceiver() {
    }
    }


+4 −2
Original line number Original line Diff line number Diff line
@@ -50,8 +50,10 @@ class android.net.UriCodec keepclass # no-pta
class android.telephony.PinResult keepclass  # no-pta
class android.telephony.PinResult keepclass  # no-pta


# Just enough to support mocking, no further functionality
# Just enough to support mocking, no further functionality
class android.content.BroadcastReceiver keep  # no-pta
class android.content.BroadcastReceiver allow-annotation
    method <init> ()V keep
    method <init> ()V allow-annotation

# TODO: Convert the following policies to "allow-annotation".
class android.content.Context keep  # no-pta
class android.content.Context keep  # no-pta
    method <init> ()V keep
    method <init> ()V keep
    method getSystemService (Ljava/lang/Class;)Ljava/lang/Object; keep  # no-pta
    method getSystemService (Ljava/lang/Class;)Ljava/lang/Object; keep  # no-pta
+3 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,9 @@
--ignore-annotation
--ignore-annotation
    android.ravenwood.annotation.RavenwoodIgnore
    android.ravenwood.annotation.RavenwoodIgnore


--partially-allowed-annotation
    android.ravenwood.annotation.RavenwoodPartiallyAllowlisted

--substitute-annotation
--substitute-annotation
    android.ravenwood.annotation.RavenwoodReplace
    android.ravenwood.annotation.RavenwoodReplace


+27 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.hosttest.annotation;

import static java.lang.annotation.ElementType.TYPE;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({TYPE})
@Retention(RetentionPolicy.CLASS)
public @interface HostSideTestPartiallyAllowlisted {
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,9 @@
--keep-class-annotation
--keep-class-annotation
    android.hosttest.annotation.HostSideTestWholeClassKeep
    android.hosttest.annotation.HostSideTestWholeClassKeep


--partially-allowed-annotation
    android.hosttest.annotation.HostSideTestPartiallyAllowlisted

--throw-annotation
--throw-annotation
    android.hosttest.annotation.HostSideTestThrow
    android.hosttest.annotation.HostSideTestThrow


Loading