Remove unused MagnificationPreferenceFragment and its related controllers

Bug: 277258376
Bug: 270481978
Test: manually on Pixel & AOSP
Change-Id: I1e0bbecf78290b85e464a4a5de658184eb91ca2c
This commit is contained in:
Chun-Ku Lin
2023-04-06 22:28:04 +00:00
parent 336ab272ac
commit b7d513b84d
19 changed files with 5 additions and 1028 deletions

View File

@@ -104,10 +104,7 @@ public class AccessibilityDetailsSettingsFragment extends InstrumentedFragment {
@Nullable ComponentName componentName) {
if (MAGNIFICATION_COMPONENT_NAME.equals(componentName)) {
final String destination = ToggleScreenMagnificationPreferenceFragment.class.getName();
final Bundle arguments = new Bundle();
MagnificationGesturesPreferenceController.populateMagnificationGesturesPreferenceExtras(
arguments, getContext());
return new LaunchFragmentArguments(destination, arguments);
return new LaunchFragmentArguments(destination, /* arguments= */ null);
}
if (ACCESSIBILITY_BUTTON_COMPONENT_NAME.equals(componentName)) {

View File

@@ -79,7 +79,6 @@ public class AccessibilitySettings extends DashboardFragment {
static final String EXTRA_PREFERENCE_KEY = "preference_key";
static final String EXTRA_CHECKED = "checked";
static final String EXTRA_TITLE = "title";
static final String EXTRA_TITLE_RES = "title_res";
static final String EXTRA_RESOLVE_INFO = "resolve_info";
static final String EXTRA_SUMMARY = "summary";
static final String EXTRA_INTRO = "intro";
@@ -87,7 +86,6 @@ public class AccessibilitySettings extends DashboardFragment {
static final String EXTRA_COMPONENT_NAME = "component_name";
static final String EXTRA_SETTINGS_COMPONENT_NAME = "settings_component_name";
static final String EXTRA_TILE_SERVICE_COMPONENT_NAME = "tile_service_component_name";
static final String EXTRA_VIDEO_RAW_RESOURCE_ID = "video_resource";
static final String EXTRA_LAUNCHED_FROM_SUW = "from_suw";
static final String EXTRA_ANIMATED_IMAGE_RES = "animated_image_res";
static final String EXTRA_HTML_DESCRIPTION = "html_description";

View File

@@ -24,7 +24,6 @@ import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIU
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
@@ -129,7 +128,6 @@ public class AccessibilitySettingsForSetupWizard extends DashboardFragment
SCREEN_READER_PACKAGE_NAME, SCREEN_READER_SERVICE_NAME);
updateAccessibilityServicePreference(mSelectToSpeakPreference,
SELECT_TO_SPEAK_PACKAGE_NAME, SELECT_TO_SPEAK_SERVICE_NAME);
configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreference);
}
@Override
@@ -220,13 +218,4 @@ public class AccessibilitySettingsForSetupWizard extends DashboardFragment
final String htmlDescription = info.loadHtmlDescription(getPackageManager());
extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription);
}
private static void configureMagnificationPreferenceIfNeeded(Preference preference) {
final Context context = preference.getContext();
preference.setFragment(
ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
final Bundle extras = preference.getExtras();
MagnificationGesturesPreferenceController
.populateMagnificationGesturesPreferenceExtras(extras, context);
}
}

View File

