Merge "UserProperties is @SystemApi & migrate 2 old props"

This commit is contained in:
Adam Bookatz
2023-01-20 18:53:02 +00:00
committed by Android (Google) Code Review
15 changed files with 196 additions and 122 deletions

View File

@@ -12881,16 +12881,6 @@ package android.content.pm {
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.SigningInfo> CREATOR;
}
public final class UserProperties implements android.os.Parcelable {
method public int describeContents();
method public int getShowInLauncher();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.UserProperties> CREATOR;
field public static final int SHOW_IN_LAUNCHER_NO = 2; // 0x2
field public static final int SHOW_IN_LAUNCHER_SEPARATE = 1; // 0x1
field public static final int SHOW_IN_LAUNCHER_WITH_PARENT = 0; // 0x0
}
public final class VersionedPackage implements android.os.Parcelable {
ctor public VersionedPackage(@NonNull String, int);
ctor public VersionedPackage(@NonNull String, long);
@@ -33225,7 +33215,6 @@ package android.os {
method public android.os.UserHandle getUserForSerialNumber(long);
method @NonNull @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.CREATE_USERS", "android.permission.QUERY_USERS", android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) public String getUserName();
method public java.util.List<android.os.UserHandle> getUserProfiles();
method @NonNull @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.QUERY_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public android.content.pm.UserProperties getUserProperties(@NonNull android.os.UserHandle);
method public android.os.Bundle getUserRestrictions();
method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.INTERACT_ACROSS_USERS"}, conditional=true) public android.os.Bundle getUserRestrictions(android.os.UserHandle);
method public boolean hasUserRestriction(String);

View File

@@ -3908,6 +3908,14 @@ package android.content.pm {
method @NonNull public android.content.pm.SuspendDialogInfo.Builder setTitle(@NonNull String);
}
public final class UserProperties implements android.os.Parcelable {
method public int describeContents();
method public boolean getIsCredentialSharableWithParent();
method public boolean getIsMediaSharedWithParent();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.UserProperties> CREATOR;
}
}
package android.content.pm.dex {
@@ -10415,6 +10423,7 @@ package android.os {
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public long[] getSerialNumbersOfUsers(boolean);
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.os.UserHandle> getUserHandles(boolean);
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.GET_ACCOUNTS_PRIVILEGED}) public android.graphics.Bitmap getUserIcon();
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public android.content.pm.UserProperties getUserProperties(@NonNull android.os.UserHandle);
method @Deprecated @android.os.UserManager.UserRestrictionSource @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public int getUserRestrictionSource(String, android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS}) public java.util.List<android.os.UserManager.EnforcingUser> getUserRestrictionSources(String, android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}) public int getUserSwitchability();
@@ -10423,11 +10432,11 @@ package android.os {
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean hasUserRestrictionForUser(@NonNull String, @NonNull android.os.UserHandle);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isAdminUser();
method public boolean isCloneProfile();
method public boolean isCredentialSharableWithParent();
method @Deprecated public boolean isCredentialSharableWithParent();
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isGuestUser();
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isMainUser();
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.QUERY_USERS, android.Manifest.permission.INTERACT_ACROSS_USERS}, conditional=true) public boolean isManagedProfile(int);
method public boolean isMediaSharedWithParent();
method @Deprecated public boolean isMediaSharedWithParent();
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS, android.Manifest.permission.QUERY_USERS}) public boolean isPrimaryUser();
method public static boolean isRemoveResultSuccessful(int);
method public boolean isRestrictedProfile();

View File

