Bite the bullet and add support for multiple device admins.

This commit is contained in:
Dianne Hackborn
2010-01-27 16:21:20 -08:00
parent 9cf5b455d9
commit d47c6ed4a9
6 changed files with 135 additions and 75 deletions

View File

@ -2518,7 +2518,7 @@ public class Activity extends ContextThemeWrapper
* and restored for you. Note that if the dialog is already created,
* {@link #onCreateDialog(int, Bundle)} will not be called with the new
* arguments but {@link #onPrepareDialog(int, Dialog, Bundle)} will be.
* If you need to rebuild the dialog, call {@link #removeDialog(int)}<EFBFBD>first.
* If you need to rebuild the dialog, call {@link #removeDialog(int)} first.
* @return Returns true if the Dialog was created; false is returned if
* it is not created because {@link #onCreateDialog(int, Bundle)} returns false.
*

View File

@ -32,6 +32,7 @@ import android.os.ServiceManager;
import android.util.Log;
import java.io.IOException;
import java.util.List;
/**
* Public interface for managing policies enforced on a device. Most clients
@ -65,10 +66,6 @@ public class DevicePolicyManager {
* <p>You can optionally include the {@link #EXTRA_ADD_EXPLANATION}
* field to provide the user with additional explanation (in addition
* to your component's description) about what is being added.
*
* <p>Note: the current platform can only have one device administrator
* active at a time. If you make this request while there is already
* an active administrator, this new request will be canceled automatically.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_ADD_DEVICE_ADMIN
@ -111,7 +108,7 @@ public class DevicePolicyManager {
public boolean isAdminActive(ComponentName who) {
if (mService != null) {
try {
return who.equals(mService.getActiveAdmin());
return mService.isAdminActive(who);
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy service", e);
}
@ -119,6 +116,22 @@ public class DevicePolicyManager {
return false;
}
/**
* Return a list of all currently active device administrator's component
* names. Note that if there are no administrators than null may be
* returned.
*/
public List<ComponentName> getActiveAdmins() {
if (mService != null) {
try {
return mService.getActiveAdmins();
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy service", e);
}
}
return null;
}
/**
* Remove a current administration component. This can only be called
* by the application that owns the administration component; if you
@ -442,26 +455,7 @@ public class DevicePolicyManager {
/**
* @hide
*/
public ComponentName getActiveAdmin() {
if (mService != null) {
try {
return mService.getActiveAdmin();
} catch (RemoteException e) {
Log.w(TAG, "Failed talking with device policy service", e);
}
}
return null;
}
/**
* @hide
*/
public DeviceAdminInfo getActiveAdminInfo() {
ComponentName cn = getActiveAdmin();
if (cn == null) {
return null;
}
public DeviceAdminInfo getAdminInfo(ComponentName cn) {
ActivityInfo ai;
try {
ai = mContext.getPackageManager().getReceiverInfo(cn,

View File

@ -45,7 +45,8 @@ interface IDevicePolicyManager {
void wipeData(int flags);
void setActiveAdmin(in ComponentName policyReceiver);
ComponentName getActiveAdmin();
boolean isAdminActive(in ComponentName policyReceiver);
List<ComponentName> getActiveAdmins();
void getRemoveWarning(in ComponentName policyReceiver, in RemoteCallback result);
void removeActiveAdmin(in ComponentName policyReceiver);