Snap for 8090552 from 423ea1825f to tm-release

Change-Id: Id48015b623096c1bb8189086bfcce63475c321ba
This commit is contained in:
Android Build Coastguard Worker
2022-01-19 02:09:19 +00:00
78 changed files with 1282 additions and 215 deletions

View File

@@ -197,11 +197,24 @@
<!-- Whether or not to show the night light suggestion. --> <!-- Whether or not to show the night light suggestion. -->
<bool name="config_night_light_suggestion_enabled">true</bool> <bool name="config_night_light_suggestion_enabled">true</bool>
<!-- Whether or not the device is capable of multiple levels of vibration intensity. <!-- The number of vibration intensity levels supported by the device.
Note that this is different from whether it can control the vibration amplitude as some
devices will be able to vary their amplitude but do not possess enough dynamic range to Note that this should correspond to the ability to vary the vibration amplitude, with
have distinct intensity levels --> enough dynamic range to have at least as many distinct intensity levels as defined here.
<bool name="config_vibration_supports_multiple_intensities">false</bool>
Supported values are 1, 2, 3. If '1', the settings app will use a toggle for the settings,
otherwise a slider. If '3', the settings app maps intensities directly to the levels
supported by the Vibrator HAL APIs. If '2', then the levels will be mapped to
VIBRATION_INTENSITY_LOW and VIBRATION_INTENSITY_HIGH, which gives the most range for
scaling vibrations. The medium intensity will be skipped.
The default intensity values are configured at
frameworks/base/core/res/res/values/config.xml's config_default[type]VibrationIntensity.
Make sure that each default intensity value is consistent with the supported levels set
here. If this settings supports only 2 levels, for example, then the default intensity
should be either LOW (1) or HIGH (3).
-->
<integer name="config_vibration_supported_intensity_levels">1</integer>
<!-- <!--
Whether or not the homepage should be powered by legacy suggestion (versus contextual cards) Whether or not the homepage should be powered by legacy suggestion (versus contextual cards)

View File

@@ -5461,6 +5461,10 @@
<string name="accessibility_notification_alarm_vibration_category_title">Notifications and alarms</string> <string name="accessibility_notification_alarm_vibration_category_title">Notifications and alarms</string>
<!-- Title for the category of preferences to configure device vibrations triggered by user interaction with the device. [CHAR LIMIT=NONE] --> <!-- Title for the category of preferences to configure device vibrations triggered by user interaction with the device. [CHAR LIMIT=NONE] -->
<string name="accessibility_interactive_haptics_category_title">Interactive haptics</string> <string name="accessibility_interactive_haptics_category_title">Interactive haptics</string>
<!-- Title for preference for configuring alarm vibrations. [CHAR LIMIT=NONE] -->
<string name="accessibility_alarm_vibration_title">Alarm vibration</string>
<!-- Title for preference for configuring media vibrations (e.g. vibrations played together with animations, music, videos, etc). [CHAR LIMIT=NONE] -->
<string name="accessibility_media_vibration_title">Media vibration</string>
<!-- Title for accessibility preference for configuring ring vibrations. [CHAR LIMIT=NONE] --> <!-- Title for accessibility preference for configuring ring vibrations. [CHAR LIMIT=NONE] -->
<string name="accessibility_ring_vibration_title">Ring vibration</string> <string name="accessibility_ring_vibration_title">Ring vibration</string>
<!-- Title for accessibility preference for configuring notification vibrations. --> <!-- Title for accessibility preference for configuring notification vibrations. -->
@@ -8254,7 +8258,11 @@
<!-- List of synonyms for ring vibration setting (changes whether your phone vibrates when it rings), used to match in settings search [CHAR LIMIT=NONE] --> <!-- List of synonyms for ring vibration setting (changes whether your phone vibrates when it rings), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_ramping_ringer_vibration">haptics, vibrate, phone, call, ring, gradually</string> <string name="keywords_ramping_ringer_vibration">haptics, vibrate, phone, call, ring, gradually</string>
<!-- List of synonyms for notification vibration setting (changes whether your phone vibrates when it shows a notification), used to match in settings search [CHAR LIMIT=NONE] --> <!-- List of synonyms for notification vibration setting (changes whether your phone vibrates when it shows a notification), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_notification_vibration">haptics, vibrate, sensitivity</string> <string name="keywords_notification_vibration">haptics, vibrate, sensitivity, notification</string>
<!-- List of synonyms for alarm vibration setting (changes whether your phone vibrates when an alarm goes off), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_alarm_vibration">haptics, vibrate, sensitivity, alarm</string>
<!-- List of synonyms for media vibration setting (changes whether your phone vibrates as part of a music, animation, video, etc), used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_media_vibration">haptics, vibrate, sensitivity, media</string>
<!-- List of synonyms for vibration and haptics setting, used to match in settings search [CHAR LIMIT=NONE] --> <!-- List of synonyms for vibration and haptics setting, used to match in settings search [CHAR LIMIT=NONE] -->
<string name="keywords_vibration">haptics, vibrate, vibration</string> <string name="keywords_vibration">haptics, vibrate, vibration</string>
<!-- Battery Saver: Search terms for sticky battery saver preference [CHAR_LIMIT=NONE] --> <!-- Battery Saver: Search terms for sticky battery saver preference [CHAR_LIMIT=NONE] -->

View File

@@ -47,6 +47,12 @@
app:keywords="@string/keywords_notification_vibration" app:keywords="@string/keywords_notification_vibration"
app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" /> app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" />
<com.android.settings.widget.SeekBarPreference
android:key="alarm_vibration_preference_screen"
android:title="@string/accessibility_alarm_vibration_title"
app:keywords="@string/keywords_alarm_vibration"
app:controller="com.android.settings.accessibility.AlarmVibrationIntensityPreferenceController" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
@@ -59,6 +65,12 @@
app:keywords="@string/keywords_touch_vibration" app:keywords="@string/keywords_touch_vibration"
app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" /> app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" />
<com.android.settings.widget.SeekBarPreference
android:key="media_vibration_preference_screen"
android:title="@string/accessibility_media_vibration_title"
app:keywords="@string/keywords_media_vibration"
app:controller="com.android.settings.accessibility.MediaVibrationIntensityPreferenceController" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -47,6 +47,12 @@
app:keywords="@string/keywords_notification_vibration" app:keywords="@string/keywords_notification_vibration"
app:controller="com.android.settings.accessibility.NotificationVibrationTogglePreferenceController" /> app:controller="com.android.settings.accessibility.NotificationVibrationTogglePreferenceController" />
<SwitchPreference
android:key="alarm_vibration_preference_screen"
android:title="@string/accessibility_alarm_vibration_title"
app:keywords="@string/keywords_alarm_vibration"
app:controller="com.android.settings.accessibility.AlarmVibrationTogglePreferenceController" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
@@ -59,6 +65,12 @@
app:keywords="@string/keywords_touch_vibration" app:keywords="@string/keywords_touch_vibration"
app:controller="com.android.settings.accessibility.HapticFeedbackTogglePreferenceController" /> app:controller="com.android.settings.accessibility.HapticFeedbackTogglePreferenceController" />
<SwitchPreference
android:key="media_vibration_preference_screen"
android:title="@string/accessibility_media_vibration_title"
app:keywords="@string/keywords_media_vibration"
app:controller="com.android.settings.accessibility.MediaVibrationTogglePreferenceController" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -0,0 +1,50 @@
/*
* 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.Context;
import android.os.VibrationAttributes;
import android.provider.Settings;
/** Preference controller for alarm vibration intensity */
public class AlarmVibrationIntensityPreferenceController
extends VibrationIntensityPreferenceController {
/** General configuration for alarm vibration intensity settings. */
public static final class AlarmVibrationPreferenceConfig extends VibrationPreferenceConfig {
public AlarmVibrationPreferenceConfig(Context context) {
super(context, Settings.System.ALARM_VIBRATION_INTENSITY,
VibrationAttributes.USAGE_ALARM);
}
}
public AlarmVibrationIntensityPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey, new AlarmVibrationPreferenceConfig(context));
}
protected AlarmVibrationIntensityPreferenceController(Context context, String preferenceKey,
int supportedIntensityLevels) {
super(context, preferenceKey, new AlarmVibrationPreferenceConfig(context),
supportedIntensityLevels);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.Context;
import com.android.settings.accessibility.AlarmVibrationIntensityPreferenceController.AlarmVibrationPreferenceConfig;
/** Preference controller for alarm vibration with only a toggle for on/off states. */
public class AlarmVibrationTogglePreferenceController extends VibrationTogglePreferenceController {
public AlarmVibrationTogglePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey, new AlarmVibrationPreferenceConfig(context));
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}

View File

@@ -74,6 +74,12 @@ public class HapticFeedbackIntensityPreferenceController
super(context, preferenceKey, new HapticFeedbackVibrationPreferenceConfig(context)); super(context, preferenceKey, new HapticFeedbackVibrationPreferenceConfig(context));
} }
protected HapticFeedbackIntensityPreferenceController(Context context, String preferenceKey,
int supportedIntensityLevels) {
super(context, preferenceKey, new HapticFeedbackVibrationPreferenceConfig(context),
supportedIntensityLevels);
}
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return AVAILABLE;

View File

