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

Commit 972e7a32 authored by Menghan Li's avatar Menghan Li Committed by Android (Google) Code Review
Browse files

Merge changes from topics "A11yFeedback", "AccessibilityFeedbackFeatureProvider" into main

* changes:
  feat(A11yFeedback): Pixel overlay to expose the feedback bucket ID
  feat(A11yFeedback): Add feedback entry for Accessibility page
  feat(A11yFeedback): Add FeedbackManager for Accessibility page
parents 2c90d304 6b916e6f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5167,6 +5167,8 @@
    <string name="accessibility_feedback_summary">Help improve by taking a survey</string>
    <!-- Summary for the accessibility feedback preference is disabled. [CHAR LIMIT=100] -->
    <string name="accessibility_feedback_disabled_summary">No surveys available</string>
    <!-- The menu item to start the feedback process for the accessibility [CHAR LIMIT=30] -->
    <string name="accessibility_send_feedback_title">Send feedback</string>
    <!-- Title for the accessibility preference category of services downloaded by the user. [CHAR LIMIT=50] -->
    <string name="user_installed_services_category_title">Downloaded apps</string>
    <!-- Title for the accessibility preference category of settings considered to be experimental, meaning they might be changed or removed in the future. [CHAR LIMIT=50] -->
+35 −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;

import android.content.ComponentName;

import androidx.annotation.Nullable;

/**
 * Provider for Accessibility feedback related features.
 */
public interface AccessibilityFeedbackFeatureProvider {

    /**
     * Returns value according to the {@code componentName}.
     *
     * @param componentName the component name of the downloaded service or activity
     * @return Feedback bucket ID
     */
    @Nullable
    String getCategory(@Nullable ComponentName componentName);
}
+31 −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;

import android.content.ComponentName;

import androidx.annotation.Nullable;

/** Default implementation of {@link AccessibilityFeedbackFeatureProvider}. */
public class AccessibilityFeedbackFeatureProviderImpl implements
        AccessibilityFeedbackFeatureProvider{

    @Override
    @Nullable
    public String getCategory(@Nullable ComponentName componentName) {
        return "";
    }
}
+38 −2
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.accessibility.AccessibilityManager;

import androidx.annotation.NonNull;
@@ -101,6 +104,8 @@ public class AccessibilitySettings extends DashboardFragment implements
    // presentation.
    private static final long DELAY_UPDATE_SERVICES_MILLIS = 1000;

    static final int MENU_ID_SEND_FEEDBACK = 0;

    private final Handler mHandler = new Handler();

    private final Runnable mUpdateRunnable = new Runnable() {
@@ -143,8 +148,9 @@ public class AccessibilitySettings extends DashboardFragment implements
        }
    };

    @VisibleForTesting
    AccessibilitySettingsContentObserver mSettingsContentObserver;
    private AccessibilitySettingsContentObserver mSettingsContentObserver;

    private FeedbackManager mFeedbackManager;

    private final Map<String, PreferenceCategory> mCategoryToPrefCategoryMap =
            new ArrayMap<>();
@@ -245,6 +251,24 @@ public class AccessibilitySettings extends DashboardFragment implements
        super.onDestroy();
    }

    @Override
    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));
        }
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == MENU_ID_SEND_FEEDBACK) {
            getFeedbackManager().sendFeedback();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.accessibility_settings;
@@ -255,6 +279,18 @@ public class AccessibilitySettings extends DashboardFragment implements
        return TAG;
    }

    @VisibleForTesting
    void setFeedbackManager(FeedbackManager feedbackManager) {
        this.mFeedbackManager = feedbackManager;
    }

    private FeedbackManager getFeedbackManager() {
        if (mFeedbackManager == null) {
            mFeedbackManager = new FeedbackManager(getActivity());
        }
        return mFeedbackManager;
    }

    /**
     * Returns the summary for the current state of this accessibilityService.
     *
+118 −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;

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

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.server.accessibility.Flags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.DeviceInfoUtils;

import java.lang.ref.WeakReference;

/**
 * Manages the feedback flow. This class is responsible for checking feedback availability and
 * sending feedback. Uses a WeakReference to the Activity to prevent memory leaks.
 */
public class FeedbackManager {

    static final String CATEGORY_TAG = "category_tag";
    private static final int FEEDBACK_INTENT_RESULT_CODE = 0;

    private final WeakReference<Activity> mActivityWeakReference;
    @Nullable private final String mReporterPackage;
    @Nullable private final String mCategoryTag;

    /**
     * Constructs a new FeedbackManager.
     *
     * @param activity The activity context. A WeakReference is used to prevent memory leaks.
     */
    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) {
        this(activity,
                DeviceInfoUtils.getFeedbackReporterPackage(activity),
                FeatureFactory.getFeatureFactory()
                        .getAccessibilityFeedbackFeatureProvider()
                        .getCategory(componentName));
    }

    /**
     * Constructs a new FeedbackManager. This constructor is visible for testing.
     *
     * @param activity The activity context. A WeakReference is used to prevent memory leaks.
     * @param reporterPackage The package name of the feedback reporter.
     * @param category The feedback bucket ID.
     */
    @VisibleForTesting
    public FeedbackManager(@Nullable Activity activity, @Nullable String reporterPackage,
            @Nullable String category) {
        this.mActivityWeakReference = new WeakReference<>(activity);
        this.mReporterPackage = reporterPackage;
        this.mCategoryTag = category;
    }

    /**
     * Checks if feedback is available on the device.
     *
     * @return {@code true} if feedback is available, {@code false} otherwise.
     */
    public boolean isAvailable() {
        if (!Flags.enableLowVisionGenericFeedback()) {
            return false;
        }

        return !TextUtils.isEmpty(mReporterPackage)
                && !TextUtils.isEmpty(mCategoryTag)
                && mActivityWeakReference.get() != null;
    }

    /**
     * Sends feedback using the available feedback reporter. This will start the feedback
     * activity. It is the responsibility of the calling activity to handle the result
     * code {@link #FEEDBACK_INTENT_RESULT_CODE} if necessary.
     *
     * @return {@code true} if the feedback intent was successfully started, {@code false}
     * otherwise.
     */
    public boolean sendFeedback() {
        Activity activity = mActivityWeakReference.get();
        if (!isAvailable() || activity == null) {
            return false;
        }

        final Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
        intent.setPackage(mReporterPackage);
        intent.putExtra(CATEGORY_TAG, mCategoryTag);
        activity.startActivityForResult(intent, FEEDBACK_INTENT_RESULT_CODE);
        return true;
    }
}
Loading