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

Commit dba037db authored by yyalan's avatar yyalan
Browse files

[Action Corner] Hide Preference when flag is off

Bug: 417700615
Flag: com.android.settings.flags.action_corner_customization
Test: ActionCornerPreferenceControllerTest.java
Change-Id: Iaafefe05eba220819884dbbf29c90c2c273b202f
parent 6ebed274
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -55,11 +55,11 @@
        android:order="36"/>

    <Preference
        android:fragment="com.android.settings.inputmethod.ActionCornersFragment"
        android:fragment="com.android.settings.inputmethod.ActionCornerFragment"
        android:key="action_corners"
        android:title="@string/action_corners_title"
        android:summary="@string/action_corners_summary"
        android:featureFlag="com.android.settings.flags.action_corner_customization"
        settings:controller="com.android.settings.inputmethod.ActionCornerPreferenceController"
        android:order="37"/>

    <SwitchPreferenceCompat
+2 −2
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ import com.android.settingslib.search.SearchIndexable;

/** Input settings for action corners. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ActionCornersFragment extends InputDeviceDashboardFragment {
public class ActionCornerFragment extends InputDeviceDashboardFragment {

    private static final String TAG = "ActionCornersFragment";
    private static final String TAG = "ActionCornerFragment";

    //TODO (b/413277948): Metrics
    @Override
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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.inputmethod;

import static com.android.settings.flags.Flags.actionCornerCustomization;
import static com.android.settings.inputmethod.InputPeripheralsSettingsUtils.isMouse;
import static com.android.settings.inputmethod.InputPeripheralsSettingsUtils.isTouchpad;

import android.content.Context;

import androidx.annotation.NonNull;

import com.android.settings.core.BasePreferenceController;

/** The top-level preference controller that handles hot corner customization. */
public class ActionCornerPreferenceController extends BasePreferenceController {

    public ActionCornerPreferenceController(@NonNull Context context,
            @NonNull String key) {
        super(context, key);
    }

    @Override
    public int getAvailabilityStatus() {
        return (actionCornerCustomization() && (isMouse() || isTouchpad()))
                ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
    }
}
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright 2025 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.inputmethod;

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

import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.InputDevice;

import androidx.test.core.app.ApplicationProvider;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
import com.android.settings.testutils.shadow.ShadowInputDevice;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

/** Tests for {@link ActionCornerPreferenceController} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
        ShadowInputDevice.class,
})
public class ActionCornerPreferenceControllerTest {
    @Rule
    public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
    private static final String PREFERENCE_KEY = "preference_key";

    private ActionCornerPreferenceController mController;

    @Before
    public void setup() {
        mController = new ActionCornerPreferenceController(
                ApplicationProvider.getApplicationContext(), PREFERENCE_KEY);
        addTouchpad();
    }

    private void addTouchpad() {
        int deviceId = 1;
        ShadowInputDevice.sDeviceIds = new int[]{deviceId};
        InputDevice device = ShadowInputDevice.makeInputDevicebyIdWithSources(deviceId,
                InputDevice.SOURCE_TOUCHPAD);
        ShadowInputDevice.addDevice(deviceId, device);
    }

    @Test
    @EnableFlags(Flags.FLAG_ACTION_CORNER_CUSTOMIZATION)
    public void getAvailabilityStatus_flagsEnabled_shouldReturnAvailable() {
        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.AVAILABLE);
    }

    @Test
    @DisableFlags(Flags.FLAG_ACTION_CORNER_CUSTOMIZATION)
    public void getAvailabilityStatus_flagsDisabled_shouldReturnUnavailable() {
        assertThat(mController.getAvailabilityStatus())
                .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
    }
}