diff options
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 6 | ||||
| -rw-r--r-- | core/java/android/content/pm/UserInfo.java | 4 | ||||
| -rw-r--r-- | core/java/android/os/UserManager.java | 8 | ||||
| -rw-r--r-- | core/tests/coretests/Android.bp | 2 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/content/pm/PackageManagerTest.java | 49 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/content/pm/UserInfoTest.java | 71 | ||||
| -rw-r--r-- | ravenwood/ravenwood-annotation-allowed-classes.txt | 15 |
7 files changed, 151 insertions, 4 deletions
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 4724e866f094..8744eaee4341 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -128,6 +128,7 @@ import java.util.function.Function; * <a href="/training/basics/intents/package-visibility">manage package visibility</a>. * </p> */ +@android.ravenwood.annotation.RavenwoodKeepPartialClass public abstract class PackageManager { private static final String TAG = "PackageManager"; @@ -5492,6 +5493,7 @@ public abstract class PackageManager { * application info. * @hide */ + @android.ravenwood.annotation.RavenwoodKeepWholeClass public static class Flags { final long mValue; protected Flags(long value) { @@ -5506,6 +5508,7 @@ public abstract class PackageManager { * Specific flags used for retrieving package info. Example: * {@code PackageManager.getPackageInfo(packageName, PackageInfoFlags.of(0)} */ + @android.ravenwood.annotation.RavenwoodKeepWholeClass public final static class PackageInfoFlags extends Flags { private PackageInfoFlags(@PackageInfoFlagsBits long value) { super(value); @@ -5519,6 +5522,7 @@ public abstract class PackageManager { /** * Specific flags used for retrieving application info. */ + @android.ravenwood.annotation.RavenwoodKeepWholeClass public final static class ApplicationInfoFlags extends Flags { private ApplicationInfoFlags(@ApplicationInfoFlagsBits long value) { super(value); @@ -5532,6 +5536,7 @@ public abstract class PackageManager { /** * Specific flags used for retrieving component info. */ + @android.ravenwood.annotation.RavenwoodKeepWholeClass public final static class ComponentInfoFlags extends Flags { private ComponentInfoFlags(@ComponentInfoFlagsBits long value) { super(value); @@ -5545,6 +5550,7 @@ public abstract class PackageManager { /** * Specific flags used for retrieving resolve info. */ + @android.ravenwood.annotation.RavenwoodKeepWholeClass public final static class ResolveInfoFlags extends Flags { private ResolveInfoFlags(@ResolveInfoFlagsBits long value) { super(value); diff --git a/core/java/android/content/pm/UserInfo.java b/core/java/android/content/pm/UserInfo.java index 8fd78bd4276c..3e9f260566bd 100644 --- a/core/java/android/content/pm/UserInfo.java +++ b/core/java/android/content/pm/UserInfo.java @@ -52,6 +52,7 @@ import java.lang.annotation.RetentionPolicy; * @hide */ @TestApi +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class UserInfo implements Parcelable { /** @@ -438,6 +439,7 @@ public class UserInfo implements Parcelable { /** * @return true if this user can be switched to. **/ + @android.ravenwood.annotation.RavenwoodThrow public boolean supportsSwitchTo() { if (partial || !isEnabled()) { // Don't support switching to disabled or partial users, which includes users with @@ -455,6 +457,7 @@ public class UserInfo implements Parcelable { * @return true if user is of type {@link UserManager#USER_TYPE_SYSTEM_HEADLESS} and * {@link com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser} is true. */ + @android.ravenwood.annotation.RavenwoodThrow private boolean canSwitchToHeadlessSystemUser() { return UserManager.USER_TYPE_SYSTEM_HEADLESS.equals(userType) && Resources.getSystem() .getBoolean(com.android.internal.R.bool.config_canSwitchToHeadlessSystemUser); @@ -465,6 +468,7 @@ public class UserInfo implements Parcelable { * @deprecated Use {@link UserInfo#supportsSwitchTo} instead. */ @Deprecated + @android.ravenwood.annotation.RavenwoodThrow public boolean supportsSwitchToByUser() { return supportsSwitchTo(); } diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index c280d132ae38..91ef2fa4cf88 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -88,6 +88,7 @@ import java.util.Set; * See {@link DevicePolicyManager#ACTION_PROVISION_MANAGED_PROFILE} for more on managed profiles. */ @SystemService(Context.USER_SERVICE) +@android.ravenwood.annotation.RavenwoodKeepPartialClass public class UserManager { private static final String TAG = "UserManager"; @@ -2906,6 +2907,7 @@ public class UserManager { * {@link UserManager#USER_TYPE_PROFILE_MANAGED managed profile}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeManagedProfile(@Nullable String userType) { return USER_TYPE_PROFILE_MANAGED.equals(userType); } @@ -2914,6 +2916,7 @@ public class UserManager { * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_GUEST guest user}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeGuest(@Nullable String userType) { return USER_TYPE_FULL_GUEST.equals(userType); } @@ -2923,6 +2926,7 @@ public class UserManager { * {@link UserManager#USER_TYPE_FULL_RESTRICTED restricted user}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeRestricted(@Nullable String userType) { return USER_TYPE_FULL_RESTRICTED.equals(userType); } @@ -2931,6 +2935,7 @@ public class UserManager { * Returns whether the user type is a {@link UserManager#USER_TYPE_FULL_DEMO demo user}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeDemo(@Nullable String userType) { return USER_TYPE_FULL_DEMO.equals(userType); } @@ -2939,6 +2944,7 @@ public class UserManager { * Returns whether the user type is a {@link UserManager#USER_TYPE_PROFILE_CLONE clone user}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeCloneProfile(@Nullable String userType) { return USER_TYPE_PROFILE_CLONE.equals(userType); } @@ -2948,6 +2954,7 @@ public class UserManager { * {@link UserManager#USER_TYPE_PROFILE_COMMUNAL communal profile}. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypeCommunalProfile(@Nullable String userType) { return USER_TYPE_PROFILE_COMMUNAL.equals(userType); } @@ -2958,6 +2965,7 @@ public class UserManager { * * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static boolean isUserTypePrivateProfile(@Nullable String userType) { return USER_TYPE_PROFILE_PRIVATE.equals(userType); } diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp index 3c56f76871b6..f47679991418 100644 --- a/core/tests/coretests/Android.bp +++ b/core/tests/coretests/Android.bp @@ -209,6 +209,8 @@ android_ravenwood_test { "testng", ], srcs: [ + "src/android/content/pm/PackageManagerTest.java", + "src/android/content/pm/UserInfoTest.java", "src/android/database/CursorWindowTest.java", "src/android/os/**/*.java", "src/android/telephony/PinResultTest.java", diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTest.java b/core/tests/coretests/src/android/content/pm/PackageManagerTest.java new file mode 100644 index 000000000000..20421d105db8 --- /dev/null +++ b/core/tests/coretests/src/android/content/pm/PackageManagerTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2024 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.content.pm; + +import static com.google.common.truth.Truth.assertThat; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class PackageManagerTest { + @Test + public void testPackageInfoFlags() throws Exception { + assertThat(PackageManager.PackageInfoFlags.of(42L).getValue()).isEqualTo(42L); + } + + @Test + public void testApplicationInfoFlags() throws Exception { + assertThat(PackageManager.ApplicationInfoFlags.of(42L).getValue()).isEqualTo(42L); + } + + @Test + public void testComponentInfoFlags() throws Exception { + assertThat(PackageManager.ComponentInfoFlags.of(42L).getValue()).isEqualTo(42L); + } + + @Test + public void testResolveInfoFlags() throws Exception { + assertThat(PackageManager.ResolveInfoFlags.of(42L).getValue()).isEqualTo(42L); + } +} diff --git a/core/tests/coretests/src/android/content/pm/UserInfoTest.java b/core/tests/coretests/src/android/content/pm/UserInfoTest.java new file mode 100644 index 000000000000..af36dbb36379 --- /dev/null +++ b/core/tests/coretests/src/android/content/pm/UserInfoTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024 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.content.pm; + +import static com.google.common.truth.Truth.assertThat; + +import android.os.UserHandle; + +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class UserInfoTest { + @Test + public void testSimple() throws Exception { + final UserInfo ui = new UserInfo(10, "Test", UserInfo.FLAG_GUEST); + + assertThat(ui.getUserHandle()).isEqualTo(UserHandle.of(10)); + assertThat(ui.name).isEqualTo("Test"); + + // Derived based on userType field + assertThat(ui.isManagedProfile()).isEqualTo(false); + assertThat(ui.isGuest()).isEqualTo(true); + assertThat(ui.isRestricted()).isEqualTo(false); + assertThat(ui.isDemo()).isEqualTo(false); + assertThat(ui.isCloneProfile()).isEqualTo(false); + assertThat(ui.isCommunalProfile()).isEqualTo(false); + assertThat(ui.isPrivateProfile()).isEqualTo(false); + + // Derived based on flags field + assertThat(ui.isPrimary()).isEqualTo(false); + assertThat(ui.isAdmin()).isEqualTo(false); + assertThat(ui.isProfile()).isEqualTo(false); + assertThat(ui.isEnabled()).isEqualTo(true); + assertThat(ui.isQuietModeEnabled()).isEqualTo(false); + assertThat(ui.isEphemeral()).isEqualTo(false); + assertThat(ui.isForTesting()).isEqualTo(false); + assertThat(ui.isInitialized()).isEqualTo(false); + assertThat(ui.isFull()).isEqualTo(false); + assertThat(ui.isMain()).isEqualTo(false); + + // Derived dynamically + assertThat(ui.canHaveProfile()).isEqualTo(false); + } + + @Test + public void testDebug() throws Exception { + final UserInfo ui = new UserInfo(10, "Test", UserInfo.FLAG_GUEST); + + assertThat(ui.toString()).isNotEmpty(); + assertThat(ui.toFullString()).isNotEmpty(); + } +} diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt index b4b0beb49477..eaf01a32592e 100644 --- a/ravenwood/ravenwood-annotation-allowed-classes.txt +++ b/ravenwood/ravenwood-annotation-allowed-classes.txt @@ -78,6 +78,7 @@ android.os.Trace android.os.UidBatteryConsumer android.os.UidBatteryConsumer$Builder android.os.UserHandle +android.os.UserManager android.os.WorkSource android.content.ClipData @@ -91,16 +92,22 @@ android.content.Intent android.content.IntentFilter android.content.UriMatcher -android.content.pm.PackageInfo +android.content.pm.ActivityInfo android.content.pm.ApplicationInfo -android.content.pm.PackageItemInfo android.content.pm.ComponentInfo -android.content.pm.ActivityInfo -android.content.pm.ServiceInfo +android.content.pm.PackageInfo +android.content.pm.PackageItemInfo +android.content.pm.PackageManager$Flags +android.content.pm.PackageManager$PackageInfoFlags +android.content.pm.PackageManager$ApplicationInfoFlags +android.content.pm.PackageManager$ComponentInfoFlags +android.content.pm.PackageManager$ResolveInfoFlags android.content.pm.PathPermission android.content.pm.ProviderInfo android.content.pm.ResolveInfo +android.content.pm.ServiceInfo android.content.pm.Signature +android.content.pm.UserInfo android.database.AbstractCursor android.database.CharArrayBuffer |