summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/DeviceAdminAdd.java
diff options
context:
space:
mode:
authorAndy Stadler <stadler@google.com>2010-12-08 15:57:18 -0800
committerAndy Stadler <stadler@google.com>2010-12-09 09:22:06 -0800
commit5cc0e4152b3c75b41c0116c167e2bb5d8d1053cf (patch)
tree7187d2f61a774b02052902e10b50ae0655d7e919 /src/com/android/settings/DeviceAdminAdd.java
parent72aa19d1a541b01e9cc7bebd0650f5d2b5f58d58 (diff)
downloadpackages_apps_settings-5cc0e4152b3c75b41c0116c167e2bb5d8d1053cf.zip
packages_apps_settings-5cc0e4152b3c75b41c0116c167e2bb5d8d1053cf.tar.gz
packages_apps_settings-5cc0e4152b3c75b41c0116c167e2bb5d8d1053cf.tar.bz2
Allow Device Admins to refresh (re-request) activation
* ACTION_ADD_DEVICE_ADMIN now works on already-added admins Bug: 3253179 Change-Id: I2090339c1fb61295e728bc61ca977ff6028a68dd
Diffstat (limited to 'src/com/android/settings/DeviceAdminAdd.java')
-rw-r--r--src/com/android/settings/DeviceAdminAdd.java46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/com/android/settings/DeviceAdminAdd.java b/src/com/android/settings/DeviceAdminAdd.java
index 005196e..93814af 100644
--- a/src/com/android/settings/DeviceAdminAdd.java
+++ b/src/com/android/settings/DeviceAdminAdd.java
@@ -81,6 +81,7 @@ public class DeviceAdminAdd extends Activity {
final ArrayList<View> mActivePolicies = new ArrayList<View>();
boolean mAdding;
+ boolean mRefreshing;
@Override
protected void onCreate(Bundle icicle) {
@@ -91,7 +92,7 @@ public class DeviceAdminAdd extends Activity {
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
if ((getIntent().getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
- Log.w(TAG, "Can now start ADD_DEVICE_ADMIN as a new task");
+ Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
finish();
return;
}
@@ -103,20 +104,10 @@ public class DeviceAdminAdd extends Activity {
finish();
return;
}
- if (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.equals(getIntent().getAction())) {
- // If this was an add request, then just exit immediately if the
- // given component is already added.
- if (mDPM.isAdminActive(cn)) {
- setResult(Activity.RESULT_OK);
- finish();
- return;
- }
- }
ActivityInfo ai;
try {
- ai = getPackageManager().getReceiverInfo(cn,
- PackageManager.GET_META_DATA);
+ ai = getPackageManager().getReceiverInfo(cn, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Unable to retrieve device policy " + cn, e);
finish();
@@ -126,7 +117,7 @@ public class DeviceAdminAdd extends Activity {
ResolveInfo ri = new ResolveInfo();
ri.activityInfo = ai;
try {
- mDeviceAdmin= new DeviceAdminInfo(this, ri);
+ mDeviceAdmin = new DeviceAdminInfo(this, ri);
} catch (XmlPullParserException e) {
Log.w(TAG, "Unable to retrieve device policy " + cn, e);
finish();
@@ -137,8 +128,29 @@ public class DeviceAdminAdd extends Activity {
return;
}
- mAddMsgText = getIntent().getCharSequenceExtra(
- DevicePolicyManager.EXTRA_ADD_EXPLANATION);
+ // This admin already exists, an we have two options at this point. If new policy
+ // bits are set, show the user the new list. If nothing has changed, simply return
+ // "OK" immediately.
+ if (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.equals(getIntent().getAction())) {
+ mRefreshing = false;
+ if (mDPM.isAdminActive(cn)) {
+ ArrayList<DeviceAdminInfo.PolicyInfo> newPolicies = mDeviceAdmin.getUsedPolicies();
+ for (int i = 0; i < newPolicies.size(); i++) {
+ DeviceAdminInfo.PolicyInfo pi = newPolicies.get(i);
+ if (!mDPM.hasGrantedPolicy(cn, pi.ident)) {
+ mRefreshing = true;
+ break;
+ }
+ }
+ if (!mRefreshing) {
+ // Nothing changed (or policies were removed) - return immediately
+ setResult(Activity.RESULT_OK);
+ finish();
+ return;
+ }
+ }
+ }
+ mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION);
setContentView(R.layout.device_admin_add);
@@ -170,7 +182,7 @@ public class DeviceAdminAdd extends Activity {
public void onClick(View v) {
if (mAdding) {
try {
- mDPM.setActiveAdmin(mDeviceAdmin.getComponent());
+ mDPM.setActiveAdmin(mDeviceAdmin.getComponent(), mRefreshing);
setResult(Activity.RESULT_OK);
} catch (RuntimeException e) {
// Something bad happened... could be that it was
@@ -260,7 +272,7 @@ public class DeviceAdminAdd extends Activity {
} else {
mAddMsg.setVisibility(View.GONE);
}
- if (mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
+ if (!mRefreshing && mDPM.isAdminActive(mDeviceAdmin.getComponent())) {
if (mActivePolicies.size() == 0) {
ArrayList<DeviceAdminInfo.PolicyInfo> policies = mDeviceAdmin.getUsedPolicies();
for (int i=0; i<policies.size(); i++) {