Adds 'more details' hyper link.

Adds a 'more details' hyper link in the footer when options are disabled
by admin.

Test: make ROBOTEST_FILTER=ScreenTimeoutSettingsTest RunSettingsRoboTests
Bug: 180314728
Change-Id: I880ccd73f4b2ef0b695619ef42ec87559dc2b65b
This commit is contained in:
Yi Jiang
2021-03-03 23:29:52 -08:00
parent c752d2e25b
commit bc6ec17120
2 changed files with 40 additions and 21 deletions

View File

@@ -26,8 +26,13 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.util.Log; import android.util.Log;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -97,15 +102,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy); mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
mPrivacyPreference.setSelectable(false); mPrivacyPreference.setSelectable(false);
mPrivacyPreference.setLayoutResource(R.layout.preference_footer); mPrivacyPreference.setLayoutResource(R.layout.preference_footer);
mDisableOptionsPreference = new FooterPreference(context);
mDisableOptionsPreference.setLayoutResource(R.layout.preference_footer);
mDisableOptionsPreference.setTitle(R.string.admin_disabled_other_options);
mDisableOptionsPreference.setIcon(R.drawable.ic_info_outline_24dp);
// The 'disabled by admin' preference should always be at the end of the setting page.
mDisableOptionsPreference.setOrder(DEFAULT_ORDER_OF_LOWEST_PREFERENCE);
mPrivacyPreference.setOrder(DEFAULT_ORDER_OF_LOWEST_PREFERENCE - 1);
} }
@Override @Override
@@ -138,14 +134,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
final PreferenceScreen screen = getPreferenceScreen(); final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll(); screen.removeAll();
if (mAdmin != null) {
mDisableOptionsPreference.setOnPreferenceClickListener(p -> {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), mAdmin);
return true;
});
screen.addPreference(mDisableOptionsPreference);
}
final List<? extends CandidateInfo> candidateList = getCandidates(); final List<? extends CandidateInfo> candidateList = getCandidates();
if (candidateList == null) { if (candidateList == null) {
return; return;
@@ -165,14 +153,43 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
} }
if (mAdmin != null) { if (mAdmin != null) {
mDisableOptionsPreference.setOnPreferenceClickListener(p -> { setupDisabledFooterPreference();
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), mAdmin);
return true;
});
screen.addPreference(mDisableOptionsPreference); screen.addPreference(mDisableOptionsPreference);
} }
} }
@VisibleForTesting
void setupDisabledFooterPreference() {
final String textDisabledByAdmin = getResources().getString(
R.string.admin_disabled_other_options);
final String textMoreDetails = getResources().getString(R.string.admin_more_details);
final SpannableString spannableString = new SpannableString(
textDisabledByAdmin + System.lineSeparator() + textMoreDetails);
final ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), mAdmin);
}
};
if (textDisabledByAdmin != null && textMoreDetails != null) {
spannableString.setSpan(clickableSpan, textDisabledByAdmin.length() + 1,
textDisabledByAdmin.length() + textMoreDetails.length() + 1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
mDisableOptionsPreference = new FooterPreference(getContext());
mDisableOptionsPreference.setLayoutResource(R.layout.preference_footer);
mDisableOptionsPreference.setTitle(spannableString);
mDisableOptionsPreference.setSelectable(false);
mDisableOptionsPreference.setIcon(R.drawable.ic_info_outline_24dp);
// The 'disabled by admin' preference should always be at the end of the setting page.
mDisableOptionsPreference.setOrder(DEFAULT_ORDER_OF_LOWEST_PREFERENCE);
mPrivacyPreference.setOrder(DEFAULT_ORDER_OF_LOWEST_PREFERENCE - 1);
}
@Override @Override
protected String getDefaultKey() { protected String getDefaultKey() {
return getCurrentSystemScreenTimeout(getContext()); return getCurrentSystemScreenTimeout(getContext());

View File

@@ -23,6 +23,7 @@ import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -138,6 +139,7 @@ public class ScreenTimeoutSettingsTest {
public void updateCandidates_enforcedAdmin_showDisabledByAdminPreference() { public void updateCandidates_enforcedAdmin_showDisabledByAdminPreference() {
mSettings.mAdmin = new RestrictedLockUtils.EnforcedAdmin(); mSettings.mAdmin = new RestrictedLockUtils.EnforcedAdmin();
mSettings.mDisableOptionsPreference = mDisableOptionsPreference; mSettings.mDisableOptionsPreference = mDisableOptionsPreference;
doNothing().when(mSettings).setupDisabledFooterPreference();
mSettings.updateCandidates(); mSettings.updateCandidates();