@@ -1,105 +0,0 @@
/*
* Copyright (C) 2018 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.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class MagnificationGesturesPreferenceController extends TogglePreferenceController {
private boolean mIsFromSUW = false;
public MagnificationGesturesPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return MagnificationPreferenceFragment.isChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
}
@Override
public boolean setChecked(boolean isChecked) {
return MagnificationPreferenceFragment.setChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, isChecked);
}
public void setIsFromSUW(boolean fromSUW) {
mIsFromSUW = fromSUW;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
Bundle extras = preference.getExtras();
populateMagnificationGesturesPreferenceExtras(extras, mContext);
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked());
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
return true;
}
return false;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(),
"screen_magnification_gestures_preference_screen");
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
@Override
public CharSequence getSummary() {
int resId = 0;
if (mIsFromSUW) {
resId = R.string.accessibility_screen_magnification_short_summary;
} else {
final boolean enabled = isChecked();
resId = (enabled ? R.string.accessibility_feature_state_on :
R.string.accessibility_feature_state_off);
}
return mContext.getString(resId);
}
static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
// TODO(b/270481978): It seems not necessary to put EXTRA_TITLE_RES.
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
R.string.accessibility_screen_magnification_gestures_title);
// TODO(b/270481978): It seems not necessary to put EXTRA_VIDEO_RAW_RESOURCE_ID.
extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
R.raw.accessibility_screen_magnification);
}
}

View File

@@ -1,102 +0,0 @@
/*
* Copyright (C) 2018 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.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class MagnificationNavbarPreferenceController extends TogglePreferenceController {
private boolean mIsFromSUW = false;
public MagnificationNavbarPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return MagnificationPreferenceFragment.isChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
}
@Override
public boolean setChecked(boolean isChecked) {
return MagnificationPreferenceFragment.setChecked(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, isChecked);
}
public void setIsFromSUW(boolean fromSUW) {
mIsFromSUW = fromSUW;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
Bundle extras = preference.getExtras();
extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED);
extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
R.string.accessibility_screen_magnification_navbar_title);
extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION,
mContext.getText(R.string.accessibility_screen_magnification_navbar_summary));
extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked());
extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
return true;
}
return false;
}
@Override
public int getAvailabilityStatus() {
return MagnificationPreferenceFragment.isApplicable(mContext.getResources())
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(),
"screen_magnification_navbar_preference_screen");
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
@Override
public CharSequence getSummary() {
int resId = 0;
if (mIsFromSUW) {
resId = R.string.accessibility_screen_magnification_navbar_short_summary;
} else {
final boolean enabled = isChecked();
resId = (enabled ? R.string.accessibility_feature_state_on :
R.string.accessibility_feature_state_off);
}
return mContext.getText(resId);
}
}

View File

@@ -17,17 +17,11 @@
package com.android.settings.accessibility;
import android.content.Context;
import android.os.Bundle;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
public class MagnificationPreferenceController extends BasePreferenceController {
private Preference mPreference;
public MagnificationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@@ -41,18 +35,4 @@ public class MagnificationPreferenceController extends BasePreferenceController
public CharSequence getSummary() {
return ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
configureMagnificationPreferenceIfNeeded();
}
private void configureMagnificationPreferenceIfNeeded() {
mPreference.setFragment(ToggleScreenMagnificationPreferenceFragment.class.getName());
final Bundle extras = mPreference.getExtras();
MagnificationGesturesPreferenceController
.populateMagnificationGesturesPreferenceExtras(extras, mContext);
}
}

View File

@@ -1,171 +0,0 @@
/*
* Copyright (C) 2017 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.accessibilityservice.AccessibilityServiceInfo;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.List;
/** Settings fragment containing magnification preference. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public final class MagnificationPreferenceFragment extends DashboardFragment {
@VisibleForTesting static final int ON = 1;
@VisibleForTesting static final int OFF = 0;
private static final String TAG = "MagnificationPreferenceFragment";
// Settings App preference keys
private static final String PREFERENCE_TITLE_KEY = "magnification_preference_screen_title";
// Pseudo ComponentName used to represent navbar magnification in Settings.Secure.
private static final String MAGNIFICATION_COMPONENT_ID =
"com.android.server.accessibility.MagnificationController";
private boolean mLaunchedFromSuw = false;
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_SCREEN_MAGNIFICATION_SETTINGS;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getHelpResource() {
return R.string.help_url_magnification;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_magnification_settings;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
final Bundle args = getArguments();
if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW)) {
mLaunchedFromSuw = args.getBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW);
}
use(MagnificationGesturesPreferenceController.class)
.setIsFromSUW(mLaunchedFromSuw);
use(MagnificationNavbarPreferenceController.class)
.setIsFromSUW(mLaunchedFromSuw);
}
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (mLaunchedFromSuw) {
// If invoked from SUW, redirect to fragment instrumented for Vision Settings metrics
preference.setFragment(
ToggleScreenMagnificationPreferenceFragmentForSetupWizard.class.getName());
}
return super.onPreferenceTreeClick(preference);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (mLaunchedFromSuw) {
// Do not call super. We don't want to see the "Help & feedback" on OOBE page.
} else {
super.onCreateOptionsMenu(menu, inflater);
}
}
static CharSequence getConfigurationWarningStringForSecureSettingsKey(String key,
Context context) {
if (!Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED.equals(key)) {
return null;
}
if (Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, 0) == 0) {
return null;
}
final AccessibilityManager am = (AccessibilityManager) context.getSystemService(
Context.ACCESSIBILITY_SERVICE);
final String assignedId = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
if (!TextUtils.isEmpty(assignedId) && !MAGNIFICATION_COMPONENT_ID.equals(assignedId)) {
final ComponentName assignedComponentName = ComponentName.unflattenFromString(
assignedId);
final List<AccessibilityServiceInfo> activeServices =
am.getEnabledAccessibilityServiceList(
AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
final int serviceCount = activeServices.size();
for (int i = 0; i < serviceCount; i++) {
final AccessibilityServiceInfo info = activeServices.get(i);
if (info.getComponentName().equals(assignedComponentName)) {
final CharSequence assignedServiceName = info.getResolveInfo().loadLabel(
context.getPackageManager());
final int messageId = AccessibilityUtil.isGestureNavigateEnabled(context)
? R.string.accessibility_screen_magnification_gesture_navigation_warning
: R.string.accessibility_screen_magnification_navbar_configuration_warning;
return context.getString(messageId, assignedServiceName);
}
}
}
return null;
}
static boolean isChecked(ContentResolver contentResolver, String settingsKey) {
return Settings.Secure.getInt(contentResolver, settingsKey, OFF) == ON;
}
static boolean setChecked(ContentResolver contentResolver, String settingsKey,
boolean isChecked) {
return Settings.Secure.putInt(contentResolver, settingsKey, isChecked ? ON : OFF);
}
/**
* @return {@code true} if this fragment should be shown, {@code false} otherwise. This
* fragment is shown in the case that more than one magnification mode is available.
*/
static boolean isApplicable(Resources res) {
return res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_magnification_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
return isApplicable(context.getResources());
}
};
}

