Snap for 8098834 from a67bb94388 to tm-release

Change-Id: I41fd12a0bc81dfad07a66a23d53fcff844ddabc0
This commit is contained in:
Android Build Coastguard Worker
2022-01-21 02:09:50 +00:00
34 changed files with 844 additions and 204 deletions

View File

@@ -13077,6 +13077,9 @@
<!-- Title for the button to initiate a heap dump for the system server. [CHAR LIMIT=NONE] -->
<string name="capture_system_heap_dump_title">Capture system heap dump</string>
<!-- Title for the button to reboot with MTE enabled. [CHAR LIMIT=NONE] -->
<string name="reboot_with_mte_title">Reboot with MTE</string>
<string name="reboot_with_mte_message">This wil reboot and allow to experiment with Memory Tagging Extensions (MTE). This may negatively impact system performance and stability. Will be reset on next subsequent reboot.</string>
<!-- Toast that is shown when the user initiates capturing a heap dump for the system server. [CHAR LIMIT=NONE] -->
<string name="capturing_system_heap_dump_message">Capturing system heap dump</string>
<!-- Toast that is shown if there's an error capturing the user initiated heap dump. [CHAR LIMIT=NONE] -->

View File

@@ -44,6 +44,10 @@
android:key="system_server_heap_dump"
android:title="@string/capture_system_heap_dump_title" />
<Preference
android:key="reboot_with_mte"
android:title="@string/reboot_with_mte_title" />
<Preference
android:key="local_backup_password"
android:title="@string/local_backup_password_title"

View File

@@ -30,7 +30,6 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
@@ -147,7 +146,7 @@ public class AccessibilitySettings extends DashboardFragment {
};
@VisibleForTesting
final SettingsContentObserver mSettingsContentObserver;
final AccessibilitySettingsContentObserver mSettingsContentObserver;
private final Map<String, PreferenceCategory> mCategoryToPrefCategoryMap =
new ArrayMap<>();
@@ -171,12 +170,9 @@ public class AccessibilitySettings extends DashboardFragment {
// Observe changes from accessibility selection menu
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
mSettingsContentObserver = new SettingsContentObserver(mHandler, shortcutFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
onContentChanged();
}
};
mSettingsContentObserver = new AccessibilitySettingsContentObserver(mHandler);
mSettingsContentObserver.registerKeysToObserverCallback(shortcutFeatureKeys,
key -> onContentChanged());
}
@Override

View File

@@ -0,0 +1,132 @@
/*
* 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 android.content.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class AccessibilitySettingsContentObserver extends ContentObserver {
private static final String TAG = "AccessibilitySettingsContentObserver";
public interface ContentObserverCallback {
void onChange(String key);
}
// Key: Preference key's uri, Value: Preference key
private final Map<Uri, String> mUriToKey = new HashMap<>(2);
// Key: Collection of preference keys, Value: onChange callback for keys
private final Map<List<String>, ContentObserverCallback> mUrisToCallback = new HashMap<>();
AccessibilitySettingsContentObserver(Handler handler) {
super(handler);
// default key to be observed
addDefaultKeysToMap();
}
public void register(ContentResolver contentResolver) {
for (Uri uri : mUriToKey.keySet()) {
contentResolver.registerContentObserver(uri, false, this);
}
}
public void unregister(ContentResolver contentResolver) {
contentResolver.unregisterContentObserver(this);
}
private void addDefaultKeysToMap() {
addKeyToMap(Settings.Secure.ACCESSIBILITY_ENABLED);
addKeyToMap(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
}
private boolean isDefaultKey(String key) {
return Settings.Secure.ACCESSIBILITY_ENABLED.equals(key)
|| Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES.equals(key);
}
private void addKeyToMap(String key) {
mUriToKey.put(Settings.Secure.getUriFor(key), key);
}
/**
* {@link ContentObserverCallback} is added to {@link ContentObserver} to handle the
* onChange event triggered by the key collection of {@code keysToObserve} and the default
* keys.
*
* Note: The following key are default to be observed.
* {@link Settings.Secure.ACCESSIBILITY_ENABLED}
* {@link Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES}
*
* @param keysToObserve A collection of keys which are going to be observed.
* @param observerCallback A callback which is used to handle the onChange event triggered
* by the key collection of {@code keysToObserve}.
*/
public void registerKeysToObserverCallback(List<String> keysToObserve,
ContentObserverCallback observerCallback) {
for (String key: keysToObserve) {
addKeyToMap(key);
}
mUrisToCallback.put(keysToObserve, observerCallback);
}
/**
* {@link ContentObserverCallback} is added to {@link ContentObserver} to handle the
* onChange event triggered by the default keys.
*
* Note: The following key are default to be observed.
* {@link Settings.Secure.ACCESSIBILITY_ENABLED}
* {@link Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES}
*
* @param observerCallback A callback which is used to handle the onChange event triggered
* * by the key collection of {@code keysToObserve}.
*/
public void registerObserverCallback(ContentObserverCallback observerCallback) {
mUrisToCallback.put(Collections.emptyList(), observerCallback);
}
@Override
public final void onChange(boolean selfChange, Uri uri) {
final String key = mUriToKey.get(uri);
if (key == null) {
Log.w(TAG, "AccessibilitySettingsContentObserver can not find the key for "
+ "uri: " + uri);
return;
}
for (List<String> keys : mUrisToCallback.keySet()) {
final boolean isDefaultKey = isDefaultKey(key);
if (isDefaultKey || keys.contains(key)) {
mUrisToCallback.get(keys).onChange(key);
}
}
}
}

