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

Commit e1061e2e authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Baseline PM flags and UserInfo for SysUI.

SysUI code relies on the straightforward Flags and UserInfo classes,
and working around them in SysUI would be quite disruptive, so this
change supports them under Ravenwood, along with tests to confirm
their behavior.

Bug: 319647875
Test: atest FrameworksCoreTestsRavenwood
Change-Id: I9f8bcf711a39b15a9aff457a8afe2a601e64eafd
parent 221597ac
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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);
+4 −0
Original line number Diff line number Diff line
@@ -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();
    }
+8 −0
Original line number Diff line number Diff line
@@ -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);
    }
+2 −0
Original line number Diff line number Diff line
@@ -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",
+49 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
Loading