Snap for 8451755 from ee6d283b82 to tm-release
Change-Id: Id3be601e421d99730e992cb056e093d2087e3f54
This commit is contained in:
@@ -519,14 +519,11 @@
|
||||
<string name="preference_of_system_locale_title">System language</string>
|
||||
|
||||
<!-- Summary for preference of the system default locale. [CHAR LIMIT=50]-->
|
||||
<string name="preference_of_system_locale_summary">System default - <xliff:g id="default_language" example="English (United States)">%1$s</xliff:g></string>
|
||||
<string name="preference_of_system_locale_summary">System default</string>
|
||||
|
||||
<!-- Description for the app without any supported languages. [CHAR LIMIT=NONE]-->
|
||||
<string name="desc_no_available_supported_locale">Language selection for this app isn\u2019t available from Settings.</string>
|
||||
|
||||
<!-- Description for the app without any supported languages. [CHAR LIMIT=NONE]-->
|
||||
<string name="desc_disallow_locale_change_in_settings">You can\u2019t select a language for this app from Settings.</string>
|
||||
|
||||
<!-- The title of the confirmation dialog shown when the user selects one / several languages and tries to remove them [CHAR LIMIT=60] -->
|
||||
<plurals name="dlg_remove_locales_title">
|
||||
<item quantity="one">Remove selected language?</item>
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.service.oemlock.OemLockManager;
|
||||
@@ -67,6 +68,8 @@ import com.google.android.setupdesign.GlifLayout;
|
||||
public class MainClearConfirm extends InstrumentedFragment {
|
||||
private static final String TAG = "MainClearConfirm";
|
||||
|
||||
private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
|
||||
|
||||
@VisibleForTesting View mContentView;
|
||||
private boolean mEraseSdCard;
|
||||
@VisibleForTesting boolean mEraseEsims;
|
||||
@@ -83,6 +86,11 @@ public class MainClearConfirm extends InstrumentedFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
// pre-flight check hardware support PersistentDataBlockManager
|
||||
if (SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("")) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
|
||||
getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
@@ -32,6 +33,8 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -49,6 +52,26 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
private static final String RESET_KEY = "reset";
|
||||
private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
|
||||
private static final String HIGHT_TEXT_CONTRAST_KEY = "toggle_high_text_contrast_preference";
|
||||
private static final String NEED_RESET_SETTINGS = "need_reset_settings";
|
||||
private FontWeightAdjustmentPreferenceController mFontWeightAdjustmentController;
|
||||
|
||||
@VisibleForTesting
|
||||
List<ResetStateListener> mResetStateListeners;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mNeedResetSettings;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
mNeedResetSettings = false;
|
||||
mResetStateListeners = getResetStateListeners();
|
||||
|
||||
if (icicle != null && icicle.getBoolean(NEED_RESET_SETTINGS)) {
|
||||
mResetStateListeners.forEach(ResetStateListener::resetState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
@@ -69,7 +92,7 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final FontSizeData fontSizeData = new FontSizeData(context);
|
||||
final DisplaySizeData displaySizeData = new DisplaySizeData(context);
|
||||
final DisplaySizeData displaySizeData = createDisplaySizeData(context);
|
||||
|
||||
final TextReadingPreviewController previewController = new TextReadingPreviewController(
|
||||
context, PREVIEW_KEY, fontSizeData, displaySizeData);
|
||||
@@ -85,9 +108,9 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
displaySizeController.setInteractionListener(previewController);
|
||||
controllers.add(displaySizeController);
|
||||
|
||||
final FontWeightAdjustmentPreferenceController fontWeightController =
|
||||
mFontWeightAdjustmentController =
|
||||
new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
|
||||
controllers.add(fontWeightController);
|
||||
controllers.add(mFontWeightAdjustmentController);
|
||||
|
||||
final HighTextContrastPreferenceController highTextContrastController =
|
||||
new HighTextContrastPreferenceController(context, HIGHT_TEXT_CONTRAST_KEY);
|
||||
@@ -126,12 +149,35 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
|
||||
return super.getDialogMetricsCategory(dialogId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (mNeedResetSettings) {
|
||||
outState.putBoolean(NEED_RESET_SETTINGS, true);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DisplaySizeData createDisplaySizeData(Context context) {
|
||||
return new DisplaySizeData(context);
|
||||
}
|
||||
|
||||
private void onPositiveButtonClicked(DialogInterface dialog, int which) {
|
||||
// To avoid showing the dialog again, probably the onDetach() of SettingsDialogFragment
|
||||
// was interrupted by unexpectedly recreating the activity.
|
||||
removeDialog(DialogEnums.DIALOG_RESET_SETTINGS);
|
||||
|
||||
getResetStateListeners().forEach(ResetStateListener::resetState);
|
||||
if (mFontWeightAdjustmentController.isChecked()) {
|
||||
// TODO(b/228956791): Consider replacing or removing it once the root cause is
|
||||
// clarified and the better method is available.
|
||||
// Probably has the race condition issue between "Bold text" and the other features
|
||||
// including "Display Size", “Font Size” if they would be enabled at the same time,
|
||||
// so our workaround is that the “Bold text” would be reset first and then do the
|
||||
// remaining to avoid flickering problem.
|
||||
mNeedResetSettings = true;
|
||||
mFontWeightAdjustmentController.resetState();
|
||||
} else {
|
||||
mResetStateListeners.forEach(ResetStateListener::resetState);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ResetStateListener> getResetStateListeners() {
|
||||
|
||||
@@ -208,13 +208,9 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
|
||||
LocaleList packageLocaleList = getPackageLocales();
|
||||
String[] assetLocaleList = getAssetLocales();
|
||||
// TODO add apended url string, "Learn more", to these both sentenses.
|
||||
if (packageLocaleList == null && assetLocaleList.length == 0) {
|
||||
// There is no locale info from PackageManager amd AssetManager.
|
||||
if ((packageLocaleList != null && packageLocaleList.isEmpty())
|
||||
|| (packageLocaleList == null && assetLocaleList.length == 0)) {
|
||||
return R.string.desc_no_available_supported_locale;
|
||||
} else if (packageLocaleList != null && packageLocaleList.isEmpty()) {
|
||||
// LocaleConfig is empty, and this means only allow user modify language
|
||||
// by the application.
|
||||
return R.string.desc_disallow_locale_change_in_settings;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -276,9 +272,7 @@ public class AppLocaleDetails extends SettingsPreferenceFragment {
|
||||
final Context contextAsUser = context.createContextAsUser(userHandle, 0);
|
||||
Locale appLocale = getAppDefaultLocale(contextAsUser, entry.info.packageName);
|
||||
if (appLocale == null) {
|
||||
Locale systemLocale = Locale.getDefault();
|
||||
return context.getString(R.string.preference_of_system_locale_summary,
|
||||
systemLocale.getDisplayName(systemLocale));
|
||||
return context.getString(R.string.preference_of_system_locale_summary);
|
||||
} else {
|
||||
return appLocale.getDisplayName(appLocale);
|
||||
}
|
||||
|
||||
@@ -69,15 +69,6 @@ public class RequestIgnoreBatteryOptimizations extends AlertActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationInfo ai;
|
||||
try {
|
||||
ai = getPackageManager().getApplicationInfo(mPackageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
debugLog("Requested package doesn't exist: " + mPackageName);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (getPackageManager().checkPermission(
|
||||
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, mPackageName)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -87,6 +78,15 @@ public class RequestIgnoreBatteryOptimizations extends AlertActivity implements
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationInfo ai;
|
||||
try {
|
||||
ai = getPackageManager().getApplicationInfo(mPackageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
debugLog("Requested package doesn't exist: " + mPackageName);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
final AlertController.AlertParams p = mAlertParams;
|
||||
final CharSequence appLabel = ai.loadSafeLabel(getPackageManager(),
|
||||
PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, PackageItemInfo.SAFE_LABEL_FLAG_TRIM
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
import android.widget.Switch;
|
||||
|
||||
@@ -101,6 +102,11 @@ public class BatterySaverButtonPreferenceController extends
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
// Cancel preference's check state once it's first time launch
|
||||
if (isChecked && (Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 0) == 0)) {
|
||||
mPreference.setChecked(false);
|
||||
}
|
||||
setChecked(isChecked);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -49,6 +50,7 @@ import com.android.settings.support.actionbar.HelpResourceProvider;
|
||||
import com.android.settings.utils.CandidateInfoExtra;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
@@ -320,6 +322,39 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment i
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return SystemNavigationPreferenceController.isGestureAvailable(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final Resources res = context.getResources();
|
||||
final List<SearchIndexableRaw> result = new ArrayList<>();
|
||||
|
||||
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(context,
|
||||
NAV_BAR_MODE_GESTURAL_OVERLAY)) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = res.getString(R.string.edge_to_edge_navigation_title);
|
||||
data.key = KEY_SYSTEM_NAV_GESTURAL;
|
||||
result.add(data);
|
||||
}
|
||||
|
||||
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(context,
|
||||
NAV_BAR_MODE_2BUTTON_OVERLAY)) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = res.getString(R.string.swipe_up_to_switch_apps_title);
|
||||
data.key = KEY_SYSTEM_NAV_2BUTTONS;
|
||||
result.add(data);
|
||||
}
|
||||
|
||||
if (SystemNavigationPreferenceController.isOverlayPackageAvailable(context,
|
||||
NAV_BAR_MODE_3BUTTON_OVERLAY)) {
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.title = res.getString(R.string.legacy_navigation_title);
|
||||
data.key = KEY_SYSTEM_NAV_3BUTTONS;
|
||||
result.add(data);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
// From HelpResourceProvider
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.app.LocalePickerWithRegion;
|
||||
@@ -49,6 +50,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||
private LocalePickerWithRegion mLocalePickerWithRegion;
|
||||
private AppLocaleDetails mAppLocaleDetails;
|
||||
private Context mContextAsUser;
|
||||
private View mAppLocaleDetailContainer;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -82,7 +84,7 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||
false /* translate only */,
|
||||
mPackageName);
|
||||
mAppLocaleDetails = AppLocaleDetails.newInstance(mPackageName);
|
||||
|
||||
mAppLocaleDetailContainer = launchAppLocaleDetailsPage();
|
||||
// Launch Locale picker part.
|
||||
launchLocalePickerPage();
|
||||
}
|
||||
@@ -134,12 +136,14 @@ public class AppLocalePickerActivity extends SettingsBaseActivity
|
||||
fragmentManager.registerFragmentLifecycleCallbacks(
|
||||
new android.app.FragmentManager.FragmentLifecycleCallbacks() {
|
||||
@Override
|
||||
public void onFragmentResumed(
|
||||
public void onFragmentViewCreated(
|
||||
android.app.FragmentManager fm,
|
||||
android.app.Fragment f) {
|
||||
super.onFragmentResumed(fm, f);
|
||||
mLocalePickerWithRegion.getListView()
|
||||
.addHeaderView(launchAppLocaleDetailsPage());
|
||||
android.app.Fragment f, View v, Bundle s) {
|
||||
super.onFragmentViewCreated(fm, f, v, s);
|
||||
ListView listView = (ListView) v.findViewById(android.R.id.list);
|
||||
if (listView != null) {
|
||||
listView.addHeaderView(mAppLocaleDetailContainer);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
fragmentManager.beginTransaction()
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import static android.app.NotificationManager.EXTRA_AUTOMATIC_RULE_ID;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -79,7 +81,8 @@ abstract public class AbstractZenModeAutomaticRulePreferenceController extends
|
||||
ComponentName configurationActivity, String ruleId) {
|
||||
final Intent intent = new Intent()
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(ConditionProviderService.EXTRA_RULE_ID, ruleId);
|
||||
.putExtra(ConditionProviderService.EXTRA_RULE_ID, ruleId)
|
||||
.putExtra(EXTRA_AUTOMATIC_RULE_ID, ruleId);
|
||||
if (configurationActivity != null) {
|
||||
intent.setComponent(configurationActivity);
|
||||
} else {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import static android.app.NotificationManager.EXTRA_AUTOMATIC_RULE_ID;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
@@ -72,9 +74,12 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
|
||||
mId = intent.getStringExtra(ConditionProviderService.EXTRA_RULE_ID);
|
||||
if (mId == null) {
|
||||
Log.w(TAG, "rule id is null");
|
||||
toastAndFinish();
|
||||
return;
|
||||
mId = intent.getStringExtra(EXTRA_AUTOMATIC_RULE_ID);
|
||||
if (mId == null) {
|
||||
Log.w(TAG, "rule id is null");
|
||||
toastAndFinish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG) Log.d(TAG, "mId=" + mId);
|
||||
|
||||
@@ -661,10 +661,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
|
||||
}
|
||||
|
||||
private void assertSafeToStartCustomActivity(Intent intent) {
|
||||
// Activity can be started if it belongs to the same app
|
||||
if (intent.getPackage() != null && intent.getPackage().equals(packageName)) {
|
||||
return;
|
||||
}
|
||||
EventLog.writeEvent(0x534e4554, "223578534", -1 /* UID */, "");
|
||||
ResolveInfo resolveInfo = mPackageManager.resolveActivity(
|
||||
intent, PackageManager.MATCH_DEFAULT_ONLY);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.wifi.tether;
|
||||
|
||||
import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
|
||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
@@ -32,7 +31,6 @@ import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -79,8 +77,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
TetherChangeReceiver mTetherChangeReceiver;
|
||||
|
||||
static {
|
||||
TETHER_STATE_CHANGE_FILTER = new IntentFilter(ACTION_TETHER_STATE_CHANGED);
|
||||
TETHER_STATE_CHANGE_FILTER.addAction(WIFI_AP_STATE_CHANGED_ACTION);
|
||||
TETHER_STATE_CHANGE_FILTER = new IntentFilter(WIFI_AP_STATE_CHANGED_ACTION);
|
||||
}
|
||||
|
||||
public WifiTetherSettings() {
|
||||
@@ -269,12 +266,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
String action = intent.getAction();
|
||||
Log.d(TAG, "updating display config due to receiving broadcast action " + action);
|
||||
updateDisplayWithNewConfig();
|
||||
if (action.equals(ACTION_TETHER_STATE_CHANGED)) {
|
||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
startTether();
|
||||
}
|
||||
} else if (action.equals(WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||
if (action.equals(WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0);
|
||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
||||
&& mRestartWifiApAfterConfigChange) {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
|
||||
import com.android.settings.accessibility.TextReadingResetController.ResetStateListener;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tests for {@link TextReadingPreferenceFragment}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TextReadingPreferenceFragmentTest {
|
||||
private TextReadingPreferenceFragment mFragment;
|
||||
private Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext.setTheme(R.style.Theme_AppCompat);
|
||||
|
||||
mFragment = spy(new TextReadingPreferenceFragment());
|
||||
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.getActivity()).thenReturn(Robolectric.setupActivity(FragmentActivity.class));
|
||||
|
||||
// Avoid a NPE is happened in ShadowWindowManagerGlobal
|
||||
doReturn(mock(DisplaySizeData.class)).when(mFragment).createDisplaySizeData(mContext);
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDialogPositiveButtonClicked_boldTextEnabled_needResetSettings() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, BOLD_TEXT_ADJUSTMENT);
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(
|
||||
DialogEnums.DIALOG_RESET_SETTINGS);
|
||||
dialog.show();
|
||||
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
|
||||
|
||||
assertThat(mFragment.mNeedResetSettings).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDialogPositiveButtonClicked_boldTextDisabled_resetAllListeners() {
|
||||
final ResetStateListener listener1 = mock(ResetStateListener.class);
|
||||
final ResetStateListener listener2 = mock(ResetStateListener.class);
|
||||
mFragment.mResetStateListeners = new ArrayList<>(Arrays.asList(listener1, listener2));
|
||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(
|
||||
DialogEnums.DIALOG_RESET_SETTINGS);
|
||||
dialog.show();
|
||||
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
|
||||
|
||||
verify(listener1).resetState();
|
||||
verify(listener2).resetState();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.provider.SettingsSlicesContract;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -75,6 +76,24 @@ public class BatterySaverButtonPreferenceControllerTest {
|
||||
.isEqualTo(SettingsSlicesContract.AUTHORITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwitchChanged_isCheckedButNotAcked_preferenceIsUnchecked() {
|
||||
setLowPowerWarningAcked(/* acked= */ 0);
|
||||
|
||||
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ true);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSwitchChanged_isCheckedAndAcked_setPowerSaveMode() {
|
||||
setLowPowerWarningAcked(/* acked= */ 1);
|
||||
|
||||
mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ true);
|
||||
|
||||
verify(mPowerManager).setPowerSaveModeEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_lowPowerOn_preferenceIsChecked() {
|
||||
when(mPowerManager.isPowerSaveMode()).thenReturn(true);
|
||||
@@ -126,4 +145,12 @@ public class BatterySaverButtonPreferenceControllerTest {
|
||||
public void isPublicSlice_returnsTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
|
||||
// 0 means not acked, 1 means acked.
|
||||
private void setLowPowerWarningAcked(int acked) {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.LOW_POWER_WARNING_ACKNOWLEDGED,
|
||||
acked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -41,10 +42,14 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -67,6 +72,8 @@ public class SystemNavigationGestureSettingsTest {
|
||||
@Mock
|
||||
private IOverlayManager mOverlayManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private OverlayInfo mOverlayInfoEnabled;
|
||||
@Mock
|
||||
private OverlayInfo mOverlayInfoDisabled;
|
||||
@@ -75,16 +82,17 @@ public class SystemNavigationGestureSettingsTest {
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mSettings = new SystemNavigationGestureSettings();
|
||||
|
||||
when(mOverlayInfoDisabled.isEnabled()).thenReturn(false);
|
||||
when(mOverlayInfoEnabled.isEnabled()).thenReturn(true);
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(mOverlayInfoDisabled);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
public void searchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
SystemNavigationGestureSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.application, true /* enabled */);
|
||||
@@ -93,6 +101,29 @@ public class SystemNavigationGestureSettingsTest {
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndexProvider_gesturePackageExist_shouldBeIndexed()
|
||||
throws NameNotFoundException {
|
||||
PackageInfo info = new PackageInfo();
|
||||
when(mPackageManager.getPackageInfo(NAV_BAR_MODE_GESTURAL_OVERLAY, 0))
|
||||
.thenReturn(info);
|
||||
|
||||
final List<SearchIndexableRaw> indexRaws =
|
||||
SystemNavigationGestureSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getRawDataToIndex(mContext, true /* enabled */);
|
||||
|
||||
assertThat(indexRaws).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchIndexProvider_noNavigationPackageExist_shouldReturnEmpty() {
|
||||
final List<SearchIndexableRaw> indexRaws =
|
||||
SystemNavigationGestureSettings.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getRawDataToIndex(mContext, true /* enabled */);
|
||||
|
||||
assertThat(indexRaws).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentSystemNavigationMode() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.notification.zen;
|
||||
|
||||
import static android.app.NotificationManager.EXTRA_AUTOMATIC_RULE_ID;
|
||||
import static android.service.notification.ConditionProviderService.EXTRA_RULE_ID;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -24,6 +27,7 @@ import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ComponentInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
@@ -166,4 +170,21 @@ public class AbstractZenModeAutomaticRulePreferenceControllerTest {
|
||||
|
||||
assertThat(actual).isEqualTo(new ComponentName(mContext.getPackageName(), "activity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRuleIntent() throws Exception {
|
||||
AutomaticZenRule rule = new AutomaticZenRule("name", null,
|
||||
new ComponentName(mContext.getPackageName(), "test"), Uri.EMPTY,
|
||||
new ZenPolicy(), NotificationManager.INTERRUPTION_FILTER_PRIORITY, true);
|
||||
rule.setPackageName(mContext.getPackageName());
|
||||
|
||||
when(mPm.getPackageUid(null, 0)).thenReturn(-1);
|
||||
when(mPm.getPackageUid(mContext.getPackageName(), 0)).thenReturn(1);
|
||||
|
||||
Intent intent = AbstractZenModeAutomaticRulePreferenceController
|
||||
.getRuleIntent(null, rule.getConfigurationActivity(), "id");
|
||||
|
||||
assertThat("id").isEqualTo(intent.getStringExtra(EXTRA_RULE_ID));
|
||||
assertThat("id").isEqualTo(intent.getStringExtra(EXTRA_AUTOMATIC_RULE_ID));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user