View File

@@ -25,7 +25,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.icu.text.CaseMap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
@@ -64,7 +63,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
protected ShortcutPreference mShortcutPreference;
private AccessibilityManager.TouchExplorationStateChangeListener
mTouchExplorationStateChangeListener;
private SettingsContentObserver mSettingsContentObserver;
private AccessibilitySettingsContentObserver mSettingsContentObserver;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -98,13 +97,11 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
mSettingsContentObserver = new SettingsContentObserver(new Handler(), shortcutFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateShortcutPreferenceData();
updateShortcutPreference();
}
};
mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
mSettingsContentObserver.registerKeysToObserverCallback(shortcutFeatureKeys, key -> {
updateShortcutPreferenceData();
updateShortcutPreference();
});
}
@Override

View File

@@ -35,6 +35,8 @@ import com.android.settings.core.TogglePreferenceController;
public class MagnificationFollowTypingPreferenceController extends TogglePreferenceController
implements LifecycleObserver {
private static final String TAG =
MagnificationFollowTypingPreferenceController.class.getSimpleName();
static final String PREF_KEY = "magnification_follow_typing";
private SwitchPreference mFollowTypingPreference;
@@ -75,6 +77,14 @@ public class MagnificationFollowTypingPreferenceController extends TogglePrefere
// TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only.
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
void onResume() {
updateState();
}
/**
* Updates the state of preference components which has been displayed by
* {@link MagnificationFollowTypingPreferenceController#displayPreference}.
*/
void updateState() {
updateState(mFollowTypingPreference);
}
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright (C) 2013 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.ContentResolver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import java.util.ArrayList;
import java.util.List;
abstract class SettingsContentObserver extends ContentObserver {
private final List<String> mKeysToObserve = new ArrayList<>(2);
public SettingsContentObserver(Handler handler) {
super(handler);
mKeysToObserve.add(Settings.Secure.ACCESSIBILITY_ENABLED);
mKeysToObserve.add(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
}
public SettingsContentObserver(Handler handler, List<String> keysToObserve) {
this(handler);
mKeysToObserve.addAll(keysToObserve);
}
public void register(ContentResolver contentResolver) {
for (int i = 0; i < mKeysToObserve.size(); i++) {
contentResolver.registerContentObserver(
Settings.Secure.getUriFor(mKeysToObserve.get(i)), false, this);
}
}
public void unregister(ContentResolver contentResolver) {
contentResolver.unregisterContentObserver(this);
}
@Override
public abstract void onChange(boolean selfChange, Uri uri);
}

View File

@@ -35,7 +35,6 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
@@ -65,15 +64,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
private static final String EMPTY_STRING = "";
private final SettingsContentObserver mSettingsContentObserver =
new SettingsContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateSwitchBarToggleSwitch();
}
};
private Dialog mDialog;
private Dialog mWarningDialog;
private BroadcastReceiver mPackageRemovedReceiver;
private boolean mDisabledStateLogged = false;
private long mStartTimeMillsForLogging = 0;
@@ -108,6 +99,13 @@ public class ToggleAccessibilityServicePreferenceFragment extends
}
}
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
contentObserver.registerObserverCallback(key -> updateSwitchBarToggleSwitch());
}
@Override
public void onStart() {
super.onStart();
@@ -123,7 +121,11 @@ public class ToggleAccessibilityServicePreferenceFragment extends
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
super.onPause();
}
@Override
@@ -172,7 +174,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
if (info == null) {
return null;
}
mDialog = AccessibilityServiceWarning
mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromEnableToggleClicked,
this::onDialogButtonFromUninstallClicked);
@@ -183,7 +185,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
if (info == null) {
return null;
}
mDialog = AccessibilityServiceWarning
mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromShortcutToggleClicked,
this::onDialogButtonFromUninstallClicked);
@@ -194,7 +196,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
if (info == null) {
return null;
}
mDialog = AccessibilityServiceWarning
mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromShortcutClicked,
this::onDialogButtonFromUninstallClicked);
@@ -205,16 +207,16 @@ public class ToggleAccessibilityServicePreferenceFragment extends
if (info == null) {
return null;
}
mDialog = AccessibilityServiceWarning
mWarningDialog = AccessibilityServiceWarning
.createDisableDialog(getPrefContext(), info,
this::onDialogButtonFromDisableToggleClicked);
break;
}
default: {
mDialog = super.onCreateDialog(dialogId);
mWarningDialog = super.onCreateDialog(dialogId);
}
}
return mDialog;
return mWarningDialog;
}
@Override
@@ -402,7 +404,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
}
private void onDialogButtonFromUninstallClicked() {
mDialog.dismiss();
mWarningDialog.dismiss();
final Intent uninstallIntent = createUninstallPackageActivityIntent();
if (uninstallIntent == null) {
return;
@@ -436,12 +438,12 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mIsDialogShown.set(false);
showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
mDialog.dismiss();
mWarningDialog.dismiss();
}
private void onDenyButtonFromEnableToggleClicked() {
handleConfirmServiceEnabled(/* confirmed= */ false);
mDialog.dismiss();
mWarningDialog.dismiss();
}
void onDialogButtonFromShortcutToggleClicked(View view) {
@@ -465,7 +467,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mIsDialogShown.set(false);
showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
mDialog.dismiss();
mWarningDialog.dismiss();
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
}
@@ -473,7 +475,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
private void onDenyButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(false);
mDialog.dismiss();
mWarningDialog.dismiss();
}
void onDialogButtonFromShortcutClicked(View view) {
@@ -491,11 +493,11 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mIsDialogShown.set(false);
showPopupDialog(DialogEnums.EDIT_SHORTCUT);
mDialog.dismiss();
mWarningDialog.dismiss();
}
private void onDenyButtonFromShortcutClicked() {
mDialog.dismiss();
mWarningDialog.dismiss();
}
private boolean onPreferenceClick(boolean isChecked) {

View File

@@ -25,7 +25,6 @@ import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
@@ -41,8 +40,6 @@ import java.util.List;
public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED;
private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver;
@Override
public int getMetricsCategory() {
@@ -86,20 +83,22 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
.authority(getPrefContext().getPackageName())
.appendPath(String.valueOf(R.raw.accessibility_color_inversion_banner))
.build();
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateSwitchBarToggleSwitch();
}
};
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
}
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
private void updateFooterPreference() {
final String title = getPrefContext().getString(
R.string.accessibility_color_inversion_about_title);
@@ -114,12 +113,10 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}

