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

Commit af478cbf authored by Menghan Li's avatar Menghan Li
Browse files

feat(DaLink): Implement disability support menu controller

Bug: 419387108
Test: atest DisabilitySupportMenuControllerTest
Flag: com.android.settings.accessibility.enable_disability_support
Change-Id: Ib12ed3325e926ce4e89b58ea2630ccddb6e509b0
parent e74fff46
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5428,6 +5428,8 @@
    <string name="accessibility_send_feedback_title">Send feedback</string>
    <!-- The menu item to start the survey process for the accessibility [CHAR LIMIT=30] -->
    <string name="accessibility_send_survey_title">Rate us</string>
    <!-- The menu item to start the disability support for the accessibility [CHAR LIMIT=30] -->
    <string name="accessibility_disability_support_title">Contact Google Disability Support</string>
    <!-- Channel name for the accessibility survey notification. [CHAR LIMIT=50] -->
    <string name="accessibility_send_survey_notification_channel">Accessibility Survey</string>
    <!-- Title of a survey notification about dark theme. [CHAR LIMIT=50] -->
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.accessibility.actionbar;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import com.android.settings.R;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected;

/**
 * A controller that adds disability support menu to any Settings page.
 */
public class DisabilitySupportMenuController implements LifecycleObserver, OnCreateOptionsMenu,
        OnOptionsItemSelected {

    @NonNull
    private final InstrumentedPreferenceFragment mHost;

    @NonNull
    private final String mDisabilitySupportUrl;

    /**
     * Initializes the DisabilitySupportMenuController for an InstrumentedPreferenceFragment.
     *
     * @param host The InstrumentedPreferenceFragment to which the menu controller will be added.
     */
    public static void init(@NonNull InstrumentedPreferenceFragment host,
            @NonNull String disabilitySupportUrl) {
        host.getSettingsLifecycle().addObserver(
                new DisabilitySupportMenuController(host, disabilitySupportUrl));
    }


    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        if (TextUtils.isEmpty(mDisabilitySupportUrl)) {
            return;
        }

        menu.add(Menu.NONE, MenusUtils.MenuId.DISABILITY_SUPPORT.getValue(), Menu.NONE,
                R.string.accessibility_disability_support_title);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem menuItem) {
        if (menuItem.getItemId() == MenusUtils.MenuId.DISABILITY_SUPPORT.getValue()) {
            final FragmentActivity activity = mHost.getActivity();
            if (activity != null) {
                final Intent browserIntent = new Intent(Intent.ACTION_VIEW);
                browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
                browserIntent.setData(Uri.parse(mDisabilitySupportUrl));
                activity.startActivity(browserIntent);
            }
            return true;
        }
        return false;
    }

    private DisabilitySupportMenuController(@NonNull InstrumentedPreferenceFragment host,
            @NonNull String disabilitySupportUrl) {
        mHost = host;
        mDisabilitySupportUrl = disabilitySupportUrl;
    }
}
+3 −7
Original line number Diff line number Diff line
@@ -35,11 +35,6 @@ import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected;
public class FeedbackMenuController implements LifecycleObserver, OnCreateOptionsMenu,
        OnOptionsItemSelected {

    /**
     * The menu item ID for the feedback menu option.
     */
    public static final int MENU_FEEDBACK = Menu.FIRST + 10;

    /**
     * The menu item ID for the feedback menu option.
     */
@@ -76,12 +71,13 @@ public class FeedbackMenuController implements LifecycleObserver, OnCreateOption
        if (!mFeedbackManager.isAvailable()) {
            return;
        }
        menu.add(Menu.NONE, MENU_FEEDBACK, Menu.NONE, R.string.accessibility_send_feedback_title);
        menu.add(Menu.NONE, MenusUtils.MenuId.FEEDBACK.getValue(), Menu.NONE,
                R.string.accessibility_send_feedback_title);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem menuItem) {
        if (menuItem.getItemId() == MENU_FEEDBACK) {
        if (menuItem.getItemId() == MenusUtils.MenuId.FEEDBACK.getValue()) {
            mFeedbackManager.sendFeedback();
            return true;
        }
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.accessibility.actionbar;

/**
 * Utility class for managing menu-related identifiers and potentially other menu-specific logic.
 */
public final class MenusUtils {

    /**
     * Represents the unique identifiers for various menu items in the application. Each menu item
     * is associated with an integer value.
     */
    public enum MenuId {

        /**
         * Identifier for the feedback menu option.
         */
        FEEDBACK(10),

        /**
         * Identifier for the send survey menu option.
         */
        SEND_SURVEY(20),

        /**
         * Identifier for the disability support menu option.
         */
        DISABILITY_SUPPORT(30);

        private final int mValue;

        /**
         * Constructs a {@code MenuId} enum constant with the specified integer value.
         *
         * @param value The unique integer value for this menu ID.
         */
        MenuId(int value) {
            this.mValue = value;
        }

        /**
         * Returns the integer value associated with this menu ID.
         *
         * @return The integer value of this menu ID.
         */
        public int getValue() {
            return mValue;
        }
    }

    private MenusUtils() {}
}
+2 −7
Original line number Diff line number Diff line
@@ -43,11 +43,6 @@ import com.android.settingslib.core.lifecycle.events.OnOptionsItemSelected;
public class SurveyMenuController implements LifecycleObserver, OnCreateOptionsMenu,
        OnOptionsItemSelected {

    /**
     * The menu item ID for the send survey menu option.
     */
    public static final int MENU_SEND_SURVEY = Menu.FIRST + 20;

    @NonNull
    private final InstrumentedPreferenceFragment mHost;
    @Nullable
@@ -96,7 +91,7 @@ public class SurveyMenuController implements LifecycleObserver, OnCreateOptionsM
        if (mSurveyFeatureProvider != null) {
            mSurveyFeatureProvider.checkSurveyAvailable(mHost, mFeedbackKey, available -> {
                if (available) {
                    menu.add(Menu.NONE, MENU_SEND_SURVEY, Menu.NONE,
                    menu.add(Menu.NONE, MenusUtils.MenuId.SEND_SURVEY.getValue(), Menu.NONE,
                            R.string.accessibility_send_survey_title);
                }
            });
@@ -105,7 +100,7 @@ public class SurveyMenuController implements LifecycleObserver, OnCreateOptionsM

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem menuItem) {
        if (menuItem.getItemId() == MENU_SEND_SURVEY) {
        if (menuItem.getItemId() == MenusUtils.MenuId.SEND_SURVEY.getValue()) {
            startSurvey();
            // Prevent repeated feedback triggers.
            menuItem.setVisible(false);
Loading