Merge "Logging for the feature "Text and reading options" in Android T." into tm-dev am: 27aa5f9d94

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/17886953

Change-Id: I900480866ed1fb85fb7629223f37538c46ff11b6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
PETER LIANG
2022-04-28 07:53:30 +00:00
committed by Automerger Merge Worker
14 changed files with 411 additions and 9 deletions

View File

@@ -41,7 +41,8 @@
android:icon="@drawable/ic_adaptive_font_download" android:icon="@drawable/ic_adaptive_font_download"
android:key="text_reading_options" android:key="text_reading_options"
android:persistent="false" android:persistent="false"
android:title="@string/accessibility_text_reading_options_title" /> android:title="@string/accessibility_text_reading_options_title"
settings:controller="com.android.settings.accessibility.TextReadingFragmentForA11ySettingsController"/>
<Preference <Preference
android:fragment="com.android.settings.accessibility.ColorAndMotionFragment" android:fragment="com.android.settings.accessibility.ColorAndMotionFragment"

View File

@@ -26,7 +26,8 @@
android:key="text_reading_options" android:key="text_reading_options"
android:persistent="false" android:persistent="false"
android:title="@string/accessibility_text_reading_options_title" android:title="@string/accessibility_text_reading_options_title"
settings:keywords="text_reading_options" /> settings:keywords="text_reading_options"
settings:controller="com.android.settings.accessibility.TextReadingFragmentForSuwController"/>
<Preference <Preference
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard" android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"

View File

@@ -72,7 +72,8 @@
android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment" android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment"
android:key="text_reading_options" android:key="text_reading_options"
android:persistent="false" android:persistent="false"
android:title="@string/accessibility_text_reading_options_title" /> android:title="@string/accessibility_text_reading_options_title"
settings:controller="com.android.settings.accessibility.TextReadingFragmentForDisplaySettingsController"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@@ -16,6 +16,16 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.BOLD_TEXT_KEY;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.DISPLAY_SIZE_KEY;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_ANYTHING_ELSE;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.FONT_SIZE_KEY;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.HIGH_TEXT_CONTRAST_KEY;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.RESET_KEY;
import android.content.ComponentName; import android.content.ComponentName;
import com.android.settings.core.instrumentation.SettingsStatsLog; import com.android.settings.core.instrumentation.SettingsStatsLog;
@@ -58,4 +68,48 @@ public final class AccessibilityStatsLogUtils {
.ACCESSIBILITY_PRIVACY_WARNING_STATUS_SERVICE_DISABLED, .ACCESSIBILITY_PRIVACY_WARNING_STATUS_SERVICE_DISABLED,
durationMills); durationMills);
} }
/**
* Converts to the key name for logging.
*
* @param prefKey the preference key
* @return the int value which maps to the key name
*/
static int convertToItemKeyName(String prefKey) {
switch (prefKey) {
case FONT_SIZE_KEY:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_FONT_SIZE;
case DISPLAY_SIZE_KEY:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_DISPLAY_SIZE;
case BOLD_TEXT_KEY:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_BOLD_TEXT;
case HIGH_TEXT_CONTRAST_KEY:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_HIGH_CONTRAST_TEXT;
case RESET_KEY:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_RESET;
default:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__NAME__TEXT_READING_UNKNOWN_ITEM;
}
}
/**
* Converts to the entry point for logging.
*
* @param entryPoint the entry point
* @return the int value which maps to the entry point
*/
static int convertToEntryPoint(int entryPoint) {
switch (entryPoint) {
case SUW_VISION_SETTINGS:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_VISION_SETTINGS;
case SUW_ANYTHING_ELSE:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_SUW_ANYTHING_ELSE;
case DISPLAY_SETTINGS:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_DISPLAY_SETTINGS;
case ACCESSIBILITY_SETTINGS:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_ACCESSIBILITY_SETTINGS;
default:
return SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED__ENTRY_POINT__TEXT_READING_UNKNOWN_ENTRY;
}
}
} }

View File

@@ -21,7 +21,9 @@ import android.graphics.fonts.FontStyle;
import android.provider.Settings; import android.provider.Settings;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.TogglePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
/** PreferenceController for displaying all text in bold. */ /** PreferenceController for displaying all text in bold. */
public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements
@@ -29,6 +31,9 @@ public class FontWeightAdjustmentPreferenceController extends TogglePreferenceCo
static final int BOLD_TEXT_ADJUSTMENT = static final int BOLD_TEXT_ADJUSTMENT =
FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL; FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
@EntryPoint
private int mEntryPoint;
public FontWeightAdjustmentPreferenceController(Context context, String preferenceKey) { public FontWeightAdjustmentPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }
@@ -46,6 +51,12 @@ public class FontWeightAdjustmentPreferenceController extends TogglePreferenceCo
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
isChecked ? 1 : 0,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
return Settings.Secure.putInt(mContext.getContentResolver(), return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, (isChecked ? BOLD_TEXT_ADJUSTMENT : 0)); Settings.Secure.FONT_WEIGHT_ADJUSTMENT, (isChecked ? BOLD_TEXT_ADJUSTMENT : 0));
} }
@@ -59,4 +70,13 @@ public class FontWeightAdjustmentPreferenceController extends TogglePreferenceCo
public void resetState() { public void resetState() {
setChecked(false); setChecked(false);
} }
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
} }