View File

@@ -24,9 +24,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
@@ -53,8 +51,6 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
private static final String KEY_PREVIEW = "daltonizer_preview";
private static final String KEY_CATEGORY_MODE = "daltonizer_mode_category";
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver;
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
@@ -84,20 +80,22 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
mComponentName = DALTONIZER_COMPONENT_NAME;
mPackageName = getText(R.string.accessibility_display_daltonizer_preference_title);
mHtmlDescription = getText(R.string.accessibility_display_daltonizer_preference_subtitle);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateSwitchBarToggleSwitch();
}
};
final View view = super.onCreateView(inflater, container, savedInstanceState);
updateFooterPreference();
return view;
}
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(ENABLED);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
private void updateFooterPreference() {
final String title = getPrefContext()
.getString(R.string.accessibility_daltonizer_about_title);
@@ -123,8 +121,6 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
mSettingsContentObserver.register(getContentResolver());
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(this);
@@ -135,7 +131,6 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(null);

View File

@@ -99,7 +99,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected static final String KEY_ANIMATED_IMAGE = "animated_image";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
private SettingsContentObserver mSettingsContentObserver;
private AccessibilitySettingsContentObserver mSettingsContentObserver;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -143,17 +143,21 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
setPreferenceScreen(preferenceScreen);
}
final List<String> shortcutFeatureKeys = getFeatureSettingsKeys();
mSettingsContentObserver = new SettingsContentObserver(new Handler(), shortcutFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateShortcutPreferenceData();
updateShortcutPreference();
}
};
mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
registerKeysToObserverCallback(mSettingsContentObserver);
}
protected List<String> getFeatureSettingsKeys() {
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
final List<String> shortcutFeatureKeys = getShortcutFeatureSettingsKeys();
contentObserver.registerKeysToObserverCallback(shortcutFeatureKeys, key -> {
updateShortcutPreferenceData();
updateShortcutPreference();
});
}
protected List<String> getShortcutFeatureSettingsKeys() {
final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);

View File

@@ -22,7 +22,6 @@ import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
@@ -50,8 +49,6 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
private static final String KEY_INTENSITY = "rbc_intensity";
private static final String KEY_PERSIST = "rbc_persist";
private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver;
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
private ColorDisplayManager mColorDisplayManager;
@@ -67,20 +64,12 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
mComponentName = AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
mPackageName = getText(R.string.reduce_bright_colors_preference_title);
mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
mRbcIntensityPreferenceController =
new ReduceBrightColorsIntensityPreferenceController(getContext(), KEY_INTENSITY);
mRbcPersistencePreferenceController =
new ReduceBrightColorsPersistencePreferenceController(getContext(), KEY_PERSIST);
mRbcIntensityPreferenceController.displayPreference(getPreferenceScreen());
mRbcPersistencePreferenceController.displayPreference(getPreferenceScreen());
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateSwitchBarToggleSwitch();
}
};
mColorDisplayManager = getContext().getSystemService(ColorDisplayManager.class);
final View view = super.onCreateView(inflater, container, savedInstanceState);
// Parent sets the title when creating the view, so set it after calling super
@@ -90,6 +79,17 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
return view;
}
@Override
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
contentObserver.registerKeysToObserverCallback(enableServiceFeatureKeys,
key -> updateSwitchBarToggleSwitch());
}
private void updateGeneralCategoryOrder() {
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
final SeekBarPreference intensity = findPreference(KEY_INTENSITY);
@@ -117,12 +117,10 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}

