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

@@ -4270,8 +4270,6 @@
<string name="accessibility_magnification_triple_tap_warning_negative_button">Cancel</string> <string name="accessibility_magnification_triple_tap_warning_negative_button">Cancel</string>
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] --> <!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
<string name="accessibility_magnification_service_settings_title">Magnification settings</string> <string name="accessibility_magnification_service_settings_title">Magnification settings</string>
<!-- Title for the accessibility preference screen to enable triple-tap gesture screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_gestures_title">Magnify with triple-tap</string>
<!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] --> <!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] -->
<string name="accessibility_screen_magnification_navbar_title">Magnify with shortcut</string> <string name="accessibility_screen_magnification_navbar_title">Magnify with shortcut</string>
<!-- Summary for the accessibility magnification setting indicating both "Magnify with button" and "Magnify with triple-tap" are enabled [CHAR LIMIT=50] --> <!-- Summary for the accessibility magnification setting indicating both "Magnify with button" and "Magnify with triple-tap" are enabled [CHAR LIMIT=50] -->

View File

@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="magnification_mode_screen"
android:persistent="false"
android:title="@string/accessibility_magnification_service_settings_title"
settings:searchable="false">
<Preference
android:key="magnification_mode"
android:persistent="false"
android:title="@string/accessibility_magnification_mode_title"
settings:searchable="false"
settings:controller="com.android.settings.accessibility.MagnificationModePreferenceController" />
</PreferenceScreen>

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/accessibility_screen_magnification_title"
settings:searchable="false">
<Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
android:key="screen_magnification_gestures_preference_screen"
android:title="@string/accessibility_screen_magnification_gestures_title"
settings:searchable="false"
settings:controller="com.android.settings.accessibility.MagnificationGesturesPreferenceController"/>
<Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
android:key="screen_magnification_navbar_preference_screen"
android:title="@string/accessibility_screen_magnification_navbar_title"
settings:searchable="false"
settings:controller="com.android.settings.accessibility.MagnificationNavbarPreferenceController"/>
</PreferenceScreen>

View File

@@ -62,7 +62,7 @@
settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/> settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>
<Preference <Preference
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment" android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragment"
android:key="magnification_preference_screen" android:key="magnification_preference_screen"
android:icon="@drawable/ic_accessibility_magnification" android:icon="@drawable/ic_accessibility_magnification"
android:persistent="false" android:persistent="false"

View File

@@ -104,10 +104,7 @@ public class AccessibilityDetailsSettingsFragment extends InstrumentedFragment {
@Nullable ComponentName componentName) { @Nullable ComponentName componentName) {
if (MAGNIFICATION_COMPONENT_NAME.equals(componentName)) { if (MAGNIFICATION_COMPONENT_NAME.equals(componentName)) {
final String destination = ToggleScreenMagnificationPreferenceFragment.class.getName(); final String destination = ToggleScreenMagnificationPreferenceFragment.class.getName();
final Bundle arguments = new Bundle(); return new LaunchFragmentArguments(destination, /* arguments= */ null);
MagnificationGesturesPreferenceController.populateMagnificationGesturesPreferenceExtras(
arguments, getContext());
return new LaunchFragmentArguments(destination, arguments);
} }
if (ACCESSIBILITY_BUTTON_COMPONENT_NAME.equals(componentName)) { 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_PREFERENCE_KEY = "preference_key";
static final String EXTRA_CHECKED = "checked"; static final String EXTRA_CHECKED = "checked";
static final String EXTRA_TITLE = "title"; 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_RESOLVE_INFO = "resolve_info";
static final String EXTRA_SUMMARY = "summary"; static final String EXTRA_SUMMARY = "summary";
static final String EXTRA_INTRO = "intro"; 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_COMPONENT_NAME = "component_name";
static final String EXTRA_SETTINGS_COMPONENT_NAME = "settings_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_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_LAUNCHED_FROM_SUW = "from_suw";
static final String EXTRA_ANIMATED_IMAGE_RES = "animated_image_res"; static final String EXTRA_ANIMATED_IMAGE_RES = "animated_image_res";
static final String EXTRA_HTML_DESCRIPTION = "html_description"; 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.accessibilityservice.AccessibilityServiceInfo;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ServiceInfo; import android.content.pm.ServiceInfo;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@@ -129,7 +128,6 @@ public class AccessibilitySettingsForSetupWizard extends DashboardFragment
SCREEN_READER_PACKAGE_NAME, SCREEN_READER_SERVICE_NAME); SCREEN_READER_PACKAGE_NAME, SCREEN_READER_SERVICE_NAME);
updateAccessibilityServicePreference(mSelectToSpeakPreference, updateAccessibilityServicePreference(mSelectToSpeakPreference,
SELECT_TO_SPEAK_PACKAGE_NAME, SELECT_TO_SPEAK_SERVICE_NAME); SELECT_TO_SPEAK_PACKAGE_NAME, SELECT_TO_SPEAK_SERVICE_NAME);
configureMagnificationPreferenceIfNeeded(mDisplayMagnificationPreference);
} }
@Override @Override
@@ -220,13 +218,4 @@ public class AccessibilitySettingsForSetupWizard extends DashboardFragment
final String htmlDescription = info.loadHtmlDescription(getPackageManager()); final String htmlDescription = info.loadHtmlDescription(getPackageManager());
extras.putString(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, htmlDescription); 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; package com.android.settings.accessibility;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
public class MagnificationPreferenceController extends BasePreferenceController { public class MagnificationPreferenceController extends BasePreferenceController {
private Preference mPreference;
public MagnificationPreferenceController(Context context, String preferenceKey) { public MagnificationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }
@@ -41,18 +35,4 @@ public class MagnificationPreferenceController extends BasePreferenceController
public CharSequence getSummary() { public CharSequence getSummary() {
return ToggleScreenMagnificationPreferenceFragment.getServiceSummary(mContext); 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) { protected void onProcessArguments(Bundle arguments) {
Context context = getContext(); 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)) { if (!arguments.containsKey(AccessibilitySettings.EXTRA_PREFERENCE_KEY)) {
arguments.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY, arguments.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
@@ -531,7 +527,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
preferenceKey)) { preferenceKey)) {
showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL); showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
} }
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled); Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? ON : OFF);
} }
@Override @Override

