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
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 "";
|
||||
}
|
||||
}
|
||||
@@ -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
src/com/android/settings/accessibility/FeedbackManager.java
Normal file
118
src/com/android/settings/accessibility/FeedbackManager.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.android.settings.overlay
|
||||
|
||||
import android.content.Context
|
||||
import com.android.settings.accessibility.AccessibilityFeedbackFeatureProvider
|
||||
import com.android.settings.accessibility.AccessibilityMetricsFeatureProvider
|
||||
import com.android.settings.accessibility.AccessibilitySearchFeatureProvider
|
||||
import com.android.settings.accounts.AccountFeatureProvider
|
||||
@@ -133,6 +134,11 @@ abstract class FeatureFactory {
|
||||
*/
|
||||
abstract val securitySettingsFeatureProvider: SecuritySettingsFeatureProvider
|
||||
|
||||
/**
|
||||
* Retrieves implementation for Accessibility feedback category feature.
|
||||
*/
|
||||
abstract val accessibilityFeedbackFeatureProvider: AccessibilityFeedbackFeatureProvider
|
||||
|
||||
/**
|
||||
* Retrieves implementation for Accessibility search index feature.
|
||||
*/
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.VpnManager
|
||||
import android.os.UserManager
|
||||
import com.android.settings.accessibility.AccessibilityFeedbackFeatureProvider
|
||||
import com.android.settings.accessibility.AccessibilityFeedbackFeatureProviderImpl
|
||||
import com.android.settings.accessibility.AccessibilityMetricsFeatureProvider
|
||||
import com.android.settings.accessibility.AccessibilityMetricsFeatureProviderImpl
|
||||
import com.android.settings.accessibility.AccessibilitySearchFeatureProvider
|
||||
@@ -165,6 +167,9 @@ open class FeatureFactoryImpl : FeatureFactory() {
|
||||
SecuritySettingsFeatureProviderImpl()
|
||||
}
|
||||
|
||||
override val accessibilityFeedbackFeatureProvider: AccessibilityFeedbackFeatureProvider
|
||||
by lazy { AccessibilityFeedbackFeatureProviderImpl() }
|
||||
|
||||
override val accessibilitySearchFeatureProvider: AccessibilitySearchFeatureProvider by lazy {
|
||||
AccessibilitySearchFeatureProviderImpl()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user