View File

@@ -23,7 +23,9 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.TogglePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
/** /**
* PreferenceController for displaying all text in high contrast style. * PreferenceController for displaying all text in high contrast style.
@@ -32,6 +34,9 @@ public class HighTextContrastPreferenceController extends TogglePreferenceContro
TextReadingResetController.ResetStateListener { TextReadingResetController.ResetStateListener {
private SwitchPreference mSwitchPreference; private SwitchPreference mSwitchPreference;
@EntryPoint
private int mEntryPoint;
public HighTextContrastPreferenceController(Context context, String preferenceKey) { public HighTextContrastPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }
@@ -49,6 +54,12 @@ public class HighTextContrastPreferenceController extends TogglePreferenceContro
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
isChecked ? 1 : 0,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
return Settings.Secure.putInt(mContext.getContentResolver(), return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0)); Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0));
} }
@@ -69,4 +80,13 @@ public class HighTextContrastPreferenceController extends TogglePreferenceContro
setChecked(false); setChecked(false);
updateState(mSwitchPreference); updateState(mSwitchPreference);
} }
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
} }

View File

@@ -22,7 +22,9 @@ import android.widget.SeekBar;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settings.widget.LabeledSeekBarPreference; import com.android.settings.widget.LabeledSeekBarPreference;
/** /**
@@ -36,6 +38,9 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
private ProgressInteractionListener mInteractionListener; private ProgressInteractionListener mInteractionListener;
private LabeledSeekBarPreference mSeekBarPreference; private LabeledSeekBarPreference mSeekBarPreference;
@EntryPoint
private int mEntryPoint;
private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener = private final SeekBar.OnSeekBarChangeListener mSeekBarChangeListener =
new SeekBar.OnSeekBarChangeListener() { new SeekBar.OnSeekBarChangeListener() {
@Override @Override
@@ -45,6 +50,12 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
if (!mSeekByTouch && mInteractionListener != null) { if (!mSeekByTouch && mInteractionListener != null) {
mInteractionListener.onProgressChanged(); mInteractionListener.onProgressChanged();
} }
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
progress,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
} }
@Override @Override
@@ -96,6 +107,15 @@ class PreviewSizeSeekBarController extends BasePreferenceController implements
mSeekBarPreference.setProgress(defaultProgress); mSeekBarPreference.setProgress(defaultProgress);
} }
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
/** /**
* Interface for callbacks when users interact with the seek bar. * Interface for callbacks when users interact with the seek bar.
*/ */

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 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.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
import android.content.Context;
import android.os.Bundle;
import androidx.preference.Preference;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController;
/**
* The base controller for the fragment{@link TextReadingPreferenceFragment}.
*/
public class TextReadingFragmentBaseController extends BasePreferenceController {
@EntryPoint
private int mEntryPoint;
private TextReadingFragmentBaseController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
TextReadingFragmentBaseController(Context context, String preferenceKey,
@EntryPoint int entryPoint) {
this(context, preferenceKey);
mEntryPoint = entryPoint;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
final Bundle extras = preference.getExtras();
extras.putInt(EXTRA_LAUNCHED_FROM, mEntryPoint);
}
return super.handlePreferenceTreeClick(preference);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2022 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.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
import android.content.Context;
/**
* The controller for the {@link TextReadingPreferenceFragment} from the accessibility settings.
*/
public class TextReadingFragmentForA11ySettingsController extends
TextReadingFragmentBaseController {
public TextReadingFragmentForA11ySettingsController(Context context, String preferenceKey) {
// Pass the fixed entry point to the parent controller for logging.
super(context, preferenceKey, ACCESSIBILITY_SETTINGS);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2022 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.TextReadingPreferenceFragment.EntryPoint.DISPLAY_SETTINGS;
import android.content.Context;
/**
* The controller for the {@link TextReadingPreferenceFragment} from the display settings.
*/
public class TextReadingFragmentForDisplaySettingsController extends
TextReadingFragmentBaseController {
public TextReadingFragmentForDisplaySettingsController(Context context, String preferenceKey) {
// Pass the fixed entry point to the parent controller for logging.
super(context, preferenceKey, DISPLAY_SETTINGS);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2022 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.TextReadingPreferenceFragment.EntryPoint.SUW_VISION_SETTINGS;
import android.content.Context;
/**
* The controller for the {@link TextReadingPreferenceFragment} during the SetupWizard.
*/
public class TextReadingFragmentForSuwController extends TextReadingFragmentBaseController {
public TextReadingFragmentForSuwController(Context context, String preferenceKey) {
// Pass the fixed entry point to the parent controller for logging.
super(context, preferenceKey, SUW_VISION_SETTINGS);
}
}

View File

@@ -22,9 +22,11 @@ import android.app.Dialog;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.IntDef;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import com.android.settings.R; import com.android.settings.R;
@@ -36,8 +38,11 @@ import com.android.settingslib.search.SearchIndexable;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -46,15 +51,40 @@ import java.util.stream.Collectors;
*/ */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class TextReadingPreferenceFragment extends DashboardFragment { public class TextReadingPreferenceFragment extends DashboardFragment {
public static final String EXTRA_LAUNCHED_FROM = "launched_from";
private static final String TAG = "TextReadingPreferenceFragment"; private static final String TAG = "TextReadingPreferenceFragment";
private static final String FONT_SIZE_KEY = "font_size"; private static final String CATEGORY_FOR_ANYTHING_ELSE =
private static final String DISPLAY_SIZE_KEY = "display_size"; "com.android.settings.suggested.category.DISPLAY_SETTINGS";
static final String FONT_SIZE_KEY = "font_size";
static final String DISPLAY_SIZE_KEY = "display_size";
static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
static final String HIGH_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
static final String RESET_KEY = "reset";
private static final String PREVIEW_KEY = "preview"; private static final String PREVIEW_KEY = "preview";
private static final String RESET_KEY = "reset";
private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
private static final String NEED_RESET_SETTINGS = "need_reset_settings"; private static final String NEED_RESET_SETTINGS = "need_reset_settings";
private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController; private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
private int mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
/**
* The entry point which launches the {@link TextReadingPreferenceFragment}.
*
* <p>This should only be used for logging.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({
EntryPoint.UNKNOWN_ENTRY,
EntryPoint.SUW_VISION_SETTINGS,
EntryPoint.SUW_ANYTHING_ELSE,
EntryPoint.DISPLAY_SETTINGS,
EntryPoint.ACCESSIBILITY_SETTINGS,
})
@interface EntryPoint {
int UNKNOWN_ENTRY = 0;
int SUW_VISION_SETTINGS = 1;
int SUW_ANYTHING_ELSE = 2;
int DISPLAY_SETTINGS = 3;
int ACCESSIBILITY_SETTINGS = 4;
}
@VisibleForTesting @VisibleForTesting
List<ResetStateListener> mResetStateListeners; List<ResetStateListener> mResetStateListeners;
@@ -91,6 +121,8 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
@Override @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
updateEntryPoint();
final List<AbstractPreferenceController> controllers = new ArrayList<>(); final List<AbstractPreferenceController> controllers = new ArrayList<>();
final FontSizeData fontSizeData = new FontSizeData(context); final FontSizeData fontSizeData = new FontSizeData(context);
final DisplaySizeData displaySizeData = createDisplaySizeData(context); final DisplaySizeData displaySizeData = createDisplaySizeData(context);
@@ -102,24 +134,29 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController( final PreviewSizeSeekBarController fontSizeController = new PreviewSizeSeekBarController(
context, FONT_SIZE_KEY, fontSizeData); context, FONT_SIZE_KEY, fontSizeData);
fontSizeController.setInteractionListener(previewController); fontSizeController.setInteractionListener(previewController);
fontSizeController.setEntryPoint(mEntryPoint);
controllers.add(fontSizeController); controllers.add(fontSizeController);
final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController( final PreviewSizeSeekBarController displaySizeController = new PreviewSizeSeekBarController(
context, DISPLAY_SIZE_KEY, displaySizeData); context, DISPLAY_SIZE_KEY, displaySizeData);
displaySizeController.setInteractionListener(previewController); displaySizeController.setInteractionListener(previewController);
displaySizeController.setEntryPoint(mEntryPoint);
controllers.add(displaySizeController); controllers.add(displaySizeController);
mFontWeightAdjustmentController = mFontWeightAdjustmentController =
new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY); new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
mFontWeightAdjustmentController.setEntryPoint(mEntryPoint);
controllers.add(mFontWeightAdjustmentController); controllers.add(mFontWeightAdjustmentController);
final HighTextContrastPreferenceController highTextContrastController = final HighTextContrastPreferenceController highTextContrastController =
new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY); new HighTextContrastPreferenceController(context, HIGH_TEXT_CONTRAST_KEY);
highTextContrastController.setEntryPoint(mEntryPoint);
controllers.add(highTextContrastController); controllers.add(highTextContrastController);
final TextReadingResetController resetController = final TextReadingResetController resetController =
new TextReadingResetController(context, RESET_KEY, new TextReadingResetController(context, RESET_KEY,
v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS)); v -> showDialog(DialogEnums.DIALOG_RESET_SETTINGS));
resetController.setEntryPoint(mEntryPoint);
controllers.add(resetController); controllers.add(resetController);
return controllers; return controllers;
@@ -162,6 +199,24 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
return new DisplaySizeData(context); return new DisplaySizeData(context);
} }
private void updateEntryPoint() {
final Bundle bundle = getArguments();
if (bundle != null && bundle.containsKey(EXTRA_LAUNCHED_FROM)) {
mEntryPoint = bundle.getInt(EXTRA_LAUNCHED_FROM, EntryPoint.UNKNOWN_ENTRY);
return;
}
final Intent intent = getIntent();
if (intent == null) {
mEntryPoint = EntryPoint.UNKNOWN_ENTRY;
return;
}
final Set<String> categories = intent.getCategories();
mEntryPoint = categories != null && categories.contains(CATEGORY_FOR_ANYTHING_ELSE)
? EntryPoint.SUW_ANYTHING_ELSE : EntryPoint.UNKNOWN_ENTRY;
}
private void onPositiveButtonClicked(DialogInterface dialog, int which) { private void onPositiveButtonClicked(DialogInterface dialog, int which) {
// To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment // To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
// was interrupted by unexpectedly recreating the activity. // was interrupted by unexpectedly recreating the activity.

View File

@@ -23,7 +23,9 @@ import androidx.annotation.Nullable;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.instrumentation.SettingsStatsLog;
import com.android.settingslib.widget.LayoutPreference; import com.android.settingslib.widget.LayoutPreference;
/** /**
@@ -32,6 +34,9 @@ import com.android.settingslib.widget.LayoutPreference;
class TextReadingResetController extends BasePreferenceController { class TextReadingResetController extends BasePreferenceController {
private final View.OnClickListener mOnResetClickListener; private final View.OnClickListener mOnResetClickListener;
@EntryPoint
private int mEntryPoint;
TextReadingResetController(Context context, String preferenceKey, TextReadingResetController(Context context, String preferenceKey,
@Nullable View.OnClickListener listener) { @Nullable View.OnClickListener listener) {
super(context, preferenceKey); super(context, preferenceKey);
@@ -52,10 +57,25 @@ class TextReadingResetController extends BasePreferenceController {
view.setOnClickListener(v -> { view.setOnClickListener(v -> {
if (mOnResetClickListener != null) { if (mOnResetClickListener != null) {
mOnResetClickListener.onClick(v); mOnResetClickListener.onClick(v);
SettingsStatsLog.write(
SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
/* reset */ -1,
AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
} }
}); });
} }
/**
* The entry point is used for logging.
*
* @param entryPoint from which settings page
*/
void setEntryPoint(@EntryPoint int entryPoint) {
mEntryPoint = entryPoint;
}
/** /**
* Interface for resetting to default state. * Interface for resetting to default state.
*/ */

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2022 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.TextReadingPreferenceFragment.EXTRA_LAUNCHED_FROM;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.ACCESSIBILITY_SETTINGS;
import static com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint.UNKNOWN_ENTRY;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
/**
* Tests for {@link TextReadingFragmentBaseController}.
*/
@RunWith(RobolectricTestRunner.class)
public class TextReadingFragmentBaseControllerTest {
private static final String FRAGMENT_PREF_KEY = "FRAGMENT_PREF_KEY";
private final Context mContext = ApplicationProvider.getApplicationContext();
@Test
public void handlePreferenceClick_getExtraWithA11ySettingsEntryPoint() {
final Preference a11ySettingsPreference = new Preference(mContext);
a11ySettingsPreference.setKey(FRAGMENT_PREF_KEY);
final TextReadingFragmentBaseController mA11ySettingsFragmentController =
new TextReadingFragmentBaseController(mContext, FRAGMENT_PREF_KEY,
ACCESSIBILITY_SETTINGS);
mA11ySettingsFragmentController.handlePreferenceTreeClick(a11ySettingsPreference);
assertThat(a11ySettingsPreference.getExtras().getInt(EXTRA_LAUNCHED_FROM,
UNKNOWN_ENTRY)).isEqualTo(ACCESSIBILITY_SETTINGS);
}
}