View File

@@ -75,6 +75,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
new TextUtils.SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
private DialogCreatable mDialogDelegate;
private MagnificationFollowTypingPreferenceController mFollowTypingPreferenceController;
protected SwitchPreference mFollowingTypingSwitchPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -177,21 +180,20 @@ public class ToggleScreenMagnificationPreferenceFragment extends
getSettingsLifecycle().addObserver(magnificationModePreferenceController);
magnificationModePreferenceController.displayPreference(getPreferenceScreen());
final SwitchPreference followingTypingSwitchPreference =
mFollowingTypingSwitchPreference =
new SwitchPreference(getPrefContext());
followingTypingSwitchPreference.setTitle(
mFollowingTypingSwitchPreference.setTitle(
R.string.accessibility_screen_magnification_follow_typing_title);
followingTypingSwitchPreference.setSummary(
mFollowingTypingSwitchPreference.setSummary(
R.string.accessibility_screen_magnification_follow_typing_summary);
followingTypingSwitchPreference.setKey(
mFollowingTypingSwitchPreference.setKey(
MagnificationFollowTypingPreferenceController.PREF_KEY);
generalCategory.addPreference(followingTypingSwitchPreference);
generalCategory.addPreference(mFollowingTypingSwitchPreference);
final MagnificationFollowTypingPreferenceController followTypingPreferenceController =
new MagnificationFollowTypingPreferenceController(getContext(),
MagnificationFollowTypingPreferenceController.PREF_KEY);
getSettingsLifecycle().addObserver(followTypingPreferenceController);
followTypingPreferenceController.displayPreference(getPreferenceScreen());
mFollowTypingPreferenceController = new MagnificationFollowTypingPreferenceController(
getContext(), MagnificationFollowTypingPreferenceController.PREF_KEY);
getSettingsLifecycle().addObserver(mFollowTypingPreferenceController);
mFollowTypingPreferenceController.displayPreference(getPreferenceScreen());
}
@Override
@@ -293,8 +295,23 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
@Override
protected List<String> getFeatureSettingsKeys() {
final List<String> shortcutKeys = super.getFeatureSettingsKeys();
protected void registerKeysToObserverCallback(
AccessibilitySettingsContentObserver contentObserver) {
super.registerKeysToObserverCallback(contentObserver);
final List<String> followingTypingKeys = new ArrayList<>();
followingTypingKeys.add(Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED);
contentObserver.registerKeysToObserverCallback(followingTypingKeys,
key -> updateFollowTypingState());
}
private void updateFollowTypingState() {
mFollowTypingPreferenceController.updateState();
}
@Override
protected List<String> getShortcutFeatureSettingsKeys() {
final List<String> shortcutKeys = super.getShortcutFeatureSettingsKeys();
shortcutKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
return shortcutKeys;
}

View File

@@ -44,9 +44,17 @@ public class ToggleScreenMagnificationPreferenceFragmentForSetupWizard
final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
description, icon);
hidePreferenceSettingComponents();
}
// Hide the setting from the vision settings.
/**
* Hide the magnification preference settings in the SuW's vision settings.
*/
private void hidePreferenceSettingComponents() {
// Setting of magnification type
mSettingsPreference.setVisible(false);
// Setting of following typing
mFollowingTypingSwitchPreference.setVisible(false);
}
@Override

View File

@@ -237,18 +237,28 @@ public class AppLocaleDetails extends AppInfoBase implements RadioButtonPreferen
mSuggestedLocales.add(appLocale);
}
// 2nd locale in suggested languages group.
if (simLocale != null && !simLocale.equals(appLocale)) {
if (simLocale != null && !compareLocale(simLocale, appLocale)) {
mSuggestedLocales.add(simLocale);
}
// Other locales in suggested languages group.
for (int i = 0; i < currentSystemLocales.size(); i++) {
Locale locale = currentSystemLocales.get(i);
if (!locale.equals(appLocale) && !locale.equals(simLocale)) {
if (!compareLocale(locale, appLocale) && !compareLocale(locale, simLocale)) {
mSuggestedLocales.add(locale);
}
}
}
static boolean compareLocale(Locale source, Locale target) {
if (source == null && target == null) {
return true;
} else if (source != null && target != null) {
return LocaleList.matchesLanguageAndScript(source, target);
} else {
return false;
}
}
@VisibleForTesting
void handleSupportedLocales() {
//TODO Waiting for PackageManager api

View File

@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
import android.app.settings.SettingsEnums;
import android.content.Context;
import androidx.preference.PreferenceFragmentCompat;
@@ -70,7 +71,11 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
mActionButtons
.setButton2Text(R.string.bluetooth_device_context_disconnect)
.setButton2Icon(R.drawable.ic_settings_close)
.setButton2OnClickListener(view -> mCachedDevice.disconnect());
.setButton2OnClickListener(view -> {
mMetricsFeatureProvider.action(mContext,
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
mCachedDevice.disconnect();
});
mConnectButtonInitialized = true;
}
} else {
@@ -79,7 +84,11 @@ public class BluetoothDetailsButtonsController extends BluetoothDetailsControlle
.setButton2Text(R.string.bluetooth_device_context_connect)
.setButton2Icon(R.drawable.ic_add_24dp)
.setButton2OnClickListener(
view -> mCachedDevice.connect());
view -> {
mMetricsFeatureProvider.action(mContext,
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_CONNECT);
mCachedDevice.connect();
});
mConnectButtonInitialized = true;
}
}

