Use disabled summary when trustagents are disabled

This makes trust agent preferences follow the behavior of other features that can be disabled by device admins, otherwise the preference is simply greyed out without context until the user clicks on the preference.

Bug: 319095039
Test: Covered by TrustAgentListPreferenceControllerTest#onResume_restrictedPreferenceShouldUseAdminDisabledSummary
Test: atest SettingsRoboTests:com.android.settings.security --host
Test: manually validated that disabled admin policy results in showing "Controlled by admin" as the summary
Flag: EXEMPT bugfix for single preference in settings
Change-Id: I89f052cf2479a120d8b5b223414162f129cde89e
This commit is contained in:
Billy Huang
2024-02-27 15:12:39 -08:00
parent c35fc38be9
commit ee6c4bacd8
2 changed files with 100 additions and 37 deletions

View File

@@ -23,6 +23,7 @@ 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;
@@ -216,7 +217,11 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
trustAgentPreference.setIntent(new Intent(Intent.ACTION_MAIN)
.setComponent(agent.componentName));
trustAgentPreference.setDisabledByAdmin(agent.admin);
if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) {
if (trustAgentPreference.isDisabledByAdmin()) {
// Ensure visibility by setting non-empty summary text.
trustAgentPreference.setSummary(TextUtils.firstNotEmpty(agent.summary, " "));
trustAgentPreference.useAdminDisabledSummary(true);
} else if (!trustAgentPreference.isDisabledByAdmin() && !hasSecurity) {
trustAgentPreference.setEnabled(false);
trustAgentPreference.setSummary(R.string.disabled_because_no_backup_security);
}