From 2278b3f9520be586e657a43d92e4c23d79127722 Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Tue, 16 May 2023 23:39:17 +0000 Subject: [PATCH] Add @UsesReflection to FeatureFactory reflection usage Ensure FeatureFactory implementations are kept using a @UsesReflection annotation at the callsite where they are instantiated via reflection. Bug: 272041779 Test: m + validate FeatureFactoryImpl is kept Change-Id: Ia9b8c4fd2c438805f33561dcacd5c10ed49dee19 --- Android.bp | 1 + src/com/android/settings/overlay/FeatureFactory.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Android.bp b/Android.bp index fd97dc36b4b..abd3e62fa4a 100644 --- a/Android.bp +++ b/Android.bp @@ -106,6 +106,7 @@ android_library { plugins: ["androidx.room_room-compiler-plugin"], libs: [ + "keepanno-annotations", "telephony-common", "ims-common", ], diff --git a/src/com/android/settings/overlay/FeatureFactory.java b/src/com/android/settings/overlay/FeatureFactory.java index 9d81baa9bca..13e56edfb07 100644 --- a/src/com/android/settings/overlay/FeatureFactory.java +++ b/src/com/android/settings/overlay/FeatureFactory.java @@ -51,6 +51,9 @@ import com.android.settings.vpn2.AdvancedVpnFeatureProvider; import com.android.settings.wifi.WifiTrackerLibProvider; import com.android.settings.wifi.factory.WifiFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; +import com.android.tools.r8.keepanno.annotations.KeepItemKind; +import com.android.tools.r8.keepanno.annotations.KeepTarget; +import com.android.tools.r8.keepanno.annotations.UsesReflection; /** * Abstract class for creating feature controllers. Allows OEM implementations to define their own @@ -70,6 +73,14 @@ public abstract class FeatureFactory { * already exist. Uses the value of {@link R.string#config_featureFactory} to instantiate * a factory implementation. */ + @UsesReflection( + description = "This method instantiates subclasses of FeatureFactory via reflection.", + value = { + @KeepTarget( + kind = KeepItemKind.CLASS_AND_MEMBERS, + extendsClassConstant = FeatureFactory.class, + methodName = "") + }) public static FeatureFactory getFactory(Context context) { if (sFactory != null) { return sFactory;