diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 071a03602da79d31f58ebb691222fb1edaecbf8f..82d3e9157986e1a41b0fa76cb75979bb1c006ae9 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -75,13 +75,13 @@ import android.content.pm.parsing.FrameworkParsingPackageUtils; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; -import android.multiuser.Flags; import android.os.Binder; import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.Environment; import android.os.FileUtils; +import android.os.Flags; import android.os.Handler; import android.os.IBinder; import android.os.IProgressListener; @@ -1557,7 +1557,7 @@ public class UserManagerService extends IUserManager.Stub { logQuietModeEnabled(userId, enableQuietMode, callingPackage); // Broadcast generic intents for all profiles - if (android.os.Flags.allowPrivateProfile()) { + if (Flags.allowPrivateProfile()) { broadcastProfileAvailabilityChanges(profile, parent.getUserHandle(), enableQuietMode, false); } @@ -3783,8 +3783,6 @@ public class UserManagerService extends IUserManager.Stub { @GuardedBy({"mPackagesLock"}) private void readUserListLP() { - // Whether guest restrictions are present on userlist.xml - boolean guestRestrictionsArePresentOnUserListXml = false; try (ResilientAtomicFile file = getUserListFile()) { FileInputStream fin = null; try { @@ -3834,7 +3832,6 @@ public class UserManagerService extends IUserManager.Stub { } } } else if (name.equals(TAG_GUEST_RESTRICTIONS)) { - guestRestrictionsArePresentOnUserListXml = true; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.END_TAG) { if (type == XmlPullParser.START_TAG) { @@ -3853,7 +3850,6 @@ public class UserManagerService extends IUserManager.Stub { updateUserIds(); upgradeIfNecessaryLP(); - updateUsersWithFeatureFlags(guestRestrictionsArePresentOnUserListXml); } catch (Exception e) { // Remove corrupted file and retry. file.failRead(fin, e); @@ -3878,25 +3874,6 @@ public class UserManagerService extends IUserManager.Stub { upgradeIfNecessaryLP(mUserVersion, mUserTypeVersion); } - /** - * Update any user formats or Xml data that need to be updated based on the current user state - * and the feature flag settings. - */ - @GuardedBy({"mPackagesLock"}) - private void updateUsersWithFeatureFlags(boolean guestRestrictionsArePresentOnUserListXml) { - // User Xml re-writes are required when guest restrictions are saved on userlist.xml but - // as per the feature flag it should be on the SYSTEM user's xml or guest restrictions - // are saved on SYSTEM user's xml but as per the flags it should not be saved there. - if (guestRestrictionsArePresentOnUserListXml - == Flags.saveGlobalAndGuestRestrictionsOnSystemUserXml()) { - for (int userId: getUserIds()) { - writeUserLP(getUserDataNoChecks(userId)); - } - - writeUserListLP(); - } - } - /** * Version of {@link #upgradeIfNecessaryLP()} that takes in the userVersion for testing * purposes. For non-tests, use {@link #upgradeIfNecessaryLP()}. @@ -4412,24 +4389,9 @@ public class UserManagerService extends IUserManager.Stub { UserRestrictionsUtils.writeRestrictions(serializer, mBaseUserRestrictions.getRestrictions(userInfo.id), TAG_RESTRICTIONS); - if (Flags.saveGlobalAndGuestRestrictionsOnSystemUserXml()) { - if (userInfo.id == UserHandle.USER_SYSTEM) { - UserRestrictionsUtils.writeRestrictions(serializer, - mDevicePolicyUserRestrictions.getRestrictions(UserHandle.USER_ALL), - TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); - - serializer.startTag(null, TAG_GUEST_RESTRICTIONS); - synchronized (mGuestRestrictions) { - UserRestrictionsUtils.writeRestrictions(serializer, mGuestRestrictions, - TAG_RESTRICTIONS); - } - serializer.endTag(null, TAG_GUEST_RESTRICTIONS); - } - } else { - UserRestrictionsUtils.writeRestrictions(serializer, - mDevicePolicyUserRestrictions.getRestrictions(UserHandle.USER_ALL), - TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); - } + UserRestrictionsUtils.writeRestrictions(serializer, + mDevicePolicyUserRestrictions.getRestrictions(UserHandle.USER_ALL), + TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyUserRestrictions.getRestrictions(userInfo.id), @@ -4498,15 +4460,12 @@ public class UserManagerService extends IUserManager.Stub { serializer.attributeInt(null, ATTR_USER_VERSION, mUserVersion); serializer.attributeInt(null, ATTR_USER_TYPE_VERSION, mUserTypeVersion); - if (!Flags.saveGlobalAndGuestRestrictionsOnSystemUserXml()) { - serializer.startTag(null, TAG_GUEST_RESTRICTIONS); - synchronized (mGuestRestrictions) { - UserRestrictionsUtils - .writeRestrictions(serializer, mGuestRestrictions, - TAG_RESTRICTIONS); - } - serializer.endTag(null, TAG_GUEST_RESTRICTIONS); + serializer.startTag(null, TAG_GUEST_RESTRICTIONS); + synchronized (mGuestRestrictions) { + UserRestrictionsUtils + .writeRestrictions(serializer, mGuestRestrictions, TAG_RESTRICTIONS); } + serializer.endTag(null, TAG_GUEST_RESTRICTIONS); int[] userIdsToWrite; synchronized (mUsersLock) { userIdsToWrite = new int[mUsers.size()]; @@ -4650,19 +4609,6 @@ public class UserManagerService extends IUserManager.Stub { localRestrictions = UserRestrictionsUtils.readRestrictions(parser); } else if (TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS.equals(tag)) { globalRestrictions = UserRestrictionsUtils.readRestrictions(parser); - } else if (name.equals(TAG_GUEST_RESTRICTIONS)) { - while ((type = parser.next()) != XmlPullParser.END_DOCUMENT - && type != XmlPullParser.END_TAG) { - if (type == XmlPullParser.START_TAG) { - if (parser.getName().equals(TAG_RESTRICTIONS)) { - synchronized (mGuestRestrictions) { - UserRestrictionsUtils - .readRestrictions(parser, mGuestRestrictions); - } - } - break; - } - } } else if (TAG_ACCOUNT.equals(tag)) { type = parser.next(); if (type == XmlPullParser.TEXT) { diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java index c5ce7f5a0f253e7e07eb8e77fea7e095470c623d..9f75cf8d552ef8530bead39a31dc563e4672bef8 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java @@ -43,7 +43,6 @@ import android.annotation.UserIdInt; import android.app.PropertyInvalidatedCache; import android.content.pm.UserInfo; import android.content.pm.UserInfo.UserInfoFlag; -import android.multiuser.Flags; import android.os.Looper; import android.os.Parcel; import android.os.UserHandle; @@ -125,34 +124,18 @@ public class UserManagerServiceUserInfoTest { mUserManagerService.putUserInfo(data.info); - //Local restrictions are written to the user specific files and global restrictions - // are written to the SYSTEM user file. + // Set a global and user restriction so they get written out to the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); mUserManagerService.writeUserLP(data, out); - byte[] secondaryUserBytes = baos.toByteArray(); - baos.reset(); - - byte[] systemUserBytes = new byte[0]; - if (Flags.saveGlobalAndGuestRestrictionsOnSystemUserXml()) { - UserData systemUserData = new UserData(); - systemUserData.info = mUserManagerService.getUserInfo(UserHandle.USER_SYSTEM); - mUserManagerService.writeUserLP(systemUserData, baos); - systemUserBytes = baos.toByteArray(); - } + byte[] bytes = baos.toByteArray(); // Clear the restrictions to see if they are properly read in from the user file. setUserRestrictions(data.info.id, globalRestriction, localRestriction, false); - //read the secondary and SYSTEM user file to fetch local/global device policy restrictions. - mUserManagerService.readUserLP(data.info.id, new ByteArrayInputStream(secondaryUserBytes)); - if (Flags.saveGlobalAndGuestRestrictionsOnSystemUserXml()) { - mUserManagerService.readUserLP(UserHandle.USER_SYSTEM, - new ByteArrayInputStream(systemUserBytes)); - } - + mUserManagerService.readUserLP(data.info.id, new ByteArrayInputStream(bytes)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(globalRestriction)); assertTrue(mUserManagerService.hasUserRestrictionOnAnyUser(localRestriction)); }