@@ -0,0 +1,51 @@
/*
* 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.Context;
import android.os.VibrationAttributes;
import android.provider.Settings;
/** Preference controller for am vibration intensity */
public class MediaVibrationIntensityPreferenceController
extends VibrationIntensityPreferenceController {
/** General configuration for alarm vibration intensity settings. */
public static final class MediaVibrationPreferenceConfig extends VibrationPreferenceConfig {
public MediaVibrationPreferenceConfig(Context context) {
super(context, Settings.System.MEDIA_VIBRATION_INTENSITY,
VibrationAttributes.USAGE_MEDIA);
}
}
public MediaVibrationIntensityPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey, new MediaVibrationPreferenceConfig(context));
}
protected MediaVibrationIntensityPreferenceController(Context context, String preferenceKey,
int supportedIntensityLevels) {
super(context, preferenceKey, new MediaVibrationPreferenceConfig(context),
supportedIntensityLevels);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.Context;
import com.android.settings.accessibility.MediaVibrationIntensityPreferenceController.MediaVibrationPreferenceConfig;
/** Preference controller for alarm vibration with only a toggle for on/off states. */
public class MediaVibrationTogglePreferenceController extends VibrationTogglePreferenceController {
public MediaVibrationTogglePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey, new MediaVibrationPreferenceConfig(context));
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}

View File

@@ -39,6 +39,12 @@ public class NotificationVibrationIntensityPreferenceController
super(context, preferenceKey, new NotificationVibrationPreferenceConfig(context)); super(context, preferenceKey, new NotificationVibrationPreferenceConfig(context));
} }
protected NotificationVibrationIntensityPreferenceController(Context context,
String preferenceKey, int supportedIntensityLevels) {
super(context, preferenceKey, new NotificationVibrationPreferenceConfig(context),
supportedIntensityLevels);
}
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return AVAILABLE;

View File

@@ -71,6 +71,12 @@ public class RingVibrationIntensityPreferenceController
super(context, preferenceKey, new RingVibrationPreferenceConfig(context)); super(context, preferenceKey, new RingVibrationPreferenceConfig(context));
} }
protected RingVibrationIntensityPreferenceController(Context context, String preferenceKey,
int supportedIntensityLevels) {
super(context, preferenceKey, new RingVibrationPreferenceConfig(context),
supportedIntensityLevels);
}
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
return AVAILABLE; return AVAILABLE;

View File

@@ -21,6 +21,7 @@ import android.os.Vibrator;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.SliderPreferenceController; import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.SeekBarPreference; import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -36,13 +37,22 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
protected final VibrationPreferenceConfig mPreferenceConfig; protected final VibrationPreferenceConfig mPreferenceConfig;
private final VibrationPreferenceConfig.SettingObserver mSettingsContentObserver; private final VibrationPreferenceConfig.SettingObserver mSettingsContentObserver;
private final int mMaxIntensity;
protected VibrationIntensityPreferenceController(Context context, String prefkey, protected VibrationIntensityPreferenceController(Context context, String prefkey,
VibrationPreferenceConfig preferenceConfig) { VibrationPreferenceConfig preferenceConfig) {
this(context, prefkey, preferenceConfig,
context.getResources().getInteger(
R.integer.config_vibration_supported_intensity_levels));
}
protected VibrationIntensityPreferenceController(Context context, String prefkey,
VibrationPreferenceConfig preferenceConfig, int supportedIntensityLevels) {
super(context, prefkey); super(context, prefkey);
mPreferenceConfig = preferenceConfig; mPreferenceConfig = preferenceConfig;
mSettingsContentObserver = new VibrationPreferenceConfig.SettingObserver( mSettingsContentObserver = new VibrationPreferenceConfig.SettingObserver(
preferenceConfig); preferenceConfig);
mMaxIntensity = Math.min(Vibrator.VIBRATION_INTENSITY_HIGH, supportedIntensityLevels);
} }
@Override @Override
@@ -74,7 +84,7 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
@Override @Override
public int getMax() { public int getMax() {
return Vibrator.VIBRATION_INTENSITY_HIGH; return mMaxIntensity;
} }
@Override @Override
@@ -85,7 +95,8 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
@Override @Override
public boolean setSliderPosition(int position) { public boolean setSliderPosition(int position) {
final boolean success = mPreferenceConfig.updateIntensity(position); final int intensity = calculateVibrationIntensity(position);
final boolean success = mPreferenceConfig.updateIntensity(intensity);
if (success && (position != Vibrator.VIBRATION_INTENSITY_OFF)) { if (success && (position != Vibrator.VIBRATION_INTENSITY_OFF)) {
mPreferenceConfig.playVibrationPreview(); mPreferenceConfig.playVibrationPreview();
@@ -93,4 +104,19 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
return success; return success;
} }
private int calculateVibrationIntensity(int position) {
int maxPosition = getMax();
if (position >= maxPosition) {
if (maxPosition == 1) {
// If there is only one intensity available besides OFF, then use the device default
// intensity to ensure no scaling will ever happen in the platform.
return mPreferenceConfig.getDefaultIntensity();
}
// If the settings granularity is lower than the platform's then map the max position to
// the highest vibration intensity, skipping intermediate values in the scale.
return Vibrator.VIBRATION_INTENSITY_HIGH;
}
return position;
}
} }

View File

