am d4057cc3
: Merge "Update list on ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED" into lmp-mr1-dev
* commit 'd4057cc312feca00eac73f908788799ab567d8a1': Update list on ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user