Snap for 6489494 from 7387ba02cc to mainline-release

Change-Id: I75493e1524f75bf8268aa5a29ae1bb84c5f34c99
This commit is contained in:
android-build-team Robot
2020-05-13 07:07:05 +00:00
22 changed files with 170 additions and 258 deletions

View File

@@ -36,6 +36,7 @@
android:layout_height="wrap_content"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
android:textColor="?android:attr/textColorPrimary"
android:textAlignment="center"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />

View File

@@ -4944,7 +4944,7 @@
<string name="accessibility_screen_magnification_navbar_summary">When magnification is turned on, you can zoom in on your screen.\n\n<b>To zoom</b>, start magnification, then tap anywhere on the screen.\n<ul><li>Drag 2 or more fingers to scroll</li>\n<li>Pinch 2 or more fingers to adjust zoom</li></ul>\n\n<b>To zoom temporarily</b>, start magnification, then touch &amp; hold anywhere on the screen.\n<ul><li>Drag to move around the screen</li>\n<li>Lift finger to zoom out</li></ul>\n\nYou cant zoom in on the keyboard or navigation bar.</string>
<!-- Title for the accessibility tutorial dialog in accessibility service with button. [CHAR LIMIT=50] -->
<string name="accessibility_tutorial_dialog_title_button">Use accessibility button to open</string>
<!-- Title for the accessibility tutorial dialog in accessibility service with volume keys. [CHAR LIMIT=50] -->
<!-- Title for the accessibility tutorial dialog in accessibility service with volume keys. [CHAR LIMIT=100] -->
<string name="accessibility_tutorial_dialog_title_volume">Hold volume keys to open</string>
<!-- Title for the accessibility tutorial dialog in accessibility service with triple tap. [CHAR LIMIT=100] -->
<string name="accessibility_tutorial_dialog_title_triple">Triple tap screen to open</string>
@@ -8197,8 +8197,6 @@
<!-- Configure Notifications: Title for the notification bubbles option. [CHAR LIMIT=60] -->
<string name="notification_bubbles_title">Bubbles</string>
<!-- Developer setting summary for bubbles [CHAR LIMIT=NONE] -->
<string name="notification_bubbles_developer_setting_summary">Some notifications can appear as bubbles on the screen</string>
<!-- Feature education for bubbles. [CHAR LIMIT=NONE] -->
<string name="bubbles_feature_education">Some notifications and other content can appear as bubbles on the screen. To open a bubble, tap it. To dismiss it, drag it down the screen.</string>
<!-- Title for the toggle shown on the app-level bubbles page [CHAR LIMIT=60] -->
@@ -8666,7 +8664,7 @@
<!-- Settings text. This text lets a user know that they should only connect work and personal apps
if they trust the work app with their personal data. The work app could potentially show that data
to the user's IT admin. [CHAR LIMIT=NONE] -->
<string name="interact_across_profiles_summary_2">Only connect apps that you trust with your personal data. Work apps may expose your data to your IT admin.</string>
<string name="interact_across_profiles_summary_2">Only connect apps if you trust them not to share personal data with your IT admin.</string>
<!-- Dialog title. This dialog is shown when a user tries to connect a work app to a personal
app (e.g. their work Calendar to their personal Calendar), and it's confirming that they should
@@ -8677,7 +8675,7 @@
app (e.g. their work Calendar to their personal Calendar), and it's confirming that they should
connect the apps only if they trust the work app with their personal data.
The placeholder is the app name. [CHAR LIMIT=NONE] -->
<string name="interact_across_profiles_consent_dialog_summary"><xliff:g id="name" example="Calendar">%1$s</xliff:g> may expose your personal data to your IT admin.</string>
<string name="interact_across_profiles_consent_dialog_summary">Only connect apps if you trust them not to share personal data with your IT admin.</string>
<!-- Title of a section in a dialog. This section shows the app data that will be
accessible when work and personal apps are connected. [CHAR LIMIT=NONE] -->
@@ -8708,12 +8706,12 @@
<!-- Banner title. This banner lets a user know that they need to install an app in their
work profile in order to connect it to the corresponding personal app.
The placeholder would be the app name (e.g. Calendar). [CHAR LIMIT=NONE]-->
<string name="interact_across_profiles_install_work_app_title">Install work <xliff:g id="name" example="Calendar">%1$s</xliff:g> to connect these apps</string>
<string name="interact_across_profiles_install_work_app_title">To connect these apps, install <xliff:g id="name" example="Calendar">%1$s</xliff:g> in your work profile</string>
<!-- Banner title. This banner lets a user know that they need to install an app in their
personal profile in order to connect it to the corresponding work app.
The placeholder would be the app name (e.g. Calendar). [CHAR LIMIT=NONE]-->
<string name="interact_across_profiles_install_personal_app_title">Install personal <xliff:g id="name" example="Calendar">%1$s</xliff:g> to connect these apps</string>
<string name="interact_across_profiles_install_personal_app_title">To connect these apps, install <xliff:g id="name" example="Calendar">%1$s</xliff:g> in your personal profile</string>
<!-- Banner text. This banner lets a user know that they need to install an app in their
work/personal profile in order to connect it to the corresponding personal app.
@@ -11820,11 +11818,6 @@
<!-- Summary for the top level Privacy Settings [CHAR LIMIT=NONE]-->
<string name="privacy_dashboard_summary">Permissions, account activity, personal data</string>
<!-- UI debug setting: show media player on quick settings title [CHAR LIMIT=60] -->
<string name="quick_settings_media_player">Media resumption</string>
<!-- UI debug setting: show media player on quick settings summary [CHAR_LIMIT=NONE] -->
<string name="quick_settings_media_player_summary">Shows and persists media player in Quick Settings. Requires reboot.</string>
<!-- Label for button in contextual card for users to remove the card [CHAR LIMIT=30] -->
<string name="contextual_card_dismiss_remove">Remove</string>
<!-- Label for button in contextual card for users to keep the card [CHAR LIMIT=30] -->

