summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jared Duke <jdduke@google.com> 2023-01-19 14:00:21 -0800
committer Jared Duke <jdduke@google.com> 2023-01-24 20:05:33 +0000
commitd91df3315e9eaffbcf3f3c146eed7d31eb67cadc (patch)
tree8832a232c169d56508ea13bff7efc50de4165f7b
parentcedba056ecece32d99f52f97b4262e2827df5c51 (diff)
Keep UserManagerInternal fields referenced with reflection
Several constant fields in UserManagerInternal are referenced by way of DebugUtils.constantToString. This tool relies on reflection to fully populate the field names, but these fields are inlined and removed by R8 after shrinking. For now, expicitly keep these fields to preserve the desired behavior. A better solution might involve an annotation on the method that triggers the DebugUtils.constantToString call, to keep any fields with the desired prefix. Note that there are a few other uses of reflection via DebugUtils in system_server, but they are generally for framework classes that are not shrunk by R8, so don't have the same issue. Bug: 265860655 Test: dexdump services.jar | grep 'USER_START_MODE_' Change-Id: I79aeeba4e4dd6f52a6f37c70f27d0778ff87d5f8
-rw-r--r--services/core/java/com/android/server/pm/UserManagerInternal.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/pm/UserManagerInternal.java b/services/core/java/com/android/server/pm/UserManagerInternal.java
index 1787116a03d4..3c5f309be64c 100644
--- a/services/core/java/com/android/server/pm/UserManagerInternal.java
+++ b/services/core/java/com/android/server/pm/UserManagerInternal.java
@@ -27,6 +27,8 @@ import android.os.Bundle;
import android.os.UserManager;
import android.util.DebugUtils;
+import com.android.internal.annotations.Keep;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
@@ -47,9 +49,10 @@ public abstract class UserManagerInternal {
public @interface OwnerType {
}
- public static final int USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE = 1;
- public static final int USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE = 2;
- public static final int USER_ASSIGNMENT_RESULT_FAILURE = -1;
+ // TODO(b/248408342): Move keep annotation to the method referencing these fields reflectively.
+ @Keep public static final int USER_ASSIGNMENT_RESULT_SUCCESS_VISIBLE = 1;
+ @Keep public static final int USER_ASSIGNMENT_RESULT_SUCCESS_INVISIBLE = 2;
+ @Keep public static final int USER_ASSIGNMENT_RESULT_FAILURE = -1;
private static final String PREFIX_USER_ASSIGNMENT_RESULT = "USER_ASSIGNMENT_RESULT_";
@IntDef(flag = false, prefix = {PREFIX_USER_ASSIGNMENT_RESULT}, value = {
@@ -59,9 +62,10 @@ public abstract class UserManagerInternal {
})
public @interface UserAssignmentResult {}
- public static final int USER_START_MODE_FOREGROUND = 1;
- public static final int USER_START_MODE_BACKGROUND = 2;
- public static final int USER_START_MODE_BACKGROUND_VISIBLE = 3;
+ // TODO(b/248408342): Move keep annotation to the method referencing these fields reflectively.
+ @Keep public static final int USER_START_MODE_FOREGROUND = 1;
+ @Keep public static final int USER_START_MODE_BACKGROUND = 2;
+ @Keep public static final int USER_START_MODE_BACKGROUND_VISIBLE = 3;
private static final String PREFIX_USER_START_MODE = "USER_START_MODE_";
@IntDef(flag = false, prefix = {PREFIX_USER_START_MODE}, value = {