View File

@@ -22,8 +22,10 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
@@ -40,6 +42,7 @@ public abstract class BluetoothDetailsController extends AbstractPreferenceContr
protected final Context mContext;
protected final PreferenceFragmentCompat mFragment;
protected final CachedBluetoothDevice mCachedDevice;
protected final MetricsFeatureProvider mMetricsFeatureProvider;
public BluetoothDetailsController(Context context, PreferenceFragmentCompat fragment,
CachedBluetoothDevice device, Lifecycle lifecycle) {
@@ -48,6 +51,7 @@ public abstract class BluetoothDetailsController extends AbstractPreferenceContr
mFragment = fragment;
mCachedDevice = device;
lifecycle.addObserver(this);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@Override

View File

@@ -15,6 +15,7 @@
*/
package com.android.settings.bluetooth;
import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
@@ -116,6 +117,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
if (device.isConnected()) {
return device.setActive();
}
mMetricsFeatureProvider.action(mPrefContext,
SettingsEnums.ACTION_SETTINGS_BLUETOOTH_CONNECT);
device.connect();
return true;
}

View File

@@ -477,6 +477,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new BugReportPreferenceController(context));
controllers.add(new BugReportHandlerPreferenceController(context));
controllers.add(new SystemServerHeapDumpPreferenceController(context));
controllers.add(new RebootWithMtePreferenceController(context, fragment));
controllers.add(new LocalBackupPasswordPreferenceController(context));
controllers.add(new StayAwakePreferenceController(context, lifecycle));
controllers.add(new HdcpCheckingPreferenceController(context));

View File

