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

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

feat(A11yFeedback): Implements page ID to feedback bucket ID mapping

This change adds a new API to a Pixel overlay feature provider,
allowing Android to map page IDs to feedback bucket IDs.

Bug: 393980229
Test: Manual testing for Pixel and non-Pixel overlay in real device
Test: atest AccessibilitySettingsTest
            FeedbackManagerTest
Flag: com.android.server.accessibility.enable_low_vision_generic_feedback
Change-Id: I8a110b08816cac9c8a8e8c3e1218530fffb6f121
parent 4cbc560d
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.settings.accessibility;

import android.content.ComponentName;

import androidx.annotation.Nullable;

/**
@@ -25,11 +23,11 @@ import androidx.annotation.Nullable;
public interface AccessibilityFeedbackFeatureProvider {

    /**
     * Returns value according to the {@code componentName}.
     * Returns value according to the {@code pageId}.
     *
     * @param componentName the component name of the downloaded service or activity
     * @return Feedback bucket ID
     * @param pageId The unique identifier of the page.
     * @return Feedback bucket ID associated with the page, or {@code null} if is not found.
     */
    @Nullable
    String getCategory(@Nullable ComponentName componentName);
    String getCategory(int pageId);
}
+2 −4
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.settings.accessibility;

import android.content.ComponentName;

import androidx.annotation.Nullable;

/** Default implementation of {@link AccessibilityFeedbackFeatureProvider}. */
@@ -25,7 +23,7 @@ public class AccessibilityFeedbackFeatureProviderImpl implements

    @Override
    @Nullable
    public String getCategory(@Nullable ComponentName componentName) {
        return "";
    public String getCategory(int pageId) {
        return null;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ public class AccessibilitySettings extends DashboardFragment implements
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        if (getFeedbackManager().isAvailable()) {
            menu.add(Menu.NONE, MENU_ID_SEND_FEEDBACK, Menu.NONE,
                    getPrefContext().getText(R.string.accessibility_send_feedback_title));
                    R.string.accessibility_send_feedback_title);
        }
        super.onCreateOptionsMenu(menu, inflater);
    }
@@ -286,7 +286,7 @@ public class AccessibilitySettings extends DashboardFragment implements

    private FeedbackManager getFeedbackManager() {
        if (mFeedbackManager == null) {
            mFeedbackManager = new FeedbackManager(getActivity());
            mFeedbackManager = new FeedbackManager(getActivity(), SettingsEnums.ACCESSIBILITY);
        }
        return mFeedbackManager;
    }
+3 −13
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.settings.accessibility;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.text.TextUtils;

@@ -46,23 +45,14 @@ public class FeedbackManager {
     * Constructs a new FeedbackManager.
     *
     * @param activity The activity context. A WeakReference is used to prevent memory leaks.
     * @param pageId The unique identifier of the page associated with the feedback.
     */
    public FeedbackManager(@Nullable Activity activity) {
        this(activity, /* componentName= */ null);
    }

    /**
     * Constructs a new FeedbackManager.
     *
     * @param activity The activity context. A WeakReference is used to prevent memory leaks.
     * @param componentName The component name associated with the feedback.
     */
    public FeedbackManager(@Nullable Activity activity, @Nullable ComponentName componentName) {
    public FeedbackManager(@Nullable Activity activity, int pageId) {
        this(activity,
                DeviceInfoUtils.getFeedbackReporterPackage(activity),
                FeatureFactory.getFeatureFactory()
                        .getAccessibilityFeedbackFeatureProvider()
                        .getCategory(componentName));
                        .getCategory(pageId));
    }

    /**
+2 −11
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -458,12 +457,10 @@ public class AccessibilitySettingsTest {
        setupFragment();
        mFragment.setFeedbackManager(
                new FeedbackManager(mFragment.getActivity(), PACKAGE_NAME, DEFAULT_CATEGORY));
        when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);

        mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);

        verify(mMenu).add(anyInt(), eq(AccessibilitySettings.MENU_ID_SEND_FEEDBACK),
                anyInt(), eq(mContext.getText(R.string.accessibility_send_feedback_title)));
        verify(mMenu).add(anyInt(), anyInt(), anyInt(), anyInt());
    }

    @Test
@@ -472,12 +469,10 @@ public class AccessibilitySettingsTest {
        setupFragment();
        mFragment.setFeedbackManager(
                new FeedbackManager(mFragment.getActivity(), PACKAGE_NAME, DEFAULT_CATEGORY));
        when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);

        mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);

        verify(mMenu, never()).add(anyInt(), eq(AccessibilitySettings.MENU_ID_SEND_FEEDBACK),
                anyInt(), eq(mContext.getText(R.string.accessibility_send_feedback_title)));
        verify(mMenu, never()).add(anyInt(), anyInt(), anyInt(), anyInt());
    }

    @Test
@@ -486,8 +481,6 @@ public class AccessibilitySettingsTest {
        setupFragment();
        mFragment.setFeedbackManager(
                new FeedbackManager(mFragment.getActivity(), PACKAGE_NAME, DEFAULT_CATEGORY));
        when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
        mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);
        when(mMenuItem.getItemId()).thenReturn(AccessibilitySettings.MENU_ID_SEND_FEEDBACK);

        mFragment.onOptionsItemSelected(mMenuItem);
@@ -502,8 +495,6 @@ public class AccessibilitySettingsTest {
        setupFragment();
        mFragment.setFeedbackManager(
                new FeedbackManager(mFragment.getActivity(), PACKAGE_NAME, DEFAULT_CATEGORY));
        when(mMenu.add(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(mMenuItem);
        mFragment.onCreateOptionsMenu(mMenu, /* inflater= */ null);
        when(mMenuItem.getItemId()).thenReturn(AccessibilitySettings.MENU_ID_SEND_FEEDBACK);

        mFragment.onOptionsItemSelected(mMenuItem);