View File

@@ -501,6 +501,11 @@
<item name="rowStyle">@style/SliceRow.Settings</item>
</style>
<style name="Widget.SliceView.ContextualCard">
<item name="rowStyle">@style/SliceRow</item>
<item name="android:background">@color/contextual_card_background</item>
</style>
<style name="Widget.SliceView.Panel">
<item name="titleSize">16sp</item>
<item name="rowStyle">@style/SliceRow</item>
@@ -511,35 +516,6 @@
<item name="rowStyle">@style/SliceRow.Slider</item>
</style>
<style name="SliceRow.Slider">
<!-- 2dp start padding for the start icon -->
<item name="titleItemStartPadding">10dp</item>
<item name="titleItemEndPadding">0dp</item>
<!-- Padding between content and the start icon is 14dp -->
<item name="contentStartPadding">5dp</item>
<!-- Padding between content and end items is 16dp -->
<item name="contentEndPadding">16dp</item>
<!-- Both side margins of end item are 16dp -->
<item name="endItemStartPadding">0dp</item>
<item name="endItemEndPadding">24dp</item>
<!-- Both side margins of bottom divider are 12dp -->
<item name="bottomDividerStartPadding">12dp</item>
<item name="bottomDividerEndPadding">12dp</item>
<item name="actionDividerHeight">32dp</item>
<!-- Align text with slider -->
<item name="titleStartPadding">6dp</item>
<item name="subContentStartPadding">6dp</item>
</style>
<style name="Widget.SliceView.ContextualCard">
<item name="rowStyle">@style/SliceRow</item>
<item name="android:background">@color/contextual_card_background</item>
</style>
<style name="SliceRow">
<!-- 2dp start padding for the start icon -->
<item name="titleItemStartPadding">2dp</item>
@@ -566,6 +542,23 @@
<item name="contentStartPadding">8dp</item>
</style>
<style name="SliceRow.Slider">
<!-- 10dp start padding for the start icon -->
<item name="titleItemStartPadding">10dp</item>
<!-- Padding between content and the start icon is 5dp -->
<item name="contentStartPadding">5dp</item>
<!-- 0dp start padding for the end item -->
<item name="endItemStartPadding">0dp</item>
<!-- 24dp end padding for the end item -->
<item name="endItemEndPadding">24dp</item>
<!-- Align text with slider -->
<item name="titleStartPadding">6dp</item>
<item name="subContentStartPadding">6dp</item>
</style>
<style name="DisclaimerPositiveButton" parent="@style/SudGlifButton.Primary">
<item name="android:layout_margin">16dp</item>
<item name="android:paddingStart">8dp</item>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false"
android:title="@string/accessibility_display_inversion_preference_title">
</PreferenceScreen>

View File