@@ -21,7 +21,6 @@ import android.database.ContentObserver;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.os.VibrationAttributes; import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.DeviceConfig; import android.provider.DeviceConfig;
@@ -37,8 +36,6 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
import com.google.common.annotations.VisibleForTesting;
/** /**
* Preference controller for the ramping ringer setting key, controlled via {@link AudioManager}. * Preference controller for the ramping ringer setting key, controlled via {@link AudioManager}.
* *
@@ -50,9 +47,15 @@ import com.google.common.annotations.VisibleForTesting;
public class VibrationRampingRingerTogglePreferenceController public class VibrationRampingRingerTogglePreferenceController
extends TogglePreferenceController implements LifecycleObserver, OnStart, OnStop { extends TogglePreferenceController implements LifecycleObserver, OnStart, OnStop {
@VisibleForTesting /** Wrapper around static {@link DeviceConfig} accessor for testing. */
static final String DEVICE_CONFIG_KEY = "ramping_ringer_enabled"; protected static class DeviceConfigProvider {
public boolean isRampingRingerEnabledOnTelephonyConfig() {
return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY,
"ramping_ringer_enabled", false);
}
}
private final DeviceConfigProvider mDeviceConfigProvider;
private final ContentObserver mSettingObserver; private final ContentObserver mSettingObserver;
private final Vibrator mVibrator; private final Vibrator mVibrator;
private final AudioManager mAudioManager; private final AudioManager mAudioManager;
@@ -60,10 +63,16 @@ public class VibrationRampingRingerTogglePreferenceController
private Preference mPreference; private Preference mPreference;
public VibrationRampingRingerTogglePreferenceController(Context context, String preferenceKey) { public VibrationRampingRingerTogglePreferenceController(Context context, String preferenceKey) {
this(context, preferenceKey, new DeviceConfigProvider());
}
protected VibrationRampingRingerTogglePreferenceController(Context context,
String preferenceKey, DeviceConfigProvider deviceConfigProvider) {
super(context, preferenceKey); super(context, preferenceKey);
mDeviceConfigProvider = deviceConfigProvider;
mVibrator = context.getSystemService(Vibrator.class); mVibrator = context.getSystemService(Vibrator.class);
mAudioManager = context.getSystemService(AudioManager.class); mAudioManager = context.getSystemService(AudioManager.class);
mSettingObserver = new ContentObserver(new Handler(Looper.getMainLooper())) { mSettingObserver = new ContentObserver(new Handler(/* async= */ true)) {
@Override @Override
public void onChange(boolean selfChange, Uri uri) { public void onChange(boolean selfChange, Uri uri) {
updateState(mPreference); updateState(mPreference);
@@ -74,7 +83,7 @@ public class VibrationRampingRingerTogglePreferenceController
@Override @Override
public int getAvailabilityStatus() { public int getAvailabilityStatus() {
final boolean rampingRingerEnabledOnTelephonyConfig = final boolean rampingRingerEnabledOnTelephonyConfig =
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY, DEVICE_CONFIG_KEY, false); mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig();
return (Utils.isVoiceCapable(mContext) && !rampingRingerEnabledOnTelephonyConfig) return (Utils.isVoiceCapable(mContext) && !rampingRingerEnabledOnTelephonyConfig)
? AVAILABLE ? AVAILABLE
: UNSUPPORTED_ON_DEVICE; : UNSUPPORTED_ON_DEVICE;

View File

@@ -41,9 +41,9 @@ public class VibrationSettings extends DashboardFragment {
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
final boolean supportsMultipleIntensities = getContext().getResources().getBoolean( final int supportedIntensities = getContext().getResources().getInteger(
R.bool.config_vibration_supports_multiple_intensities); R.integer.config_vibration_supported_intensity_levels);
return supportsMultipleIntensities return supportedIntensities > 1
? R.xml.accessibility_vibration_intensity_settings ? R.xml.accessibility_vibration_intensity_settings
: R.xml.accessibility_vibration_settings; : R.xml.accessibility_vibration_settings;
} }

View File

@@ -129,6 +129,35 @@ public class VpnPreferenceController extends AbstractPreferenceController
} }
UserManager userManager = mContext.getSystemService(UserManager.class); UserManager userManager = mContext.getSystemService(UserManager.class);
VpnManager vpnManager = mContext.getSystemService(VpnManager.class); VpnManager vpnManager = mContext.getSystemService(VpnManager.class);
String summary = getInsecureVpnSummaryOverride(userManager, vpnManager);
if (summary == null) {
final UserInfo userInfo = userManager.getUserInfo(UserHandle.myUserId());
final int uid;
if (userInfo.isRestricted()) {
uid = userInfo.restrictedProfileParentId;
} else {
uid = userInfo.id;
}
VpnConfig vpn = vpnManager.getVpnConfig(uid);
if ((vpn != null) && vpn.legacy) {
// Legacy VPNs should do nothing if the network is disconnected. Third-party
// VPN warnings need to continue as traffic can still go to the app.
final LegacyVpnInfo legacyVpn = vpnManager.getLegacyVpnInfo(uid);
if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
vpn = null;
}
}
if (vpn == null) {
summary = mContext.getString(R.string.vpn_disconnected_summary);
} else {
summary = getNameForVpnConfig(vpn, UserHandle.of(uid));
}
}
final String finalSummary = summary;
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(finalSummary));
}
protected int getNumberOfNonLegacyVpn(UserManager userManager, VpnManager vpnManager) {
// Copied from SystemUI::SecurityControllerImpl // Copied from SystemUI::SecurityControllerImpl
SparseArray<VpnConfig> vpns = new SparseArray<>(); SparseArray<VpnConfig> vpns = new SparseArray<>();
final List<UserInfo> users = userManager.getUsers(); final List<UserInfo> users = userManager.getUsers();
@@ -149,38 +178,22 @@ public class VpnPreferenceController extends AbstractPreferenceController
} }
vpns.put(user.id, cfg); vpns.put(user.id, cfg);
} }
int numberOfNonLegacyVpn = vpns.size() - connectedLegacyVpnCount; return vpns.size() - connectedLegacyVpnCount;
String summary = getInsecureVpnSummaryOverride(numberOfNonLegacyVpn);
if (summary == null) {
final UserInfo userInfo = userManager.getUserInfo(UserHandle.myUserId());
final int uid;
if (userInfo.isRestricted()) {
uid = userInfo.restrictedProfileParentId;
} else {
uid = userInfo.id;
}
VpnConfig vpn = vpns.get(uid);
if (vpn == null) {
summary = mContext.getString(R.string.vpn_disconnected_summary);
} else {
summary = getNameForVpnConfig(vpn, UserHandle.of(uid));
}
}
final String finalSummary = summary;
ThreadUtils.postOnMainThread(() -> mPreference.setSummary(finalSummary));
} }
protected String getInsecureVpnSummaryOverride(int numberOfNonLegacyVpn) { protected String getInsecureVpnSummaryOverride(UserManager userManager,
VpnManager vpnManager) {
// Optionally add warning icon if an insecure VPN is present. // Optionally add warning icon if an insecure VPN is present.
if (mPreference instanceof VpnInfoPreference) { if (mPreference instanceof VpnInfoPreference) {
final int insecureVpnCount = getInsecureVpnCount(); final int insecureVpnCount = getInsecureVpnCount();
boolean isInsecureVPN = insecureVpnCount > 0; boolean isInsecureVPN = insecureVpnCount > 0;
((VpnInfoPreference) mPreference).setInsecureVpn(isInsecureVPN); ((VpnInfoPreference) mPreference).setInsecureVpn(isInsecureVPN);
// Set the summary based on the total number of VPNs and insecure VPNs. // Set the summary based on the total number of VPNs and insecure VPNs.
if (isInsecureVPN) { if (isInsecureVPN) {
// Add the users and the number of legacy vpns to determine if there is more than // Add the users and the number of legacy vpns to determine if there is more than
// one vpn, since there can be more than one VPN per user. // one vpn, since there can be more than one VPN per user.
final int vpnCount = numberOfNonLegacyVpn final int vpnCount = getNumberOfNonLegacyVpn(userManager, vpnManager)
+ LegacyVpnProfileStore.list(Credentials.VPN).length; + LegacyVpnProfileStore.list(Credentials.VPN).length;
if (vpnCount == 1) { if (vpnCount == 1) {
return mContext.getString(R.string.vpn_settings_insecure_single); return mContext.getString(R.string.vpn_settings_insecure_single);

View File

@@ -37,6 +37,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.wifi.WifiEnterpriseRestrictionUtils; import com.android.settingslib.wifi.WifiEnterpriseRestrictionUtils;
import com.android.settingslib.wifi.WifiUtils;
import java.util.List; import java.util.List;
@@ -136,9 +137,9 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
if (mPreference != null if (mPreference != null
&& mSoftApState == WifiManager.WIFI_AP_STATE_ENABLED) { && mSoftApState == WifiManager.WIFI_AP_STATE_ENABLED) {
// Only show the number of clients when state is on // Only show the number of clients when state is on
mPreference.setSummary(mContext.getResources().getQuantityString( mPreference.setSummary(
R.plurals.wifi_tether_connected_summary, clients.size(), WifiUtils.getWifiTetherSummaryForConnectedDevices(mContext,
clients.size())); clients.size()));
} }
} }
}); });

View File

@@ -0,0 +1,137 @@
/*
* 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.when;
import android.content.Context;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class AlarmVibrationIntensityPreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key";
@Mock private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
private Context mContext;
private Vibrator mVibrator;
private AlarmVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mContext = ApplicationProvider.getApplicationContext();
mVibrator = mContext.getSystemService(Vibrator.class);
mController = new AlarmVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void verifyConstants() {
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
assertThat(mController.getMin()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(mController.getMax()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
@Test
public void missingSetting_shouldReturnDefault() {
Settings.System.putString(mContext.getContentResolver(),
Settings.System.ALARM_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM));
}
@Test
public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
@Test
public void setProgress_updatesIntensitySetting() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value);
}
private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey);
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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.when;
import android.content.Context;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class AlarmVibrationTogglePreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key";
@Mock private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
private Context mContext;
private Vibrator mVibrator;
private AlarmVibrationTogglePreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mContext = ApplicationProvider.getApplicationContext();
mVibrator = mContext.getSystemService(Vibrator.class);
mController = new AlarmVibrationTogglePreferenceController(mContext, PREFERENCE_KEY);
mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void verifyConstants() {
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void missingSetting_shouldReturnDefault() {
Settings.System.putString(mContext.getContentResolver(),
Settings.System.ALARM_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_shouldDisplayOnOffState() {
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void setChecked_updatesIntensityAndDependentSettings() throws Exception {
updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
mController.setChecked(true);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY)).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM));
mController.setChecked(false);
assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value);
}
private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey);
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -49,10 +47,8 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
private static final int OFF = 0; private static final int OFF = 0;
private static final int ON = 1; private static final int ON = 1;
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -62,16 +58,16 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY); mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -115,27 +111,27 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
@Test @Test
@Ignore @Ignore
public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setProgress_updatesIntensityAndDependentSettings() throws Exception {
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_LOW); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); .isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); .isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_HIGH); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); .isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF);
@@ -148,8 +144,4 @@ public class HapticFeedbackIntensityPreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -49,10 +47,8 @@ public class HapticFeedbackTogglePreferenceControllerTest {
private static final int OFF = 0; private static final int OFF = 0;
private static final int ON = 1; private static final int ON = 1;
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -62,16 +58,15 @@ public class HapticFeedbackTogglePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new HapticFeedbackTogglePreferenceController(mContext, PREFERENCE_KEY); mController = new HapticFeedbackTogglePreferenceController(mContext, PREFERENCE_KEY);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -116,12 +111,12 @@ public class HapticFeedbackTogglePreferenceControllerTest {
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isFalse();
mPreference.setChecked(true); mController.setChecked(true);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH)); .isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH));
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(ON);
mPreference.setChecked(false); mController.setChecked(false);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_ENABLED)).isEqualTo(OFF);
@@ -134,8 +129,4 @@ public class HapticFeedbackTogglePreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -0,0 +1,138 @@
/*
* 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.when;
import android.content.Context;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
/** Test for {@link MediaVibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class MediaVibrationIntensityPreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key";
@Mock private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
private Context mContext;
private Vibrator mVibrator;
private MediaVibrationIntensityPreferenceController mController;
private SeekBarPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mContext = ApplicationProvider.getApplicationContext();
mVibrator = mContext.getSystemService(Vibrator.class);
mController = new MediaVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void verifyConstants() {
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
assertThat(mController.getMin()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(mController.getMax()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
@Test
public void missingSetting_shouldReturnDefault() {
Settings.System.putString(mContext.getContentResolver(),
Settings.System.MEDIA_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_MEDIA));
}
@Test
public void updateState_shouldDisplayIntensityInSliderPosition() {
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
@Test
public void setProgress_updatesIntensitySetting() throws Exception {
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value);
}
private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey);
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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.when;
import android.content.Context;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
/** Test for {@link MediaVibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class MediaVibrationTogglePreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key";
@Mock private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
private Context mContext;
private Vibrator mVibrator;
private MediaVibrationTogglePreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mContext = ApplicationProvider.getApplicationContext();
mVibrator = mContext.getSystemService(Vibrator.class);
mController = new MediaVibrationTogglePreferenceController(mContext, PREFERENCE_KEY);
mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void verifyConstants() {
assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void missingSetting_shouldReturnDefault() {
Settings.System.putString(mContext.getContentResolver(),
Settings.System.MEDIA_VIBRATION_INTENSITY, /* value= */ null);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_shouldDisplayOnOffState() {
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY,
Vibrator.VIBRATION_INTENSITY_MEDIUM);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void setChecked_updatesIntensityAndDependentSettings() throws Exception {
updateSetting(Settings.System.MEDIA_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
mController.setChecked(true);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY)).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_MEDIA));
mController.setChecked(false);
assertThat(readSetting(Settings.System.MEDIA_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value);
}
private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey);
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -47,10 +45,8 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key"; private static final String PREFERENCE_KEY = "preference_key";
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -60,17 +56,16 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new NotificationVibrationIntensityPreferenceController(mContext, mController = new NotificationVibrationIntensityPreferenceController(mContext,
PREFERENCE_KEY); PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -118,19 +113,19 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
@Test @Test
@Ignore @Ignore
public void setProgress_updatesIntensitySetting() throws Exception { public void setProgress_updatesIntensitySetting() throws Exception {
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_LOW); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); .isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); .isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_HIGH); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); .isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
} }
@@ -142,8 +137,4 @@ public class NotificationVibrationIntensityPreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -47,10 +45,8 @@ public class NotificationVibrationTogglePreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key"; private static final String PREFERENCE_KEY = "preference_key";
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -60,16 +56,15 @@ public class NotificationVibrationTogglePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new NotificationVibrationTogglePreferenceController(mContext, PREFERENCE_KEY); mController = new NotificationVibrationTogglePreferenceController(mContext, PREFERENCE_KEY);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -118,11 +113,11 @@ public class NotificationVibrationTogglePreferenceControllerTest {
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isFalse();
mPreference.setChecked(true); mController.setChecked(true);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)).isEqualTo( assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_NOTIFICATION)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_NOTIFICATION));
mPreference.setChecked(false); mController.setChecked(false);
assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.NOTIFICATION_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
} }
@@ -134,8 +129,4 @@ public class NotificationVibrationTogglePreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -50,10 +48,8 @@ public class RingVibrationIntensityPreferenceControllerTest {
private static final int OFF = 0; private static final int OFF = 0;
private static final int ON = 1; private static final int ON = 1;
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -63,16 +59,16 @@ public class RingVibrationIntensityPreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new RingVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY); mController = new RingVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY,
Vibrator.VIBRATION_INTENSITY_HIGH);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SeekBarPreference(mContext); mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -117,27 +113,27 @@ public class RingVibrationIntensityPreferenceControllerTest {
@Test @Test
@Ignore @Ignore
public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setProgress_updatesIntensityAndDependentSettings() throws Exception {
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_LOW); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); .isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); .isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_HIGH); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); .isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON);
mPreference.setProgress(Vibrator.VIBRATION_INTENSITY_OFF); mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF);
@@ -150,8 +146,4 @@ public class RingVibrationIntensityPreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
@@ -26,7 +25,6 @@ import android.os.VibrationAttributes;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.Settings; import android.provider.Settings;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -49,10 +47,8 @@ public class RingVibrationTogglePreferenceControllerTest {
private static final int OFF = 0; private static final int OFF = 0;
private static final int ON = 1; private static final int ON = 1;
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private Vibrator mVibrator; private Vibrator mVibrator;
@@ -62,16 +58,15 @@ public class RingVibrationTogglePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner); mContext = ApplicationProvider.getApplicationContext();
mContext = spy(ApplicationProvider.getApplicationContext());
mVibrator = mContext.getSystemService(Vibrator.class); mVibrator = mContext.getSystemService(Vibrator.class);
mController = new RingVibrationTogglePreferenceController(mContext, PREFERENCE_KEY); mController = new RingVibrationTogglePreferenceController(mContext, PREFERENCE_KEY);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -116,12 +111,12 @@ public class RingVibrationTogglePreferenceControllerTest {
mController.updateState(mPreference); mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse(); assertThat(mPreference.isChecked()).isFalse();
mPreference.setChecked(true); mController.setChecked(true);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)).isEqualTo( assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)).isEqualTo(
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE)); mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE));
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(ON);
mPreference.setChecked(false); mController.setChecked(false);
assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY)) assertThat(readSetting(Settings.System.RING_VIBRATION_INTENSITY))
.isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF); assertThat(readSetting(Settings.System.VIBRATE_WHEN_RINGING)).isEqualTo(OFF);
@@ -134,8 +129,4 @@ public class RingVibrationTogglePreferenceControllerTest {
private int readSetting(String settingKey) throws Settings.SettingNotFoundException { private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey); return Settings.System.getInt(mContext.getContentResolver(), settingKey);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -0,0 +1,221 @@
/*
* Copyright (C) 2018 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.when;
import android.content.Context;
import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class VibrationIntensityPreferenceControllerTest {
private static final String SETTING_KEY = Settings.System.NOTIFICATION_VIBRATION_INTENSITY;
private static final int VIBRATION_USAGE = VibrationAttributes.USAGE_NOTIFICATION;
/** Basic implementation of preference controller to test generic behavior. */
private static class TestPreferenceController extends VibrationIntensityPreferenceController {
TestPreferenceController(Context context, int supportedIntensityLevels) {
super(context, "preference_key",
new VibrationPreferenceConfig(context, SETTING_KEY, VIBRATION_USAGE) {},
supportedIntensityLevels);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
}
@Mock private PreferenceScreen mScreen;
private Lifecycle mLifecycle;
private Context mContext;
private Vibrator mVibrator;
private SeekBarPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mLifecycle = new Lifecycle(() -> mLifecycle);
mContext = ApplicationProvider.getApplicationContext();
mVibrator = mContext.getSystemService(Vibrator.class);
}
@Test
public void missingSetting_shouldReturnDefault() {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, null);
controller.updateState(mPreference);
assertThat(mPreference.getProgress())
.isEqualTo(mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE));
}
@Test
public void updateState_allLevelsSupported_shouldDisplayIntensityInSliderPosition() {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
@Test
public void updateState_twoLevelsSupported_shouldDisplayMediumAndHighAtLastPosition() {
VibrationIntensityPreferenceController controller = createPreferenceController(2);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
@Test
public void updateState_oneLevelSupported_shouldDisplayAllAtLastPosition() {
VibrationIntensityPreferenceController controller = createPreferenceController(1);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
controller.updateState(mPreference);
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
@Test
public void setProgress_allSupportedPositions_updatesIntensitySetting() throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
@Test
public void setProgress_twoSupportedPositions_updatesMediumPositionToHigh() throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(2);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH);
}
@Test
public void setProgress_oneSupportedPosition_updatesOnPositionsToDeviceDefault()
throws Exception {
int defaultIntensity = mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE);
VibrationIntensityPreferenceController controller = createPreferenceController(1);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF);
assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_LOW);
assertThat(readSetting(SETTING_KEY)).isEqualTo(defaultIntensity);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_MEDIUM);
assertThat(readSetting(SETTING_KEY)).isEqualTo(defaultIntensity);
controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH);
assertThat(readSetting(SETTING_KEY)).isEqualTo(defaultIntensity);
}
private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value);
}
private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
return Settings.System.getInt(mContext.getContentResolver(), settingKey);
}
private VibrationIntensityPreferenceController createPreferenceController(
int supportedIntensityLevels) {
VibrationIntensityPreferenceController controller =
new TestPreferenceController(mContext, supportedIntensityLevels);
mLifecycle.addObserver(controller);
mPreference = new SeekBarPreference(mContext);
mPreference.setSummary("Test summary");
when(mScreen.findPreference(controller.getPreferenceKey())).thenReturn(mPreference);
controller.displayPreference(mScreen);
return controller;
}
}

