Loading services/devicepolicy/java/com/android/server/devicepolicy/Owners.java +36 −1 Original line number Diff line number Diff line Loading @@ -28,10 +28,10 @@ import android.os.Environment; import android.os.RemoteException; import android.os.UserManager; import android.util.AtomicFile; import android.util.Log; import android.util.Slog; import android.util.Xml; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FastXmlSerializer; import org.xmlpull.v1.XmlPullParser; Loading @@ -58,6 +58,8 @@ import libcore.io.IoUtils; class Owners { private static final String TAG = "DevicePolicyManagerService"; private static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE private static final String DEVICE_OWNER_XML_LEGACY = "device_owner.xml"; private static final String DEVICE_OWNER_XML = "device_owner_2.xml"; Loading Loading @@ -106,11 +108,18 @@ class Owners { final File legacy = getLegacyConfigFileWithTestOverride(); if (readLegacyOwnerFile(legacy)) { if (DEBUG) { Log.d(TAG, "Legacy config file found."); } // Legacy file exists, write to new files and remove the legacy one. writeDeviceOwner(); for (int userId : getProfileOwnerKeys()) { writeProfileOwner(userId); } if (DEBUG) { Log.d(TAG, "Deleting legacy config file"); } if (!legacy.delete()) { Slog.e(TAG, "Failed to remove the legacy setting file"); } Loading Loading @@ -181,6 +190,11 @@ class Owners { return profileOwner != null ? profileOwner.name : null; } String getProfileOwnerPackage(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.packageName : null; } Set<Integer> getProfileOwnerKeys() { return mProfileOwners.keySet(); } Loading Loading @@ -301,12 +315,18 @@ class Owners { void writeDeviceOwner() { synchronized (this) { if (DEBUG) { Log.d(TAG, "Writing to device owner file"); } new DeviceOwnerReadWriter().writeToFileLocked(); } } void writeProfileOwner(int userId) { synchronized (this) { if (DEBUG) { Log.d(TAG, "Writing to profile owner file for user " + userId); } new ProfileOwnerReadWriter(userId).writeToFileLocked(); } } Loading @@ -322,14 +342,23 @@ class Owners { void writeToFileLocked() { if (!shouldWrite()) { if (DEBUG) { Log.d(TAG, "No need to write to " + mFile); } // No contents, remove the file. if (mFile.exists()) { if (DEBUG) { Log.d(TAG, "Deleting existing " + mFile); } if (!mFile.delete()) { Slog.e(TAG, "Failed to remove " + mFile.getPath()); } } return; } if (DEBUG) { Log.d(TAG, "Writing to " + mFile); } final AtomicFile f = new AtomicFile(mFile); FileOutputStream outputStream = null; Loading Loading @@ -364,8 +393,14 @@ class Owners { void readFromFileLocked() { if (!mFile.exists()) { if (DEBUG) { Log.d(TAG, "" + mFile + " doesn't exist"); } return; } if (DEBUG) { Log.d(TAG, "Reading from " + mFile); } final AtomicFile f = new AtomicFile(mFile); InputStream input = null; try { Loading services/tests/servicestests/assets/OwnersTest/test01/input.xml 0 → 100644 +1 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> services/tests/servicestests/assets/OwnersTest/test02/input.xml 0 → 100644 +2 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <device-owner package="com.google.android.testdpc" /> services/tests/servicestests/assets/OwnersTest/test03/input.xml 0 → 100644 +3 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" /> <profile-owner package="com.google.android.testdpc1" name="1" userId="11" /> services/tests/servicestests/assets/OwnersTest/test04/input.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <device-owner package="com.google.android.testdpc" /> <profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" /> <profile-owner package="com.google.android.testdpc1" name="1" userId="11" /> <device-initializer package="com.google.android.testdpcx" name="di" component="com.google.android.testdpcx/receiver" /> <system-update-policy policy_type="5" /> Loading
services/devicepolicy/java/com/android/server/devicepolicy/Owners.java +36 −1 Original line number Diff line number Diff line Loading @@ -28,10 +28,10 @@ import android.os.Environment; import android.os.RemoteException; import android.os.UserManager; import android.util.AtomicFile; import android.util.Log; import android.util.Slog; import android.util.Xml; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FastXmlSerializer; import org.xmlpull.v1.XmlPullParser; Loading @@ -58,6 +58,8 @@ import libcore.io.IoUtils; class Owners { private static final String TAG = "DevicePolicyManagerService"; private static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE private static final String DEVICE_OWNER_XML_LEGACY = "device_owner.xml"; private static final String DEVICE_OWNER_XML = "device_owner_2.xml"; Loading Loading @@ -106,11 +108,18 @@ class Owners { final File legacy = getLegacyConfigFileWithTestOverride(); if (readLegacyOwnerFile(legacy)) { if (DEBUG) { Log.d(TAG, "Legacy config file found."); } // Legacy file exists, write to new files and remove the legacy one. writeDeviceOwner(); for (int userId : getProfileOwnerKeys()) { writeProfileOwner(userId); } if (DEBUG) { Log.d(TAG, "Deleting legacy config file"); } if (!legacy.delete()) { Slog.e(TAG, "Failed to remove the legacy setting file"); } Loading Loading @@ -181,6 +190,11 @@ class Owners { return profileOwner != null ? profileOwner.name : null; } String getProfileOwnerPackage(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.packageName : null; } Set<Integer> getProfileOwnerKeys() { return mProfileOwners.keySet(); } Loading Loading @@ -301,12 +315,18 @@ class Owners { void writeDeviceOwner() { synchronized (this) { if (DEBUG) { Log.d(TAG, "Writing to device owner file"); } new DeviceOwnerReadWriter().writeToFileLocked(); } } void writeProfileOwner(int userId) { synchronized (this) { if (DEBUG) { Log.d(TAG, "Writing to profile owner file for user " + userId); } new ProfileOwnerReadWriter(userId).writeToFileLocked(); } } Loading @@ -322,14 +342,23 @@ class Owners { void writeToFileLocked() { if (!shouldWrite()) { if (DEBUG) { Log.d(TAG, "No need to write to " + mFile); } // No contents, remove the file. if (mFile.exists()) { if (DEBUG) { Log.d(TAG, "Deleting existing " + mFile); } if (!mFile.delete()) { Slog.e(TAG, "Failed to remove " + mFile.getPath()); } } return; } if (DEBUG) { Log.d(TAG, "Writing to " + mFile); } final AtomicFile f = new AtomicFile(mFile); FileOutputStream outputStream = null; Loading Loading @@ -364,8 +393,14 @@ class Owners { void readFromFileLocked() { if (!mFile.exists()) { if (DEBUG) { Log.d(TAG, "" + mFile + " doesn't exist"); } return; } if (DEBUG) { Log.d(TAG, "Reading from " + mFile); } final AtomicFile f = new AtomicFile(mFile); InputStream input = null; try { Loading
services/tests/servicestests/assets/OwnersTest/test01/input.xml 0 → 100644 +1 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?>
services/tests/servicestests/assets/OwnersTest/test02/input.xml 0 → 100644 +2 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <device-owner package="com.google.android.testdpc" />
services/tests/servicestests/assets/OwnersTest/test03/input.xml 0 → 100644 +3 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" /> <profile-owner package="com.google.android.testdpc1" name="1" userId="11" />
services/tests/servicestests/assets/OwnersTest/test04/input.xml 0 → 100644 +6 −0 Original line number Diff line number Diff line <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <device-owner package="com.google.android.testdpc" /> <profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" /> <profile-owner package="com.google.android.testdpc1" name="1" userId="11" /> <device-initializer package="com.google.android.testdpcx" name="di" component="com.google.android.testdpcx/receiver" /> <system-update-policy policy_type="5" />