Loading core/java/android/app/admin/DevicePolicyManager.java +0 −21 Original line number Diff line number Diff line Loading @@ -2422,27 +2422,6 @@ public class DevicePolicyManager { return true; } /** * @deprecated Use setProfileOwner(ComponentName ...) * @hide * Sets the given package as the profile owner of the given user profile. The package must * already be installed and there shouldn't be an existing profile owner registered for this * user. Also, this method must be called before the user has been used for the first time. * @param packageName the package name of the application to be registered as profile owner. * @param ownerName the human readable name of the organisation associated with this DPM. * @param userHandle the userId to set the profile owner for. * @return whether the package was successfully registered as the profile owner. * @throws IllegalArgumentException if packageName is null, the package isn't installed, or * the user has already been set up. */ public boolean setProfileOwner(String packageName, String ownerName, int userHandle) throws IllegalArgumentException { if (packageName == null) { throw new NullPointerException("packageName cannot be null"); } return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle); } /** * @hide * Sets the given component as the profile owner of the given user profile. The package must Loading services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java +7 −32 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ import java.util.Set; * Stores and restores state for the Device and Profile owners. By definition there can be * only one device owner, but there may be a profile owner for each user. */ public class DeviceOwner { class DeviceOwner { private static final String TAG = "DevicePolicyManagerService"; private static final String DEVICE_OWNER_XML = "device_owner.xml"; Loading Loading @@ -101,16 +101,6 @@ public class DeviceOwner { return owner; } /** * @deprecated Use a component name instead of package name * Creates an instance of the device owner object with the profile owner set. */ static DeviceOwner createWithProfileOwner(String packageName, String ownerName, int userId) { DeviceOwner owner = new DeviceOwner(); owner.mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName)); return owner; } /** * Creates an instance of the device owner object with the profile owner set. */ Loading @@ -136,13 +126,6 @@ public class DeviceOwner { mDeviceOwner = null; } /** * @deprecated */ void setProfileOwner(String packageName, String ownerName, int userId) { mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName)); } void setProfileOwner(ComponentName admin, String ownerName, int userId) { mProfileOwners.put(userId, new OwnerInfo(ownerName, admin)); } Loading @@ -151,16 +134,6 @@ public class DeviceOwner { mProfileOwners.remove(userId); } /** * @deprecated Use getProfileOwnerComponent * @param userId * @return */ String getProfileOwnerPackageName(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.packageName : null; } ComponentName getProfileOwnerComponent(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.admin : null; Loading Loading @@ -207,6 +180,7 @@ public class DeviceOwner { return false; } @VisibleForTesting void readOwnerFile() { try { InputStream input = openRead(); Loading Loading @@ -259,6 +233,7 @@ public class DeviceOwner { } } @VisibleForTesting void writeOwnerFile() { synchronized (this) { writeOwnerFileLocked(); Loading Loading @@ -329,10 +304,10 @@ public class DeviceOwner { } } static class OwnerInfo { public String name; public String packageName; public ComponentName admin; private static class OwnerInfo { public final String name; public final String packageName; public final ComponentName admin; public OwnerInfo(String name, String packageName) { this.name = name; Loading services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class ApplicationRestrictionsTest extends AndroidTestCase { sDpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 0); sDpm.setProfileOwner(context.getPackageName(), "Test", UserHandle.myUserId()); sDpm.setProfileOwner(sAdminReceiver, "Test", UserHandle.myUserId()); Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1); // Remove the admin if already registered. It's async, so add it back Loading services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java +21 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.devicepolicy; import android.content.ComponentName; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -32,7 +33,7 @@ import java.io.ByteArrayOutputStream; public class DeviceOwnerTest extends AndroidTestCase { private ByteArrayInputStream mInputStreamForTest; private ByteArrayOutputStream mOutputStreamForTest = new ByteArrayOutputStream(); private final ByteArrayOutputStream mOutputStreamForTest = new ByteArrayOutputStream(); @SmallTest public void testDeviceOwnerOnly() throws Exception { Loading @@ -46,13 +47,15 @@ public class DeviceOwnerTest extends AndroidTestCase { assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); assertEquals("owner", in.getDeviceOwnerName()); assertNull(in.getProfileOwnerPackageName(1)); assertNull(in.getProfileOwnerComponent(1)); } @SmallTest public void testProfileOwnerOnly() throws Exception { DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); out.setProfileOwner("some.profile.owner.package", "some-company", 1); ComponentName admin = new ComponentName( "some.profile.owner.package", "some.profile.owner.package.Class"); out.setProfileOwner(admin, "some-company", 1); out.writeOwnerFile(); mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); Loading @@ -61,16 +64,24 @@ public class DeviceOwnerTest extends AndroidTestCase { assertNull(in.getDeviceOwnerPackageName()); assertNull(in.getDeviceOwnerName()); assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); assertEquals(admin, in.getProfileOwnerComponent(1)); assertEquals("some-company", in.getProfileOwnerName(1)); } @SmallTest public void testDeviceAndProfileOwners() throws Exception { DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); ComponentName profileAdmin = new ComponentName( "some.profile.owner.package", "some.profile.owner.package.Class"); ComponentName otherProfileAdmin = new ComponentName( "some.other.profile.owner", "some.other.profile.owner.OtherClass"); // Old code used package name rather than component name, so the class // bit could be empty. ComponentName legacyComponentName = new ComponentName("legacy.profile.owner.package", ""); out.setDeviceOwner("some.device.owner.package", "owner"); out.setProfileOwner("some.profile.owner.package", "some-company", 1); out.setProfileOwner("some.other.profile.owner", "some-other-company", 2); out.setProfileOwner(profileAdmin, "some-company", 1); out.setProfileOwner(otherProfileAdmin, "some-other-company", 2); out.setProfileOwner(legacyComponentName, "legacy-company", 3); out.writeOwnerFile(); mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); Loading @@ -80,9 +91,10 @@ public class DeviceOwnerTest extends AndroidTestCase { assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); assertEquals("owner", in.getDeviceOwnerName()); assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); assertEquals(profileAdmin, in.getProfileOwnerComponent(1)); assertEquals("some-company", in.getProfileOwnerName(1)); assertEquals("some.other.profile.owner", in.getProfileOwnerPackageName(2)); assertEquals(otherProfileAdmin, in.getProfileOwnerComponent(2)); assertEquals("some-other-company", in.getProfileOwnerName(2)); assertEquals(legacyComponentName, in.getProfileOwnerComponent(3)); } } Loading
core/java/android/app/admin/DevicePolicyManager.java +0 −21 Original line number Diff line number Diff line Loading @@ -2422,27 +2422,6 @@ public class DevicePolicyManager { return true; } /** * @deprecated Use setProfileOwner(ComponentName ...) * @hide * Sets the given package as the profile owner of the given user profile. The package must * already be installed and there shouldn't be an existing profile owner registered for this * user. Also, this method must be called before the user has been used for the first time. * @param packageName the package name of the application to be registered as profile owner. * @param ownerName the human readable name of the organisation associated with this DPM. * @param userHandle the userId to set the profile owner for. * @return whether the package was successfully registered as the profile owner. * @throws IllegalArgumentException if packageName is null, the package isn't installed, or * the user has already been set up. */ public boolean setProfileOwner(String packageName, String ownerName, int userHandle) throws IllegalArgumentException { if (packageName == null) { throw new NullPointerException("packageName cannot be null"); } return setProfileOwner(new ComponentName(packageName, ""), ownerName, userHandle); } /** * @hide * Sets the given component as the profile owner of the given user profile. The package must Loading
services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java +7 −32 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ import java.util.Set; * Stores and restores state for the Device and Profile owners. By definition there can be * only one device owner, but there may be a profile owner for each user. */ public class DeviceOwner { class DeviceOwner { private static final String TAG = "DevicePolicyManagerService"; private static final String DEVICE_OWNER_XML = "device_owner.xml"; Loading Loading @@ -101,16 +101,6 @@ public class DeviceOwner { return owner; } /** * @deprecated Use a component name instead of package name * Creates an instance of the device owner object with the profile owner set. */ static DeviceOwner createWithProfileOwner(String packageName, String ownerName, int userId) { DeviceOwner owner = new DeviceOwner(); owner.mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName)); return owner; } /** * Creates an instance of the device owner object with the profile owner set. */ Loading @@ -136,13 +126,6 @@ public class DeviceOwner { mDeviceOwner = null; } /** * @deprecated */ void setProfileOwner(String packageName, String ownerName, int userId) { mProfileOwners.put(userId, new OwnerInfo(ownerName, packageName)); } void setProfileOwner(ComponentName admin, String ownerName, int userId) { mProfileOwners.put(userId, new OwnerInfo(ownerName, admin)); } Loading @@ -151,16 +134,6 @@ public class DeviceOwner { mProfileOwners.remove(userId); } /** * @deprecated Use getProfileOwnerComponent * @param userId * @return */ String getProfileOwnerPackageName(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.packageName : null; } ComponentName getProfileOwnerComponent(int userId) { OwnerInfo profileOwner = mProfileOwners.get(userId); return profileOwner != null ? profileOwner.admin : null; Loading Loading @@ -207,6 +180,7 @@ public class DeviceOwner { return false; } @VisibleForTesting void readOwnerFile() { try { InputStream input = openRead(); Loading Loading @@ -259,6 +233,7 @@ public class DeviceOwner { } } @VisibleForTesting void writeOwnerFile() { synchronized (this) { writeOwnerFileLocked(); Loading Loading @@ -329,10 +304,10 @@ public class DeviceOwner { } } static class OwnerInfo { public String name; public String packageName; public ComponentName admin; private static class OwnerInfo { public final String name; public final String packageName; public final ComponentName admin; public OwnerInfo(String name, String packageName) { this.name = name; Loading
services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class ApplicationRestrictionsTest extends AndroidTestCase { sDpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 0); sDpm.setProfileOwner(context.getPackageName(), "Test", UserHandle.myUserId()); sDpm.setProfileOwner(sAdminReceiver, "Test", UserHandle.myUserId()); Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1); // Remove the admin if already registered. It's async, so add it back Loading
services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java +21 −9 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.server.devicepolicy; import android.content.ComponentName; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -32,7 +33,7 @@ import java.io.ByteArrayOutputStream; public class DeviceOwnerTest extends AndroidTestCase { private ByteArrayInputStream mInputStreamForTest; private ByteArrayOutputStream mOutputStreamForTest = new ByteArrayOutputStream(); private final ByteArrayOutputStream mOutputStreamForTest = new ByteArrayOutputStream(); @SmallTest public void testDeviceOwnerOnly() throws Exception { Loading @@ -46,13 +47,15 @@ public class DeviceOwnerTest extends AndroidTestCase { assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); assertEquals("owner", in.getDeviceOwnerName()); assertNull(in.getProfileOwnerPackageName(1)); assertNull(in.getProfileOwnerComponent(1)); } @SmallTest public void testProfileOwnerOnly() throws Exception { DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); out.setProfileOwner("some.profile.owner.package", "some-company", 1); ComponentName admin = new ComponentName( "some.profile.owner.package", "some.profile.owner.package.Class"); out.setProfileOwner(admin, "some-company", 1); out.writeOwnerFile(); mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); Loading @@ -61,16 +64,24 @@ public class DeviceOwnerTest extends AndroidTestCase { assertNull(in.getDeviceOwnerPackageName()); assertNull(in.getDeviceOwnerName()); assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); assertEquals(admin, in.getProfileOwnerComponent(1)); assertEquals("some-company", in.getProfileOwnerName(1)); } @SmallTest public void testDeviceAndProfileOwners() throws Exception { DeviceOwner out = new DeviceOwner(null, mOutputStreamForTest); ComponentName profileAdmin = new ComponentName( "some.profile.owner.package", "some.profile.owner.package.Class"); ComponentName otherProfileAdmin = new ComponentName( "some.other.profile.owner", "some.other.profile.owner.OtherClass"); // Old code used package name rather than component name, so the class // bit could be empty. ComponentName legacyComponentName = new ComponentName("legacy.profile.owner.package", ""); out.setDeviceOwner("some.device.owner.package", "owner"); out.setProfileOwner("some.profile.owner.package", "some-company", 1); out.setProfileOwner("some.other.profile.owner", "some-other-company", 2); out.setProfileOwner(profileAdmin, "some-company", 1); out.setProfileOwner(otherProfileAdmin, "some-other-company", 2); out.setProfileOwner(legacyComponentName, "legacy-company", 3); out.writeOwnerFile(); mInputStreamForTest = new ByteArrayInputStream(mOutputStreamForTest.toByteArray()); Loading @@ -80,9 +91,10 @@ public class DeviceOwnerTest extends AndroidTestCase { assertEquals("some.device.owner.package", in.getDeviceOwnerPackageName()); assertEquals("owner", in.getDeviceOwnerName()); assertEquals("some.profile.owner.package", in.getProfileOwnerPackageName(1)); assertEquals(profileAdmin, in.getProfileOwnerComponent(1)); assertEquals("some-company", in.getProfileOwnerName(1)); assertEquals("some.other.profile.owner", in.getProfileOwnerPackageName(2)); assertEquals(otherProfileAdmin, in.getProfileOwnerComponent(2)); assertEquals("some-other-company", in.getProfileOwnerName(2)); assertEquals(legacyComponentName, in.getProfileOwnerComponent(3)); } }