@@ -527,11 +527,6 @@
android:title="@string/usb_audio_disable_routing"
android:summary="@string/usb_audio_disable_routing_summary" />
<SwitchPreference
android:key="quick_settings_media_player"
android:title="@string/quick_settings_media_player"
android:summary="@string/quick_settings_media_player_summary" />
</PreferenceCategory>
<PreferenceCategory
@@ -638,12 +633,6 @@
<Preference
android:key="reset_shortcut_manager_throttling"
android:title="@string/reset_shortcut_manager_throttling" />
<SwitchPreference
android:key="notification_bubbles"
android:title="@string/notification_bubbles_title"
android:summary="@string/notification_bubbles_developer_setting_summary"/>
</PreferenceCategory>
<com.android.settings.development.autofill.AutofillPreferenceCategory

View File

@@ -56,6 +56,11 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
Settings.Secure.putInt(getContentResolver(), ENABLED, enabled ? ON : OFF);
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_color_inversion_settings;
}
@Override
protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchPreferenceToggleSwitch();

View File

@@ -30,6 +30,7 @@ import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.Html;
@@ -96,6 +97,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private int mUserShortcutTypes = UserShortcutType.EMPTY;
private CheckBox mSoftwareTypeCheckBox;
private CheckBox mHardwareTypeCheckBox;
private SettingsContentObserver mSettingsContentObserver;
// For html description of accessibility service, must follow the rule, such as
// <img src="R.drawable.fileName"/>, a11y settings will get the resources successfully.
@@ -133,6 +135,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
removeDialog(DialogEnums.EDIT_SHORTCUT);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
};
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();
}
};
return super.onCreateView(inflater, container, savedInstanceState);
}
@@ -229,6 +242,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final AccessibilityManager am = getPrefContext().getSystemService(
AccessibilityManager.class);
am.addTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
mSettingsContentObserver.register(getContentResolver());
updateShortcutPreferenceData();
updateShortcutPreference();
}
@@ -238,6 +252,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final AccessibilityManager am = getPrefContext().getSystemService(
AccessibilityManager.class);
am.removeTouchExplorationStateChangeListener(mTouchExplorationStateChangeListener);
mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}
@@ -618,7 +633,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
getShortcutTypeSummary(getPrefContext()));
}
private void updateShortcutPreferenceData() {
protected void updateShortcutPreferenceData() {
if (mComponentName == null) {
return;
}
@@ -651,7 +666,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
mShortcutPreference.setTitle(title);
}
private void updateShortcutPreference() {
protected void updateShortcutPreference() {
if (mComponentName == null) {
return;
}

View File

@@ -467,7 +467,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
showDialog(DialogEnums.MAGNIFICATION_EDIT_SHORTCUT);
}
private void updateShortcutPreferenceData() {
@Override
protected void updateShortcutPreferenceData() {
// Get the user shortcut type from settings provider.
mUserShortcutType = getUserShortcutTypeFromSettings(getPrefContext());
if (mUserShortcutType != UserShortcutType.EMPTY) {
@@ -489,7 +490,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
mShortcutPreference.setTitle(title);
}
private void updateShortcutPreference() {
@Override
protected void updateShortcutPreference() {
final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
mShortcutPreference.setChecked(
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));

View File

@@ -255,11 +255,6 @@ public class InteractAcrossProfilesDetails extends AppInfoBase
dialogTitle.setText(
getString(R.string.interact_across_profiles_consent_dialog_title, mAppLabel));
final TextView dialogSummary = dialogView.findViewById(
R.id.interact_across_profiles_consent_dialog_summary);
dialogSummary.setText(
getString(R.string.interact_across_profiles_consent_dialog_summary, mAppLabel));
final TextView appDataSummary = dialogView.findViewById(R.id.app_data_summary);
appDataSummary.setText(getString(
R.string.interact_across_profiles_consent_dialog_app_data_summary, mAppLabel));

View File

@@ -496,7 +496,6 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new DebugNonRectClipOperationsPreferenceController(context));
controllers.add(new ForceDarkPreferenceController(context));
controllers.add(new EnableBlursPreferenceController(context));
controllers.add(new QuickSettingsMediaPlayerPreferenceController(context));
controllers.add(new ForceMSAAPreferenceController(context));
controllers.add(new HardwareOverlaysPreferenceController(context));
controllers.add(new SimulateColorSpacePreferenceController(context));

View File

@@ -1,73 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import android.content.Context;
import android.provider.Settings;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
/**
* Controls whether the media player should be visible in quick settings.
*/
public class QuickSettingsMediaPlayerPreferenceController extends
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
private static final String PREFERENCE_KEY = "quick_settings_media_player";
@VisibleForTesting
static final String SETTING_NAME = Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS;
@VisibleForTesting
static final int SETTING_VALUE_ON = 1;
@VisibleForTesting
static final int SETTING_VALUE_OFF = 0;
public QuickSettingsMediaPlayerPreferenceController(Context context) {
super(context);
}
@Override
public String getPreferenceKey() {
return PREFERENCE_KEY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isEnabled = (Boolean) newValue;
Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME,
isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
return true;
}
@Override
public void updateState(Preference preference) {
final int mode = Settings.Global.getInt(mContext.getContentResolver(), SETTING_NAME,
SETTING_VALUE_OFF);
((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF);
((SwitchPreference) mPreference).setChecked(false);
}
}

View File

@@ -74,7 +74,7 @@ public class NightDisplayAutoModePreferenceController extends BasePreferenceCont
if (String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT).equals(newValue)
&& !mLocationManager.isLocationEnabled()) {
TwilightLocationDialog.show(mContext);
return false;
return true;
}
return mColorDisplayManager.setNightDisplayAutoMode(Integer.parseInt((String) newValue));
}

View File

@@ -33,7 +33,7 @@ import com.android.settings.display.TwilightLocationDialog;
*/
public class DarkModeScheduleSelectorController extends BasePreferenceController
implements Preference.OnPreferenceChangeListener {
private static final String TAG = DarkModeScheduleSelectorController.class.getSimpleName();
private final UiModeManager mUiModeManager;
private PowerManager mPowerManager;
private DropDownPreference mPreference;
@@ -51,7 +51,6 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
init();
}
@Override
@@ -59,7 +58,8 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
return BasePreferenceController.AVAILABLE;
}
private void init() {
@Override
public final void updateState(Preference preference) {
final boolean batterySaver = mPowerManager.isPowerSaveMode();
mPreference.setEnabled(!batterySaver);
mCurrentMode = getCurrentMode();
@@ -87,25 +87,25 @@ public class DarkModeScheduleSelectorController extends BasePreferenceController
if (newMode == mCurrentMode) {
return false;
}
mCurrentMode = newMode;
if (mCurrentMode == mPreference.findIndexOfValue(
if (newMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_never))) {
boolean active = (mContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_YES) != 0;
int mode = active ? UiModeManager.MODE_NIGHT_YES
: UiModeManager.MODE_NIGHT_NO;
mUiModeManager.setNightMode(mode);
} else if (mCurrentMode == mPreference.findIndexOfValue(
} else if (newMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_auto))) {
if (!mLocationManager.isLocationEnabled()) {
TwilightLocationDialog.show(mContext);
return false;
return true;
}
mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_AUTO);
} else if (mCurrentMode == mPreference.findIndexOfValue(
} else if (newMode == mPreference.findIndexOfValue(
mContext.getString(R.string.dark_ui_auto_mode_custom))) {
mUiModeManager.setNightMode(UiModeManager.MODE_NIGHT_CUSTOM);
}
mCurrentMode = newMode;
return true;
}
}

