Remove unused TrustAgentManager from CarDevOptions
This is to remove confusion for OEMs who should be using
CarTrustAgentEnrollmentManager.
Bug: 133453218
Test: build, manual
Change-Id: I1ce246187e5b6b3176c42d4cfbd92cd2360f0e46
diff --git a/tests/CarDeveloperOptions/res/xml/security_dashboard_settings.xml b/tests/CarDeveloperOptions/res/xml/security_dashboard_settings.xml
index a797b2d..d10b977 100644
--- a/tests/CarDeveloperOptions/res/xml/security_dashboard_settings.xml
+++ b/tests/CarDeveloperOptions/res/xml/security_dashboard_settings.xml
@@ -133,13 +133,6 @@
android:fragment="com.android.car.developeroptions.security.EncryptionAndCredential" />
<Preference
- android:order="70"
- android:key="manage_trust_agents"
- android:title="@string/manage_trust_agents"
- android:summary="@string/summary_placeholder"
- android:fragment="com.android.car.developeroptions.security.trustagent.TrustAgentSettings" />
-
- <Preference
android:order="80"
android:key="screen_pinning_settings"
android:title="@string/screen_pinning_title"
diff --git a/tests/CarDeveloperOptions/res/xml/trust_agent_settings.xml b/tests/CarDeveloperOptions/res/xml/trust_agent_settings.xml
deleted file mode 100644
index da6c9a8..0000000
--- a/tests/CarDeveloperOptions/res/xml/trust_agent_settings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:key="trust_agents"
- android:title="@string/manage_trust_agents"
- settings:controller="com.android.car.developeroptions.security.trustagent.TrustAgentsPreferenceController">
-</PreferenceScreen>
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProvider.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProvider.java
index d0872b5..95d601d 100644
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProvider.java
+++ b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProvider.java
@@ -19,15 +19,11 @@
import android.content.Context;
import com.android.internal.widget.LockPatternUtils;
-import com.android.car.developeroptions.security.trustagent.TrustAgentManager;
/** FeatureProvider for security. */
public interface SecurityFeatureProvider {
- /** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
- TrustAgentManager getTrustAgentManager();
-
/**
* Returns a {@link LockPatternUtils} instance bound to application context.
*/
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProviderImpl.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProviderImpl.java
index 4ea9ece..21df466 100644
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProviderImpl.java
+++ b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecurityFeatureProviderImpl.java
@@ -19,23 +19,13 @@
import android.content.Context;
import com.android.internal.widget.LockPatternUtils;
-import com.android.car.developeroptions.security.trustagent.TrustAgentManager;
/** Implementation for {@code SecurityFeatureProvider}. */
public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
- private TrustAgentManager mTrustAgentManager;
private LockPatternUtils mLockPatternUtils;
@Override
- public TrustAgentManager getTrustAgentManager() {
- if (mTrustAgentManager == null) {
- mTrustAgentManager = new TrustAgentManager();
- }
- return mTrustAgentManager;
- }
-
- @Override
public LockPatternUtils getLockPatternUtils(Context context) {
if (mLockPatternUtils == null) {
mLockPatternUtils = new LockPatternUtils(context.getApplicationContext());
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecuritySettings.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecuritySettings.java
index e866727..5aa22e5 100644
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecuritySettings.java
+++ b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/SecuritySettings.java
@@ -30,8 +30,6 @@
import com.android.car.developeroptions.dashboard.DashboardFragment;
import com.android.car.developeroptions.enterprise.EnterprisePrivacyPreferenceController;
import com.android.car.developeroptions.search.BaseSearchIndexProvider;
-import com.android.car.developeroptions.security.trustagent.ManageTrustAgentsPreferenceController;
-import com.android.car.developeroptions.security.trustagent.TrustAgentListPreferenceController;
import com.android.car.developeroptions.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -82,10 +80,6 @@
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (use(TrustAgentListPreferenceController.class)
- .handleActivityResult(requestCode, resultCode)) {
- return;
- }
if (use(LockUnificationPreferenceController.class)
.handleActivityResult(requestCode, resultCode, data)) {
return;
@@ -105,12 +99,10 @@
Lifecycle lifecycle, SecuritySettings host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new EnterprisePrivacyPreferenceController(context));
- controllers.add(new ManageTrustAgentsPreferenceController(context));
controllers.add(new ScreenPinningPreferenceController(context));
controllers.add(new SimLockPreferenceController(context));
controllers.add(new EncryptionStatusPreferenceController(context,
PREF_KEY_ENCRYPTION_SECURITY_PAGE));
- controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
final List<AbstractPreferenceController> securityPreferenceControllers = new ArrayList<>();
securityPreferenceControllers.add(new FaceStatusPreferenceController(context));
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/LockAfterTimeoutPreferenceController.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/LockAfterTimeoutPreferenceController.java
index 9805171..79ced0c 100644
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/LockAfterTimeoutPreferenceController.java
+++ b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/LockAfterTimeoutPreferenceController.java
@@ -22,17 +22,14 @@
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
-import android.text.TextUtils;
import android.util.Log;
import androidx.preference.Preference;
-import com.android.internal.widget.LockPatternUtils;
import com.android.car.developeroptions.R;
import com.android.car.developeroptions.core.PreferenceControllerMixin;
import com.android.car.developeroptions.display.TimeoutListPreference;
-import com.android.car.developeroptions.overlay.FeatureFactory;
-import com.android.car.developeroptions.security.trustagent.TrustAgentManager;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -44,7 +41,6 @@
private final int mUserId;
private final LockPatternUtils mLockPatternUtils;
- private final TrustAgentManager mTrustAgentManager;
private final DevicePolicyManager mDPM;
public LockAfterTimeoutPreferenceController(Context context, int userId,
@@ -53,8 +49,6 @@
mUserId = userId;
mLockPatternUtils = lockPatternUtils;
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
- mTrustAgentManager = FeatureFactory.getFactory(context)
- .getSecurityFeatureProvider().getTrustAgentManager();
}
@Override
@@ -137,20 +131,7 @@
best = i;
}
}
-
- final CharSequence trustAgentLabel = mTrustAgentManager
- .getActiveTrustAgentLabel(mContext, mLockPatternUtils);
- if (!TextUtils.isEmpty(trustAgentLabel)) {
- if (Long.valueOf(values[best].toString()) == 0) {
- summary = mContext.getString(R.string.lock_immediately_summary_with_exception,
- trustAgentLabel);
- } else {
- summary = mContext.getString(R.string.lock_after_timeout_summary_with_exception,
- entries[best], trustAgentLabel);
- }
- } else {
- summary = mContext.getString(R.string.lock_after_timeout_summary, entries[best]);
- }
+ summary = mContext.getString(R.string.lock_after_timeout_summary, entries[best]);
}
preference.setSummary(summary);
}
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/PowerButtonInstantLockPreferenceController.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/PowerButtonInstantLockPreferenceController.java
index adc7acf..27e1d58 100644
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/PowerButtonInstantLockPreferenceController.java
+++ b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/screenlock/PowerButtonInstantLockPreferenceController.java
@@ -18,16 +18,13 @@
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;
-import com.android.internal.widget.LockPatternUtils;
import com.android.car.developeroptions.R;
import com.android.car.developeroptions.core.PreferenceControllerMixin;
-import com.android.car.developeroptions.overlay.FeatureFactory;
-import com.android.car.developeroptions.security.trustagent.TrustAgentManager;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.core.AbstractPreferenceController;
public class PowerButtonInstantLockPreferenceController extends AbstractPreferenceController
@@ -37,15 +34,12 @@
private final int mUserId;
private final LockPatternUtils mLockPatternUtils;
- private final TrustAgentManager mTrustAgentManager;
public PowerButtonInstantLockPreferenceController(Context context, int userId,
LockPatternUtils lockPatternUtils) {
super(context);
mUserId = userId;
mLockPatternUtils = lockPatternUtils;
- mTrustAgentManager = FeatureFactory.getFactory(context)
- .getSecurityFeatureProvider().getTrustAgentManager();
}
@Override
@@ -71,15 +65,7 @@
public void updateState(Preference preference) {
((TwoStatePreference) preference).setChecked(
mLockPatternUtils.getPowerButtonInstantlyLocks(mUserId));
- final CharSequence trustAgentLabel = mTrustAgentManager.getActiveTrustAgentLabel(
- mContext, mLockPatternUtils);
- if (!TextUtils.isEmpty(trustAgentLabel)) {
- preference.setSummary(mContext.getString(
- R.string.lockpattern_settings_power_button_instantly_locks_summary,
- trustAgentLabel));
- } else {
- preference.setSummary(R.string.summary_placeholder);
- }
+ preference.setSummary(R.string.summary_placeholder);
}
@Override
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/ManageTrustAgentsPreferenceController.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/ManageTrustAgentsPreferenceController.java
deleted file mode 100644
index 6633e34..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/ManageTrustAgentsPreferenceController.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import android.content.Context;
-import android.os.UserHandle;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-
-import com.android.internal.widget.LockPatternUtils;
-import com.android.car.developeroptions.R;
-import com.android.car.developeroptions.core.BasePreferenceController;
-import com.android.car.developeroptions.overlay.FeatureFactory;
-import com.android.car.developeroptions.security.SecurityFeatureProvider;
-
-public class ManageTrustAgentsPreferenceController extends BasePreferenceController {
-
- @VisibleForTesting
- static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
- private static final int MY_USER_ID = UserHandle.myUserId();
-
- private final LockPatternUtils mLockPatternUtils;
- private TrustAgentManager mTrustAgentManager;
-
- public ManageTrustAgentsPreferenceController(Context context) {
- super(context, KEY_MANAGE_TRUST_AGENTS);
- final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
- .getSecurityFeatureProvider();
- mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
- mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mContext.getResources().getBoolean(R.bool.config_show_manage_trust_agents)
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- public void updateState(Preference preference) {
- final int numberOfTrustAgent = getTrustAgentCount();
- if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
- preference.setEnabled(false);
- preference.setSummary(R.string.disabled_because_no_backup_security);
- } else if (numberOfTrustAgent > 0) {
- preference.setEnabled(true);
- preference.setSummary(mContext.getResources().getQuantityString(
- R.plurals.manage_trust_agents_summary_on,
- numberOfTrustAgent, numberOfTrustAgent));
- } else {
- preference.setEnabled(true);
- preference.setSummary(R.string.manage_trust_agents_summary);
- }
- }
-
- private int getTrustAgentCount() {
- return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils).size();
- }
-}
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentInfo.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentInfo.java
deleted file mode 100644
index 634935a..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentInfo.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import android.content.ComponentName;
-import android.graphics.drawable.Drawable;
-
-public class TrustAgentInfo implements Comparable<TrustAgentInfo> {
- private final CharSequence mLabel;
- private final ComponentName mComponentName;
- private final Drawable mIcon;
-
- public TrustAgentInfo(CharSequence label, ComponentName componentName, Drawable icon) {
- mLabel = label;
- mComponentName = componentName;
- mIcon = icon;
- }
-
- public CharSequence getLabel() {
- return mLabel;
- }
-
- public ComponentName getComponentName() {
- return mComponentName;
- }
-
- public Drawable getIcon() {
- return mIcon;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof TrustAgentInfo) {
- return mComponentName.equals(((TrustAgentInfo) other).getComponentName());
- }
- return false;
- }
-
- @Override
- public int compareTo(TrustAgentInfo other) {
- return mComponentName.compareTo(other.getComponentName());
- }
-}
\ No newline at end of file
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentListPreferenceController.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentListPreferenceController.java
deleted file mode 100644
index fde9b6c..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentListPreferenceController.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import static com.android.car.developeroptions.security.SecuritySettings.CHANGE_TRUST_AGENT_SETTINGS;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.text.TextUtils;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
-import com.android.internal.widget.LockPatternUtils;
-import com.android.car.developeroptions.R;
-import com.android.car.developeroptions.core.PreferenceControllerMixin;
-import com.android.car.developeroptions.overlay.FeatureFactory;
-import com.android.car.developeroptions.password.ChooseLockSettingsHelper;
-import com.android.car.developeroptions.security.SecurityFeatureProvider;
-import com.android.car.developeroptions.security.SecuritySettings;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.core.lifecycle.Lifecycle;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnCreate;
-import com.android.settingslib.core.lifecycle.events.OnResume;
-import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
-
-import java.util.List;
-
-public class TrustAgentListPreferenceController extends AbstractPreferenceController
- implements PreferenceControllerMixin, LifecycleObserver, OnSaveInstanceState,
- OnCreate, OnResume {
-
- private static final String TRUST_AGENT_CLICK_INTENT = "trust_agent_click_intent";
- @VisibleForTesting
- static final String PREF_KEY_TRUST_AGENT = "trust_agent";
- @VisibleForTesting
- static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
- private static final int MY_USER_ID = UserHandle.myUserId();
-
- private final LockPatternUtils mLockPatternUtils;
- private final TrustAgentManager mTrustAgentManager;
- private final SecuritySettings mHost;
-
- private Intent mTrustAgentClickIntent;
- private PreferenceCategory mSecurityCategory;
-
- public TrustAgentListPreferenceController(Context context, SecuritySettings host,
- Lifecycle lifecycle) {
- super(context);
- final SecurityFeatureProvider provider = FeatureFactory.getFactory(context)
- .getSecurityFeatureProvider();
- mHost = host;
- mLockPatternUtils = provider.getLockPatternUtils(context);
- mTrustAgentManager = provider.getTrustAgentManager();
- if (lifecycle != null) {
- lifecycle.addObserver(this);
- }
- }
-
- @Override
- public boolean isAvailable() {
- return mContext.getResources().getBoolean(R.bool.config_show_trust_agent_click_intent);
- }
-
- @Override
- public String getPreferenceKey() {
- return PREF_KEY_TRUST_AGENT;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
- updateTrustAgents();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- if (savedInstanceState != null
- && savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
- mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- if (mTrustAgentClickIntent != null) {
- outState.putParcelable(TRUST_AGENT_CLICK_INTENT, mTrustAgentClickIntent);
- }
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
- return super.handlePreferenceTreeClick(preference);
- }
- final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(
- mHost.getActivity(), mHost);
- mTrustAgentClickIntent = preference.getIntent();
- boolean confirmationLaunched = helper.launchConfirmationActivity(
- CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
-
- if (!confirmationLaunched && mTrustAgentClickIntent != null) {
- // If this returns false, it means no password confirmation is required.
- mHost.startActivity(mTrustAgentClickIntent);
- mTrustAgentClickIntent = null;
- }
- return true;
- }
-
- @Override
- public void onResume() {
- updateTrustAgents();
- }
-
- private void updateTrustAgents() {
- if (mSecurityCategory == null) {
- return;
- }
- // First remove all old trust agents.
- while (true) {
- final Preference oldAgent = mSecurityCategory.findPreference(PREF_KEY_TRUST_AGENT);
- if (oldAgent == null) {
- break;
- } else {
- mSecurityCategory.removePreference(oldAgent);
- }
- }
- // If for some reason the preference is no longer available, don't proceed to add.
- if (!isAvailable()) {
- return;
- }
- // Then add new ones.
- final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
- final List<TrustAgentManager.TrustAgentComponentInfo> agents =
- mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils);
- if (agents == null) {
- return;
- }
- for (TrustAgentManager.TrustAgentComponentInfo agent : agents) {
- final RestrictedPreference trustAgentPreference =
- new RestrictedPreference(mSecurityCategory.getContext());
- trustAgentPreference.setKey(PREF_KEY_TRUST_AGENT);
- trustAgentPreference.setTitle(agent.title);
- trustAgentPreference.setSummary(agent.summary);
- // Create intent for this preference.
- trustAgentPreference.setIntent(new Intent(Intent.ACTION_MAIN)
- .setComponent(agent.componentName));
- trustAgentPreference.setDisabledByAdmin(agent.admin);
- if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) {
- trustAgentPreference.setEnabled(false);
- trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
- }
- // Add preference to the settings menu.
- mSecurityCategory.addPreference(trustAgentPreference);
- }
- }
-
- public boolean handleActivityResult(int requestCode, int resultCode) {
- if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
- if (mTrustAgentClickIntent != null) {
- mHost.startActivity(mTrustAgentClickIntent);
- mTrustAgentClickIntent = null;
- }
- return true;
- }
- return false;
- }
-}
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentManager.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentManager.java
deleted file mode 100644
index 9be291e..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentManager.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import static android.service.trust.TrustAgentService.TRUST_AGENT_META_DATA;
-
-import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.os.UserHandle;
-import android.service.trust.TrustAgentService;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Slog;
-import android.util.Xml;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.internal.widget.LockPatternUtils;
-import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.RestrictedLockUtilsInternal;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-
-/** A manager for trust agent state. */
-public class TrustAgentManager {
-
- // Only allow one trust agent on the platform.
- private static final boolean ONLY_ONE_TRUST_AGENT = false;
-
- public static class TrustAgentComponentInfo {
- public ComponentName componentName;
- public String title;
- public String summary;
- public RestrictedLockUtils.EnforcedAdmin admin = null;
- }
-
- private static final String TAG = "TrustAgentManager";
- private static final Intent TRUST_AGENT_INTENT =
- new Intent(TrustAgentService.SERVICE_INTERFACE);
-
- @VisibleForTesting
- static final String PERMISSION_PROVIDE_AGENT =
- android.Manifest.permission.PROVIDE_TRUST_AGENT;
-
- /**
- * Determines if the service associated with a resolved trust agent intent is allowed to provide
- * trust on this device.
- *
- * @param resolveInfo The entry corresponding to the matched trust agent intent.
- * @param pm The package manager to be used to check for permissions.
- * @return {@code true} if the associated service is allowed to provide a trust agent, and
- * {@code false} if otherwise.
- */
- public boolean shouldProvideTrust(ResolveInfo resolveInfo, PackageManager pm) {
- final String packageName = resolveInfo.serviceInfo.packageName;
- if (pm.checkPermission(PERMISSION_PROVIDE_AGENT, packageName)
- != PackageManager.PERMISSION_GRANTED) {
- Log.w(TAG, "Skipping agent because package " + packageName
- + " does not have permission " + PERMISSION_PROVIDE_AGENT + ".");
- return false;
- }
- return true;
- }
-
- /**
- * Return the display label for active trust agent.
- */
- public CharSequence getActiveTrustAgentLabel(Context context, LockPatternUtils utils) {
- final List<TrustAgentComponentInfo> agents = getActiveTrustAgents(context, utils);
- return agents.isEmpty() ? null : agents.get(0).title;
- }
-
- /**
- * 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.
- */
- public List<TrustAgentComponentInfo> getActiveTrustAgents(Context context,
- LockPatternUtils utils) {
- final int myUserId = UserHandle.myUserId();
- final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
- final PackageManager pm = context.getPackageManager();
- final List<TrustAgentComponentInfo> result = new ArrayList<>();
-
- final List<ResolveInfo> resolveInfos = pm.queryIntentServices(TRUST_AGENT_INTENT,
- PackageManager.GET_META_DATA);
- final List<ComponentName> enabledTrustAgents = utils.getEnabledTrustAgents(myUserId);
- final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtilsInternal
- .checkIfKeyguardFeaturesDisabled(
- context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, myUserId);
-
- if (enabledTrustAgents != null && !enabledTrustAgents.isEmpty()) {
- for (ResolveInfo resolveInfo : resolveInfos) {
- if (resolveInfo.serviceInfo == null || !shouldProvideTrust(resolveInfo, pm)) {
- continue;
- }
- final TrustAgentComponentInfo trustAgentComponentInfo =
- getSettingsComponent(pm, resolveInfo);
- if (trustAgentComponentInfo.componentName == null ||
- !enabledTrustAgents.contains(getComponentName(resolveInfo)) ||
- TextUtils.isEmpty(trustAgentComponentInfo.title)) {
- continue;
- }
- if (admin != null && dpm.getTrustAgentConfiguration(
- null, getComponentName(resolveInfo)) == null) {
- trustAgentComponentInfo.admin = admin;
- }
- result.add(trustAgentComponentInfo);
- if (ONLY_ONE_TRUST_AGENT) {
- break;
- }
- }
- }
- return result;
- }
-
- public ComponentName getComponentName(ResolveInfo resolveInfo) {
- if (resolveInfo == null || resolveInfo.serviceInfo == null) return null;
- return new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
- }
-
- private TrustAgentComponentInfo getSettingsComponent(PackageManager pm,
- ResolveInfo resolveInfo) {
- if (resolveInfo == null || resolveInfo.serviceInfo == null
- || resolveInfo.serviceInfo.metaData == null) {
- return null;
- }
- String cn = null;
- TrustAgentComponentInfo trustAgentComponentInfo = new TrustAgentComponentInfo();
- XmlResourceParser parser = null;
- Exception caughtException = null;
- try {
- parser = resolveInfo.serviceInfo.loadXmlMetaData(pm, TRUST_AGENT_META_DATA);
- if (parser == null) {
- Slog.w(TAG, "Can't find " + TRUST_AGENT_META_DATA + " meta-data");
- return null;
- }
- Resources res = pm.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
- AttributeSet attrs = Xml.asAttributeSet(parser);
- int type;
- while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
- && type != XmlPullParser.START_TAG) {
- }
- String nodeName = parser.getName();
- if (!"trust-agent".equals(nodeName)) {
- Slog.w(TAG, "Meta-data does not start with trust-agent tag");
- return null;
- }
- TypedArray sa =
- res.obtainAttributes(attrs, com.android.internal.R.styleable.TrustAgent);
- trustAgentComponentInfo.summary =
- sa.getString(com.android.internal.R.styleable.TrustAgent_summary);
- trustAgentComponentInfo.title =
- sa.getString(com.android.internal.R.styleable.TrustAgent_title);
- cn = sa.getString(com.android.internal.R.styleable.TrustAgent_settingsActivity);
- sa.recycle();
- } catch (PackageManager.NameNotFoundException e) {
- caughtException = e;
- } catch (IOException e) {
- caughtException = e;
- } catch (XmlPullParserException e) {
- caughtException = e;
- } finally {
- if (parser != null) parser.close();
- }
- if (caughtException != null) {
- Slog.w(TAG, "Error parsing : " + resolveInfo.serviceInfo.packageName, caughtException);
- return null;
- }
- if (cn != null && cn.indexOf('/') < 0) {
- cn = resolveInfo.serviceInfo.packageName + "/" + cn;
- }
- trustAgentComponentInfo.componentName =
- (cn == null) ? null : ComponentName.unflattenFromString(cn);
- return trustAgentComponentInfo;
- }
-}
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentSettings.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentSettings.java
deleted file mode 100644
index b861741..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentSettings.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import android.app.settings.SettingsEnums;
-import android.content.Context;
-import android.provider.SearchIndexableResource;
-
-import com.android.car.developeroptions.R;
-import com.android.car.developeroptions.dashboard.DashboardFragment;
-import com.android.car.developeroptions.search.BaseSearchIndexProvider;
-import com.android.car.developeroptions.search.Indexable;
-import com.android.settingslib.search.SearchIndexable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@SearchIndexable
-public class TrustAgentSettings extends DashboardFragment {
- private static final String TAG = "TrustAgentSettings";
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.TRUST_AGENT;
- }
-
- @Override
- public int getHelpResource() {
- return R.string.help_url_trust_agent;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.trust_agent_settings;
- }
-
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- final List<SearchIndexableResource> result = new ArrayList<>();
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.trust_agent_settings;
- result.add(sir);
- return result;
- }
- };
-}
diff --git a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentsPreferenceController.java b/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentsPreferenceController.java
deleted file mode 100644
index 926436b..0000000
--- a/tests/CarDeveloperOptions/src/com/android/car/developeroptions/security/trustagent/TrustAgentsPreferenceController.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.developeroptions.security.trustagent;
-
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
-import android.app.admin.DevicePolicyManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
-import android.os.UserHandle;
-import android.service.trust.TrustAgentService;
-import android.text.TextUtils;
-import android.util.ArrayMap;
-import android.util.ArraySet;
-import android.util.IconDrawableFactory;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.internal.widget.LockPatternUtils;
-import com.android.car.developeroptions.core.BasePreferenceController;
-import com.android.car.developeroptions.overlay.FeatureFactory;
-import com.android.car.developeroptions.security.SecurityFeatureProvider;
-import com.android.settingslib.RestrictedLockUtilsInternal;
-import com.android.settingslib.RestrictedSwitchPreference;
-import com.android.settingslib.core.lifecycle.LifecycleObserver;
-import com.android.settingslib.core.lifecycle.events.OnStart;
-
-import java.util.List;
-
-public class TrustAgentsPreferenceController extends BasePreferenceController
- implements Preference.OnPreferenceChangeListener, LifecycleObserver, OnStart {
-
- private static final Intent TRUST_AGENT_INTENT =
- new Intent(TrustAgentService.SERVICE_INTERFACE);
-
- private final ArrayMap<ComponentName, TrustAgentInfo> mAvailableAgents;
- private final ArraySet<ComponentName> mActiveAgents;
- private final DevicePolicyManager mDevicePolicyManager;
- private final IconDrawableFactory mIconDrawableFactory;
- private final LockPatternUtils mLockPatternUtils;
- private final PackageManager mPackageManager;
- private final TrustAgentManager mTrustAgentManager;
-
- private PreferenceScreen mScreen;
-
- public TrustAgentsPreferenceController(Context context, String key) {
- super(context, key);
- mAvailableAgents = new ArrayMap<>();
- mActiveAgents = new ArraySet<>();
- mDevicePolicyManager = context.getSystemService(DevicePolicyManager.class);
- mIconDrawableFactory = IconDrawableFactory.newInstance(context);
- final SecurityFeatureProvider securityFeatureProvider =
- FeatureFactory.getFactory(context).getSecurityFeatureProvider();
- mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
- mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
- mPackageManager = context.getPackageManager();
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- mScreen = screen;
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public void onStart() {
- updateAgents();
- }
-
- private void updateAgents() {
- findAvailableTrustAgents();
- loadActiveAgents();
- removeUselessExistingPreferences();
-
- final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
- mContext, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
-
- for (TrustAgentInfo agent : mAvailableAgents.values()) {
- final ComponentName componentName = agent.getComponentName();
- RestrictedSwitchPreference preference = (RestrictedSwitchPreference)
- mScreen.findPreference(componentName.flattenToString());
- if (preference == null) {
- preference = new RestrictedSwitchPreference(mScreen.getContext());
- }
- preference.setKey(componentName.flattenToString());
- preference.useAdminDisabledSummary(true);
- preference.setTitle(agent.getLabel());
- preference.setIcon(agent.getIcon());
- preference.setOnPreferenceChangeListener(this);
- preference.setChecked(mActiveAgents.contains(componentName));
- if (admin != null && mDevicePolicyManager.getTrustAgentConfiguration(null /* admin */,
- componentName) == null) {
- preference.setChecked(false);
- preference.setDisabledByAdmin(admin);
- }
- mScreen.addPreference(preference);
- }
- }
-
- private void loadActiveAgents() {
- final List<ComponentName> activeTrustAgents = mLockPatternUtils.getEnabledTrustAgents(
- UserHandle.myUserId());
- if (activeTrustAgents != null) {
- mActiveAgents.addAll(activeTrustAgents);
- }
- }
-
- private void saveActiveAgents() {
- mLockPatternUtils.setEnabledTrustAgents(mActiveAgents, UserHandle.myUserId());
- }
-
- private void findAvailableTrustAgents() {
- final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(
- TRUST_AGENT_INTENT, PackageManager.GET_META_DATA);
- mAvailableAgents.clear();
- for (ResolveInfo resolveInfo : resolveInfos) {
- if (resolveInfo.serviceInfo == null) {
- continue;
- }
- if (!mTrustAgentManager.shouldProvideTrust(resolveInfo, mPackageManager)) {
- continue;
- }
- final CharSequence label = resolveInfo.loadLabel(mPackageManager);
- final ComponentName componentName = mTrustAgentManager.getComponentName(resolveInfo);
- final Drawable icon = mIconDrawableFactory.getBadgedIcon(
- resolveInfo.getComponentInfo().applicationInfo);
- final TrustAgentInfo agentInfo = new TrustAgentInfo(label, componentName, icon);
- mAvailableAgents.put(componentName, agentInfo);
- }
- }
-
- private void removeUselessExistingPreferences() {
- final int count = mScreen.getPreferenceCount();
- if (count <= 0) {
- return;
- }
- for (int i = count - 1; i >= 0; i--) {
- final Preference pref = mScreen.getPreference(i);
- final String[] names = TextUtils.split(pref.getKey(), "/");
- final ComponentName componentName = new ComponentName(names[0], names[1]);
- if (!mAvailableAgents.containsKey(componentName)) {
- mScreen.removePreference(pref);
- mActiveAgents.remove(componentName);
- }
- }
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (!(preference instanceof SwitchPreference)) {
- return false;
- }
- for (TrustAgentInfo agent : mAvailableAgents.values()) {
- final ComponentName componentName = agent.getComponentName();
- if (!TextUtils.equals(preference.getKey(), componentName.flattenToString())) {
- continue;
- }
- if ((Boolean) newValue && !mActiveAgents.contains(componentName)) {
- mActiveAgents.add(componentName);
- } else {
- mActiveAgents.remove(componentName);
- }
- saveActiveAgents();
- return true;
- }
- return false;
- }
-}