@@ -0,0 +1,75 @@
/*
* 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.development;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.SystemProperties;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class RebootWithMteDialog extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener {
public static final String TAG = "RebootWithMteDlg";
private Context mContext;
public RebootWithMteDialog(Context context) {
mContext = context;
}
public static void show(Context context, Fragment host) {
FragmentManager manager = host.getActivity().getSupportFragmentManager();
if (manager.findFragmentByTag(TAG) == null) {
RebootWithMteDialog dialog = new RebootWithMteDialog(context);
dialog.setTargetFragment(host, 0 /* requestCode */);
dialog.show(manager, TAG);
}
}
@Override
public int getMetricsCategory() {
return SettingsEnums.REBOOT_WITH_MTE;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.reboot_with_mte_title)
.setMessage(R.string.reboot_with_mte_message)
.setPositiveButton(android.R.string.ok, this /* onClickListener */)
.setNegativeButton(android.R.string.cancel, null /* onClickListener */)
.setIcon(android.R.drawable.ic_dialog_alert)
.create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
PowerManager pm = mContext.getSystemService(PowerManager.class);
SystemProperties.set("arm64.memtag.bootctl", "memtag-once");
pm.reboot(null);
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.development;
import android.content.Context;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class RebootWithMtePreferenceController extends DeveloperOptionsPreferenceController
implements PreferenceControllerMixin {
private static final String KEY_REBOOT_WITH_MTE = "reboot_with_mte";
private final DevelopmentSettingsDashboardFragment mFragment;
public RebootWithMtePreferenceController(
Context context, DevelopmentSettingsDashboardFragment fragment) {
super(context);
mFragment = fragment;
}
@Override
public boolean isAvailable() {
return android.os.SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false);
}
@Override
public String getPreferenceKey() {
return KEY_REBOOT_WITH_MTE;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (Utils.isMonkeyRunning()) {
return false;
}
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
RebootWithMteDialog.show(mContext, mFragment);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContentResolver;
import java.util.Collection;
import java.util.List;
/** Test for {@link AccessibilitySettingsContentObserver}. */
@RunWith(RobolectricTestRunner.class)
public class AccessibilitySettingsContentObserverTest {
private static final String SPECIFIC_KEY_A_1 = "SPECIFIC_KEY_A_1";
private static final String SPECIFIC_KEY_A_2 = "SPECIFIC_KEY_A_2";
private static final String SPECIFIC_KEY_B_1 = "SPECIFIC_KEY_B_1";
private final Context mContext = ApplicationProvider.getApplicationContext();
private final AccessibilitySettingsContentObserver mObserver =
new AccessibilitySettingsContentObserver(new Handler());
private final AccessibilitySettingsContentObserver.ContentObserverCallback mObserverCallbackA =
spy(new TestableContentObserverCallback());
private final AccessibilitySettingsContentObserver.ContentObserverCallback mObserverCallbackB =
spy(new TestableContentObserverCallback());
private final ContentResolver mContentResolver = mContext.getContentResolver();
@Test
public void register_shouldRegisterContentObserverForDefaultKeys() {
mObserver.register(mContentResolver);
ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
assertObserverToUri(shadowContentResolver,
Settings.Secure.ACCESSIBILITY_ENABLED, mObserver);
assertObserverToUri(shadowContentResolver,
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, mObserver);
}
@Test
public void unregister_shouldUnregisterContentObserver() {
mObserver.register(mContentResolver);
mObserver.unregister(mContentResolver);
ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
assertNotObserverToUri(shadowContentResolver, Settings.Secure.ACCESSIBILITY_ENABLED);
assertNotObserverToUri(shadowContentResolver,
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
}
@Test
public void register_addSpecificKeys_shouldRegisterContentObserverForSpecificAndDefaultKeys() {
mObserver.registerKeysToObserverCallback(List.of(SPECIFIC_KEY_A_1), mObserverCallbackA);
mObserver.register(mContentResolver);
ShadowContentResolver shadowContentResolver = Shadow.extract(mContentResolver);
assertObserverToUri(shadowContentResolver,
Settings.Secure.ACCESSIBILITY_ENABLED, mObserver);
assertObserverToUri(shadowContentResolver,
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, mObserver);
assertObserverToUri(shadowContentResolver, SPECIFIC_KEY_A_1, mObserver);
}
@Test
public void onChange_shouldTriggerCallbackOnDefaultKey() {
mObserver.registerObserverCallback(mObserverCallbackA);
mObserver.register(mContentResolver);
mObserver.onChange(/* selfChange= */ false,
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_ENABLED));
verify(mObserverCallbackA).onChange(Settings.Secure.ACCESSIBILITY_ENABLED);
}
@Test
public void onChange_registerSpecificKeys_shouldTriggerSpecificCallback() {
mObserver.registerKeysToObserverCallback(
List.of(SPECIFIC_KEY_A_1, SPECIFIC_KEY_A_2), mObserverCallbackA);
mObserver.register(mContentResolver);
mObserver.onChange(/* selfChange= */ false,
Settings.Secure.getUriFor(SPECIFIC_KEY_A_2));
verify(mObserverCallbackA).onChange(SPECIFIC_KEY_A_2);
}
@Test
public void onChange_registerSpecificKeys_withoutTriggerOtherCallback() {
mObserver.registerKeysToObserverCallback(
List.of(SPECIFIC_KEY_A_1, SPECIFIC_KEY_A_2), mObserverCallbackA);
mObserver.registerKeysToObserverCallback(
List.of(SPECIFIC_KEY_B_1), mObserverCallbackB);
mObserver.register(mContentResolver);
mObserver.onChange(/* selfChange= */ false,
Settings.Secure.getUriFor(SPECIFIC_KEY_B_1));
verify(mObserverCallbackA, never()).onChange(SPECIFIC_KEY_A_1);
verify(mObserverCallbackA, never()).onChange(SPECIFIC_KEY_A_2);
verify(mObserverCallbackA, never()).onChange(SPECIFIC_KEY_B_1);
verify(mObserverCallbackB).onChange(SPECIFIC_KEY_B_1);
}
@After
public void tearDown() {
mObserver.unregister(mContentResolver);
}
private void assertNotObserverToUri(ShadowContentResolver resolver, String key) {
assertThat(resolver.getContentObservers(Settings.Secure.getUriFor(key))).isEmpty();
}
private void assertObserverToUri(ShadowContentResolver resolver,
String key, ContentObserver observer) {
Collection<ContentObserver> observers =
resolver.getContentObservers(Settings.Secure.getUriFor(key));
assertThat(observers).contains(observer);
}
private static class TestableContentObserverCallback implements
AccessibilitySettingsContentObserver.ContentObserverCallback {
@Override
public void onChange(String key) {
// do nothing
}
}
}

View File

@@ -281,10 +281,10 @@ public class AccessibilitySettingsTest {
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)),
anyBoolean(),
any(SettingsContentObserver.class));
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)), anyBoolean(),
any(SettingsContentObserver.class));
any(AccessibilitySettingsContentObserver.class));
verify(mActivity, atLeast(1)).registerReceiver(any(PackageMonitor.class), captor.capture(),
isNull(), any());
intentFilter = captor.getAllValues().get(/* first time */ 0);
@@ -301,7 +301,8 @@ public class AccessibilitySettingsTest {
mFragment.onDestroy();
verify(mContentResolver).unregisterContentObserver(any(SettingsContentObserver.class));
verify(mContentResolver).unregisterContentObserver(
any(AccessibilitySettingsContentObserver.class));
verify(mActivity).unregisterReceiver(any(PackageMonitor.class));
}

View File

