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

Commit a8f517b3 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9752887 from 7626600b to tm-qpr3-release

Change-Id: I8e34019c0e0beed23acb9d61cffce1efbcc10ae6
parents 5648b61a 7626600b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14464,6 +14464,10 @@
    <string name="dream_complications_toggle_title">Show additional information</string>
    <!-- The summary of what overlays this toggle controls [CHAR LIMIT=none] -->
    <string name="dream_complications_toggle_summary">Display things like the time, weather, or other information on the screen saver</string>
    <!-- The title of the toggle which enables/disables the home controls button on top of the screen saver [CHAR LIMIT=none] -->
    <string name="dream_home_controls_toggle_title">Show home controls</string>
    <!-- The summary of the home controls toggle [CHAR LIMIT=none] -->
    <string name="dream_home_controls_toggle_summary">Show home controls button from the screen saver</string>
    <!-- The title of the category to show for the screensaver miscellaneous settings [CHAR LIMIT=none] -->
    <string name="dream_more_settings_category">More settings</string>
    <!-- The title of the screen saver setup page [CHAR LIMIT=none] -->
+6 −0
Original line number Diff line number Diff line
@@ -46,6 +46,12 @@
        android:summary="@string/dream_complications_toggle_summary"
        settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>

    <SwitchPreference
        android:key="dream_home_controls_toggle"
        android:title="@string/dream_home_controls_toggle_title"
        android:summary="@string/dream_home_controls_toggle_summary"
        settings:controller="com.android.settings.dream.DreamHomeControlsPreferenceController"/>

    <com.android.settings.applications.SpacePreference
        android:layout_height="16dp" />

+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.settings.dream;

import android.content.Context;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.dream.DreamBackend;

/**
 * Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
 * overlays should be enabled.
 */
public class DreamHomeControlsPreferenceController extends TogglePreferenceController {
    private final DreamBackend mBackend;

    public DreamHomeControlsPreferenceController(Context context, String key) {
        this(context, key, DreamBackend.getInstance(context));
    }

    @VisibleForTesting
    public DreamHomeControlsPreferenceController(Context context, String key,
            DreamBackend dreamBackend) {
        super(context, key);
        mBackend = dreamBackend;
    }

    @Override
    public int getAvailabilityStatus() {
        final boolean supported =
                mBackend.getSupportedComplications()
                        .contains(DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
        return supported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }

    @Override
    public boolean isChecked() {
        return mBackend.getEnabledComplications().contains(
                DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        mBackend.setHomeControlsEnabled(isChecked);
        return true;
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_display;
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class NotificationAccessSettings extends EmptyTextSettings {
    private static final String TAG = "NotifAccessSettings";
    private static final String ALLOWED_KEY = "allowed";
    private static final String NOT_ALLOWED_KEY = "not_allowed";
    private static final int MAX_CN_LENGTH = 500;

    private static final ManagedServiceSettings.Config CONFIG =
            new ManagedServiceSettings.Config.Builder()
@@ -101,6 +102,12 @@ public class NotificationAccessSettings extends EmptyTextSettings {
                .setNoun(CONFIG.noun)
                .setSetting(CONFIG.setting)
                .setTag(CONFIG.tag)
                .setValidator(info -> {
                    if (info.getComponentName().flattenToString().length() > MAX_CN_LENGTH) {
                        return false;
                    }
                    return true;
                })
                .build();
        mServiceListing.addCallback(this::updateList);

+116 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.settings.dream;

import static com.android.settingslib.dream.DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.content.Context;
import android.util.ArraySet;

import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;

import com.android.settingslib.dream.DreamBackend;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContentResolver;
import org.robolectric.shadows.ShadowSettings;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowSettings.ShadowSecure.class})
public class DreamHomeControlsPreferenceControllerTest {

    private Context mContext;
    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
    private PreferenceScreen mScreen;
    private DreamHomeControlsPreferenceController mController;
    private SwitchPreference mPreference;
    private DreamBackend mBackend;
    private ShadowContentResolver mShadowContentResolver;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = ApplicationProvider.getApplicationContext();
        mShadowContentResolver = Shadow.extract(mContext.getContentResolver());
        mBackend = new DreamBackend(mContext);
        mController = new DreamHomeControlsPreferenceController(mContext, "key", mBackend);
        mPreference = new SwitchPreference(mContext);
        mPreference.setKey(mController.getPreferenceKey());
        when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
        mController.displayPreference(mScreen);

        // Make home controls supported by default
        mBackend.setSupportedComplications(
                new ArraySet<>(new Integer[]{COMPLICATION_TYPE_HOME_CONTROLS}));
    }

    @After
    public void tearDown() {
        ShadowSettings.ShadowSecure.reset();
    }

    @Test
    public void testSetChecked_setTrue_enablesSetting() {
        mBackend.setHomeControlsEnabled(false);
        assertThat(mBackend.getEnabledComplications())
                .doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);

        mController.setChecked(true);
        assertThat(mBackend.getEnabledComplications())
                .contains(COMPLICATION_TYPE_HOME_CONTROLS);
    }

    @Test
    public void testSetChecked_setFalse_disablesSetting() {
        mBackend.setHomeControlsEnabled(true);
        assertThat(mBackend.getEnabledComplications())
                .contains(COMPLICATION_TYPE_HOME_CONTROLS);

        mController.setChecked(false);
        assertThat(mBackend.getEnabledComplications())
                .doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);
    }

    @Test
    public void testIsChecked_returnsFalse() {
        mBackend.setHomeControlsEnabled(false);
        assertThat(mController.isChecked()).isFalse();
    }

    @Test
    public void testIsChecked_returnsTrue() {
        mBackend.setHomeControlsEnabled(true);
        assertThat(mBackend.getEnabledComplications())
                .contains(COMPLICATION_TYPE_HOME_CONTROLS);
        assertThat(mController.isChecked()).isTrue();
    }
}