summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/DeviceAdminSettings.java
diff options
context:
space:
mode:
authorFyodor Kupolov <fkupolov@google.com>2014-11-25 17:34:22 -0800
committerFyodor Kupolov <fkupolov@google.com>2014-12-02 17:24:13 -0800
commitcfae855d67990e783c24fdcafe1e6795f43b8caa (patch)
treea56507745cb7073a166618aef0c49a20d9895166 /src/com/android/settings/DeviceAdminSettings.java
parent647f9752ce1bdd4c02cd44028dac769369140764 (diff)
downloadpackages_apps_Settings-cfae855d67990e783c24fdcafe1e6795f43b8caa.zip
packages_apps_Settings-cfae855d67990e783c24fdcafe1e6795f43b8caa.tar.gz
packages_apps_Settings-cfae855d67990e783c24fdcafe1e6795f43b8caa.tar.bz2
Update list on ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
Added BroadcastReceiver for ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED to refresh the list, if event has been received. It could be that checkboxes need to be updated. Also disable the checkbox while admin is being removed. Bug: 17609838 Change-Id: Id1f72c27111c280a77a03ba6ba26bcdbbb10bb58
Diffstat (limited to 'src/com/android/settings/DeviceAdminSettings.java')
-rw-r--r--src/com/android/settings/DeviceAdminSettings.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/com/android/settings/DeviceAdminSettings.java b/src/com/android/settings/DeviceAdminSettings.java
index bc22637..334d18f 100644
--- a/src/com/android/settings/DeviceAdminSettings.java
+++ b/src/com/android/settings/DeviceAdminSettings.java
@@ -16,7 +16,6 @@
package com.android.settings;
-import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
@@ -25,9 +24,11 @@ import android.app.ListFragment;
import android.app.admin.DeviceAdminInfo;
import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyManager;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -49,14 +50,13 @@ import android.widget.TextView;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Collection;
public class DeviceAdminSettings extends ListFragment {
static final String TAG = "DeviceAdminSettings";
- static final int DIALOG_WARNING = 1;
private DevicePolicyManager mDPM;
private UserManager mUm;
@@ -70,6 +70,18 @@ public class DeviceAdminSettings extends ListFragment {
private String mDeviceOwnerPkg;
private SparseArray<ComponentName> mProfileOwnerComponents = new SparseArray<ComponentName>();
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // Refresh the list, if state change has been received. It could be that checkboxes
+ // need to be updated
+ if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(
+ intent.getAction())) {
+ updateList();
+ }
+ }
+ };
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -93,6 +105,10 @@ public class DeviceAdminSettings extends ListFragment {
@Override
public void onResume() {
super.onResume();
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
+ getActivity().registerReceiverAsUser(
+ mBroadcastReceiver, UserHandle.ALL, filter, null, null);
mDeviceOwnerPkg = mDPM.getDeviceOwner();
if (mDeviceOwnerPkg != null && !mDPM.isDeviceOwner(mDeviceOwnerPkg)) {
mDeviceOwnerPkg = null;
@@ -107,6 +123,12 @@ public class DeviceAdminSettings extends ListFragment {
updateList();
}
+ @Override
+ public void onPause() {
+ getActivity().unregisterReceiver(mBroadcastReceiver);
+ super.onPause();
+ }
+
/**
* Update the internal collection of available admins for all profiles associated with the
* current user.
@@ -264,6 +286,10 @@ public class DeviceAdminSettings extends ListFragment {
&& (isDeviceOwner(info) || isProfileOwner(info))) {
return false;
}
+ // Disable item if admin is being removed
+ if (isRemovingAdmin(info)) {
+ return false;
+ }
return true;
}
@@ -340,6 +366,10 @@ public class DeviceAdminSettings extends ListFragment {
return mDPM.isAdminActiveAsUser(item.getComponent(), getUserId(item));
}
+ private boolean isRemovingAdmin(DeviceAdminInfo item) {
+ return mDPM.isRemovingAdmin(item.getComponent(), getUserId(item));
+ }
+
/**
* Add device admins to the internal collection that belong to a profile.
*