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

Commit 0731ab74 authored by Massimo Carli's avatar Massimo Carli
Browse files

[2/n] Create compat ui education status

Store the state of Compat UI education in Settings
to allow other application to be informed of their
state.

Flag: com.android.window.flags.enable_compat_ui_visibility_status
Fix: 350953004
Test: atest WMShellUnitTests:CompatUIStatusManagerTest
Test: atest SettingsProviderTest:SettingsBackupTest

Change-Id: I01c360ff08c090a3be94ebe6c0c85a5f8a8098a7
parent fc53eaec
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -12542,6 +12542,19 @@ public final class Settings {
        public static final String LAUNCHER_TASKBAR_EDUCATION_SHOWING =
                "launcher_taskbar_education_showing";
        /**
         * Whether any Compat UI Education is currently showing.
         *
         * <p>1 if true, 0 or unset otherwise.
         *
         * <p>This setting is used to inform other components that the Compat UI Education is
         * currently showing, which can prevent them from showing something else to the user.
         *
         * @hide
         */
        public static final String COMPAT_UI_EDUCATION_SHOWING =
                "compat_ui_education_showing";
        /**
         * Whether or not adaptive charging feature is enabled by user.
         * Type: int (0 for false, 1 for true)
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.wm.shell.compatui;

import android.annotation.NonNull;

import java.util.function.IntConsumer;
import java.util.function.IntSupplier;

/** Handle the visibility state of the Compat UI components. */
public class CompatUIStatusManager {

    public static final int COMPAT_UI_EDUCATION_HIDDEN = 0;
    public static final int COMPAT_UI_EDUCATION_VISIBLE = 1;

    @NonNull
    private final IntConsumer mWriter;
    @NonNull
    private final IntSupplier mReader;

    public CompatUIStatusManager(@NonNull IntConsumer writer, @NonNull IntSupplier reader) {
        mWriter = writer;
        mReader = reader;
    }

    public CompatUIStatusManager() {
        this(i -> { }, () -> COMPAT_UI_EDUCATION_HIDDEN);
    }

    void onEducationShown() {
        mWriter.accept(COMPAT_UI_EDUCATION_VISIBLE);
    }

    void onEducationHidden() {
        mWriter.accept(COMPAT_UI_EDUCATION_HIDDEN);
    }

    boolean isEducationVisible() {
        return mReader.getAsInt() == COMPAT_UI_EDUCATION_VISIBLE;
    }
}
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.wm.shell.compatui;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.testing.AndroidTestingRunner;

import androidx.test.filters.SmallTest;

import com.android.wm.shell.ShellTestCase;


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.function.IntConsumer;
import java.util.function.IntSupplier;

/**
 * Tests for {@link CompatUILayout}.
 *
 * Build/Install/Run:
 *  atest WMShellUnitTests:CompatUIStatusManagerTest
 */
@RunWith(AndroidTestingRunner.class)
@SmallTest
public class CompatUIStatusManagerTest extends ShellTestCase {

    private FakeCompatUIStatusManagerTest mTestState;
    private CompatUIStatusManager mStatusManager;

    @Before
    public void setUp() {
        mTestState = new FakeCompatUIStatusManagerTest();
        mStatusManager = new CompatUIStatusManager(mTestState.mWriter, mTestState.mReader);
    }

    @Test
    public void isEducationShown() {
        assertFalse(mStatusManager.isEducationVisible());

        mStatusManager.onEducationShown();
        assertTrue(mStatusManager.isEducationVisible());

        mStatusManager.onEducationHidden();
        assertFalse(mStatusManager.isEducationVisible());
    }

    static class FakeCompatUIStatusManagerTest {

        int mCurrentStatus = 0;

        final IntSupplier mReader = () -> mCurrentStatus;

        final IntConsumer mWriter = newStatus -> mCurrentStatus = newStatus;

    }
}
+1 −0
Original line number Diff line number Diff line
@@ -677,6 +677,7 @@ public class SettingsBackupTest {
                 Settings.Secure.CAMERA_LIFT_TRIGGER_ENABLED, // Candidate for backup?
                 Settings.Secure.CARRIER_APPS_HANDLED,
                 Settings.Secure.CMAS_ADDITIONAL_BROADCAST_PKG,
                 Settings.Secure.COMPAT_UI_EDUCATION_SHOWING,
                 Settings.Secure.COMPLETED_CATEGORY_PREFIX,
                 Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS,
                 Settings.Secure.CONTENT_CAPTURE_ENABLED,