View File

@@ -1,138 +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 static com.android.settings.accessibility.MagnificationPreferenceFragment.OFF;
import static com.android.settings.accessibility.MagnificationPreferenceFragment.ON;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class MagnificationGesturesPreferenceControllerTest {
private Context mContext;
private MagnificationGesturesPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mController = new MagnificationGesturesPreferenceController(mContext, "pref_key");
mPreference = new Preference(mContext);
mController.updateState(mPreference);
}
@Test
public void isAlwaysAvailable() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void updateState_shouldRefreshSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_on));
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_off));
}
@Test
public void updateState_shouldRefreshSummarySuw() {
mController.setIsFromSUW(true);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.
accessibility_screen_magnification_short_summary));
}
@Test
public void isChecked_enabled() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_disabled() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void setChecked_enabled() {
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1))
.isEqualTo(ON);
}
@Test
public void setChecked_disabled() {
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1))
.isEqualTo(OFF);
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final MagnificationGesturesPreferenceController controller =
new MagnificationGesturesPreferenceController(mContext,
"screen_magnification_gestures_preference_screen");
assertThat(controller.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final MagnificationGesturesPreferenceController controller =
new MagnificationGesturesPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
@Test
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
}

View File

@@ -16,9 +16,9 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import static com.android.settings.accessibility.MagnificationCapabilities.MagnificationMode; import static com.android.settings.accessibility.MagnificationCapabilities.MagnificationMode;
import static com.android.settings.accessibility.MagnificationModePreferenceController.MagnificationModeInfo; import static com.android.settings.accessibility.MagnificationModePreferenceController.MagnificationModeInfo;
import static com.android.settings.accessibility.MagnificationPreferenceFragment.ON;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;

View File