@@ -946,6 +946,13 @@ package android.content.pm {
field public String userType;
}
public final class UserProperties implements android.os.Parcelable {
method public int getShowInLauncher();
field public static final int SHOW_IN_LAUNCHER_NO = 2; // 0x2
field public static final int SHOW_IN_LAUNCHER_SEPARATE = 1; // 0x1
field public static final int SHOW_IN_LAUNCHER_WITH_PARENT = 0; // 0x0
}
}
package android.content.res {

View File

@@ -19,6 +19,8 @@ package android.content.pm;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Slog;
@@ -36,7 +38,10 @@ import java.lang.annotation.RetentionPolicy;
/**
* Class holding the properties of a user that derive mostly from its user type.
*
* @hide
*/
@SystemApi
public final class UserProperties implements Parcelable {
private static final String LOG_TAG = UserProperties.class.getSimpleName();
@@ -52,6 +57,10 @@ public final class UserProperties implements Parcelable {
"crossProfileIntentFilterAccessControl";
private static final String ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY =
"crossProfileIntentResolutionStrategy";
private static final String ATTR_MEDIA_SHARED_WITH_PARENT =
"mediaSharedWithParent";
private static final String ATTR_CREDENTIAL_SHARABLE_WITH_PARENT =
"credentialSharableWithParent";
/** Index values of each property (to indicate whether they are present in this object). */
@IntDef(prefix = "INDEX_", value = {
@@ -62,7 +71,9 @@ public final class UserProperties implements Parcelable {
INDEX_USE_PARENTS_CONTACTS,
INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA,
INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL,
INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY
INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY,
INDEX_MEDIA_SHARED_WITH_PARENT,
INDEX_CREDENTIAL_SHARABLE_WITH_PARENT
})
@Retention(RetentionPolicy.SOURCE)
private @interface PropertyIndex {
@@ -75,6 +86,8 @@ public final class UserProperties implements Parcelable {
private static final int INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA = 5;
private static final int INDEX_CROSS_PROFILE_INTENT_FILTER_ACCESS_CONTROL = 6;
private static final int INDEX_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY = 7;
private static final int INDEX_MEDIA_SHARED_WITH_PARENT = 8;
private static final int INDEX_CREDENTIAL_SHARABLE_WITH_PARENT = 9;
/** A bit set, mapping each PropertyIndex to whether it is present (1) or absent (0). */
private long mPropertiesPresent = 0;
@@ -95,16 +108,22 @@ public final class UserProperties implements Parcelable {
* Suggests that the launcher should show this user's apps in the main tab.
* That is, either this user is a full user, so its apps should be presented accordingly, or, if
* this user is a profile, then its apps should be shown alongside its parent's apps.
* @hide
*/
@TestApi
public static final int SHOW_IN_LAUNCHER_WITH_PARENT = 0;
/**
* Suggests that the launcher should show this user's apps, but separately from the apps of this
* user's parent.
* @hide
*/
@TestApi
public static final int SHOW_IN_LAUNCHER_SEPARATE = 1;
/**
* Suggests that the launcher should not show this user.
* @hide
*/
@TestApi
public static final int SHOW_IN_LAUNCHER_NO = 2;
/**
@@ -304,6 +323,8 @@ public final class UserProperties implements Parcelable {
}
// Add items that have no permission requirements at all.
setShowInLauncher(orig.getShowInLauncher());
setIsMediaSharedWithParent(orig.getIsMediaSharedWithParent());
setIsCredentialSharableWithParent(orig.getIsCredentialSharableWithParent());
}
/**
@@ -337,7 +358,9 @@ public final class UserProperties implements Parcelable {
* and {@link #SHOW_IN_LAUNCHER_NO}.
*
* @return whether, and how, a profile should be shown in the Launcher.
* @hide
*/
@TestApi
public @ShowInLauncher int getShowInLauncher() {
if (isPresent(INDEX_SHOW_IN_LAUNCHER)) return mShowInLauncher;
if (mDefaultProperties != null) return mDefaultProperties.mShowInLauncher;
@@ -463,13 +486,45 @@ public final class UserProperties implements Parcelable {
throw new SecurityException("You don't have permission to query "
+ "updateCrossProfileIntentFiltersOnOTA");
}
/** @hide */
public void setUpdateCrossProfileIntentFiltersOnOTA(boolean val) {
this.mUpdateCrossProfileIntentFiltersOnOTA = val;
setPresent(INDEX_UPDATE_CROSS_PROFILE_INTENT_FILTERS_ON_OTA);
}
/**
* Returns whether a profile shares media with its parent user.
* This only applies for users that have parents (i.e. for profiles).
*/
public boolean getIsMediaSharedWithParent() {
if (isPresent(INDEX_MEDIA_SHARED_WITH_PARENT)) return mMediaSharedWithParent;
if (mDefaultProperties != null) return mDefaultProperties.mMediaSharedWithParent;
throw new SecurityException("You don't have permission to query isMediaSharedWithParent");
}
/** @hide */
public void setIsMediaSharedWithParent(boolean val) {
this.mMediaSharedWithParent = val;
setPresent(INDEX_MEDIA_SHARED_WITH_PARENT);
}
private boolean mMediaSharedWithParent;
/**
* Returns whether a profile can have shared lockscreen credential with its parent user.
* This only applies for users that have parents (i.e. for profiles).
*/
public boolean getIsCredentialSharableWithParent() {
if (isPresent(INDEX_CREDENTIAL_SHARABLE_WITH_PARENT)) return mCredentialSharableWithParent;
if (mDefaultProperties != null) return mDefaultProperties.mCredentialSharableWithParent;
throw new SecurityException(
"You don't have permission to query isCredentialSharableWithParent");
}
/** @hide */
public void setIsCredentialSharableWithParent(boolean val) {
this.mCredentialSharableWithParent = val;
setPresent(INDEX_CREDENTIAL_SHARABLE_WITH_PARENT);
}
private boolean mCredentialSharableWithParent;
/*
Indicate if {@link com.android.server.pm.CrossProfileIntentFilter}s need to be updated during
OTA update between user-parent
@@ -550,6 +605,8 @@ public final class UserProperties implements Parcelable {
+ getCrossProfileIntentFilterAccessControl()
+ ", mCrossProfileIntentResolutionStrategy="
+ getCrossProfileIntentResolutionStrategy()
+ ", mMediaSharedWithParent=" + getIsMediaSharedWithParent()
+ ", mCredentialSharableWithParent=" + getIsCredentialSharableWithParent()
+ "}";
}
@@ -572,6 +629,9 @@ public final class UserProperties implements Parcelable {
+ getCrossProfileIntentFilterAccessControl());
pw.println(prefix + " mCrossProfileIntentResolutionStrategy="
+ getCrossProfileIntentResolutionStrategy());
pw.println(prefix + " mMediaSharedWithParent=" + getIsMediaSharedWithParent());
pw.println(prefix + " mCredentialSharableWithParent="
+ getIsCredentialSharableWithParent());
}
/**
@@ -629,6 +689,12 @@ public final class UserProperties implements Parcelable {
case ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY:
setCrossProfileIntentResolutionStrategy(parser.getAttributeInt(i));
break;
case ATTR_MEDIA_SHARED_WITH_PARENT:
setIsMediaSharedWithParent(parser.getAttributeBoolean(i));
break;
case ATTR_CREDENTIAL_SHARABLE_WITH_PARENT:
setIsCredentialSharableWithParent(parser.getAttributeBoolean(i));
break;
default:
Slog.w(LOG_TAG, "Skipping unknown property " + attributeName);
}
@@ -676,6 +742,14 @@ public final class UserProperties implements Parcelable {
serializer.attributeInt(null, ATTR_CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY,
mCrossProfileIntentResolutionStrategy);
}
if (isPresent(INDEX_MEDIA_SHARED_WITH_PARENT)) {
serializer.attributeBoolean(null, ATTR_MEDIA_SHARED_WITH_PARENT,
mMediaSharedWithParent);
}
if (isPresent(INDEX_CREDENTIAL_SHARABLE_WITH_PARENT)) {
serializer.attributeBoolean(null, ATTR_CREDENTIAL_SHARABLE_WITH_PARENT,
mCredentialSharableWithParent);
}
}
// For use only with an object that has already had any permission-lacking fields stripped out.
@@ -690,6 +764,8 @@ public final class UserProperties implements Parcelable {
dest.writeBoolean(mUpdateCrossProfileIntentFiltersOnOTA);
dest.writeInt(mCrossProfileIntentFilterAccessControl);
dest.writeInt(mCrossProfileIntentResolutionStrategy);
dest.writeBoolean(mMediaSharedWithParent);
dest.writeBoolean(mCredentialSharableWithParent);
}
/**
@@ -708,6 +784,8 @@ public final class UserProperties implements Parcelable {
mUpdateCrossProfileIntentFiltersOnOTA = source.readBoolean();
mCrossProfileIntentFilterAccessControl = source.readInt();
mCrossProfileIntentResolutionStrategy = source.readInt();
mMediaSharedWithParent = source.readBoolean();
mCredentialSharableWithParent = source.readBoolean();
}
@Override
@@ -743,6 +821,8 @@ public final class UserProperties implements Parcelable {
CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_ALL;
private @CrossProfileIntentResolutionStrategy int mCrossProfileIntentResolutionStrategy =
CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_DEFAULT;
private boolean mMediaSharedWithParent = false;
private boolean mCredentialSharableWithParent = false;
public Builder setShowInLauncher(@ShowInLauncher int showInLauncher) {
mShowInLauncher = showInLauncher;
@@ -794,6 +874,16 @@ public final class UserProperties implements Parcelable {
return this;
}
public Builder setIsMediaSharedWithParent(boolean mediaSharedWithParent) {
mMediaSharedWithParent = mediaSharedWithParent;
return this;
}
public Builder setIsCredentialSharableWithParent(boolean credentialSharableWithParent) {
mCredentialSharableWithParent = credentialSharableWithParent;
return this;
}
/** Builds a UserProperties object with *all* values populated. */
public UserProperties build() {
return new UserProperties(
@@ -804,7 +894,9 @@ public final class UserProperties implements Parcelable {
mUseParentsContacts,
mUpdateCrossProfileIntentFiltersOnOTA,
mCrossProfileIntentFilterAccessControl,
mCrossProfileIntentResolutionStrategy);
mCrossProfileIntentResolutionStrategy,
mMediaSharedWithParent,
mCredentialSharableWithParent);
}
} // end Builder
@@ -816,7 +908,9 @@ public final class UserProperties implements Parcelable {
@InheritDevicePolicy int inheritDevicePolicy,
boolean useParentsContacts, boolean updateCrossProfileIntentFiltersOnOTA,
@CrossProfileIntentFilterAccessControlLevel int crossProfileIntentFilterAccessControl,
@CrossProfileIntentResolutionStrategy int crossProfileIntentResolutionStrategy) {
@CrossProfileIntentResolutionStrategy int crossProfileIntentResolutionStrategy,
boolean mediaSharedWithParent,
boolean credentialSharableWithParent) {
mDefaultProperties = null;
setShowInLauncher(showInLauncher);
@@ -827,5 +921,7 @@ public final class UserProperties implements Parcelable {
setUpdateCrossProfileIntentFiltersOnOTA(updateCrossProfileIntentFiltersOnOTA);
setCrossProfileIntentFilterAccessControl(crossProfileIntentFilterAccessControl);
setCrossProfileIntentResolutionStrategy(crossProfileIntentResolutionStrategy);
setIsMediaSharedWithParent(mediaSharedWithParent);
setIsCredentialSharableWithParent(credentialSharableWithParent);
}
}

View File

@@ -116,8 +116,6 @@ interface IUserManager {
boolean someUserHasSeedAccount(in String accountName, in String accountType);
boolean someUserHasAccount(in String accountName, in String accountType);
String getProfileType(int userId);
boolean isMediaSharedWithParent(int userId);
boolean isCredentialSharableWithParent(int userId);
boolean isDemoUser(int userId);
boolean isPreCreated(int userId);
UserInfo createProfileForUserEvenWhenDisallowedWithThrow(in String name, in String userType, int flags,

View File

@@ -3248,7 +3248,10 @@ public class UserManager {
* @param userHandle the user handle of the user whose information is being requested.
* @return a UserProperties object for a specific user.
* @throws IllegalArgumentException if {@code userHandle} doesn't correspond to an existing user
*
* @hide
*/
@SystemApi
@RequiresPermission(anyOf = {
android.Manifest.permission.MANAGE_USERS,
android.Manifest.permission.QUERY_USERS,
@@ -5165,19 +5168,25 @@ public class UserManager {
* Returns false for any other type of user.
*
* @return true if the user shares media with its parent user, false otherwise.
*
* @deprecated use {@link #getUserProperties(UserHandle)} with
* {@link UserProperties#getIsMediaSharedWithParent()} instead.
* @hide
*/
@SystemApi
@Deprecated
@UserHandleAware(
requiresAnyOfPermissionsIfNotCallerProfileGroup = {
Manifest.permission.MANAGE_USERS,
Manifest.permission.QUERY_USERS,
Manifest.permission.INTERACT_ACROSS_USERS})
@SuppressAutoDoc
public boolean isMediaSharedWithParent() {
try {
return mService.isMediaSharedWithParent(mUserId);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
return getUserProperties(UserHandle.of(mUserId)).getIsMediaSharedWithParent();
} catch (IllegalArgumentException e) {
// If the user doesn't exist, return false (for historical reasons)
return false;
}
}
@@ -5187,19 +5196,24 @@ public class UserManager {
* This API only works for {@link UserManager#isProfile() profiles}
* and will always return false for any other user type.
*
* @deprecated use {@link #getUserProperties(UserHandle)} with
* {@link UserProperties#getIsMediaSharedWithParent()} instead.
* @hide
*/
@SystemApi
@Deprecated
@UserHandleAware(
requiresAnyOfPermissionsIfNotCallerProfileGroup = {
Manifest.permission.MANAGE_USERS,
Manifest.permission.QUERY_USERS,
Manifest.permission.INTERACT_ACROSS_USERS})
@SuppressAutoDoc
public boolean isCredentialSharableWithParent() {
try {
return mService.isCredentialSharableWithParent(mUserId);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
return getUserProperties(UserHandle.of(mUserId)).getIsCredentialSharableWithParent();
} catch (IllegalArgumentException e) {
// If the user doesn't exist, return false (for historical reasons)
return false;
}
}

View File

@@ -57,6 +57,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PathPermission;
import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.pm.UserProperties;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Binder;
@@ -87,7 +88,6 @@ import com.android.server.LocalManagerRegistry;
import com.android.server.LocalServices;
import com.android.server.RescueParty;
import com.android.server.pm.UserManagerInternal;
import com.android.server.pm.UserManagerService;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.sdksandbox.SdkSandboxManagerLocal;
@@ -186,7 +186,7 @@ public class ContentProviderHelper {
checkTime(startTime, "getContentProviderImpl: getProviderByName");
UserManagerService userManagerService = UserManagerService.getInstance();
UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class);
/*
For clone user profile and allowed authority, skipping finding provider and redirecting
@@ -196,8 +196,10 @@ public class ContentProviderHelper {
used and redirect to owner user's MediaProvider.
*/
//todo(b/236121588) MediaProvider should not be installed in clone profile.
if (!isAuthorityRedirectedForCloneProfile(name)
|| !userManagerService.isMediaSharedWithParent(userId)) {
final UserProperties userProps = umInternal.getUserProperties(userId);
final boolean isMediaSharedWithParent =
userProps != null && userProps.getIsMediaSharedWithParent();
if (!isAuthorityRedirectedForCloneProfile(name) || !isMediaSharedWithParent) {
// First check if this content provider has been published...
cpr = mProviderMap.getProviderByName(name, userId);
}
@@ -215,9 +217,7 @@ public class ContentProviderHelper {
userId = UserHandle.USER_SYSTEM;
checkCrossUser = false;
} else if (isAuthorityRedirectedForCloneProfile(name)) {
if (userManagerService.isMediaSharedWithParent(userId)) {
UserManagerInternal umInternal = LocalServices.getService(
UserManagerInternal.class);
if (isMediaSharedWithParent) {
userId = umInternal.getProfileParentId(userId);
checkCrossUser = false;
}

View File

@@ -1457,8 +1457,7 @@ class UserController implements Handler.Callback {
}
private boolean shouldStartWithParent(UserInfo user) {
final UserProperties properties = mInjector.getUserManagerInternal()
.getUserProperties(user.id);
final UserProperties properties = getUserProperties(user.id);
return (properties != null && properties.getStartWithParent())
&& !user.isQuietModeEnabled();
}
@@ -2773,6 +2772,10 @@ class UserController implements Handler.Callback {
return mInjector.getUserManager().getUserInfo(userId);
}
private @Nullable UserProperties getUserProperties(@UserIdInt int userId) {
return mInjector.getUserManagerInternal().getUserProperties(userId);
}
int[] getUserIds() {
return mInjector.getUserManager().getUserIds();
}
@@ -2903,7 +2906,8 @@ class UserController implements Handler.Callback {
if (getStartedUserState(userId) == null) {
return false;
}
if (!mInjector.getUserManager().isCredentialSharableWithParent(userId)) {
final UserProperties properties = getUserProperties(userId);
if (properties == null || !properties.getIsCredentialSharableWithParent()) {
return false;
}
if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userId)) {

View File

@@ -1778,28 +1778,6 @@ public class UserManagerService extends IUserManager.Stub {
}
}
@Override
public boolean isMediaSharedWithParent(@UserIdInt int userId) {
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId,
"isMediaSharedWithParent");
synchronized (mUsersLock) {
UserTypeDetails userTypeDetails = getUserTypeDetailsNoChecks(userId);
return userTypeDetails != null ? userTypeDetails.isProfile()
&& userTypeDetails.isMediaSharedWithParent() : false;
}
}
@Override
public boolean isCredentialSharableWithParent(@UserIdInt int userId) {
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId,
"isCredentialSharableWithParent");
synchronized (mUsersLock) {
UserTypeDetails userTypeDetails = getUserTypeDetailsNoChecks(userId);
return userTypeDetails != null && userTypeDetails.isProfile()
&& userTypeDetails.isCredentialSharableWithParent();
}
}
@Override
public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
checkManageOrInteractPermissionIfCallerInOtherProfileGroup(userId,

View File

@@ -150,20 +150,6 @@ public final class UserTypeDetails {
*/
private final @Nullable int[] mDarkThemeBadgeColors;
/**
* Denotes if the user shares media with its parent user.
*
* <p> Default value is false
*/
private final boolean mIsMediaSharedWithParent;
/**
* Denotes if the user shares encryption credentials with its parent user.
*
* <p> Default value is false
*/
private final boolean mIsCredentialSharableWithParent;
/**
* The default {@link UserProperties} for the user type.
* <p> The uninitialized value of each property is implied by {@link UserProperties.Builder}.
@@ -180,8 +166,6 @@ public final class UserTypeDetails {
@Nullable Bundle defaultSystemSettings,
@Nullable Bundle defaultSecureSettings,
@Nullable List<DefaultCrossProfileIntentFilter> defaultCrossProfileIntentFilters,
boolean isMediaSharedWithParent,
boolean isCredentialSharableWithParent,
@NonNull UserProperties defaultUserProperties) {
this.mName = name;
this.mEnabled = enabled;
@@ -201,8 +185,6 @@ public final class UserTypeDetails {
this.mBadgeLabels = badgeLabels;
this.mBadgeColors = badgeColors;
this.mDarkThemeBadgeColors = darkThemeBadgeColors;
this.mIsMediaSharedWithParent = isMediaSharedWithParent;
this.mIsCredentialSharableWithParent = isCredentialSharableWithParent;
this.mDefaultUserProperties = defaultUserProperties;
}
@@ -309,21 +291,6 @@ public final class UserTypeDetails {
return mDarkThemeBadgeColors[Math.min(badgeIndex, mDarkThemeBadgeColors.length - 1)];
}
/**
* Returns true if the user has shared media with parent user or false otherwise.
*/
public boolean isMediaSharedWithParent() {
return mIsMediaSharedWithParent;
}
/**
* Returns true if the user has shared encryption credential with parent user or
* false otherwise.
*/
public boolean isCredentialSharableWithParent() {
return mIsCredentialSharableWithParent;
}
/**
* Returns the reference to the default {@link UserProperties} for this type of user.
@@ -437,8 +404,6 @@ public final class UserTypeDetails {
private @DrawableRes int mIconBadge = Resources.ID_NULL;
private @DrawableRes int mBadgePlain = Resources.ID_NULL;
private @DrawableRes int mBadgeNoBackground = Resources.ID_NULL;
private boolean mIsMediaSharedWithParent = false;
private boolean mIsCredentialSharableWithParent = false;
// Default UserProperties cannot be null but for efficiency we don't initialize it now.
// If it isn't set explicitly, {@link UserProperties.Builder#build()} will be used.
private @Nullable UserProperties mDefaultUserProperties = null;
@@ -532,24 +497,6 @@ public final class UserTypeDetails {
return this;
}
/**
* Sets shared media property for the user.
* @param isMediaSharedWithParent the value to be set, true or false
*/
public Builder setIsMediaSharedWithParent(boolean isMediaSharedWithParent) {
mIsMediaSharedWithParent = isMediaSharedWithParent;
return this;
}
/**
* Sets shared media property for the user.
* @param isCredentialSharableWithParent the value to be set, true or false
*/
public Builder setIsCredentialSharableWithParent(boolean isCredentialSharableWithParent) {
mIsCredentialSharableWithParent = isCredentialSharableWithParent;
return this;
}
/**
* Sets (replacing if necessary) the default UserProperties object for this user type.
* Takes a builder, rather than a built object, to efficiently ensure that a fresh copy of
@@ -609,8 +556,6 @@ public final class UserTypeDetails {
mDefaultSystemSettings,
mDefaultSecureSettings,
mDefaultCrossProfileIntentFilters,
mIsMediaSharedWithParent,
mIsCredentialSharableWithParent,
getDefaultUserProperties());
}

View File

@@ -122,8 +122,6 @@ public final class UserTypeFactory {
.setMaxAllowedPerParent(1)
.setLabel(0)
.setDefaultRestrictions(null)
.setIsMediaSharedWithParent(true)
.setIsCredentialSharableWithParent(true)
.setDefaultCrossProfileIntentFilters(getDefaultCloneCrossProfileIntentFilter())
.setDefaultUserProperties(new UserProperties.Builder()
.setStartWithParent(true)
@@ -135,7 +133,10 @@ public final class UserTypeFactory {
.setCrossProfileIntentFilterAccessControl(
UserProperties.CROSS_PROFILE_INTENT_FILTER_ACCESS_LEVEL_SYSTEM)
.setCrossProfileIntentResolutionStrategy(UserProperties
.CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_NO_FILTERING));
.CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_NO_FILTERING)
.setIsMediaSharedWithParent(true)
.setIsCredentialSharableWithParent(true)
);
}
/**
@@ -167,11 +168,11 @@ public final class UserTypeFactory {
.setDefaultRestrictions(getDefaultManagedProfileRestrictions())
.setDefaultSecureSettings(getDefaultManagedProfileSecureSettings())
.setDefaultCrossProfileIntentFilters(getDefaultManagedCrossProfileIntentFilter())
.setIsCredentialSharableWithParent(true)
.setDefaultUserProperties(new UserProperties.Builder()
.setStartWithParent(true)
.setShowInLauncher(UserProperties.SHOW_IN_LAUNCHER_SEPARATE)
.setShowInSettings(UserProperties.SHOW_IN_SETTINGS_SEPARATE));
.setShowInSettings(UserProperties.SHOW_IN_SETTINGS_SEPARATE)
.setIsCredentialSharableWithParent(true));
}
/**

View File

@@ -36,6 +36,8 @@
useParentsContacts='false'
crossProfileIntentFilterAccessControl='20'
crossProfileIntentResolutionStrategy='0'
mediaSharedWithParent='true'
credentialSharableWithParent='false'
/>
</profile-type>
<profile-type name='custom.test.1' max-allowed-per-parent='14' />

View File

@@ -64,6 +64,8 @@ public class UserManagerServiceUserPropertiesTest {
.setUseParentsContacts(false)
.setCrossProfileIntentFilterAccessControl(10)
.setCrossProfileIntentResolutionStrategy(0)
.setIsMediaSharedWithParent(false)
.setIsCredentialSharableWithParent(true)
.build();
final UserProperties actualProps = new UserProperties(defaultProps);
actualProps.setShowInLauncher(14);
@@ -72,6 +74,8 @@ public class UserManagerServiceUserPropertiesTest {
actualProps.setUseParentsContacts(true);
actualProps.setCrossProfileIntentFilterAccessControl(20);
actualProps.setCrossProfileIntentResolutionStrategy(1);
actualProps.setIsMediaSharedWithParent(true);
actualProps.setIsCredentialSharableWithParent(false);
// Write the properties to xml.
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -111,6 +115,7 @@ public class UserManagerServiceUserPropertiesTest {
.setStartWithParent(true)
.setShowInSettings(3452)
.setInheritDevicePolicy(1732)
.setIsMediaSharedWithParent(true)
.build();
final UserProperties orig = new UserProperties(defaultProps);
orig.setShowInLauncher(2841);
@@ -169,7 +174,10 @@ public class UserManagerServiceUserPropertiesTest {
// Items with no permission requirements.
assertEqualGetterOrThrows(orig::getShowInLauncher, copy::getShowInLauncher, true);
assertEqualGetterOrThrows(orig::getIsMediaSharedWithParent,
copy::getIsMediaSharedWithParent, true);
assertEqualGetterOrThrows(orig::getIsCredentialSharableWithParent,
copy::getIsCredentialSharableWithParent, true);
}
/**
@@ -215,5 +223,9 @@ public class UserManagerServiceUserPropertiesTest {
.isEqualTo(actual.getCrossProfileIntentFilterAccessControl());
assertThat(expected.getCrossProfileIntentResolutionStrategy())
.isEqualTo(actual.getCrossProfileIntentResolutionStrategy());
assertThat(expected.getIsMediaSharedWithParent())
.isEqualTo(actual.getIsMediaSharedWithParent());
assertThat(expected.getIsCredentialSharableWithParent())
.isEqualTo(actual.getIsCredentialSharableWithParent());
}
}

View File

@@ -86,7 +86,9 @@ public class UserManagerServiceUserTypeTest {
.setShowInLauncher(17)
.setUseParentsContacts(true)
.setCrossProfileIntentFilterAccessControl(10)
.setCrossProfileIntentResolutionStrategy(1);
.setCrossProfileIntentResolutionStrategy(1)
.setIsMediaSharedWithParent(true)
.setIsCredentialSharableWithParent(false);
final UserTypeDetails type = new UserTypeDetails.Builder()
.setName("a.name")
.setEnabled(1)
@@ -148,6 +150,8 @@ public class UserManagerServiceUserTypeTest {
.getCrossProfileIntentFilterAccessControl());
assertEquals(1, type.getDefaultUserPropertiesReference()
.getCrossProfileIntentResolutionStrategy());
assertTrue(type.getDefaultUserPropertiesReference().getIsMediaSharedWithParent());
assertFalse(type.getDefaultUserPropertiesReference().getIsCredentialSharableWithParent());
assertEquals(23, type.getBadgeLabel(0));
assertEquals(24, type.getBadgeLabel(1));
@@ -196,6 +200,8 @@ public class UserManagerServiceUserTypeTest {
assertEquals(UserProperties.SHOW_IN_LAUNCHER_WITH_PARENT, props.getShowInLauncher());
assertEquals(UserProperties.CROSS_PROFILE_INTENT_RESOLUTION_STRATEGY_DEFAULT,
props.getCrossProfileIntentResolutionStrategy());
assertFalse(props.getIsMediaSharedWithParent());
assertFalse(props.getIsCredentialSharableWithParent());
assertFalse(type.hasBadge());
}
@@ -279,7 +285,9 @@ public class UserManagerServiceUserTypeTest {
.setStartWithParent(true)
.setUseParentsContacts(true)
.setCrossProfileIntentFilterAccessControl(10)
.setCrossProfileIntentResolutionStrategy(1);
.setCrossProfileIntentResolutionStrategy(1)
.setIsMediaSharedWithParent(false)
.setIsCredentialSharableWithParent(true);
final ArrayMap<String, UserTypeDetails.Builder> builders = new ArrayMap<>();
builders.put(userTypeAosp1, new UserTypeDetails.Builder()
.setName(userTypeAosp1)
@@ -312,6 +320,9 @@ public class UserManagerServiceUserTypeTest {
assertTrue(aospType.getDefaultUserPropertiesReference().getStartWithParent());
assertTrue(aospType.getDefaultUserPropertiesReference()
.getUseParentsContacts());
assertFalse(aospType.getDefaultUserPropertiesReference().getIsMediaSharedWithParent());
assertTrue(aospType.getDefaultUserPropertiesReference()
.getIsCredentialSharableWithParent());
// userTypeAosp2 should be modified.
aospType = builders.get(userTypeAosp2).createUserTypeDetails();
@@ -348,6 +359,9 @@ public class UserManagerServiceUserTypeTest {
assertFalse(aospType.getDefaultUserPropertiesReference().getStartWithParent());
assertFalse(aospType.getDefaultUserPropertiesReference()
.getUseParentsContacts());
assertTrue(aospType.getDefaultUserPropertiesReference().getIsMediaSharedWithParent());
assertFalse(aospType.getDefaultUserPropertiesReference()
.getIsCredentialSharableWithParent());
// userTypeOem1 should be created.
UserTypeDetails.Builder customType = builders.get(userTypeOem1);

View File

@@ -19,7 +19,6 @@ package com.android.server.pm;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.testng.Assert.assertThrows;
@@ -189,6 +188,10 @@ public final class UserManagerTest {
cloneUserProperties::getCrossProfileIntentFilterAccessControl);
assertThrows(SecurityException.class,
cloneUserProperties::getCrossProfileIntentResolutionStrategy);
assertThat(typeProps.getIsMediaSharedWithParent())
.isEqualTo(cloneUserProperties.getIsMediaSharedWithParent());
assertThat(typeProps.getIsCredentialSharableWithParent())
.isEqualTo(cloneUserProperties.getIsCredentialSharableWithParent());
// Verify clone user parent
assertThat(mUserManager.getProfileParent(mainUserId)).isNull();
@@ -834,11 +837,13 @@ public final class UserManagerTest {
// provided that the test caller has the necessary permissions.
assertThat(userProps.getShowInLauncher()).isEqualTo(typeProps.getShowInLauncher());
assertThat(userProps.getShowInSettings()).isEqualTo(typeProps.getShowInSettings());
assertFalse(userProps.getUseParentsContacts());
assertThat(userProps.getUseParentsContacts()).isFalse();
assertThrows(SecurityException.class, userProps::getCrossProfileIntentFilterAccessControl);
assertThrows(SecurityException.class, userProps::getCrossProfileIntentResolutionStrategy);
assertThrows(SecurityException.class, userProps::getStartWithParent);
assertThrows(SecurityException.class, userProps::getInheritDevicePolicy);
assertThat(userProps.getIsMediaSharedWithParent()).isFalse();
assertThat(userProps.getIsCredentialSharableWithParent()).isTrue();
}
// Make sure only max managed profiles can be created