Disable trust agent settings when disabled by policy
Bug: 19868604 Change-Id: Ie476be0338da399a6bc2d20953f6f005ae5eb423
This commit is contained in:
@@ -6175,6 +6175,9 @@
|
||||
<!-- Description for advanced menu option to reset app preferences [CHAR LIMIT=NONE] -->
|
||||
<string name="reset_app_preferences_description">Reset preferences across all apps to defaults</string>
|
||||
|
||||
<!-- Summary for a trust agent that was disabled by the device policy [LIMIT=NONE] -->
|
||||
<string name="trust_agent_disabled_device_admin">Disabled by administrator</string>
|
||||
|
||||
<!-- Description of settings item that leads to list of all apps [CHAR LIMIT=NONE] -->
|
||||
<string name="all_apps_summary"><xliff:g id="count" example="10">%d</xliff:g> apps installed, including system and downloaded apps</string>
|
||||
|
||||
|
@@ -362,7 +362,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
private void addTrustAgentSettings(PreferenceGroup securityCategory) {
|
||||
final boolean hasSecurity = mLockPatternUtils.isSecure();
|
||||
ArrayList<TrustAgentComponentInfo> agents =
|
||||
getActiveTrustAgents(getPackageManager(), mLockPatternUtils);
|
||||
getActiveTrustAgents(getPackageManager(), mLockPatternUtils, mDPM);
|
||||
for (int i = 0; i < agents.size(); i++) {
|
||||
final TrustAgentComponentInfo agent = agents.get(i);
|
||||
Preference trustAgentPreference =
|
||||
@@ -377,7 +377,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
trustAgentPreference.setIntent(intent);
|
||||
// Add preference to the settings menu.
|
||||
securityCategory.addPreference(trustAgentPreference);
|
||||
if (!hasSecurity) {
|
||||
|
||||
if (agent.disabledByAdministrator) {
|
||||
trustAgentPreference.setEnabled(false);
|
||||
trustAgentPreference.setSummary(R.string.trust_agent_disabled_device_admin);
|
||||
} else if (!hasSecurity) {
|
||||
trustAgentPreference.setEnabled(false);
|
||||
trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
|
||||
}
|
||||
@@ -422,11 +426,15 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
private static ArrayList<TrustAgentComponentInfo> getActiveTrustAgents(
|
||||
PackageManager pm, LockPatternUtils utils) {
|
||||
PackageManager pm, LockPatternUtils utils, DevicePolicyManager dpm) {
|
||||
ArrayList<TrustAgentComponentInfo> result = new ArrayList<TrustAgentComponentInfo>();
|
||||
List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
|
||||
PackageManager.GET_META_DATA);
|
||||
List<ComponentName> enabledTrustAgents = utils.getEnabledTrustAgents();
|
||||
|
||||
boolean disableTrustAgents = (dpm.getKeyguardDisabledFeatures(null)
|
||||
& DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
|
||||
|
||||
if (enabledTrustAgents != null && !enabledTrustAgents.isEmpty()) {
|
||||
for (int i = 0; i < resolveInfos.size(); i++) {
|
||||
ResolveInfo resolveInfo = resolveInfos.get(i);
|
||||
@@ -438,6 +446,10 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
!enabledTrustAgents.contains(
|
||||
TrustAgentUtils.getComponentName(resolveInfo)) ||
|
||||
TextUtils.isEmpty(trustAgentComponentInfo.title)) continue;
|
||||
if (disableTrustAgents && dpm.getTrustAgentConfiguration(
|
||||
null, TrustAgentUtils.getComponentName(resolveInfo)) == null) {
|
||||
trustAgentComponentInfo.disabledByAdministrator = true;
|
||||
}
|
||||
result.add(trustAgentComponentInfo);
|
||||
if (ONLY_ONE_TRUST_AGENT) break;
|
||||
}
|
||||
@@ -772,7 +784,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
|
||||
if (lockPatternUtils.isSecure()) {
|
||||
ArrayList<TrustAgentComponentInfo> agents =
|
||||
getActiveTrustAgents(context.getPackageManager(), lockPatternUtils);
|
||||
getActiveTrustAgents(context.getPackageManager(), lockPatternUtils,
|
||||
context.getSystemService(DevicePolicyManager.class));
|
||||
for (int i = 0; i < agents.size(); i++) {
|
||||
final TrustAgentComponentInfo agent = agents.get(i);
|
||||
data = new SearchIndexableRaw(context);
|
||||
|
@@ -18,6 +18,7 @@ package com.android.settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -38,9 +39,11 @@ import com.android.internal.widget.LockPatternUtils;
|
||||
public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
private static final String SERVICE_INTERFACE = TrustAgentService.SERVICE_INTERFACE;
|
||||
|
||||
private ArrayMap<ComponentName, AgentInfo> mAvailableAgents;
|
||||
private final ArraySet<ComponentName> mActiveAgents = new ArraySet<ComponentName>();
|
||||
private LockPatternUtils mLockPatternUtils;
|
||||
private DevicePolicyManager mDpm;
|
||||
|
||||
public static final class AgentInfo {
|
||||
CharSequence label;
|
||||
@@ -69,6 +72,7 @@ public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
mDpm = getActivity().getSystemService(DevicePolicyManager.class);
|
||||
addPreferencesFromResource(R.xml.trust_agent_settings);
|
||||
}
|
||||
|
||||
@@ -89,6 +93,10 @@ public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
PreferenceGroup category =
|
||||
(PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
|
||||
category.removeAll();
|
||||
|
||||
boolean disabledByDevicePolicy = (mDpm.getKeyguardDisabledFeatures(null)
|
||||
& DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
|
||||
|
||||
final int count = mAvailableAgents.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
AgentInfo agent = mAvailableAgents.valueAt(i);
|
||||
@@ -100,6 +108,13 @@ public class TrustAgentSettings extends SettingsPreferenceFragment implements
|
||||
preference.setPersistent(false);
|
||||
preference.setOnPreferenceChangeListener(this);
|
||||
preference.setChecked(mActiveAgents.contains(agent.component));
|
||||
|
||||
if (disabledByDevicePolicy
|
||||
&& mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
|
||||
preference.setEnabled(false);
|
||||
preference.setSummary(R.string.trust_agent_disabled_device_admin);
|
||||
}
|
||||
|
||||
category.addPreference(agent.preference);
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,7 @@ public class TrustAgentUtils {
|
||||
ComponentName componentName;
|
||||
String title;
|
||||
String summary;
|
||||
boolean disabledByAdministrator;
|
||||
}
|
||||
|
||||
public static ComponentName getComponentName(ResolveInfo resolveInfo) {
|
||||
|
Reference in New Issue
Block a user