@@ -1,182 +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 static com.android.settings.accessibility.MagnificationPreferenceFragment.OFF;
import static com.android.settings.accessibility.MagnificationPreferenceFragment.ON;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.R;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.Resetter;
@RunWith(RobolectricTestRunner.class)
public class MagnificationNavbarPreferenceControllerTest {
private Context mContext;
private MagnificationNavbarPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mController = new MagnificationNavbarPreferenceController(mContext, "test_key");
mPreference = new Preference(mContext);
mController.updateState(mPreference);
}
@After
public void tearDown() {
ShadowMagnificationPreferenceFragment.reset();
}
@Test
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
public void isAvailable_unsupported_shouldNotBeAvailable() {
ShadowMagnificationPreferenceFragment.setApplicable(false);
assertThat(mController.getAvailabilityStatus())
.isNotEqualTo(AVAILABLE);
}
@Test
@Config(shadows = ShadowMagnificationPreferenceFragment.class)
public void isAvailable_supported_shouldBeAvailable() {
ShadowMagnificationPreferenceFragment.setApplicable(true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(AVAILABLE);
}
@Test
public void updateState_shouldRefreshSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, ON);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_on));
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, OFF);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getText(R.string.accessibility_feature_state_off));
}
@Test
public void updateState_shouldRefreshSummarySuw() {
mController.setIsFromSUW(true);
mController.updateState(mPreference);
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getString(R.string.
accessibility_screen_magnification_navbar_short_summary));
}
@Test
public void isChecked_enabled() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_disabled() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, OFF);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void setChecked_enabled() {
mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, -1))
.isEqualTo(ON);
}
@Test
public void setChecked_disabled() {
mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED, -1))
.isEqualTo(OFF);
}
@Implements(MagnificationPreferenceFragment.class)
public static class ShadowMagnificationPreferenceFragment {
private static boolean sIsApplicable;
@Resetter
static void reset() {
sIsApplicable = false;
}
@Implementation
protected static boolean isApplicable(Resources res) {
return sIsApplicable;
}
static void setApplicable(boolean applicable) {
sIsApplicable = applicable;
}
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final MagnificationNavbarPreferenceController controller =
new MagnificationNavbarPreferenceController(mContext,
"screen_magnification_navbar_preference_screen");
assertThat(controller.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final MagnificationNavbarPreferenceController controller =
new MagnificationNavbarPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
@Test
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright (C) 2021 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 static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.DialogCreatable;
import com.android.settings.R;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.List;
/** Tests for {@link MagnificationSettingsFragment} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowDashboardFragment.class)
public class MagnificationSettingsFragmentTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
private MagnificationSettingsFragment mFragment;
private PreferenceScreen mScreen;
@Before
public void setup() {
mContext.setTheme(R.style.Theme_AppCompat);
mFragment = spy(new MagnificationSettingsFragment());
mScreen = new PreferenceScreen(mContext, null);
doReturn(mContext).when(mFragment).getContext();
doReturn(mScreen).when(mFragment).getPreferenceScreen();
doReturn(mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS)).when(
mFragment).getChildFragmentManager();
}
@Test
public void showPreferenceOnTheScreen_setDialogHelper() {
showPreferenceOnTheScreen(null);
verify(mFragment).setDialogDelegate(any(MagnificationModePreferenceController.class));
}
@Test
public void onCreateDialog_setDialogDelegate_invokeDialogDelegate() {
final DialogCreatable dialogDelegate = mock(DialogCreatable.class, RETURNS_DEEP_STUBS);
when(dialogDelegate.getDialogMetricsCategory(anyInt())).thenReturn(1);
mFragment.setDialogDelegate(dialogDelegate);
mFragment.onCreateDialog(1);
mFragment.getDialogMetricsCategory(1);
verify(dialogDelegate).onCreateDialog(1);
verify(dialogDelegate).getDialogMetricsCategory(1);
}
@Test
public void getMetricsCategory_returnsCorrectCategory() {
assertThat(mFragment.getMetricsCategory()).isEqualTo(
SettingsEnums.ACCESSIBILITY_MAGNIFICATION_SETTINGS);
}
@Test
public void getPreferenceScreenResId_returnsCorrectXml() {
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
R.xml.accessibility_magnification_service_settings);
}
@Test
public void getLogTag_returnsCorrectTag() {
assertThat(mFragment.getLogTag()).isEqualTo("MagnificationSettingsFragment");
}
@Test
public void getNonIndexableKeys_existInXmlLayout() {
final List<String> niks =
ShortcutsSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(mContext);
final List<String> keys =
XmlTestUtils.getKeysFromPreferenceXml(mContext,
R.xml.accessibility_magnification_service_settings);
assertThat(keys).containsAtLeastElementsIn(niks);
}
private void showPreferenceOnTheScreen(Bundle savedInstanceState) {
mFragment.onAttach(mContext);
mFragment.onCreate(savedInstanceState);
mFragment.onResume();
}
}

View File

@@ -71,7 +71,7 @@ public class VideoPreferenceTest {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mAnimationController = spy( mAnimationController = spy(
new MediaAnimationController(mContext, R.raw.accessibility_screen_magnification)); new MediaAnimationController(mContext, R.raw.sample_video));
mVideoPreference = new VideoPreference(mContext, null /* attrs */); mVideoPreference = new VideoPreference(mContext, null /* attrs */);
mVideoPreference.mAnimationController = mAnimationController; mVideoPreference.mAnimationController = mAnimationController;
when(mAnimationController.getVideoWidth()).thenReturn(VIDEO_WIDTH); when(mAnimationController.getVideoWidth()).thenReturn(VIDEO_WIDTH);