am d2534f8c: Merge "Don\'t remove restrictions files that are valid" into klp-dev

* commit 'd2534f8c05ccdf692f1e265ae719b67290d15050':
  Don't remove restrictions files that are valid
This commit is contained in:
Amith Yamasani
2013-09-26 14:04:21 -07:00
committed by Android Git Automerger

View File

@@ -110,6 +110,7 @@ public class UserManagerService extends IUserManager.Stub {
private static final String USER_PHOTO_FILENAME = "photo.png"; private static final String USER_PHOTO_FILENAME = "photo.png";
private static final String RESTRICTIONS_FILE_PREFIX = "res_"; private static final String RESTRICTIONS_FILE_PREFIX = "res_";
private static final String XML_SUFFIX = ".xml";
private static final int MIN_USER_ID = 10; private static final int MIN_USER_ID = 10;
@@ -622,7 +623,7 @@ public class UserManagerService extends IUserManager.Stub {
*/ */
private void writeUserLocked(UserInfo userInfo) { private void writeUserLocked(UserInfo userInfo) {
FileOutputStream fos = null; FileOutputStream fos = null;
AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + ".xml")); AtomicFile userFile = new AtomicFile(new File(mUsersDir, userInfo.id + XML_SUFFIX));
try { try {
fos = userFile.startWrite(); fos = userFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos); final BufferedOutputStream bos = new BufferedOutputStream(fos);
@@ -751,7 +752,7 @@ public class UserManagerService extends IUserManager.Stub {
FileInputStream fis = null; FileInputStream fis = null;
try { try {
AtomicFile userFile = AtomicFile userFile =
new AtomicFile(new File(mUsersDir, Integer.toString(id) + ".xml")); new AtomicFile(new File(mUsersDir, Integer.toString(id) + XML_SUFFIX));
fis = userFile.openRead(); fis = userFile.openRead();
XmlPullParser parser = Xml.newPullParser(); XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, null); parser.setInput(fis, null);
@@ -909,7 +910,7 @@ public class UserManagerService extends IUserManager.Stub {
if (all) { if (all) {
resFile.delete(); resFile.delete();
} else { } else {
String pkg = fileName.substring(RESTRICTIONS_FILE_PREFIX.length()); String pkg = restrictionsFileNameToPackage(fileName);
if (!isPackageInstalled(pkg, userId)) { if (!isPackageInstalled(pkg, userId)) {
resFile.delete(); resFile.delete();
} }
@@ -926,7 +927,7 @@ public class UserManagerService extends IUserManager.Stub {
private void cleanAppRestrictionsForPackage(String pkg, int userId) { private void cleanAppRestrictionsForPackage(String pkg, int userId) {
synchronized (mPackagesLock) { synchronized (mPackagesLock) {
File dir = Environment.getUserSystemDirectory(userId); File dir = Environment.getUserSystemDirectory(userId);
File resFile = new File(dir, RESTRICTIONS_FILE_PREFIX + pkg); File resFile = new File(dir, packageToRestrictionsFileName(pkg));
if (resFile.exists()) { if (resFile.exists()) {
resFile.delete(); resFile.delete();
} }
@@ -1072,7 +1073,7 @@ public class UserManagerService extends IUserManager.Stub {
mRestrictionsPinStates.remove(userHandle); mRestrictionsPinStates.remove(userHandle);
// Remove user file // Remove user file
AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + XML_SUFFIX));
userFile.delete(); userFile.delete();
// Update the user list // Update the user list
writeUserListLocked(); writeUserListLocked();
@@ -1307,7 +1308,7 @@ public class UserManagerService extends IUserManager.Stub {
try { try {
AtomicFile restrictionsFile = AtomicFile restrictionsFile =
new AtomicFile(new File(Environment.getUserSystemDirectory(userId), new AtomicFile(new File(Environment.getUserSystemDirectory(userId),
RESTRICTIONS_FILE_PREFIX + packageName + ".xml")); packageToRestrictionsFileName(packageName)));
fis = restrictionsFile.openRead(); fis = restrictionsFile.openRead();
XmlPullParser parser = Xml.newPullParser(); XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, null); parser.setInput(fis, null);
@@ -1368,7 +1369,7 @@ public class UserManagerService extends IUserManager.Stub {
FileOutputStream fos = null; FileOutputStream fos = null;
AtomicFile restrictionsFile = new AtomicFile( AtomicFile restrictionsFile = new AtomicFile(
new File(Environment.getUserSystemDirectory(userId), new File(Environment.getUserSystemDirectory(userId),
RESTRICTIONS_FILE_PREFIX + packageName + ".xml")); packageToRestrictionsFileName(packageName)));
try { try {
fos = restrictionsFile.startWrite(); fos = restrictionsFile.startWrite();
final BufferedOutputStream bos = new BufferedOutputStream(fos); final BufferedOutputStream bos = new BufferedOutputStream(fos);
@@ -1498,6 +1499,15 @@ public class UserManagerService extends IUserManager.Stub {
} }
} }
private String packageToRestrictionsFileName(String packageName) {
return RESTRICTIONS_FILE_PREFIX + packageName + XML_SUFFIX;
}
private String restrictionsFileNameToPackage(String fileName) {
return fileName.substring(RESTRICTIONS_FILE_PREFIX.length(),
(int) (fileName.length() - XML_SUFFIX.length()));
}
@Override @Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)