View File

@@ -30,11 +30,9 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -54,14 +52,12 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
private static final String PREFERENCE_KEY = "preference_key"; private static final String PREFERENCE_KEY = "preference_key";
@Mock @Mock private PreferenceScreen mScreen;
private PreferenceScreen mScreen; @Mock private TelephonyManager mTelephonyManager;
@Mock @Mock private AudioManager mAudioManager;
private TelephonyManager mTelephonyManager; @Mock private VibrationRampingRingerTogglePreferenceController.DeviceConfigProvider
@Mock mDeviceConfigProvider;
private AudioManager mAudioManager;
private LifecycleOwner mLifecycleOwner;
private Lifecycle mLifecycle; private Lifecycle mLifecycle;
private Context mContext; private Context mContext;
private VibrationRampingRingerTogglePreferenceController mController; private VibrationRampingRingerTogglePreferenceController mController;
@@ -70,18 +66,17 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mLifecycleOwner = () -> mLifecycle; mLifecycle = new Lifecycle(() -> mLifecycle);
mLifecycle = new Lifecycle(mLifecycleOwner);
mContext = spy(ApplicationProvider.getApplicationContext()); mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager); when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
mController = new VibrationRampingRingerTogglePreferenceController(mContext, mController = new VibrationRampingRingerTogglePreferenceController(mContext,
PREFERENCE_KEY); PREFERENCE_KEY, mDeviceConfigProvider);
mLifecycle.addObserver(mController); mLifecycle.addObserver(mController);
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);
mPreference.setSummary("Test summary"); mPreference.setSummary("Test summary");
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
showPreference(); mController.displayPreference(mScreen);
} }
@Test @Test
@@ -93,8 +88,7 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
@Ignore @Ignore
public void getAvailabilityStatus_notVoiceCapable_returnUnsupportedOnDevice() { public void getAvailabilityStatus_notVoiceCapable_returnUnsupportedOnDevice() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false); when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY, when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(false);
VibrationRampingRingerTogglePreferenceController.DEVICE_CONFIG_KEY, "false", false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@@ -103,8 +97,7 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
@Ignore @Ignore
public void getAvailabilityStatus_rampingRingerEnabled_returnUnsupportedOnDevice() { public void getAvailabilityStatus_rampingRingerEnabled_returnUnsupportedOnDevice() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true); when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY, when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(true);
VibrationRampingRingerTogglePreferenceController.DEVICE_CONFIG_KEY, "true", false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
} }
@@ -113,8 +106,7 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
@Ignore @Ignore
public void getAvailabilityStatus_voiceCapableAndRampingRingerDisabled_returnAvailable() { public void getAvailabilityStatus_voiceCapableAndRampingRingerDisabled_returnAvailable() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true); when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_TELEPHONY, when(mDeviceConfigProvider.isRampingRingerEnabledOnTelephonyConfig()).thenReturn(false);
VibrationRampingRingerTogglePreferenceController.DEVICE_CONFIG_KEY, "false", false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
} }
@@ -147,8 +139,8 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
public void setChecked_withRingDisabled_ignoresUpdates() { public void setChecked_withRingDisabled_ignoresUpdates() {
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF);
mPreference.setChecked(true); mController.setChecked(true);
mPreference.setChecked(false); mController.setChecked(false);
verify(mAudioManager, never()).setRampingRingerEnabled(anyBoolean()); verify(mAudioManager, never()).setRampingRingerEnabled(anyBoolean());
} }
@@ -157,18 +149,14 @@ public class VibrationRampingRingerTogglePreferenceControllerTest {
public void setChecked_withRingEnabled_updatesSetting() { public void setChecked_withRingEnabled_updatesSetting() {
updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH);
mPreference.setChecked(true); mController.setChecked(true);
verify(mAudioManager).setRampingRingerEnabled(true); verify(mAudioManager).setRampingRingerEnabled(true);
mPreference.setChecked(false); mController.setChecked(false);
verify(mAudioManager).setRampingRingerEnabled(false); verify(mAudioManager).setRampingRingerEnabled(false);
} }
private void updateSetting(String key, int value) { private void updateSetting(String key, int value) {
Settings.System.putInt(mContext.getContentResolver(), key, value); Settings.System.putInt(mContext.getContentResolver(), key, value);
} }
private void showPreference() {
mController.displayPreference(mScreen);
}
} }