View File

@@ -1,91 +0,0 @@
/*
* Copyright (C) 2019 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.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.DialogCreatable;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
/** Settings page for magnification. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MagnificationSettingsFragment extends DashboardFragment implements
MagnificationModePreferenceController.DialogHelper {
private static final String TAG = "MagnificationSettingsFragment";
private DialogCreatable mDialogDelegate;
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_MAGNIFICATION_SETTINGS;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(MagnificationModePreferenceController.class).setDialogHelper(this);
}
@Override
public void showDialog(int dialogId) {
super.showDialog(dialogId);
}
@Override
public void setDialogDelegate(DialogCreatable delegate) {
mDialogDelegate = delegate;
}
@Override
public int getDialogMetricsCategory(int dialogId) {
if (mDialogDelegate != null) {
return mDialogDelegate.getDialogMetricsCategory(dialogId);
}
return 0;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_magnification_service_settings;
}
@Override
public Dialog onCreateDialog(int dialogId) {
if (mDialogDelegate != null) {
final Dialog dialog = mDialogDelegate.onCreateDialog(dialogId);
if (dialog != null) {
return dialog;
}
}
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_magnification_service_settings);
}

View File

@@ -225,10 +225,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
protected void onProcessArguments(Bundle arguments) {
Context context = getContext();
// This Fragment may get arguments from MagnificationGesturesPreferenceController or
// MagnificationNavbarPreferenceController and it's necessary to check if a key exists
// before putting a new value into arguments.
if (!arguments.containsKey(AccessibilitySettings.EXTRA_PREFERENCE_KEY)) {
arguments.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
@@ -531,7 +527,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
preferenceKey)) {
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? ON : OFF);
}
@Override