Fix Incorrect Trust Agent Count
The total number of trustagents can still be incorrect if the user enables a trustagent, and then the trust agent component gets disabled, since the user does not manually toggle the preference themselves. Fixed by switching back to the original method of using TrustAgentManager, but also pass a flag that allows us to choose on whether we want to filter the trustagents based on whether it has an activity (which not all trustagents are guaranteed to have). Bug: 240969157 Test: Local test + atest Change-Id: I5106859f61ddf36c1bf008da18be889ceaf27a8d
This commit is contained in:
@@ -32,12 +32,14 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
|
||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||
|
||||
private final LockPatternUtils mLockPatternUtils;
|
||||
private TrustAgentManager mTrustAgentManager;
|
||||
|
||||
public ManageTrustAgentsPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getSecurityFeatureProvider();
|
||||
mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
|
||||
mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +66,6 @@ public class ManageTrustAgentsPreferenceController extends BasePreferenceControl
|
||||
}
|
||||
|
||||
private int getTrustAgentCount() {
|
||||
return mLockPatternUtils.getEnabledTrustAgents(MY_USER_ID).size();
|
||||
return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils, false).size();
|
||||
}
|
||||
}
|
||||
|
@@ -99,13 +99,27 @@ public class TrustAgentManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of trust agents.
|
||||
* Returns a list of trust agents that have a android:settingsActivity set in their declaration.
|
||||
*
|
||||
* If {@link #ONLY_ONE_TRUST_AGENT} is set, the list will contain up to 1 agent instead of all
|
||||
* available agents on device.
|
||||
*/
|
||||
public List<TrustAgentComponentInfo> getActiveTrustAgents(Context context,
|
||||
LockPatternUtils utils) {
|
||||
return getActiveTrustAgents(context, utils, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of trust agents.
|
||||
*
|
||||
* If {@link #ONLY_ONE_TRUST_AGENT} is set, the list will contain up to 1 agent instead of all
|
||||
* available agents on device.
|
||||
*
|
||||
* @param skipTrustAgentsWithNoActivity {@code false} to only include trustagents with
|
||||
* android:settingsActivity set in their declaration, {@code true} otherwise.
|
||||
*/
|
||||
public List<TrustAgentComponentInfo> getActiveTrustAgents(Context context,
|
||||
LockPatternUtils utils, boolean skipTrustAgentsWithNoActivity) {
|
||||
final int myUserId = UserHandle.myUserId();
|
||||
final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
@@ -125,9 +139,12 @@ public class TrustAgentManager {
|
||||
}
|
||||
final TrustAgentComponentInfo trustAgentComponentInfo =
|
||||
getSettingsComponent(pm, resolveInfo);
|
||||
if (trustAgentComponentInfo.componentName == null ||
|
||||
!enabledTrustAgents.contains(getComponentName(resolveInfo)) ||
|
||||
TextUtils.isEmpty(trustAgentComponentInfo.title)) {
|
||||
if (skipTrustAgentsWithNoActivity
|
||||
&& trustAgentComponentInfo.componentName == null) {
|
||||
continue;
|
||||
}
|
||||
if (!enabledTrustAgents.contains(getComponentName(resolveInfo))
|
||||
|| TextUtils.isEmpty(trustAgentComponentInfo.title)) {
|
||||
continue;
|
||||
}
|
||||
if (admin != null && dpm.getTrustAgentConfiguration(
|
||||
|
Reference in New Issue
Block a user