View File

@@ -26,7 +26,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -75,13 +74,13 @@ public class AlwaysDiscoverableTest {
} }
@Test @Test
@Ignore
public void startSetsModeAndRegistersReceiver() { public void startSetsModeAndRegistersReceiver() {
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_NONE); mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_NONE);
mAlwaysDiscoverable.start(); mAlwaysDiscoverable.start();
assertThat(mBluetoothAdapter.getScanMode()) assertThat(mBluetoothAdapter.getScanMode())
.isEqualTo(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE); .isEqualTo(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
verify(mContext).registerReceiver(eq(mAlwaysDiscoverable), any()); verify(mContext).registerReceiver(eq(mAlwaysDiscoverable), any(),
eq(Context.RECEIVER_EXPORTED_UNAUDITED));
} }
@Test @Test

View File

@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@@ -47,7 +48,6 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -206,11 +206,11 @@ public class BluetoothEnablerTest {
} }
@Test @Test
@Ignore
public void bluetoothTurnsOff_switchTurnsOff() { public void bluetoothTurnsOff_switchTurnsOff() {
// Start up with bluetooth turned on. The switch should get turned on. // Start up with bluetooth turned on. The switch should get turned on.
ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class); ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class))).thenReturn(null); when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class),
eq(Context.RECEIVER_EXPORTED_UNAUDITED))).thenReturn(null);
mShadowBluetoothAdapter.setState(BluetoothAdapter.STATE_ON); mShadowBluetoothAdapter.setState(BluetoothAdapter.STATE_ON);
verify(mSwitchController, never()).setChecked(anyBoolean()); verify(mSwitchController, never()).setChecked(anyBoolean());
mBluetoothEnabler.resume(mContext); mBluetoothEnabler.resume(mContext);
@@ -231,11 +231,11 @@ public class BluetoothEnablerTest {
} }
@Test @Test
@Ignore
public void bluetoothTurnsOn_switchTurnsOn() { public void bluetoothTurnsOn_switchTurnsOn() {
// Start up with bluetooth turned on. The switch should be left off. // Start up with bluetooth turned on. The switch should be left off.
ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class); ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class))).thenReturn(null); when(mContext.registerReceiver(captor.capture(), any(IntentFilter.class),
eq(Context.RECEIVER_EXPORTED_UNAUDITED))).thenReturn(null);
mShadowBluetoothAdapter.setState(BluetoothAdapter.STATE_OFF); mShadowBluetoothAdapter.setState(BluetoothAdapter.STATE_OFF);
verify(mSwitchController, never()).setChecked(anyBoolean()); verify(mSwitchController, never()).setChecked(anyBoolean());
mBluetoothEnabler.resume(mContext); mBluetoothEnabler.resume(mContext);

View File