@@ -94,4 +94,15 @@ public class MagnificationFollowTypingPreferenceControllerTest {
assertThat(mController.isChecked()).isFalse();
assertThat(mSwitchPreference.isChecked()).isFalse();
}
@Test
public void updateState_disableFollowTyping_shouldReturnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, OFF);
mController.updateState();
verify(mSwitchPreference).setChecked(false);
assertThat(mController.isChecked()).isFalse();
assertThat(mSwitchPreference.isChecked()).isFalse();
}
}

View File

@@ -20,6 +20,8 @@ import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -27,6 +29,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@@ -75,12 +78,16 @@ public class ToggleFeaturePreferenceFragmentTest {
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
private TestToggleFeaturePreferenceFragment mFragment;
private PreferenceScreen mScreen;
private Context mContext = ApplicationProvider.getApplicationContext();
private final Context mContext = ApplicationProvider.getApplicationContext();
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
@Mock
private FragmentActivity mActivity;
@Mock
private ContentResolver mContentResolver;
@Before
public void setUpTestFragment() {
MockitoAnnotations.initMocks(this);
@@ -89,9 +96,11 @@ public class ToggleFeaturePreferenceFragmentTest {
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
mScreen = spy(new PreferenceScreen(mContext, null));
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(mScreen).when(mFragment).getPreferenceScreen();
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
final PreferenceScreen screen = spy(new PreferenceScreen(mContext, null));
when(screen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(screen).when(mFragment).getPreferenceScreen();
}
@Test
@@ -103,6 +112,25 @@ public class ToggleFeaturePreferenceFragmentTest {
verify(mFragment).addPreferencesFromResource(R.xml.placeholder_prefs);
}
@Test
@Config(shadows = {ShadowFragment.class})
public void onResume_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext);
mFragment.onCreate(Bundle.EMPTY);
mFragment.onResume();
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
}
@Test
public void updateShortcutPreferenceData_assignDefaultValueToVariable() {
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;

View File

@@ -25,14 +25,15 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
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.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
@@ -63,8 +64,8 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
@@ -96,17 +97,22 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
private Context mContext;
private Resources mResources;
@Mock
private FragmentActivity mActivity;
@Mock
private ContentResolver mContentResolver;
@Before
public void setUpTestFragment() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
mFragment = spy(new TestToggleScreenMagnificationPreferenceFragment(mContext));
mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources);
when(mFragment.getContext().getResources()).thenReturn(mResources);
doReturn(activity).when(mFragment).getActivity();
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
}
@Ignore("Ignore it since a NPE is happened in ShadowWindowManagerGlobal. (Ref. b/214161063)")
@@ -142,6 +148,30 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
assertThat(switchPreference.isChecked()).isFalse();
}
@Test
@Config(shadows = {ShadowFragment.class})
public void onResume_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext);
mFragment.onCreate(Bundle.EMPTY);
mFragment.onResume();
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
}
@Test
public void hasValueInSettings_putValue_hasValue() {
setMagnificationTripleTapEnabled(/* enabled= */ true);

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.development;
import static junit.framework.Assert.assertEquals;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemProperties;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowPowerManager;
import org.robolectric.shadows.ShadowSystemProperties;
@RunWith(RobolectricTestRunner.class)
public class RebootWithMteDialogTest {
private Context mContext;
private ShadowPowerManager mShadowPowerManager;
private RebootWithMteDialog mDialog;
@Before
public void setup() throws Exception {
mContext = ApplicationProvider.getApplicationContext();
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
mDialog = new RebootWithMteDialog(mContext);
}
@Test
@Config(
shadows = {
ShadowSystemProperties.class,
ShadowPowerManager.class,
})
public void onClick_shouldSetPropAndReboot() {
mDialog.onClick(null, 0);
assertEquals(SystemProperties.get("arm64.memtag.bootctl"), "memtag-once");
assertEquals(mShadowPowerManager.getTimesRebooted(), 1);
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.development;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import android.content.Context;
import android.os.SystemProperties;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSystemProperties;
@RunWith(RobolectricTestRunner.class)
@Config(
shadows = {
ShadowSystemProperties.class,
})
public class RebootWithMtePreferenceControllerTest {
private Context mContext;
private RebootWithMtePreferenceController mController;
@Mock private DevelopmentSettingsDashboardFragment mSettings;
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
mController = new RebootWithMtePreferenceController(mContext, mSettings);
}
@Test
public void onAvailable_falseByDefault() {
assertFalse(mController.isAvailable());
}
@Test
public void onAvailable_sysPropEnabled() {
SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1");
assertTrue(mController.isAvailable());
}
}

View File

@@ -24,6 +24,8 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.os.UserManager;
import androidx.preference.PreferenceScreen;
@@ -32,7 +34,6 @@ import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -47,6 +48,7 @@ import java.util.ArrayList;
@Config(shadows = ShadowNfcAdapter.class)
public class NfcPaymentPreferenceControllerTest {
private static final String USER_TEST = "user_test";
private static final String PREF_KEY = PaymentSettingsTest.PAYMENT_KEY;
@Mock
@@ -55,6 +57,12 @@ public class NfcPaymentPreferenceControllerTest {
private PreferenceScreen mScreen;
@Mock
private PackageManager mManager;
@Mock
private UserManager mUserManager;
@Mock
private UserHandle mUserHandle;
@Mock
private Context mContextAsUser;
private Context mContext;
private NfcPaymentPreference mPreference;
@@ -68,6 +76,9 @@ public class NfcPaymentPreferenceControllerTest {
mController = new NfcPaymentPreferenceController(mContext, PREF_KEY);
mPreference = spy(new NfcPaymentPreference(mContext, null));
when(mScreen.findPreference(PREF_KEY)).thenReturn(mPreference);
when(mContext.createContextAsUser(UserHandle.CURRENT, 0)).thenReturn(mContextAsUser);
when(mContextAsUser.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.getUserName()).thenReturn(USER_TEST);
}
@Test
@@ -134,7 +145,6 @@ public class NfcPaymentPreferenceControllerTest {
}
@Test
@Ignore
public void onPaymentAppsChanged_shouldRefreshSummary() {
mController.setPaymentBackend(mPaymentBackend);
mController.displayPreference(mScreen);
@@ -147,10 +157,12 @@ public class NfcPaymentPreferenceControllerTest {
final PaymentAppInfo appInfo = new PaymentAppInfo();
appInfo.label = "test label";
appInfo.userHandle = UserHandle.CURRENT;
when(mPaymentBackend.getDefaultApp()).thenReturn(appInfo);
mController.onPaymentAppsChanged();
assertThat(mPreference.getSummary()).isEqualTo(appInfo.label);
assertThat(mPreference.getSummary())
.isEqualTo(appInfo.label + " (" + USER_TEST + ")");
}
}
}

View File

@@ -68,7 +68,9 @@ public class SearchFeatureProviderImplTest {
final Intent searchIntent = new Intent(Settings.ACTION_APP_SEARCH_SETTINGS)
.setPackage(mActivity.getString(R.string.config_settingsintelligence_package_name));
final ResolveInfo info = new ResolveInfo();
info.activityInfo = new ActivityInfo();
final ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "com.android.example";
info.activityInfo = activityInfo;
mPackageManager.addResolveInfoForIntent(searchIntent, info);
// Should not crash.

View File

@@ -28,7 +28,6 @@ import com.android.settings.R;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -91,12 +90,6 @@ public class ScreenPinningPreferenceControllerTest {
.isEqualTo(mContext.getString(R.string.switch_on_text));
}
@Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("screen_pinning_settings");
}
@Test
public void getPreferenceKey_whenGivenValue_returnsGivenValue() {
mController = new ScreenPinningPreferenceController(mContext, "key");

View File

@@ -38,7 +38,6 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -139,12 +138,6 @@ public class SimLockPreferenceControllerTest {
assertThat(mPreference.isEnabled()).isTrue();
}
@Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("sim_lock_settings");
}
@Test
public void getPreferenceKey_whenGivenValue_returnsGivenValue() {
mController = new SimLockPreferenceController(mContext, "key");

View File

@@ -31,7 +31,6 @@ import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComp
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -119,12 +118,6 @@ public class ManageTrustAgentsPreferenceControllerTest {
R.plurals.manage_trust_agents_summary_on, 1, 1));
}
@Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("manage_trust_agents");
}
@Test
public void getPreferenceKey_whenGivenValue_returnsGivenValue() {
mController = new ManageTrustAgentsPreferenceController(mContext, "key");

View File

@@ -152,6 +152,26 @@ public class AppLocaleDetailsTest {
assertFalse(helper.getSupportedLocales().isEmpty());
}
@Test
@UiThreadTest
public void handleAllLocalesData_compareLocale() {
//Use LocaleList.matchScore() to compare two locales.
assertTrue(DummyAppLocaleDetailsHelper.compareLocale(Locale.forLanguageTag("en-US"),
Locale.forLanguageTag("en-CA")));
assertTrue(DummyAppLocaleDetailsHelper.compareLocale(Locale.forLanguageTag("zh-CN"),
Locale.forLanguageTag("zh")));
assertTrue(DummyAppLocaleDetailsHelper.compareLocale(Locale.forLanguageTag("zh-CN"),
Locale.forLanguageTag("zh-Hans")));
assertTrue(DummyAppLocaleDetailsHelper.compareLocale(Locale.forLanguageTag("zh-TW"),
Locale.forLanguageTag("zh-Hant")));
//Use Locale.equals() to compare two locales.
assertFalse(Locale.forLanguageTag("en-US").equals(Locale.forLanguageTag("en-CA")));
assertFalse(Locale.forLanguageTag("zh-CN").equals(Locale.forLanguageTag("zh")));
assertFalse(Locale.forLanguageTag("zh-CN").equals(Locale.forLanguageTag("zh-Hans")));
assertFalse(Locale.forLanguageTag("zh-TW").equals(Locale.forLanguageTag("zh-Hant")));
}
/**
* Sets the initial Locale data
*