Merge "[Panlingual] Suggested locales update"
diff --git a/res/values/config.xml b/res/values/config.xml
index 7a2f641..ec239a2 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -573,4 +573,14 @@
<!-- Whether to give option to add restricted profiles -->
<bool name="config_offer_restricted_profiles">false</bool>
+
+ <!-- An array of packages for which Applications whose per-app locale cannot be changed. -->
+ <string-array name="config_disallowed_app_localeChange_packages" translatable="false">
+ <!--
+ <item>com.example.package.first</item>
+ <item>com.example.package.second</item>
+ <item>...</item>
+ -->
+ </string-array>
+
</resources>
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 8e8c7e4..c08e669 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -30,7 +30,6 @@
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 @@
};
@VisibleForTesting
- final SettingsContentObserver mSettingsContentObserver;
+ final AccessibilitySettingsContentObserver mSettingsContentObserver;
private final Map<String, PreferenceCategory> mCategoryToPrefCategoryMap =
new ArrayMap<>();
@@ -171,12 +170,9 @@
// 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
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsContentObserver.java b/src/com/android/settings/accessibility/AccessibilitySettingsContentObserver.java
new file mode 100644
index 0000000..d2ca754
--- /dev/null
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsContentObserver.java
@@ -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);
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
index 22f037b..115f44f 100644
--- a/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java
@@ -25,7 +25,6 @@
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 @@
protected ShortcutPreference mShortcutPreference;
private AccessibilityManager.TouchExplorationStateChangeListener
mTouchExplorationStateChangeListener;
- private SettingsContentObserver mSettingsContentObserver;
+ private AccessibilitySettingsContentObserver mSettingsContentObserver;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
@@ -98,13 +97,11 @@
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
diff --git a/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java b/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java
index 8757fdf..a758276 100644
--- a/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java
+++ b/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceController.java
@@ -35,6 +35,8 @@
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 @@
// 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);
}
}
diff --git a/src/com/android/settings/accessibility/SettingsContentObserver.java b/src/com/android/settings/accessibility/SettingsContentObserver.java
deleted file mode 100644
index de67f6c..0000000
--- a/src/com/android/settings/accessibility/SettingsContentObserver.java
+++ /dev/null
@@ -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);
-}
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 04b5347..0632d3f 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -35,7 +35,6 @@
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 @@
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;
@@ -109,6 +100,13 @@
}
@Override
+ protected void registerKeysToObserverCallback(
+ AccessibilitySettingsContentObserver contentObserver) {
+ super.registerKeysToObserverCallback(contentObserver);
+ contentObserver.registerObserverCallback(key -> updateSwitchBarToggleSwitch());
+ }
+
+ @Override
public void onStart() {
super.onStart();
final AccessibilityServiceInfo serviceInfo = getAccessibilityServiceInfo();
@@ -123,7 +121,11 @@
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
- mSettingsContentObserver.register(getContentResolver());
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
}
@Override
@@ -172,7 +174,7 @@
if (info == null) {
return null;
}
- mDialog = AccessibilityServiceWarning
+ mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromEnableToggleClicked,
this::onDialogButtonFromUninstallClicked);
@@ -183,7 +185,7 @@
if (info == null) {
return null;
}
- mDialog = AccessibilityServiceWarning
+ mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromShortcutToggleClicked,
this::onDialogButtonFromUninstallClicked);
@@ -194,7 +196,7 @@
if (info == null) {
return null;
}
- mDialog = AccessibilityServiceWarning
+ mWarningDialog = AccessibilityServiceWarning
.createCapabilitiesDialog(getPrefContext(), info,
this::onDialogButtonFromShortcutClicked,
this::onDialogButtonFromUninstallClicked);
@@ -205,16 +207,16 @@
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 @@
}
private void onDialogButtonFromUninstallClicked() {
- mDialog.dismiss();
+ mWarningDialog.dismiss();
final Intent uninstallIntent = createUninstallPackageActivityIntent();
if (uninstallIntent == null) {
return;
@@ -436,12 +438,12 @@
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 @@
mIsDialogShown.set(false);
showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
- mDialog.dismiss();
+ mWarningDialog.dismiss();
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
}
@@ -473,7 +475,7 @@
private void onDenyButtonFromShortcutToggleClicked() {
mShortcutPreference.setChecked(false);
- mDialog.dismiss();
+ mWarningDialog.dismiss();
}
void onDialogButtonFromShortcutClicked(View view) {
@@ -491,11 +493,11 @@
mIsDialogShown.set(false);
showPopupDialog(DialogEnums.EDIT_SHORTCUT);
- mDialog.dismiss();
+ mWarningDialog.dismiss();
}
private void onDenyButtonFromShortcutClicked() {
- mDialog.dismiss();
+ mWarningDialog.dismiss();
}
private boolean onPreferenceClick(boolean isChecked) {
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 419514f..e65c9c5 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -25,7 +25,6 @@
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 @@
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 @@
.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 void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
- mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
- mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index c9449d24..f0a4f0a 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -24,9 +24,7 @@
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 @@
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 @@
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 void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
- mSettingsContentObserver.register(getContentResolver());
-
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(this);
@@ -135,7 +131,6 @@
@Override
public void onPause() {
- mSettingsContentObserver.unregister(getContentResolver());
for (AbstractPreferenceController controller :
buildPreferenceControllers(getPrefContext(), getSettingsLifecycle())) {
((DaltonizerRadioButtonPreferenceController) controller).setOnChangeListener(null);
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 233b7ee..cba5d83 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -99,7 +99,7 @@
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 @@
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);
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index 81bd45a..feb41a1 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -22,7 +22,6 @@
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 @@
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 @@
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 @@
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 void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
- mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
- mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index d1e9b56..5f76d5a 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -75,6 +75,9 @@
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 @@
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 @@
}
@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;
}
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
index 799508b..d92fd51 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java
@@ -44,9 +44,17 @@
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
diff --git a/src/com/android/settings/applications/AppLocaleUtil.java b/src/com/android/settings/applications/AppLocaleUtil.java
new file mode 100644
index 0000000..e795b01
--- /dev/null
+++ b/src/com/android/settings/applications/AppLocaleUtil.java
@@ -0,0 +1,68 @@
+/*
+ * 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.applications;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+
+/** This class provides methods that help dealing with per app locale. */
+public class AppLocaleUtil {
+ private static final String TAG = AppLocaleUtil.class.getSimpleName();
+
+ /**
+ * Decides the UI display of per app locale.
+ */
+ public static boolean canDisplayLocaleUi(Context context, AppEntry app) {
+ return !isDisallowedPackage(context, app.info.packageName)
+ && !isSignedWithPlatformKey(context, app.info.packageName)
+ && app.hasLauncherEntry;
+ }
+
+ private static boolean isDisallowedPackage(Context context, String packageName) {
+ final String[] disallowedPackages = context.getResources().getStringArray(
+ R.array.config_disallowed_app_localeChange_packages);
+ for (String disallowedPackage : disallowedPackages) {
+ if (packageName.equals(disallowedPackage)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isSignedWithPlatformKey(Context context, String packageName) {
+ PackageInfo packageInfo = null;
+ PackageManager packageManager = context.getPackageManager();
+ ActivityManager activityManager = context.getSystemService(ActivityManager.class);
+ try {
+ packageInfo = packageManager.getPackageInfoAsUser(
+ packageName, /* flags= */ 0,
+ activityManager.getCurrentUser());
+ } catch (PackageManager.NameNotFoundException ex) {
+ Log.e(TAG, "package not found: " + packageName);
+ }
+ if (packageInfo == null) {
+ return false;
+ }
+ return packageInfo.applicationInfo.isSignedWithPlatformKey();
+ }
+}
diff --git a/src/com/android/settings/applications/AppStateLocaleBridge.java b/src/com/android/settings/applications/AppStateLocaleBridge.java
new file mode 100644
index 0000000..ebaf4ab
--- /dev/null
+++ b/src/com/android/settings/applications/AppStateLocaleBridge.java
@@ -0,0 +1,77 @@
+/*
+ * 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.applications;
+
+import android.content.Context;
+import android.util.Log;
+
+import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+import com.android.settingslib.applications.ApplicationsState.AppFilter;
+
+import java.util.List;
+
+/**
+ * Creates a application filter to restrict UI display of applications.
+ * This is to avoid users from changing the per apps locale
+ * Also provides app filters that can use the info.
+ */
+public class AppStateLocaleBridge extends AppStateBaseBridge {
+ private static final String TAG = AppStateLocaleBridge.class.getSimpleName();
+
+ private final Context mContext;
+
+ public AppStateLocaleBridge(Context context, ApplicationsState appState,
+ Callback callback) {
+ super(appState, callback);
+ mContext = context;
+ }
+
+ @Override
+ protected void updateExtraInfo(AppEntry app, String packageName, int uid) {
+ app.extraInfo = AppLocaleUtil.canDisplayLocaleUi(mContext, app)
+ ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ @Override
+ protected void loadAllExtraInfo() {
+ final List<AppEntry> allApps = mAppSession.getAllApps();
+ for (int i = 0; i < allApps.size(); i++) {
+ AppEntry app = allApps.get(i);
+ app.extraInfo = AppLocaleUtil.canDisplayLocaleUi(mContext, app)
+ ? Boolean.TRUE : Boolean.FALSE;
+ }
+ }
+
+ /** For the Settings which shows category of per app's locale. */
+ public static final AppFilter FILTER_APPS_LOCALE =
+ new AppFilter() {
+ @Override
+ public void init() {
+ }
+
+ @Override
+ public boolean filterApp(AppEntry entry) {
+ if (entry.extraInfo == null) {
+ Log.d(TAG, "No extra info.");
+ return false;
+ }
+ return (Boolean) entry.extraInfo;
+ }
+ };
+
+
+}
diff --git a/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java b/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
index f1e43ad..810d230 100644
--- a/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppLocalePreferenceController.java
@@ -20,20 +20,23 @@
import android.util.FeatureFlagUtils;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.applications.AppLocaleUtil;
/**
* A controller to update current locale information of application.
*/
public class AppLocalePreferenceController extends AppInfoPreferenceControllerBase {
+ private static final String TAG = AppLocalePreferenceController.class.getSimpleName();
+
public AppLocalePreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
- return FeatureFlagUtils
- .isEnabled(mContext, FeatureFlagUtils.SETTINGS_APP_LANGUAGE_SELECTION)
- ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ boolean isFeatureOn = FeatureFlagUtils
+ .isEnabled(mContext, FeatureFlagUtils.SETTINGS_APP_LANGUAGE_SELECTION);
+ return isFeatureOn && canDisplayLocaleUi() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@Override
@@ -45,4 +48,8 @@
public CharSequence getSummary() {
return AppLocaleDetails.getSummary(mContext, mParent.getAppEntry().info.packageName);
}
+
+ boolean canDisplayLocaleUi() {
+ return AppLocaleUtil.canDisplayLocaleUi(mContext, mParent.getAppEntry());
+ }
}
diff --git a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
index d1d4f62..6e67815 100644
--- a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
+++ b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
@@ -21,6 +21,7 @@
import com.android.settings.R;
import com.android.settings.applications.AppStateAlarmsAndRemindersBridge;
import com.android.settings.applications.AppStateInstallAppsBridge;
+import com.android.settings.applications.AppStateLocaleBridge;
import com.android.settings.applications.AppStateManageExternalStorageBridge;
import com.android.settings.applications.AppStateMediaManagementAppsBridge;
import com.android.settings.applications.AppStateNotificationBridge;
@@ -54,6 +55,7 @@
FILTER_APPS_BLOCKED,
FILTER_ALARMS_AND_REMINDERS,
FILTER_APPS_MEDIA_MANAGEMENT,
+ FILTER_APPS_LOCALE,
})
@interface FilterType {
}
@@ -79,14 +81,15 @@
public static final int FILTER_MANAGE_EXTERNAL_STORAGE = 17;
public static final int FILTER_ALARMS_AND_REMINDERS = 18;
public static final int FILTER_APPS_MEDIA_MANAGEMENT = 19;
- // Next id: 20. If you add an entry here, length of mFilters should be updated
+ public static final int FILTER_APPS_LOCALE = 20;
+ // Next id: 21. If you add an entry here, length of mFilters should be updated
private static AppFilterRegistry sRegistry;
private final AppFilterItem[] mFilters;
private AppFilterRegistry() {
- mFilters = new AppFilterItem[20];
+ mFilters = new AppFilterItem[21];
// High power allowlist, on
mFilters[FILTER_APPS_POWER_ALLOWLIST] = new AppFilterItem(
@@ -203,8 +206,16 @@
AppStateMediaManagementAppsBridge.FILTER_MEDIA_MANAGEMENT_APPS,
FILTER_APPS_MEDIA_MANAGEMENT,
R.string.media_management_apps_title);
+
+ // Apps that can configurate appication's locale.
+ mFilters[FILTER_APPS_LOCALE] = new AppFilterItem(
+ AppStateLocaleBridge.FILTER_APPS_LOCALE,
+ FILTER_APPS_LOCALE,
+ R.string.app_locale_picker_title);
}
+
+
public static AppFilterRegistry getInstance() {
if (sRegistry == null) {
sRegistry = new AppFilterRegistry();
@@ -235,6 +246,8 @@
return FILTER_ALARMS_AND_REMINDERS;
case ManageApplications.LIST_TYPE_MEDIA_MANAGEMENT_APPS:
return FILTER_APPS_MEDIA_MANAGEMENT;
+ case ManageApplications.LIST_TYPE_APPS_LOCALE:
+ return FILTER_APPS_LOCALE;
default:
return FILTER_APPS_ALL;
}
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index d985482..01bc2f1 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -95,6 +95,7 @@
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateBaseBridge;
import com.android.settings.applications.AppStateInstallAppsBridge;
+import com.android.settings.applications.AppStateLocaleBridge;
import com.android.settings.applications.AppStateManageExternalStorageBridge;
import com.android.settings.applications.AppStateMediaManagementAppsBridge;
import com.android.settings.applications.AppStateNotificationBridge;
@@ -232,7 +233,7 @@
public static final int LIST_MANAGE_EXTERNAL_STORAGE = 11;
public static final int LIST_TYPE_ALARMS_AND_REMINDERS = 12;
public static final int LIST_TYPE_MEDIA_MANAGEMENT_APPS = 13;
- public static final int LIST_TYPE_APPS_LOCAL = 14;
+ public static final int LIST_TYPE_APPS_LOCALE = 14;
// List types that should show instant apps.
public static final Set<Integer> LIST_TYPES_WITH_INSTANT = new ArraySet<>(Arrays.asList(
@@ -321,7 +322,7 @@
mNotificationBackend = new NotificationBackend();
mSortOrder = R.id.sort_order_recent_notification;
} else if (className.equals(AppLocaleDetails.class.getName())) {
- mListType = LIST_TYPE_APPS_LOCAL;
+ mListType = LIST_TYPE_APPS_LOCALE;
} else {
mListType = LIST_TYPE_MAIN;
}
@@ -504,7 +505,7 @@
return SettingsEnums.ALARMS_AND_REMINDERS;
case LIST_TYPE_MEDIA_MANAGEMENT_APPS:
return SettingsEnums.MEDIA_MANAGEMENT_APPS;
- case LIST_TYPE_APPS_LOCAL:
+ case LIST_TYPE_APPS_LOCALE:
return SettingsEnums.APPS_LOCALE_LIST;
default:
return SettingsEnums.PAGE_UNKNOWN;
@@ -629,7 +630,7 @@
startAppInfoFragment(MediaManagementAppsDetails.class,
R.string.media_management_apps_title);
break;
- case LIST_TYPE_APPS_LOCAL:
+ case LIST_TYPE_APPS_LOCALE:
startAppInfoFragment(AppLocaleDetails.class,
R.string.app_locale_picker_title);
break;
@@ -743,9 +744,9 @@
&& mSortOrder != R.id.sort_order_size);
mOptionsMenu.findItem(R.id.show_system).setVisible(!mShowSystem
- && mListType != LIST_TYPE_HIGH_POWER);
+ && mListType != LIST_TYPE_HIGH_POWER && mListType != LIST_TYPE_APPS_LOCALE);
mOptionsMenu.findItem(R.id.hide_system).setVisible(mShowSystem
- && mListType != LIST_TYPE_HIGH_POWER);
+ && mListType != LIST_TYPE_HIGH_POWER && mListType != LIST_TYPE_APPS_LOCALE);
mOptionsMenu.findItem(R.id.reset_app_preferences).setVisible(mListType == LIST_TYPE_MAIN);
@@ -1100,6 +1101,8 @@
mExtraInfoBridge = new AppStateAlarmsAndRemindersBridge(mContext, mState, this);
} else if (mManageApplications.mListType == LIST_TYPE_MEDIA_MANAGEMENT_APPS) {
mExtraInfoBridge = new AppStateMediaManagementAppsBridge(mContext, mState, this);
+ } else if (mManageApplications.mListType == LIST_TYPE_APPS_LOCALE) {
+ mExtraInfoBridge = new AppStateLocaleBridge(mContext, mState, this);
} else {
mExtraInfoBridge = null;
}
@@ -1533,7 +1536,7 @@
case LIST_TYPE_MEDIA_MANAGEMENT_APPS:
holder.setSummary(MediaManagementAppsDetails.getSummary(mContext, entry));
break;
- case LIST_TYPE_APPS_LOCAL:
+ case LIST_TYPE_APPS_LOCALE:
holder.setSummary(AppLocaleDetails
.getSummary(mContext, entry.info.packageName));
break;
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index a8a30b4..ba660ee 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -20,6 +20,7 @@
import android.icu.text.RelativeDateTimeFormatter;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -85,11 +86,17 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mCategoryRecentLocationRequests = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ mCategoryRecentLocationRequests.removeAll();
final Context prefContext = mCategoryRecentLocationRequests.getContext();
final List<RecentAppOpsAccess.Access> recentLocationAccesses = new ArrayList<>();
final UserManager userManager = UserManager.get(mContext);
- for (RecentAppOpsAccess.Access access : mRecentLocationApps.getAppListSorted(
- /* showSystemApps= */ false)) {
+ final boolean showSystem = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
+ for (RecentAppOpsAccess.Access access : mRecentLocationApps.getAppListSorted(showSystem)) {
if (isRequestMatchesProfileType(userManager, access, mType)) {
recentLocationAccesses.add(access);
if (recentLocationAccesses.size() == MAX_APPS) {
diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllFragment.java b/src/com/android/settings/location/RecentLocationAccessSeeAllFragment.java
index e27b28c..f7bf31a 100644
--- a/src/com/android/settings/location/RecentLocationAccessSeeAllFragment.java
+++ b/src/com/android/settings/location/RecentLocationAccessSeeAllFragment.java
@@ -17,6 +17,7 @@
import android.content.Context;
import android.os.Bundle;
+import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -36,7 +37,6 @@
private static final int MENU_SHOW_SYSTEM = Menu.FIRST + 1;
private static final int MENU_HIDE_SYSTEM = Menu.FIRST + 2;
- private static final String EXTRA_SHOW_SYSTEM = "show_system";
private boolean mShowSystem = false;
private MenuItem mShowSystemMenu;
@@ -58,18 +58,8 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (savedInstanceState != null) {
- mShowSystem = savedInstanceState.getBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
- }
- if (mController != null) {
- mController.setShowSystem(mShowSystem);
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
+ mShowSystem = Settings.Secure.getInt(getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
}
@Override
@@ -88,6 +78,8 @@
case MENU_SHOW_SYSTEM:
case MENU_HIDE_SYSTEM:
mShowSystem = menuItem.getItemId() == MENU_SHOW_SYSTEM;
+ Settings.Secure.putInt(getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, mShowSystem ? 1 : 0);
updateMenu();
if (mController != null) {
mController.setShowSystem(mShowSystem);
diff --git a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
index bca4486..e3379c7 100644
--- a/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessSeeAllPreferenceController.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.os.UserManager;
+import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -43,6 +44,8 @@
public RecentLocationAccessSeeAllPreferenceController(Context context, String key) {
super(context, key);
+ mShowSystem = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
mRecentLocationAccesses = RecentAppOpsAccess.createForLocation(context);
}
diff --git a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
index 812a440..a14e047 100644
--- a/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationRequestPreferenceController.java
@@ -17,6 +17,7 @@
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -83,8 +84,11 @@
final Context prefContext = mCategoryRecentLocationRequests.getContext();
final List<RecentLocationApps.Request> recentLocationRequests = new ArrayList<>();
final UserManager userManager = UserManager.get(mContext);
+ final boolean showSystem = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 0) == 1;
+
for (RecentLocationApps.Request request : mRecentLocationApps.getAppListSorted(
- false /* systemApps */)) {
+ showSystem)) {
if (isRequestMatchesProfileType(userManager, request, mType)) {
recentLocationRequests.add(request);
if (recentLocationRequests.size() == MAX_APPS) {
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsContentObserverTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsContentObserverTest.java
new file mode 100644
index 0000000..e23d2d7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsContentObserverTest.java
@@ -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
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index d1c59f7..5843265 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -281,10 +281,10 @@
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 @@
mFragment.onDestroy();
- verify(mContentResolver).unregisterContentObserver(any(SettingsContentObserver.class));
+ verify(mContentResolver).unregisterContentObserver(
+ any(AccessibilitySettingsContentObserver.class));
verify(mActivity).unregisterReceiver(any(PackageMonitor.class));
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java
index ccb66ad..fd282a0 100644
--- a/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/MagnificationFollowTypingPreferenceControllerTest.java
@@ -94,4 +94,15 @@
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();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index c47a793..4584b15 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -20,6 +20,8 @@
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.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 @@
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 @@
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
@@ -104,6 +113,25 @@
}
@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;
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
index 10495c5..8500e61 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentTest.java
@@ -25,14 +25,15 @@
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.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 @@
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)")
@@ -143,6 +149,30 @@
}
@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);
diff --git a/tests/robotests/src/com/android/settings/accounts/WorkModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/WorkModePreferenceControllerTest.java
index c7e571f..b5d1cc7 100644
--- a/tests/robotests/src/com/android/settings/accounts/WorkModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/WorkModePreferenceControllerTest.java
@@ -18,6 +18,7 @@
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.spy;
import static org.mockito.Mockito.verify;
@@ -32,7 +33,6 @@
import com.android.settings.R;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -106,10 +106,9 @@
}
@Test
- @Ignore
public void onStart_shouldRegisterReceiver() {
mController.onStart();
- verify(mContext).registerReceiver(eq(mController.mReceiver), any());
+ verify(mContext).registerReceiver(eq(mController.mReceiver), any(), anyInt());
}
@Test
diff --git a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
index ad928da..ae62724 100644
--- a/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationInjectedServicesPreferenceControllerTest.java
@@ -43,7 +43,6 @@
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -98,16 +97,15 @@
}
@Test
- @Ignore
public void onResume_shouldRegisterListener() {
mController.onResume();
verify(mContext).registerReceiver(eq(mController.mInjectedSettingsReceiver),
- eq(mController.INTENT_FILTER_INJECTED_SETTING_CHANGED));
+ eq(mController.INTENT_FILTER_INJECTED_SETTING_CHANGED),
+ anyInt());
}
@Test
- @Ignore
public void onPause_shouldUnregisterListener() {
mController.onResume();
mController.onPause();
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 52068c4..225f91b 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -19,9 +19,12 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
@@ -34,12 +37,15 @@
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settingslib.applications.RecentAppOpsAccess;
+import com.google.common.collect.ImmutableList;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@@ -107,4 +113,20 @@
mContext.getText(R.string.location_recent_location_access_view_details));
assertThat(details.hasOnClickListeners()).isTrue();
}
+
+ /** Verifies the title text, details text are correct, and the click listener is set. */
+ @Test
+ public void updateState_showSystemAccess() {
+ doReturn(ImmutableList.of(
+ new RecentAppOpsAccess.Access("app", UserHandle.CURRENT, null, "app", "", 0)))
+ .when(mRecentLocationApps).getAppListSorted(false);
+ doReturn(new ArrayList<>()).when(mRecentLocationApps).getAppListSorted(true);
+ mController.displayPreference(mScreen);
+ mController.updateState(mLayoutPreference);
+ verify(mLayoutPreference).addPreference(Mockito.any());
+
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), Settings.Secure.LOCATION_SHOW_SYSTEM_OPS, 1);
+ verify(mLayoutPreference, Mockito.times(1)).addPreference(Mockito.any());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
index 545a358..be778cb 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationRequestPreferenceControllerTest.java
@@ -26,6 +26,7 @@
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
+import android.provider.Settings;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -82,6 +83,25 @@
}
@Test
+ public void updateState_whenAppListMoreThanThree_showSystem() {
+ when(mController.mRecentLocationApps.getAppListSorted(false))
+ .thenReturn(createMockRequest(2));
+ when(mController.mRecentLocationApps.getAppListSorted(true))
+ .thenReturn(createMockRequest(3));
+
+ mController.displayPreference(mScreen);
+ verify(mCategory, times(2)).addPreference(any());
+
+ Settings.Secure.putInt(
+ mContext.getContentResolver(),
+ Settings.Secure.LOCATION_SHOW_SYSTEM_OPS,
+ 1);
+
+ mController.displayPreference(mScreen);
+ verify(mCategory, times(5)).addPreference(any());
+ }
+
+ @Test
public void updateState_workProfile_shouldShowOnlyWorkProfileApps() {
final List<RecentLocationApps.Request> requests = createMockRequest(6);
when(mController.mRecentLocationApps.getAppListSorted(false)).thenReturn(requests);
diff --git a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
index bcc6455..15a124d 100644
--- a/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/search/SearchFeatureProviderImplTest.java
@@ -68,7 +68,9 @@
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.
diff --git a/tests/unit/src/com/android/settings/applications/AppLocaleUtilTest.java b/tests/unit/src/com/android/settings/applications/AppLocaleUtilTest.java
new file mode 100644
index 0000000..22a055f
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/AppLocaleUtilTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.applications;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import com.android.settingslib.applications.ApplicationsState.AppEntry;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(AndroidJUnit4.class)
+public class AppLocaleUtilTest {
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private ActivityManager mActivityManager;
+ @Mock
+ private AppEntry mEntry;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
+ @Mock
+ private Resources mResources;
+
+ private Context mContext;
+ private String mDisallowedPackage = "com.disallowed.package";
+ private String mAallowedPackage = "com.allowed.package";
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mContext.getSystemService(ActivityManager.class)).thenReturn(mActivityManager);
+ }
+
+ @Test
+ public void isDisplayLocaleUi_showUI() throws PackageManager.NameNotFoundException {
+ setTestAppEntry(mAallowedPackage);
+ setDisallowedPackageName(mDisallowedPackage);
+ setApplicationInfo(/*no platform key*/false);
+ mEntry.hasLauncherEntry = true;
+
+ assertTrue(AppLocaleUtil.canDisplayLocaleUi(mContext, mEntry));
+ }
+
+ @Test
+ public void isDisplayLocaleUi_notShowUI_hasPlatformKey()
+ throws PackageManager.NameNotFoundException {
+ setTestAppEntry(mAallowedPackage);
+ setDisallowedPackageName(mDisallowedPackage);
+ setApplicationInfo(/*has platform key*/true);
+ mEntry.hasLauncherEntry = true;
+
+ assertFalse(AppLocaleUtil.canDisplayLocaleUi(mContext, mEntry));
+ }
+
+ @Test
+ public void isDisplayLocaleUi_notShowUI_noLauncherEntry()
+ throws PackageManager.NameNotFoundException {
+ setTestAppEntry(mAallowedPackage);
+ setDisallowedPackageName(mDisallowedPackage);
+ setApplicationInfo(/*no platform key*/false);
+ mEntry.hasLauncherEntry = false;
+
+ assertFalse(AppLocaleUtil.canDisplayLocaleUi(mContext, mEntry));
+ }
+
+ @Test
+ public void isDisplayLocaleUi_notShowUI_matchDisallowedPackageList()
+ throws PackageManager.NameNotFoundException {
+ setTestAppEntry(mDisallowedPackage);
+ setDisallowedPackageName(mDisallowedPackage);
+ setApplicationInfo(/*no platform key*/false);
+ mEntry.hasLauncherEntry = false;
+
+ assertFalse(AppLocaleUtil.canDisplayLocaleUi(mContext, mEntry));
+ }
+
+ private void setTestAppEntry(String packageName) {
+ mEntry.info = mApplicationInfo;
+ mApplicationInfo.packageName = packageName;
+ }
+
+ private void setDisallowedPackageName(String packageName) {
+ when(mContext.getResources()).thenReturn(mResources);
+ when(mResources.getStringArray(anyInt())).thenReturn(new String[]{packageName});
+ }
+
+ private void setApplicationInfo(boolean signedWithPlatformKey)
+ throws PackageManager.NameNotFoundException {
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ if (signedWithPlatformKey) {
+ applicationInfo.privateFlags = applicationInfo.privateFlags
+ | ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY;
+ }
+
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.applicationInfo = applicationInfo;
+ when(mPackageManager.getPackageInfoAsUser(anyString(), anyInt(), anyInt())).thenReturn(
+ packageInfo);
+ }
+}
diff --git a/tests/unit/src/com/android/settings/applications/appinfo/AppLocalePreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/appinfo/AppLocalePreferenceControllerTest.java
index d7e3f92..526b6cc 100644
--- a/tests/unit/src/com/android/settings/applications/appinfo/AppLocalePreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/appinfo/AppLocalePreferenceControllerTest.java
@@ -18,8 +18,6 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.spy;
-
import android.content.Context;
import android.util.FeatureFlagUtils;
@@ -37,20 +35,27 @@
public class AppLocalePreferenceControllerTest {
private Context mContext;
+ private boolean mCanDisplayLocaleUi;
private AppLocalePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(ApplicationProvider.getApplicationContext());
+ mContext = ApplicationProvider.getApplicationContext();
- mController = spy(new AppLocalePreferenceController(mContext, "test_key"));
+ mController = new AppLocalePreferenceController(mContext, "test_key") {
+ @Override
+ boolean canDisplayLocaleUi() {
+ return mCanDisplayLocaleUi;
+ }
+ };
FeatureFlagUtils
.setEnabled(mContext, FeatureFlagUtils.SETTINGS_APP_LANGUAGE_SELECTION, true);
}
@Test
- public void getAvailabilityStatus_featureFlagOff_shouldReturnUnavailable() {
+ public void getAvailabilityStatus_canShowUiButFeatureFlagOff_shouldReturnUnavailable() {
+ mCanDisplayLocaleUi = true;
FeatureFlagUtils
.setEnabled(mContext, FeatureFlagUtils.SETTINGS_APP_LANGUAGE_SELECTION, false);
@@ -59,8 +64,28 @@
}
@Test
- public void getAvailabilityStatus_featureFlagOn_shouldReturnAvailable() {
+ public void getAvailabilityStatus_canShowUiAndFeatureFlagOn_shouldReturnAvailable() {
+ mCanDisplayLocaleUi = true;
+
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
+
+ @Test
+ public void getAvailabilityStatus_featureFlagOnButCanNotShowUi_shouldReturnUnavailable() {
+ mCanDisplayLocaleUi = false;
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_featureFlagOffAndCanNotShowUi_shouldReturnUnavailable() {
+ mCanDisplayLocaleUi = false;
+ FeatureFlagUtils
+ .setEnabled(mContext, FeatureFlagUtils.SETTINGS_APP_LANGUAGE_SELECTION, false);
+
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
}