am db5b4ecc: am 4e2add3e: Merge "Write packages.list when adding/removing users." into mnc-dev

* commit 'db5b4eccf9fe38d1f18d910bdacc209c94134475':
  Write packages.list when adding/removing users.
This commit is contained in:
Jeff Sharkey
2015-05-20 19:30:07 +00:00
committed by Android Git Automerger
2 changed files with 99 additions and 78 deletions

View File

@@ -381,10 +381,10 @@ public final class PermissionsState {
* *
* @return The gids for all device users. * @return The gids for all device users.
*/ */
public int[] computeGids() { public int[] computeGids(int[] userIds) {
int[] gids = mGlobalGids; int[] gids = mGlobalGids;
for (int userId : UserManagerService.getInstance().getUserIds()) { for (int userId : userIds) {
final int[] userGids = computeGids(userId); final int[] userGids = computeGids(userId);
gids = appendInts(gids, userGids); gids = appendInts(gids, userGids);
} }

View File

@@ -2022,14 +2022,53 @@ final class Settings {
|FileUtils.S_IRGRP|FileUtils.S_IWGRP, |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
-1, -1); -1, -1);
writePackageListLPr();
writeAllUsersPackageRestrictionsLPr();
writeAllRuntimePermissionsLPr();
return;
} catch(XmlPullParserException e) {
Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+ "current changes will be lost at reboot", e);
} catch(java.io.IOException e) {
Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+ "current changes will be lost at reboot", e);
}
// Clean up partially written files
if (mSettingsFilename.exists()) {
if (!mSettingsFilename.delete()) {
Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: "
+ mSettingsFilename);
}
}
//Debug.stopMethodTracing();
}
void writePackageListLPr() {
writePackageListLPr(-1);
}
void writePackageListLPr(int creatingUserId) {
// Only derive GIDs for active users (not dying)
final List<UserInfo> users = UserManagerService.getInstance().getUsers(true);
int[] userIds = new int[users.size()];
for (int i = 0; i < userIds.length; i++) {
userIds[i] = users.get(i).id;
}
if (creatingUserId != -1) {
userIds = ArrayUtils.appendInt(userIds, creatingUserId);
}
// Write package list file now, use a JournaledFile. // Write package list file now, use a JournaledFile.
File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp"); File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp");
JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile); JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
final File writeTarget = journal.chooseForWrite(); final File writeTarget = journal.chooseForWrite();
FileOutputStream fstr = null;
BufferedOutputStream str = null;
try {
fstr = new FileOutputStream(writeTarget); fstr = new FileOutputStream(writeTarget);
str = new BufferedOutputStream(fstr); str = new BufferedOutputStream(fstr);
try {
FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID); FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -2042,7 +2081,7 @@ final class Settings {
final ApplicationInfo ai = pkg.pkg.applicationInfo; final ApplicationInfo ai = pkg.pkg.applicationInfo;
final String dataPath = ai.dataDir; final String dataPath = ai.dataDir;
final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
final int[] gids = pkg.getPermissionsState().computeGids(); final int[] gids = pkg.getPermissionsState().computeGids(userIds);
// Avoid any application that has a space in its path. // Avoid any application that has a space in its path.
if (dataPath.indexOf(" ") >= 0) if (dataPath.indexOf(" ") >= 0)
@@ -2096,27 +2135,6 @@ final class Settings {
IoUtils.closeQuietly(str); IoUtils.closeQuietly(str);
journal.rollback(); journal.rollback();
} }
writeAllUsersPackageRestrictionsLPr();
writeAllRuntimePermissionsLPr();
return;
} catch(XmlPullParserException e) {
Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+ "current changes will be lost at reboot", e);
} catch(java.io.IOException e) {
Slog.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+ "current changes will be lost at reboot", e);
}
// Clean up partially written files
if (mSettingsFilename.exists()) {
if (!mSettingsFilename.delete()) {
Slog.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: "
+ mSettingsFilename);
}
}
//Debug.stopMethodTracing();
} }
void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg) void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
@@ -3491,6 +3509,7 @@ final class Settings {
} }
readDefaultPreferredAppsLPw(service, userHandle); readDefaultPreferredAppsLPw(service, userHandle);
writePackageRestrictionsLPr(userHandle); writePackageRestrictionsLPr(userHandle);
writePackageListLPr(userHandle);
} }
void removeUserLPw(int userId) { void removeUserLPw(int userId) {
@@ -3506,6 +3525,8 @@ final class Settings {
removeCrossProfileIntentFiltersLPw(userId); removeCrossProfileIntentFiltersLPw(userId);
mRuntimePermissionsPersistence.onUserRemoved(userId); mRuntimePermissionsPersistence.onUserRemoved(userId);
writePackageListLPr();
} }
void removeCrossProfileIntentFiltersLPw(int userId) { void removeCrossProfileIntentFiltersLPw(int userId) {