View File

@@ -18,6 +18,8 @@ package com.android.settings.network.telephony;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -274,6 +276,7 @@ public class Enhanced4gLteSliceHelper {
*/
private PendingIntent getActivityIntent(String action) {
final Intent intent = new Intent(action);
intent.setPackage(SETTINGS_PACKAGE_NAME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}

View File

@@ -124,6 +124,9 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements
List<Integer> mResultCodeArrayList;
@VisibleForTesting
WifiPickerTracker mWifiPickerTracker;
// Worker thread used for WifiPickerTracker work
@VisibleForTesting
HandlerThread mWorkerThread;
private boolean mIsSingleNetwork;
private boolean mAnyNetworkSavedSuccess;
@@ -133,8 +136,6 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements
private UiConfigurationItemAdapter mUiConfigurationItemAdapter;
private WifiManager.ActionListener mSaveListener;
private WifiManager mWifiManager;
// Worker thread used for WifiPickerTracker work
private HandlerThread mWorkerThread;
private final Handler mHandler = new Handler() {
@Override
@@ -202,6 +203,13 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements
return inflater.inflate(R.layout.wifi_add_app_networks, container, false);
}
@Override
public void onDestroy() {
mWorkerThread.quit();
super.onDestroy();
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

View File

@@ -20,6 +20,7 @@ import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static com.android.settings.slices.CustomSliceRegistry.WIFI_CALLING_PREFERENCE_URI;
import static com.android.settings.slices.CustomSliceRegistry.WIFI_CALLING_URI;
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import android.app.PendingIntent;
import android.content.ComponentName;
@@ -554,6 +555,7 @@ public class WifiCallingSliceHelper {
*/
private PendingIntent getActivityIntent(String action) {
final Intent intent = new Intent(action);
intent.setPackage(SETTINGS_PACKAGE_NAME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}

View File

@@ -56,6 +56,7 @@ import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowAppUtils;
import com.android.settings.testutils.shadow.ShadowUserManager;
import com.android.settings.widget.LoadingViewController;
import com.android.settingslib.applications.ApplicationsState;
@@ -76,7 +77,7 @@ import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowUserManager.class)
@Config(shadows = {ShadowUserManager.class, ShadowAppUtils.class})
public class ManageApplicationsTest {
@Mock

View File

@@ -1,111 +0,0 @@
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development;
import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_NAME;
import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_OFF;
import static com.android.settings.development.QuickSettingsMediaPlayerPreferenceController.SETTING_VALUE_ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class QuickSettingsMediaPlayerPreferenceControllerTest {
@Mock
private SwitchPreference mPreference;
@Mock
private PreferenceScreen mPreferenceScreen;
@Rule
public MockitoRule mMockitoRule = MockitoJUnit.rule();
private Context mContext;
private QuickSettingsMediaPlayerPreferenceController mController;
@Before
public void setup() {
mContext = RuntimeEnvironment.application;
mController = new QuickSettingsMediaPlayerPreferenceController(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
}
@Test
public void onPreferenceChanged_turnOnPreference_shouldEnable() {
mController.onPreferenceChange(mPreference, true /* new value */);
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
SETTING_NAME, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_ON);
}
@Test
public void onPreferenceChanged_turnOffPreference_shouldDisable() {
mController.onPreferenceChange(mPreference, false /* new value */);
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
SETTING_NAME, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
}
@Test
public void updateState_settingEnabled_preferenceShouldBeChecked() {
Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_ON);
mController.updateState(mPreference);
verify(mPreference).setChecked(true);
}
@Test
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
Settings.Global.putInt(mContext.getContentResolver(), SETTING_NAME, SETTING_VALUE_OFF);
mController.updateState(mPreference);
verify(mPreference).setChecked(false);
}
@Test
public void onDeveloperOptionsSwitchDisabled_shouldDisable() {
mController.onDeveloperOptionsSwitchDisabled();
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
SETTING_NAME, -1 /* default */);
assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
verify(mPreference).setEnabled(false);
verify(mPreference).setChecked(false);
}
}

View File

@@ -20,6 +20,7 @@ import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_TITLE;
import static android.app.slice.SliceItem.FORMAT_TEXT;
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -248,6 +249,7 @@ public class Enhanced4gLteSliceHelperTest {
private PendingIntent getActivityIntent(String action) {
final Intent intent = new Intent(action);
intent.setPackage(SETTINGS_PACKAGE_NAME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2020 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.testutils.shadow;
import android.content.Context;
import com.android.settingslib.applications.AppUtils;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import java.util.HashMap;
import java.util.Map;
@Implements(AppUtils.class)
public class ShadowAppUtils {
private static Map<String, String> sAppContentDesMap;
@Implementation
protected static CharSequence getAppContentDescription(Context context, String packageName,
int userId) {
if (sAppContentDesMap != null) {
return sAppContentDesMap.get(packageName);
}
return null;
}
public static void setAppContentDescription(String packageName, String appContentDes) {
if (sAppContentDesMap == null) {
sAppContentDesMap = new HashMap<>();
}
sAppContentDesMap.put(packageName, appContentDes);
}
}

View File

@@ -19,7 +19,9 @@ package com.android.settings.wifi.addappnetworks;
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.app.settings.SettingsEnums;
@@ -27,6 +29,7 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkSuggestion;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Parcelable;
import android.provider.Settings;
import android.widget.TextView;
@@ -247,6 +250,19 @@ public class AddAppNetworksFragmentTest {
SCANED_LEVEL0);
}
@Test
public void onDestroy_quitWorkerThread() {
mAddAppNetworksFragment.mWorkerThread = mock(HandlerThread.class);
try {
mAddAppNetworksFragment.onDestroy();
} catch (IllegalArgumentException e) {
// Ignore the exception from super class.
}
verify(mAddAppNetworksFragment.mWorkerThread).quit();
}
private void setUpOneScannedNetworkWithScanedLevel4() {
final ArrayList list = new ArrayList<>();
list.add(mMockWifiEntry);

View File

@@ -20,6 +20,7 @@ import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_TITLE;
import static android.app.slice.SliceItem.FORMAT_TEXT;
import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -400,6 +401,7 @@ public class WifiCallingSliceHelperTest {
private PendingIntent getActivityIntent(String action) {
final Intent intent = new Intent(action);
intent.setPackage(SETTINGS_PACKAGE_NAME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
}