Refactored TrustAgentUtils to allow agent check injection.

Notes:
- TrustAgentUtils defined a method that allowed callers to determine if a Trust Agent package is allowed to provide trust. If it is, it adds it to the list of available trust agents that can be displayed in the Settings->Security screen.
- The logic used to define what agents are permitted on the device can now be injected.

Test: Ran 'm RunSettingsRoboTest' and added a new test for the TrustAgentFeatureProviderImpl.
Bug: 34354635
Change-Id: I24c54c14bde26073ce6fa907379b86aae2841600
This commit is contained in:
Zachary Iqbal
2017-01-17 14:55:49 -08:00
parent 964bcccd62
commit ccae73f228
8 changed files with 205 additions and 25 deletions

View File

@@ -67,6 +67,7 @@ import com.android.settings.search.Index;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.trustagent.TrustAgentManager;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -144,6 +145,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
private DashboardFeatureProvider mDashboardFeatureProvider;
private DevicePolicyManager mDPM;
private SecurityFeatureProvider mSecurityFeatureProvider;
private TrustAgentManager mTrustAgentManager;
private SubscriptionManager mSubscriptionManager;
private UserManager mUm;
@@ -199,6 +201,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
mSecurityFeatureProvider = FeatureFactory.getFactory(activity).getSecurityFeatureProvider();
mTrustAgentManager = mSecurityFeatureProvider.getTrustAgentManager();
if (savedInstanceState != null
&& savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
@@ -472,8 +476,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
private void addTrustAgentSettings(PreferenceGroup securityCategory) {
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
ArrayList<TrustAgentComponentInfo> agents =
getActiveTrustAgents(getActivity(), mLockPatternUtils, mDPM);
ArrayList<TrustAgentComponentInfo> agents = getActiveTrustAgents(
getActivity(), mTrustAgentManager, mLockPatternUtils, mDPM);
for (int i = 0; i < agents.size(); i++) {
final TrustAgentComponentInfo agent = agents.get(i);
RestrictedPreference trustAgentPreference =
@@ -534,8 +538,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
return false;
}
private static ArrayList<TrustAgentComponentInfo> getActiveTrustAgents(
Context context, LockPatternUtils utils, DevicePolicyManager dpm) {
private static ArrayList<TrustAgentComponentInfo> getActiveTrustAgents(Context context,
TrustAgentManager trustAgentManager, LockPatternUtils utils,
DevicePolicyManager dpm) {
PackageManager pm = context.getPackageManager();
ArrayList<TrustAgentComponentInfo> result = new ArrayList<TrustAgentComponentInfo>();
List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
@@ -549,7 +554,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
for (int i = 0; i < resolveInfos.size(); i++) {
ResolveInfo resolveInfo = resolveInfos.get(i);
if (resolveInfo.serviceInfo == null) continue;
if (!TrustAgentUtils.checkProvidePermission(resolveInfo, pm)) continue;
if (!trustAgentManager.shouldProvideTrust(resolveInfo, pm)) {
continue;
}
TrustAgentComponentInfo trustAgentComponentInfo =
TrustAgentUtils.getSettingsComponent(pm, resolveInfo);
if (trustAgentComponentInfo.componentName == null ||
@@ -989,8 +996,11 @@ public class SecuritySettings extends SettingsPreferenceFragment
// Advanced
if (lockPatternUtils.isSecure(MY_USER_ID)) {
ArrayList<TrustAgentComponentInfo> agents =
getActiveTrustAgents(context, lockPatternUtils,
final TrustAgentManager trustAgentManager =
FeatureFactory.getFactory(context).getSecurityFeatureProvider()
.getTrustAgentManager();
final List<TrustAgentComponentInfo> agents =
getActiveTrustAgents(context, trustAgentManager, lockPatternUtils,
context.getSystemService(DevicePolicyManager.class));
for (int i = 0; i < agents.size(); i++) {
final TrustAgentComponentInfo agent = agents.get(i);