Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0894378 authored by Yi Jiang's avatar Yi Jiang Committed by Android (Google) Code Review
Browse files

Merge "Adds 'more details' hyper link." into sc-dev

parents 18a68878 bc6ec171
Loading
Loading
Loading
Loading
+38 −21
Original line number Diff line number Diff line
@@ -26,8 +26,13 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

@@ -97,15 +102,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
        mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
        mPrivacyPreference.setSelectable(false);
        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
@@ -138,14 +134,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
        final PreferenceScreen screen = getPreferenceScreen();
        screen.removeAll();

        if (mAdmin != null) {
            mDisableOptionsPreference.setOnPreferenceClickListener(p -> {
                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), mAdmin);
                return true;
            });
            screen.addPreference(mDisableOptionsPreference);
        }

        final List<? extends CandidateInfo> candidateList = getCandidates();
        if (candidateList == null) {
            return;
@@ -165,14 +153,43 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
        }

        if (mAdmin != null) {
            mDisableOptionsPreference.setOnPreferenceClickListener(p -> {
                RestrictedLockUtils.sendShowAdminSupportDetailsIntent(getContext(), mAdmin);
                return true;
            });
            setupDisabledFooterPreference();
            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
    protected String getDefaultKey() {
        return getCurrentSystemScreenTimeout(getContext());
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -138,6 +139,7 @@ public class ScreenTimeoutSettingsTest {
    public void updateCandidates_enforcedAdmin_showDisabledByAdminPreference() {
        mSettings.mAdmin = new RestrictedLockUtils.EnforcedAdmin();
        mSettings.mDisableOptionsPreference = mDisableOptionsPreference;
        doNothing().when(mSettings).setupDisabledFooterPreference();

        mSettings.updateCandidates();