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