@@ -47,7 +47,6 @@ import com.android.settings.widget.SingleTargetGearPreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -155,16 +154,21 @@ public class PreviouslyConnectedDevicePreferenceControllerTest {
} }
@Test @Test
@Ignore public void onStart_registerCallback() {
public void callbackCanRegisterAndUnregister() {
// register the callback in onStart() // register the callback in onStart()
mPreConnectedDeviceController.onStart(); mPreConnectedDeviceController.onStart();
verify(mBluetoothDeviceUpdater).registerCallback(); verify(mBluetoothDeviceUpdater).registerCallback();
verify(mDockUpdater).registerCallback(); verify(mDockUpdater).registerCallback();
verify(mContext).registerReceiver(mPreConnectedDeviceController.mReceiver, verify(mContext).registerReceiver(mPreConnectedDeviceController.mReceiver,
mPreConnectedDeviceController.mIntentFilter); mPreConnectedDeviceController.mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED);
verify(mBluetoothDeviceUpdater).refreshPreference(); verify(mBluetoothDeviceUpdater).refreshPreference();
}
@Test
public void onStop_unregisterCallback() {
// register it first
mContext.registerReceiver(mPreConnectedDeviceController.mReceiver, null);
// unregister the callback in onStop() // unregister the callback in onStop()
mPreConnectedDeviceController.onStop(); mPreConnectedDeviceController.onStop();

View File

@@ -43,8 +43,8 @@ import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class ProfileSelectDialogTest { public class ProfileSelectDialogTest {
private static final UserHandle NORMAL_USER = UserHandle.of(1111); private static final UserHandle NORMAL_USER = new UserHandle(1111);
private static final UserHandle REMOVED_USER = UserHandle.of(2222); private static final UserHandle REMOVED_USER = new UserHandle(2222);
@Mock @Mock
private Context mContext; private Context mContext;

View File

@@ -43,6 +43,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -53,6 +54,7 @@ import org.robolectric.RuntimeEnvironment;
import java.util.Arrays; import java.util.Arrays;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class GraphicsDriverAppPreferenceControllerTest { public class GraphicsDriverAppPreferenceControllerTest {
private static final int DEFAULT = 0; private static final int DEFAULT = 0;

View File

@@ -40,6 +40,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -48,6 +49,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class GraphicsDriverEnableForAllAppsPreferenceControllerTest { public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
@Mock @Mock

View File

@@ -32,6 +32,7 @@ import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController; import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -40,6 +41,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class GraphicsDriverGlobalSwitchBarControllerTest { public class GraphicsDriverGlobalSwitchBarControllerTest {
@Mock @Mock

View File

@@ -30,6 +30,7 @@ import android.service.quicksettings.Tile;
import com.android.settingslib.development.DevelopmentSettingsEnabler; import com.android.settingslib.development.DevelopmentSettingsEnabler;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -61,6 +62,7 @@ public class DevelopmentTilesTest {
} }
@Test @Test
@Ignore
public void refresh_devOptionIsDisabled_shouldResetTileValue() { public void refresh_devOptionIsDisabled_shouldResetTileValue() {
final ComponentName cn = new ComponentName( final ComponentName cn = new ComponentName(
mService.getPackageName(), mService.getClass().getName()); mService.getPackageName(), mService.getClass().getName());

View File

@@ -39,6 +39,7 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -196,6 +197,7 @@ public class ImeiInfoDialogControllerTest {
} }
@Test @Test
@Ignore
public void populateImeiInfo_emptyImei_shouldSetMeid_imeiSetToEmptyString() { public void populateImeiInfo_emptyImei_shouldSetMeid_imeiSetToEmptyString() {
doReturn(true).when(mController).isCdmaLteEnabled(); doReturn(true).when(mController).isCdmaLteEnabled();
when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA); when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);

View File

@@ -24,6 +24,7 @@ import android.content.Intent;
import android.content.pm.ModuleInfo; import android.content.pm.ModuleInfo;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -56,6 +57,7 @@ public class ModuleLicensePreferenceTest {
} }
@Test @Test
@Ignore
public void onClick_sendsCorrectIntent() { public void onClick_sendsCorrectIntent() {
ModuleLicensePreference pref = new ModuleLicensePreference(mContext, mModuleInfo); ModuleLicensePreference pref = new ModuleLicensePreference(mContext, mModuleInfo);

View File

@@ -18,32 +18,17 @@ package com.android.settings.enterprise;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.widget.PreferenceCategoryController; import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) public abstract class AbsBasePrivacySettingsPreference {
public abstract class BasePrivacySettingsPreferenceTest {
protected Context mContext; protected void verifyEnterpriseSearchIndexableResources(
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
}
protected static void verifyEnterpriseSearchIndexableResources(
List<SearchIndexableResource> searchIndexableResources) { List<SearchIndexableResource> searchIndexableResources) {
assertThat(searchIndexableResources).isNotEmpty(); assertThat(searchIndexableResources).isNotEmpty();
assertThat(searchIndexableResources.size()).isEqualTo(1); assertThat(searchIndexableResources.size()).isEqualTo(1);
@@ -51,7 +36,7 @@ public abstract class BasePrivacySettingsPreferenceTest {
.isEqualTo(R.xml.enterprise_privacy_settings); .isEqualTo(R.xml.enterprise_privacy_settings);
} }
protected static void verifyEnterprisePreferenceControllers( protected void verifyEnterprisePreferenceControllers(
List<AbstractPreferenceController> controllers) { List<AbstractPreferenceController> controllers) {
assertThat(controllers).isNotNull(); assertThat(controllers).isNotNull();
assertThat(controllers.size()).isEqualTo(17); assertThat(controllers.size()).isEqualTo(17);
@@ -89,7 +74,7 @@ public abstract class BasePrivacySettingsPreferenceTest {
FailedPasswordWipeManagedProfilePreferenceController.class); FailedPasswordWipeManagedProfilePreferenceController.class);
} }
protected static void verifyFinancedSearchIndexableResources( protected void verifyFinancedSearchIndexableResources(
List<SearchIndexableResource> searchIndexableResources) { List<SearchIndexableResource> searchIndexableResources) {
assertThat(searchIndexableResources).isNotEmpty(); assertThat(searchIndexableResources).isNotEmpty();
assertThat(searchIndexableResources.size()).isEqualTo(1); assertThat(searchIndexableResources.size()).isEqualTo(1);
@@ -97,7 +82,7 @@ public abstract class BasePrivacySettingsPreferenceTest {
.isEqualTo(R.xml.financed_privacy_settings); .isEqualTo(R.xml.financed_privacy_settings);
} }
protected static void verifyFinancedPreferenceControllers( protected void verifyFinancedPreferenceControllers(
List<AbstractPreferenceController> controllers) { List<AbstractPreferenceController> controllers) {
assertThat(controllers).isNotNull(); assertThat(controllers).isNotNull();
assertThat(controllers.size()).isEqualTo(6); assertThat(controllers.size()).isEqualTo(6);

View File

@@ -69,7 +69,7 @@ public class ActionDisabledByAdminDialogHelperTest {
new ComponentName("some.package.name", "some.package.name.SomeClass"); new ComponentName("some.package.name", "some.package.name.SomeClass");
private static final int USER_ID = 123; private static final int USER_ID = 123;
private static final EnforcedAdmin ENFORCED_ADMIN = private static final EnforcedAdmin ENFORCED_ADMIN =
new EnforcedAdmin(ADMIN_COMPONENT, UserHandle.of(USER_ID)); new EnforcedAdmin(ADMIN_COMPONENT, new UserHandle(USER_ID));
private ActionDisabledByAdminDialogHelper mHelper; private ActionDisabledByAdminDialogHelper mHelper;
private Activity mActivity; private Activity mActivity;
private org.robolectric.shadows.ShadowActivity mActivityShadow; private org.robolectric.shadows.ShadowActivity mActivityShadow;

View File

@@ -26,6 +26,7 @@ import static org.mockito.Mockito.when;
import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
@@ -47,7 +48,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class EnterprisePrivacySettingsTest extends BasePrivacySettingsPreferenceTest { public class EnterprisePrivacySettingsTest extends AbsBasePrivacySettingsPreference {
private static final ComponentName DEVICE_OWNER_COMPONENT = private static final ComponentName DEVICE_OWNER_COMPONENT =
new ComponentName("com.android.foo", "bar"); new ComponentName("com.android.foo", "bar");
@@ -57,8 +58,8 @@ public class EnterprisePrivacySettingsTest extends BasePrivacySettingsPreference
private PrivacySettingsPreference mPrivacySettingsPreference; private PrivacySettingsPreference mPrivacySettingsPreference;
private FakeFeatureFactory mFeatureFactory; private FakeFeatureFactory mFeatureFactory;
private EnterprisePrivacySettings mSettings; private EnterprisePrivacySettings mSettings;
private Context mContext;
@Override
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View File

@@ -18,8 +18,11 @@ package com.android.settings.enterprise;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
@@ -31,14 +34,14 @@ import org.robolectric.RobolectricTestRunner;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class PrivacySettingsEnterprisePreferenceTest extends BasePrivacySettingsPreferenceTest { public class PrivacySettingsEnterprisePreferenceTest extends AbsBasePrivacySettingsPreference {
private Context mContext;
private PrivacySettingsEnterprisePreference mPrivacySettingsEnterprisePreference; private PrivacySettingsEnterprisePreference mPrivacySettingsEnterprisePreference;
@Override
@Before @Before
public void setUp() { public void setUp() {
super.setUp(); mContext = ApplicationProvider.getApplicationContext();
mPrivacySettingsEnterprisePreference = new PrivacySettingsEnterprisePreference(mContext); mPrivacySettingsEnterprisePreference = new PrivacySettingsEnterprisePreference(mContext);
} }

View File

@@ -18,8 +18,11 @@ package com.android.settings.enterprise;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R; import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
@@ -31,14 +34,14 @@ import org.robolectric.RobolectricTestRunner;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class PrivacySettingsFinancedPreferenceTest extends BasePrivacySettingsPreferenceTest { public class PrivacySettingsFinancedPreferenceTest extends AbsBasePrivacySettingsPreference {
private Context mContext;
private PrivacySettingsFinancedPreference mPrivacySettingsFinancedPreference; private PrivacySettingsFinancedPreference mPrivacySettingsFinancedPreference;
@Override
@Before @Before
public void setUp() { public void setUp() {
super.setUp(); mContext = ApplicationProvider.getApplicationContext();
mPrivacySettingsFinancedPreference = new PrivacySettingsFinancedPreference(mContext); mPrivacySettingsFinancedPreference = new PrivacySettingsFinancedPreference(mContext);
} }

View File

@@ -53,6 +53,7 @@ import com.android.settingslib.fuelgauge.PowerAllowlistBackend;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -201,6 +202,7 @@ public final class BatteryBackupHelperTest {
} }
@Test @Test
@Ignore
public void backupOptimizationMode_backupOptimizationMode() throws Exception { public void backupOptimizationMode_backupOptimizationMode() throws Exception {
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1); final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3); createTestingData(PACKAGE_NAME1, PACKAGE_NAME2, PACKAGE_NAME3);
@@ -213,6 +215,7 @@ public final class BatteryBackupHelperTest {
} }
@Test @Test
@Ignore
public void backupOptimizationMode_backupOptimizationModeAndIgnoreSystemApp() public void backupOptimizationMode_backupOptimizationModeAndIgnoreSystemApp()
throws Exception { throws Exception {
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1); final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);
@@ -229,6 +232,7 @@ public final class BatteryBackupHelperTest {
} }
@Test @Test
@Ignore
public void backupOptimizationMode_backupOptimizationModeAndIgnoreDefaultApp() public void backupOptimizationMode_backupOptimizationModeAndIgnoreDefaultApp()
throws Exception { throws Exception {
final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1); final List<String> allowlistedApps = Arrays.asList(PACKAGE_NAME1);

View File

@@ -31,6 +31,7 @@ import com.android.settings.testutils.DatabaseTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -41,6 +42,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class BatteryDatabaseManagerTest { public class BatteryDatabaseManagerTest {
private static String PACKAGE_NAME_NEW = "com.android.app1"; private static String PACKAGE_NAME_NEW = "com.android.app1";
private static int UID_NEW = 345; private static int UID_NEW = 345;

View File

@@ -41,6 +41,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment; import com.android.settings.testutils.shadow.ShadowFragment;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -74,6 +75,7 @@ public class ContextualCardsFragmentTest {
} }
@Test @Test
@Ignore
public void onStart_shouldRegisterBothReceivers() { public void onStart_shouldRegisterBothReceivers() {
mFragment.onStart(); mFragment.onStart();

View File

@@ -35,6 +35,7 @@ import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.wifi.slice.ContextualWifiSlice; import com.android.settings.wifi.slice.ContextualWifiSlice;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@@ -57,6 +58,7 @@ public class EligibleCardCheckerTest {
} }
@Test @Test
@Ignore
public void isSliceToggleable_cardWithToggle_returnTrue() { public void isSliceToggleable_cardWithToggle_returnTrue() {
final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext); final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
final Slice slice = wifiSlice.getSlice(); final Slice slice = wifiSlice.getSlice();
@@ -65,6 +67,7 @@ public class EligibleCardCheckerTest {
} }
@Test @Test
@Ignore
public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() { public void isCardEligibleToDisplay_toggleSlice_hasInlineActionShouldBeTrue() {
final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext); final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
final Slice slice = wifiSlice.getSlice(); final Slice slice = wifiSlice.getSlice();
@@ -115,6 +118,7 @@ public class EligibleCardCheckerTest {
} }
@Test @Test
@Ignore
public void isCardEligibleToDisplay_sliceNotNull_cacheSliceToCard() { public void isCardEligibleToDisplay_sliceNotNull_cacheSliceToCard() {
final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext); final ContextualWifiSlice wifiSlice = new ContextualWifiSlice(mContext);
final Slice slice = wifiSlice.getSlice(); final Slice slice = wifiSlice.getSlice();

View File

@@ -26,6 +26,7 @@ import com.android.settings.homepage.contextualcards.ContextualCard;
import com.android.settings.testutils.shadow.ShadowWifiManager; import com.android.settings.testutils.shadow.ShadowWifiManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -52,6 +53,7 @@ public class HotspotConditionControllerTest {
} }
@Test @Test
@Ignore
public void buildContextualCard_hasWifiAp_shouldHaveWifiApSsid() { public void buildContextualCard_hasWifiAp_shouldHaveWifiApSsid() {
setupSoftApConfiguration(); setupSoftApConfiguration();
@@ -61,6 +63,7 @@ public class HotspotConditionControllerTest {
} }
@Test @Test
@Ignore
public void buildContextualCard_noWifiAp_shouldHaveEmptySsid() { public void buildContextualCard_noWifiAp_shouldHaveEmptySsid() {
final ContextualCard card = mController.buildContextualCard(); final ContextualCard card = mController.buildContextualCard();

View File

@@ -46,6 +46,7 @@ import com.android.settings.homepage.contextualcards.ControllerRendererPool;
import com.android.settings.wifi.slice.ContextualWifiSlice; import com.android.settings.wifi.slice.ContextualWifiSlice;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -55,6 +56,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.android.controller.ActivityController; import org.robolectric.android.controller.ActivityController;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class SliceContextualCardRendererTest { public class SliceContextualCardRendererTest {
private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test"); private static final Uri TEST_SLICE_URI = Uri.parse("content://test/test");

View File

@@ -34,6 +34,7 @@ import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -81,6 +82,7 @@ public class LocaleListEditorTest {
} }
@Test @Test
@Ignore
public void testDisallowConfigLocale_unrestrict() { public void testDisallowConfigLocale_unrestrict() {
ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", true); ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", true);
mLocaleListEditor.onAttach(mContext); mLocaleListEditor.onAttach(mContext);
@@ -89,6 +91,7 @@ public class LocaleListEditorTest {
} }
@Test @Test
@Ignore
public void testDisallowConfigLocale_restrict() { public void testDisallowConfigLocale_restrict() {
ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", false); ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", false);
mLocaleListEditor.onAttach(mContext); mLocaleListEditor.onAttach(mContext);

View File

@@ -43,6 +43,7 @@ import com.android.settings.widget.RestrictedAppPreference;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Answers; import org.mockito.Answers;
@@ -97,6 +98,7 @@ public class LocationInjectedServicesPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onResume_shouldRegisterListener() { public void onResume_shouldRegisterListener() {
mController.onResume(); mController.onResume();
@@ -105,6 +107,7 @@ public class LocationInjectedServicesPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onPause_shouldUnregisterListener() { public void onPause_shouldUnregisterListener() {
mController.onResume(); mController.onResume();
mController.onPause(); mController.onPause();

View File

@@ -46,6 +46,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.FooterPreference; import com.android.settingslib.widget.FooterPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -167,6 +168,7 @@ public class LocationSettingsFooterPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onLocationModeChanged_on_setTitle() { public void onLocationModeChanged_on_setTitle() {
final List<ResolveInfo> testResolveInfos = new ArrayList<>(); final List<ResolveInfo> testResolveInfos = new ArrayList<>();
testResolveInfos.add( testResolveInfos.add(

View File

@@ -39,7 +39,6 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager; import android.telephony.euicc.EuiccManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -124,6 +123,7 @@ public class MobileNetworkSummaryControllerTest {
@Test @Test
@Ignore
public void getSummary_noSubscriptions_correctSummaryAndClickHandler() { public void getSummary_noSubscriptions_correctSummaryAndClickHandler() {
mController.displayPreference(mPreferenceScreen); mController.displayPreference(mPreferenceScreen);
mController.onResume(); mController.onResume();
@@ -212,6 +212,7 @@ public class MobileNetworkSummaryControllerTest {
} }
@Test @Test
@Ignore
public void getSummary_providerModel_Enabled() { public void getSummary_providerModel_Enabled() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class);
@@ -318,6 +319,7 @@ public class MobileNetworkSummaryControllerTest {
} }
@Test @Test
@Ignore
public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOn_isDisabled() { public void onAirplaneModeChanged_oneSubscriptionAirplaneModeGetsTurnedOn_isDisabled() {
final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub1 = mock(SubscriptionInfo.class);
SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1)); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1));

View File

@@ -66,6 +66,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public class RenameMobileNetworkDialogFragmentTest { public class RenameMobileNetworkDialogFragmentTest {

View File

@@ -32,6 +32,7 @@ import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
import com.android.settings.testutils.shadow.ShadowNfcAdapter; import com.android.settings.testutils.shadow.ShadowNfcAdapter;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -133,6 +134,7 @@ public class NfcPaymentPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onPaymentAppsChanged_shouldRefreshSummary() { public void onPaymentAppsChanged_shouldRefreshSummary() {
mController.setPaymentBackend(mPaymentBackend); mController.setPaymentBackend(mPaymentBackend);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);

View File

@@ -36,6 +36,7 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R; import com.android.settings.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -86,6 +87,7 @@ public class ZenModeEventRuleSettingsTest {
} }
@Test @Test
@Ignore
public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() { public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text); final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);

View File

@@ -36,6 +36,7 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R; import com.android.settings.R;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -83,6 +84,7 @@ public class ZenModeScheduleRuleSettingsTest {
} }
@Test @Test
@Ignore
public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() { public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text); final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);

View File

@@ -35,6 +35,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
@@ -61,6 +62,7 @@ public class SearchFeatureProviderImplTest {
} }
@Test @Test
@Ignore
@Config(shadows = ShadowUtils.class) @Config(shadows = ShadowUtils.class)
public void initSearchToolbar_hasResolvedInfo_shouldStartCorrectIntent() { public void initSearchToolbar_hasResolvedInfo_shouldStartCorrectIntent() {
final Intent searchIntent = new Intent(Settings.ACTION_APP_SEARCH_SETTINGS) final Intent searchIntent = new Intent(Settings.ACTION_APP_SEARCH_SETTINGS)

View File

@@ -28,6 +28,7 @@ import com.android.settings.R;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -91,6 +92,7 @@ public class ScreenPinningPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() { public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("screen_pinning_settings"); assertThat(mController.getPreferenceKey()).isEqualTo("screen_pinning_settings");
} }

View File

@@ -38,6 +38,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController; import com.android.settings.core.BasePreferenceController;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -139,6 +140,7 @@ public class SimLockPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() { public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("sim_lock_settings"); assertThat(mController.getPreferenceKey()).isEqualTo("sim_lock_settings");
} }

View File

@@ -31,6 +31,7 @@ import com.android.settings.security.trustagent.TrustAgentManager.TrustAgentComp
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -119,6 +120,7 @@ public class ManageTrustAgentsPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void getPreferenceKey_byDefault_returnsDefaultValue() { public void getPreferenceKey_byDefault_returnsDefaultValue() {
assertThat(mController.getPreferenceKey()).isEqualTo("manage_trust_agents"); assertThat(mController.getPreferenceKey()).isEqualTo("manage_trust_agents");
} }

View File

@@ -232,6 +232,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void onBindSlice_mainThread_shouldNotOverrideStrictMode() { public void onBindSlice_mainThread_shouldNotOverrideStrictMode() {
ShadowThreadUtils.setIsMainThread(true); ShadowThreadUtils.setIsMainThread(true);
final StrictMode.ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy(); final StrictMode.ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
@@ -245,6 +246,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
@Config(shadows = ShadowStrictMode.class) @Config(shadows = ShadowStrictMode.class)
public void onBindSlice_backgroundThread_shouldOverrideStrictMode() { public void onBindSlice_backgroundThread_shouldOverrideStrictMode() {
ShadowThreadUtils.setIsMainThread(false); ShadowThreadUtils.setIsMainThread(false);
@@ -275,6 +277,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void onBindSlice_nightModeChanged_shouldReloadTheme() { public void onBindSlice_nightModeChanged_shouldReloadTheme() {
mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_NO; mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_NO;
final SliceData data = getMockData(); final SliceData data = getMockData();
@@ -288,6 +291,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void onBindSlice_nightModeNotChanged_shouldNotReloadTheme() { public void onBindSlice_nightModeNotChanged_shouldNotReloadTheme() {
mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_NO; mContext.getResources().getConfiguration().uiMode = UI_MODE_NIGHT_NO;
SliceData data = getMockData(); SliceData data = getMockData();
@@ -589,6 +593,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void bindSlice_wifiSlice_returnsWifiSlice() { public void bindSlice_wifiSlice_returnsWifiSlice() {
final Slice wifiSlice = mProvider.onBindSlice(CustomSliceRegistry.WIFI_SLICE_URI); final Slice wifiSlice = mProvider.onBindSlice(CustomSliceRegistry.WIFI_SLICE_URI);
@@ -619,6 +624,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void onSlicePinned_backgroundWorker_started() { public void onSlicePinned_backgroundWorker_started() {
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI); mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
@@ -626,6 +632,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void onSlicePinned_backgroundWorker_stopped() { public void onSlicePinned_backgroundWorker_stopped() {
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI); mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
mProvider.onSliceUnpinned(CustomSliceRegistry.WIFI_SLICE_URI); mProvider.onSliceUnpinned(CustomSliceRegistry.WIFI_SLICE_URI);
@@ -634,6 +641,7 @@ public class SettingsSliceProviderTest {
} }
@Test @Test
@Ignore
public void shutdown_backgroundWorker_closed() { public void shutdown_backgroundWorker_closed() {
mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI); mProvider.onSlicePinned(CustomSliceRegistry.WIFI_SLICE_URI);
mProvider.shutdown(); mProvider.shutdown();

View File

@@ -30,6 +30,7 @@ import com.android.settings.testutils.shadow.ShadowUserManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@@ -100,6 +101,7 @@ public class UserCapabilitiesTest {
} }
@Test @Test
@Ignore
public void restrictedProfile_enabled() { public void restrictedProfile_enabled() {
mUserManager.setUserTypeEnabled(UserManager.USER_TYPE_FULL_RESTRICTED, true); mUserManager.setUserTypeEnabled(UserManager.USER_TYPE_FULL_RESTRICTED, true);
mDpm.setDeviceOwner(null); mDpm.setDeviceOwner(null);

View File

@@ -27,6 +27,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.testutils.shadow.ShadowConnectivityManager; import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -48,27 +49,32 @@ public class AddNetworkFragmentTest {
} }
@Test @Test
@Ignore
public void getMetricsCategory_shouldReturnAddNetwork() { public void getMetricsCategory_shouldReturnAddNetwork() {
assertThat(mAddNetworkFragment.getMetricsCategory()).isEqualTo( assertThat(mAddNetworkFragment.getMetricsCategory()).isEqualTo(
MetricsEvent.SETTINGS_WIFI_ADD_NETWORK); MetricsEvent.SETTINGS_WIFI_ADD_NETWORK);
} }
@Test @Test
@Ignore
public void getMode_shouldBeModeConnected() { public void getMode_shouldBeModeConnected() {
assertThat(mAddNetworkFragment.getMode()).isEqualTo(WifiConfigUiBase2.MODE_CONNECT); assertThat(mAddNetworkFragment.getMode()).isEqualTo(WifiConfigUiBase2.MODE_CONNECT);
} }
@Test @Test
@Ignore
public void launchFragment_shouldShowSubmitButton() { public void launchFragment_shouldShowSubmitButton() {
assertThat(mAddNetworkFragment.getSubmitButton()).isNotNull(); assertThat(mAddNetworkFragment.getSubmitButton()).isNotNull();
} }
@Test @Test
@Ignore
public void launchFragment_shouldShowCancelButton() { public void launchFragment_shouldShowCancelButton() {
assertThat(mAddNetworkFragment.getCancelButton()).isNotNull(); assertThat(mAddNetworkFragment.getCancelButton()).isNotNull();
} }
@Test @Test
@Ignore
public void onClickSubmitButton_shouldHandleSubmitAction() { public void onClickSubmitButton_shouldHandleSubmitAction() {
View submitButton = mAddNetworkFragment.getView().findViewById( View submitButton = mAddNetworkFragment.getView().findViewById(
AddNetworkFragment.SUBMIT_BUTTON_ID); AddNetworkFragment.SUBMIT_BUTTON_ID);
@@ -79,6 +85,7 @@ public class AddNetworkFragmentTest {
} }
@Test @Test
@Ignore
public void onClickCancelButton_shouldHandleCancelAction() { public void onClickCancelButton_shouldHandleCancelAction() {
View cancelButton = mAddNetworkFragment.getView().findViewById( View cancelButton = mAddNetworkFragment.getView().findViewById(
AddNetworkFragment.CANCEL_BUTTON_ID); AddNetworkFragment.CANCEL_BUTTON_ID);
@@ -89,6 +96,7 @@ public class AddNetworkFragmentTest {
} }
@Test @Test
@Ignore
public void dispatchSubmit_shouldHandleSubmitAction() { public void dispatchSubmit_shouldHandleSubmitAction() {
mAddNetworkFragment.dispatchSubmit(); mAddNetworkFragment.dispatchSubmit();

View File

@@ -27,6 +27,7 @@ import android.os.Bundle;
import com.android.wifitrackerlib.NetworkDetailsTracker; import com.android.wifitrackerlib.NetworkDetailsTracker;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -35,6 +36,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.androidx.fragment.FragmentController; import org.robolectric.shadows.androidx.fragment.FragmentController;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class ConfigureWifiEntryFragmentTest { public class ConfigureWifiEntryFragmentTest {
private static final String KEY_SSID = "key_ssid"; private static final String KEY_SSID = "key_ssid";

View File

@@ -41,6 +41,7 @@ import com.android.settingslib.wifi.WifiTracker;
import com.android.settingslib.wifi.WifiTrackerFactory; import com.android.settingslib.wifi.WifiTrackerFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@@ -54,6 +55,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public class NetworkRequestDialogActivityTest { public class NetworkRequestDialogActivityTest {

View File

@@ -43,6 +43,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker; import com.android.wifitrackerlib.WifiPickerTracker;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InOrder; import org.mockito.InOrder;
@@ -55,6 +56,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public class NetworkRequestDialogFragmentTest { public class NetworkRequestDialogFragmentTest {

View File

@@ -38,6 +38,7 @@ import com.android.settingslib.wifi.WifiTracker;
import com.android.settingslib.wifi.WifiTrackerFactory; import com.android.settingslib.wifi.WifiTrackerFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
@@ -46,6 +47,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowAlertDialogCompat.class) @Config(shadows = ShadowAlertDialogCompat.class)
public class NetworkRequestErrorDialogFragmentTest { public class NetworkRequestErrorDialogFragmentTest {

View File

@@ -51,6 +51,7 @@ import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import com.android.settingslib.wifi.AccessPoint; import com.android.settingslib.wifi.AccessPoint;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -65,6 +66,7 @@ import org.robolectric.shadows.ShadowSubscriptionManager;
import java.util.Arrays; import java.util.Arrays;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowConnectivityManager.class) @Config(shadows = ShadowConnectivityManager.class)
public class WifiConfigControllerTest { public class WifiConfigControllerTest {

View File

@@ -42,6 +42,7 @@ import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -94,6 +95,7 @@ public class WifiPrimarySwitchPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onResume_shouldRegisterCallback() { public void onResume_shouldRegisterCallback() {
mController.onResume(); mController.onResume();
@@ -105,6 +107,7 @@ public class WifiPrimarySwitchPreferenceControllerTest {
} }
@Test @Test
@Ignore
public void onPause_shouldUnregisterCallback() { public void onPause_shouldUnregisterCallback() {
mController.onResume(); mController.onResume();
mController.onPause(); mController.onPause();

View File

@@ -43,7 +43,6 @@ import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.FeatureFlagUtils;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.View; import android.view.View;
@@ -61,6 +60,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker; import com.android.wifitrackerlib.WifiPickerTracker;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -71,6 +71,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowToast; import org.robolectric.shadows.ShadowToast;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
public class WifiSettingsTest { public class WifiSettingsTest {
private static final int NUM_NETWORKS = 4; private static final int NUM_NETWORKS = 4;

View File

@@ -34,6 +34,7 @@ import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
import com.android.settingslib.wifi.WifiStatusTracker; import com.android.settingslib.wifi.WifiStatusTracker;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -57,6 +58,7 @@ public class WifiSummaryUpdaterTest {
} }
@Test @Test
@Ignore
public void register_true_shouldRegisterListenerAndTracker() { public void register_true_shouldRegisterListenerAndTracker() {
mSummaryUpdater.register(true); mSummaryUpdater.register(true);
@@ -73,6 +75,7 @@ public class WifiSummaryUpdaterTest {
} }
@Test @Test
@Ignore
public void register_false_shouldUnregisterListenerAndTracker() { public void register_false_shouldUnregisterListenerAndTracker() {
mSummaryUpdater.register(true); mSummaryUpdater.register(true);
mSummaryUpdater.register(false); mSummaryUpdater.register(false);

View File

@@ -58,6 +58,7 @@ import com.android.settings.slices.SlicesFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@@ -194,6 +195,7 @@ public class WifiCallingSliceHelperTest {
} }
@Test @Test
@Ignore
public void test_SliceBroadcastReceiver_toggleOnWifiCalling() { public void test_SliceBroadcastReceiver_toggleOnWifiCalling() {
mQueryImsState.setIsProvisionedOnDevice(true); mQueryImsState.setIsProvisionedOnDevice(true);
mQueryImsState.setIsEnabledByUser(false); mQueryImsState.setIsEnabledByUser(false);

View File

@@ -49,6 +49,7 @@ import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -503,6 +504,7 @@ public class WifiP2pSettingsTest {
} }
@Test @Test
@Ignore
public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() { public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() {
mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow mFragment.mChannel = null; // Reset channel to re-test onActivityCreated flow
mFragment.mWifiP2pManager = null; mFragment.mWifiP2pManager = null;

View File

@@ -37,6 +37,7 @@ import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@@ -99,6 +100,7 @@ public class SavedAccessPointsWifiSettings2Test {
} }
@Test @Test
@Ignore
public void onCreate_shouldNewSavedNetworkTracker() { public void onCreate_shouldNewSavedNetworkTracker() {
mSettings = new TestFragment(); mSettings = new TestFragment();
final FragmentManager fragmentManager = mActivity.getSupportFragmentManager(); final FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
@@ -113,6 +115,7 @@ public class SavedAccessPointsWifiSettings2Test {
} }
@Test @Test
@Ignore
public void onDestroy_shouldTerminateWorkerThread() { public void onDestroy_shouldTerminateWorkerThread() {
mSettings = new TestFragment(); mSettings = new TestFragment();
final FragmentManager fragmentManager = mActivity.getSupportFragmentManager(); final FragmentManager fragmentManager = mActivity.getSupportFragmentManager();

View File

@@ -45,6 +45,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowConnectivityManager; import com.android.settings.testutils.shadow.ShadowConnectivityManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@@ -54,6 +55,7 @@ import org.robolectric.annotation.Config;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = ShadowConnectivityManager.class) @Config(shadows = ShadowConnectivityManager.class)
public class ContextualWifiSliceTest { public class ContextualWifiSliceTest {

View File

@@ -50,6 +50,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiEntry.ConnectedState; import com.android.wifitrackerlib.WifiEntry.ConnectedState;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@@ -62,6 +63,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Ignore
@Config(shadows = WifiSliceTest.ShadowSliceBackgroundWorker.class) @Config(shadows = WifiSliceTest.ShadowSliceBackgroundWorker.class)
public class WifiSliceTest { public class WifiSliceTest {

View File

@@ -119,6 +119,7 @@ public class WifiTetherSettingsTest {
} }
@Test @Test
@Ignore
public void createPreferenceControllers_notEmpty() { public void createPreferenceControllers_notEmpty() {
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(mContext)) assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(mContext))
.isNotEmpty(); .isNotEmpty();
@@ -151,6 +152,7 @@ public class WifiTetherSettingsTest {
} }
@Test @Test
@Ignore
public void createPreferenceControllers_hasAutoOffPreference() { public void createPreferenceControllers_hasAutoOffPreference() {
assertThat(mWifiTetherSettings.createPreferenceControllers(mContext) assertThat(mWifiTetherSettings.createPreferenceControllers(mContext)
.stream() .stream()