summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Talavera <etalavera@google.com>2014-12-23 17:15:29 +0000
committerEsteban Talavera <etalavera@google.com>2014-12-24 09:38:13 +0000
commit8add57224ffcf73705e507f1b73954e5de15eb88 (patch)
tree0c097f1d4d8d7d19bf590bd49ad38f9da754b2af
parent898de6fd8c78d84ae1425e052b27a97ec6f230ad (diff)
downloadframeworks_base-8add57224ffcf73705e507f1b73954e5de15eb88.zip
frameworks_base-8add57224ffcf73705e507f1b73954e5de15eb88.tar.gz
frameworks_base-8add57224ffcf73705e507f1b73954e5de15eb88.tar.bz2
Remove deprecated version of setProfileOwner that takes packageName
The ComponentName equivalent should be used instead. Bug: 17654371 Change-Id: I7001e86ab1709b824944148a3c44af5243dacb83
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java21
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java39
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java4
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java30
4 files changed, 30 insertions, 64 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index ae32311..c5c6d06 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -2423,27 +2423,6 @@ public class DevicePolicyManager {
}
/**
- * @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
* already be installed and there shouldn't be an existing profile owner registered for this
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
index 9fd0e09..f0e02bc 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DeviceOwner.java
@@ -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";
@@ -102,16 +102,6 @@ public class DeviceOwner {
}
/**
- * @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.
*/
static DeviceOwner createWithProfileOwner(ComponentName admin, String ownerName, int userId) {
@@ -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));
}
@@ -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;
@@ -207,6 +180,7 @@ public class DeviceOwner {
return false;
}
+ @VisibleForTesting
void readOwnerFile() {
try {
InputStream input = openRead();
@@ -259,6 +233,7 @@ public class DeviceOwner {
}
}
+ @VisibleForTesting
void writeOwnerFile() {
synchronized (this) {
writeOwnerFileLocked();
@@ -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;
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java
index 8e8e4e6..ca270e7 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/ApplicationRestrictionsTest.java
@@ -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
@@ -132,4 +132,4 @@ public class ApplicationRestrictionsTest extends AndroidTestCase {
Bundle returned = sDpm.getApplicationRestrictions(sAdminReceiver, RESTRICTED_APP);
assertEquals(returned.getString("KEY_FANCY_TEXT"), fancyText);
}
-} \ No newline at end of file
+}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java
index f913b97..7c3014c 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DeviceOwnerTest.java
@@ -16,6 +16,7 @@
package com.android.server.devicepolicy;
+import android.content.ComponentName;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -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 {
@@ -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());
@@ -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());
@@ -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));
}
-} \ No newline at end of file
+}