Snap for 4466732 from 03b2d4c44c to pi-release

Change-Id: Ic6099d8dc1c61d3a57b7dda50b094cdc7a53614f
This commit is contained in:
android-build-team Robot
2017-11-23 08:20:45 +00:00
52 changed files with 352 additions and 88 deletions

View File

@@ -1920,7 +1920,8 @@
android:label="@string/development_settings_title" android:label="@string/development_settings_title"
android:icon="@drawable/ic_settings_development" android:icon="@drawable/ic_settings_development"
android:taskAffinity="com.android.settings" android:taskAffinity="com.android.settings"
android:parentActivityName="Settings"> android:parentActivityName="Settings"
android:enabled="false">
<intent-filter android:priority="1"> <intent-filter android:priority="1">
<action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" /> <action android:name="android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
<action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" /> <action android:name="com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS" />
@@ -1989,15 +1990,6 @@
android:value="com.android.settings.print.PrintJobSettingsFragment" /> android:value="com.android.settings.print.PrintJobSettingsFragment" />
</activity> </activity>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name="DevelopmentSettings"
android:exported="true"
android:label="@string/development_settings_title"
android:targetActivity="Settings$DevelopmentSettingsDashboardActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.development.DevelopmentSettingsDashboardFragment" />
</activity-alias>
<activity android:name=".development.AppPicker" <activity android:name=".development.AppPicker"
android:label="@string/select_application" android:label="@string/select_application"
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" /> android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
@@ -2006,15 +1998,6 @@
android:label="@string/select_webview_provider_dialog_title"> android:label="@string/select_webview_provider_dialog_title">
</activity> </activity>
<!-- Keep compatibility with old shortcuts. -->
<activity-alias android:name="UsbSettings"
android:exported="true"
android:label="@string/storage_title_usb"
android:targetActivity="Settings$DevelopmentSettingsDashboardActivity">
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.deviceinfo.UsbSettings" />
</activity-alias>
<!-- Bluetooth stuff --> <!-- Bluetooth stuff -->
<activity android:name=".bluetooth.BluetoothPairingDialog" <activity android:name=".bluetooth.BluetoothPairingDialog"

View File

@@ -32,7 +32,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/search_bar_margin" android:layout_margin="@dimen/search_bar_margin"
app:cardCornerRadius="2dp" app:cardCornerRadius="@dimen/search_bar_half_height"
app:cardBackgroundColor="?android:attr/colorBackground" app:cardBackgroundColor="?android:attr/colorBackground"
app:cardElevation="2dp"> app:cardElevation="2dp">
<Toolbar <Toolbar

View File

@@ -60,6 +60,7 @@
<dimen name="switchbar_subsettings_margin_end">24dp</dimen> <dimen name="switchbar_subsettings_margin_end">24dp</dimen>
<dimen name="search_bar_height">64dp</dimen> <dimen name="search_bar_height">64dp</dimen>
<dimen name="search_bar_half_height">32dp</dimen>
<!-- Dimensions for Wifi Assistant Card --> <!-- Dimensions for Wifi Assistant Card -->
<dimen name="wifi_assistant_padding_top_bottom">24dp</dimen> <dimen name="wifi_assistant_padding_top_bottom">24dp</dimen>

View File

@@ -121,6 +121,7 @@
<dimen name="search_bar_negative_margin">-8dp</dimen> <dimen name="search_bar_negative_margin">-8dp</dimen>
<dimen name="search_bar_height">48dp</dimen> <dimen name="search_bar_height">48dp</dimen>
<dimen name="search_bar_half_height">24dp</dimen>
<dimen name="search_bar_text_size">16dp</dimen> <dimen name="search_bar_text_size">16dp</dimen>
<!-- Dimensions for Wifi Assistant Card --> <!-- Dimensions for Wifi Assistant Card -->

View File

@@ -29,32 +29,37 @@
android:summaryOn="@string/date_time_auto_summaryOn" android:summaryOn="@string/date_time_auto_summaryOn"
android:summaryOff="@string/date_time_auto_summaryOff" android:summaryOff="@string/date_time_auto_summaryOff"
settings:useAdditionalSummary="true" settings:useAdditionalSummary="true"
settings:restrictedSwitchSummary="@string/enabled_by_admin" /> settings:restrictedSwitchSummary="@string/enabled_by_admin"
settings:userRestriction="no_config_date_time" />
<Preference <com.android.settingslib.RestrictedPreference
android:key="date" android:key="date"
android:title="@string/date_time_set_date" android:title="@string/date_time_set_date"
android:summary="@string/summary_placeholder" /> android:summary="@string/summary_placeholder"
settings:userRestriction="no_config_date_time" />
<Preference <com.android.settingslib.RestrictedPreference
android:key="time" android:key="time"
android:title="@string/date_time_set_time" android:title="@string/date_time_set_time"
android:summary="@string/summary_placeholder" /> android:summary="@string/summary_placeholder"
settings:userRestriction="no_config_date_time" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="time_zone_preference_category"> android:key="time_zone_preference_category">
<SwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="auto_zone" android:key="auto_zone"
android:title="@string/zone_auto" android:title="@string/zone_auto"
android:summaryOn="@string/zone_auto_summaryOn" android:summaryOn="@string/zone_auto_summaryOn"
android:summaryOff="@string/zone_auto_summaryOff" /> android:summaryOff="@string/zone_auto_summaryOff"
settings:userRestriction="no_config_date_time" />
<Preference <com.android.settingslib.RestrictedPreference
android:fragment="com.android.settings.datetime.ZonePicker" android:fragment="com.android.settings.datetime.ZonePicker"
android:key="timezone" android:key="timezone"
android:title="@string/date_time_set_timezone" android:title="@string/date_time_set_timezone"
android:summary="GMT-8:00" /> android:summary="GMT-8:00"
settings:userRestriction="no_config_date_time" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@@ -835,7 +835,8 @@ public class SettingsActivity extends SettingsDrawerActivity
|| somethingChanged; || somethingChanged;
final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this) final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
&& !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES); && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES)
&& !Utils.isMonkeyRunning();
somethingChanged = setTileEnabled(new ComponentName(packageName, somethingChanged = setTileEnabled(new ComponentName(packageName,
Settings.DevelopmentSettingsDashboardActivity.class.getName()), Settings.DevelopmentSettingsDashboardActivity.class.getName()),

View File

@@ -46,8 +46,10 @@ public class AutoTimePreferenceController extends AbstractPreferenceController
if (!(preference instanceof RestrictedSwitchPreference)) { if (!(preference instanceof RestrictedSwitchPreference)) {
return; return;
} }
if (!((RestrictedSwitchPreference) preference).isDisabledByAdmin()) {
((RestrictedSwitchPreference) preference).setDisabledByAdmin( ((RestrictedSwitchPreference) preference).setDisabledByAdmin(
getEnforcedAdminProperty()); getEnforcedAdminProperty());
}
((RestrictedSwitchPreference) preference).setChecked(isEnabled()); ((RestrictedSwitchPreference) preference).setChecked(isEnabled());
} }

View File

@@ -27,6 +27,7 @@ import android.text.format.DateFormat;
import android.widget.DatePicker; import android.widget.DatePicker;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Calendar; import java.util.Calendar;
@@ -59,10 +60,15 @@ public class DatePreferenceController extends AbstractPreferenceController
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (!(preference instanceof RestrictedPreference)) {
return;
}
final Calendar now = Calendar.getInstance(); final Calendar now = Calendar.getInstance();
preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime())); preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime()));
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
preference.setEnabled(!mAutoTimePreferenceController.isEnabled()); preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
} }
}
@Override @Override
public boolean handlePreferenceTreeClick(Preference preference) { public boolean handlePreferenceTreeClick(Preference preference) {

View File

@@ -26,6 +26,7 @@ import android.text.format.DateFormat;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import java.util.Calendar; import java.util.Calendar;
@@ -60,10 +61,15 @@ public class TimePreferenceController extends AbstractPreferenceController
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (!(preference instanceof RestrictedPreference)) {
return;
}
final Calendar now = Calendar.getInstance(); final Calendar now = Calendar.getInstance();
preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime())); preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime()));
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
preference.setEnabled(!mAutoTimePreferenceController.isEnabled()); preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
} }
}
@Override @Override
public boolean handlePreferenceTreeClick(Preference preference) { public boolean handlePreferenceTreeClick(Preference preference) {

View File

@@ -21,6 +21,7 @@ import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.datetime.ZoneGetter; import com.android.settingslib.datetime.ZoneGetter;
@@ -41,9 +42,14 @@ public class TimeZonePreferenceController extends AbstractPreferenceController
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (!(preference instanceof RestrictedPreference)) {
return;
}
preference.setSummary(getTimeZoneOffsetAndName()); preference.setSummary(getTimeZoneOffsetAndName());
if( !((RestrictedPreference) preference).isDisabledByAdmin()) {
preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled()); preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
} }
}
@Override @Override
public boolean isAvailable() { public boolean isAvailable() {

View File

@@ -298,12 +298,15 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
Log.d(TAG, "Creating pref screen"); return Utils.isMonkeyRunning()? R.xml.placeholder_prefs : R.xml.development_settings;
return R.xml.development_settings;
} }
@Override @Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
if (Utils.isMonkeyRunning()) {
mPreferenceControllers = new ArrayList<>();
return null;
}
mPreferenceControllers = buildPreferenceControllers(context, getActivity(), getLifecycle(), mPreferenceControllers = buildPreferenceControllers(context, getActivity(), getLifecycle(),
this /* devOptionsDashboardFragment */, this /* devOptionsDashboardFragment */,
new BluetoothA2dpConfigStore()); new BluetoothA2dpConfigStore());
@@ -326,6 +329,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
} }
private void enableDeveloperOptions() { private void enableDeveloperOptions() {
if (Utils.isMonkeyRunning()) {
return;
}
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true); DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
for (AbstractPreferenceController controller : mPreferenceControllers) { for (AbstractPreferenceController controller : mPreferenceControllers) {
if (controller instanceof DeveloperOptionsPreferenceController) { if (controller instanceof DeveloperOptionsPreferenceController) {
@@ -335,6 +341,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
} }
private void disableDeveloperOptions() { private void disableDeveloperOptions() {
if (Utils.isMonkeyRunning()) {
return;
}
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false); DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
final SystemPropPoker poker = SystemPropPoker.getInstance(); final SystemPropPoker poker = SystemPropPoker.getInstance();
poker.blockPokes(); poker.blockPokes();

View File

@@ -30,6 +30,7 @@ import com.android.settings.password.ChooseLockPattern.IntentBuilder;
import com.android.settings.password.SetupChooseLockPattern; import com.android.settings.password.SetupChooseLockPattern;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources; import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowResourcesImpl;
import com.android.settings.testutils.shadow.ShadowEventLogWriter; import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils; import com.android.settings.testutils.shadow.ShadowUtils;
@@ -44,9 +45,10 @@ import org.robolectric.shadows.ShadowPackageManager.ComponentState;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config( @Config(
manifest = TestConfig.MANIFEST_PATH, manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION, sdk = TestConfig.SDK_VERSION_O,
shadows = { shadows = {
SettingsShadowResources.class, SettingsShadowResources.class,
SettingsShadowResourcesImpl.class,
SettingsShadowResources.SettingsShadowTheme.class, SettingsShadowResources.SettingsShadowTheme.class,
ShadowEventLogWriter.class, ShadowEventLogWriter.class,
ShadowUtils.class ShadowUtils.class

View File

@@ -33,7 +33,7 @@ import java.util.List;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccessibilitySettingsTest { public class AccessibilitySettingsTest {
@Test @Test

View File

@@ -41,7 +41,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ShortcutServicePickerFragmentTest { public class ShortcutServicePickerFragmentTest {
private static final String TEST_SERVICE_KEY_1 = "abc/123"; private static final String TEST_SERVICE_KEY_1 = "abc/123";

View File

@@ -38,7 +38,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.FragmentTestUtil; import org.robolectric.util.FragmentTestUtil;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = { shadows = {
SettingsShadowResources.class, SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class, SettingsShadowResources.SettingsShadowTheme.class,

View File

@@ -55,15 +55,13 @@ import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf; import static org.robolectric.Shadows.shadowOf;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountDetailDashboardFragmentTest { public class AccountDetailDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category"; private static final String METADATA_CATEGORY = "com.android.settings.category";
private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account"; private static final String METADATA_ACCOUNT_TYPE = "com.android.settings.ia.account";
private static final String METADATA_USER_HANDLE = "user_handle"; private static final String METADATA_USER_HANDLE = "user_handle";
@Mock(answer = RETURNS_DEEP_STUBS)
private Activity mActivity;
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)
private AccountManager mAccountManager; private AccountManager mAccountManager;
@Mock @Mock
@@ -129,11 +127,11 @@ public class AccountDetailDashboardFragmentTest {
@Test @Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() { public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
FakeFeatureFactory.setupForTest(mActivity); FakeFeatureFactory.setupForTest(mContext);
final FakeFeatureFactory featureFactory = final FakeFeatureFactory featureFactory =
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity); (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
final DashboardFeatureProviderImpl dashboardFeatureProvider = final DashboardFeatureProviderImpl dashboardFeatureProvider =
new DashboardFeatureProviderImpl(mActivity); new DashboardFeatureProviderImpl(mContext);
final PackageManager packageManager = mock(PackageManager.class); final PackageManager packageManager = mock(PackageManager.class);
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager); ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
when(packageManager.resolveActivity(any(Intent.class), anyInt())) when(packageManager.resolveActivity(any(Intent.class), anyInt()))

View File

@@ -56,7 +56,7 @@ import org.robolectric.annotation.Implements;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config( @Config(
manifest = TestConfig.MANIFEST_PATH, manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION, sdk = TestConfig.SDK_VERSION_O,
shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
) )
public class AccountHeaderPreferenceControllerTest { public class AccountHeaderPreferenceControllerTest {

View File

@@ -68,7 +68,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountPreferenceControllerTest { public class AccountPreferenceControllerTest {

View File

@@ -35,7 +35,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountPreferenceTest { public class AccountPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowAccountManager.class, ShadowContentResolver.class}) shadows = {ShadowAccountManager.class, ShadowContentResolver.class})
public class AccountSyncPreferenceControllerTest { public class AccountSyncPreferenceControllerTest {

View File

@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AccountTypePreferenceLoaderTest { public class AccountTypePreferenceLoaderTest {
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AddUserWhenLockedPreferenceControllerTest { public class AddUserWhenLockedPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -44,14 +44,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncDataPreferenceControllerTest { public class AutoSyncDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)
private UserManager mUserManager; private UserManager mUserManager;
@Mock(answer = RETURNS_DEEP_STUBS) @Mock
private Fragment mFragment; private Fragment mFragment;
private Preference mPreference; private Preference mPreference;

View File

@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncPersonalDataPreferenceControllerTest { public class AutoSyncPersonalDataPreferenceControllerTest {
@Mock(answer = RETURNS_DEEP_STUBS) @Mock(answer = RETURNS_DEEP_STUBS)

View File

@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AutoSyncWorkDataPreferenceControllerTest { public class AutoSyncWorkDataPreferenceControllerTest {
private static int MANAGED_PROFILE_ID = 10; private static int MANAGED_PROFILE_ID = 10;

View File

@@ -32,7 +32,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ProviderPreferenceTest { public class ProviderPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -40,6 +40,7 @@ import android.os.Handler;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.support.v14.preference.PreferenceFragment; import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.widget.Button; import android.widget.Button;
@@ -60,7 +61,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RemoveAccountPreferenceControllerTest { public class RemoveAccountPreferenceControllerTest {
private static final String KEY_REMOVE_ACCOUNT = "remove_account"; private static final String KEY_REMOVE_ACCOUNT = "remove_account";
@@ -70,9 +71,11 @@ public class RemoveAccountPreferenceControllerTest {
private AccountManager mAccountManager; private AccountManager mAccountManager;
@Mock @Mock
private DevicePolicyManagerWrapper mDevicePolicyManager; private DevicePolicyManagerWrapper mDevicePolicyManager;
@Mock(answer = RETURNS_DEEP_STUBS) @Mock
private PreferenceFragment mFragment; private PreferenceFragment mFragment;
@Mock @Mock
private PreferenceManager mPreferenceManager;
@Mock
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock @Mock
private FragmentManager mFragmentManager; private FragmentManager mFragmentManager;
@@ -92,7 +95,8 @@ public class RemoveAccountPreferenceControllerTest {
mContext = spy(shadowContext.getApplicationContext()); mContext = spy(shadowContext.getApplicationContext());
when(mFragment.getPreferenceScreen()).thenReturn(mScreen); when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext); when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mPreferenceManager.getContext()).thenReturn(mContext);
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager); when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction); when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn( when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(

View File

@@ -28,7 +28,7 @@ import java.lang.reflect.Modifier;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RemoveUserFragmentTest { public class RemoveUserFragmentTest {
@Test @Test

View File

@@ -43,7 +43,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class UserAndAccountDashboardFragmentTest { public class UserAndAccountDashboardFragmentTest {
private static final String METADATA_CATEGORY = "com.android.settings.category"; private static final String METADATA_CATEGORY = "com.android.settings.category";

View File

@@ -22,6 +22,7 @@ import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settingslib.RestrictedPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -48,14 +49,15 @@ public class DatePreferenceControllerTest {
@Mock @Mock
private AutoTimePreferenceController mAutoTimePreferenceController; private AutoTimePreferenceController mAutoTimePreferenceController;
private Preference mPreference; private RestrictedPreference mPreference;
private DatePreferenceController mController; private DatePreferenceController mController;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager); when(mContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mAlarmManager);
mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext()); mPreference = new RestrictedPreference(ShadowApplication.getInstance().
getApplicationContext());
mController = new DatePreferenceController(mContext, mHost, mAutoTimePreferenceController); mController = new DatePreferenceController(mContext, mHost, mAutoTimePreferenceController);
} }
@@ -72,6 +74,9 @@ public class DatePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeEnabled_shouldDisablePref() { public void updateState_autoTimeEnabled_shouldDisablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true); when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -80,6 +85,9 @@ public class DatePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeDisabled_shouldEnablePref() { public void updateState_autoTimeDisabled_shouldEnablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false); when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -17,10 +17,11 @@
package com.android.settings.datetime; package com.android.settings.datetime;
import android.content.Context; import android.content.Context;
import android.support.v7.preference.Preference; import android.os.UserManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settingslib.RestrictedPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -31,6 +32,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowApplication;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -46,12 +48,13 @@ public class TimePreferenceControllerTest {
private AutoTimePreferenceController mAutoTimePreferenceController; private AutoTimePreferenceController mAutoTimePreferenceController;
private TimePreferenceController mController; private TimePreferenceController mController;
private Preference mPreference; private RestrictedPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext()); mPreference = new RestrictedPreference(
ShadowApplication.getInstance().getApplicationContext());
mController = new TimePreferenceController(mContext, mHost, mAutoTimePreferenceController); mController = new TimePreferenceController(mContext, mHost, mAutoTimePreferenceController);
} }
@@ -62,6 +65,9 @@ public class TimePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeEnabled_shouldDisablePref() { public void updateState_autoTimeEnabled_shouldDisablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true); when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -70,6 +76,9 @@ public class TimePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeDisabled_shouldEnablePref() { public void updateState_autoTimeDisabled_shouldEnablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false); when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -21,6 +21,7 @@ import android.support.v7.preference.Preference;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settingslib.RestrictedPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -41,15 +42,16 @@ public class TimeZonePreferenceControllerTest {
@Mock @Mock
private AutoTimeZonePreferenceController mAutoTimeZonePreferenceController; private AutoTimeZonePreferenceController mAutoTimeZonePreferenceController;
private Context mContext; private Context mContext;
private TimeZonePreferenceController mController; private TimeZonePreferenceController mController;
private Preference mPreference; private RestrictedPreference mPreference;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = ShadowApplication.getInstance().getApplicationContext(); mContext = ShadowApplication.getInstance().getApplicationContext();
mPreference = new Preference(mContext); mPreference = new RestrictedPreference(mContext);
mController = spy(new TimeZonePreferenceController(mContext, mController = spy(new TimeZonePreferenceController(mContext,
mAutoTimeZonePreferenceController)); mAutoTimeZonePreferenceController));
} }
@@ -61,6 +63,9 @@ public class TimeZonePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeZoneEnabled_shouldDisablePref() { public void updateState_autoTimeZoneEnabled_shouldDisablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName(); doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(true); when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(true);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -70,6 +75,9 @@ public class TimeZonePreferenceControllerTest {
@Test @Test
public void updateState_autoTimeZoneDisabled_shouldEnablePref() { public void updateState_autoTimeZoneDisabled_shouldEnablePref() {
// Make sure not disabled by admin.
mPreference.setDisabledByAdmin(null);
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName(); doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(false); when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(false);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -101,6 +101,13 @@ public class SettingsShadowResources extends ShadowResources {
return directlyOn(realResources, Resources.class).getColorStateList(id, theme); return directlyOn(realResources, Resources.class).getColorStateList(id, theme);
} }
/**
* Deprecated because SDK 24+ uses
* {@link SettingsShadowResourcesImpl#loadDrawable(Resources, TypedValue, int, int, Theme)}
*
* TODO: Delete when all tests have been migrated to sdk 26
*/
@Deprecated
@Implementation @Implementation
public Drawable loadDrawable(TypedValue value, int id, Theme theme) public Drawable loadDrawable(TypedValue value, int id, Theme theme)
throws NotFoundException { throws NotFoundException {

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.testutils.shadow;
import android.content.res.Resources;
import android.content.res.ResourcesImpl;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import com.android.settings.R;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowResourcesImpl;
@Implements(
value = ResourcesImpl.class,
isInAndroidSdk = false,
minSdk = 26
)
public class SettingsShadowResourcesImpl extends ShadowResourcesImpl {
@Implementation
public Drawable loadDrawable(Resources wrapper, TypedValue value, int id, int density,
Resources.Theme theme) {
// The drawable item in switchbar_background.xml refers to a very recent color attribute
// that Robolectric isn't yet aware of.
// TODO: Remove this once Robolectric is updated.
if (id == R.drawable.switchbar_background) {
return new ColorDrawable();
} else if (id == R.drawable.ic_launcher_settings) {
// ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
// change it to a normal drawable.
id = R.drawable.ic_settings_wireless;
} else if (id == R.drawable.app_filter_spinner_background) {
id = R.drawable.ic_expand_more_inverse;
} else if (id == R.drawable.selectable_card_grey) {
id = R.drawable.ic_expand_more_inverse;
}
return super.loadDrawable(wrapper, value, id, density, theme);
}
}

View File

@@ -45,7 +45,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ActionBarShadowControllerTest { public class ActionBarShadowControllerTest {
@Mock @Mock

View File

@@ -40,7 +40,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ActionButtonPreferenceTest { public class ActionButtonPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -33,7 +33,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppPreferenceTest { public class AppPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -33,7 +33,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AppSwitchPreferenceTest { public class AppSwitchPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -32,7 +32,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers; import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class AspectRatioFrameLayoutTest { public class AspectRatioFrameLayoutTest {
private Context mContext; private Context mContext;

View File

@@ -29,7 +29,7 @@ import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class DefaultIndicatorSeekBarTest { public class DefaultIndicatorSeekBarTest {
private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar; private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;

View File

@@ -58,7 +58,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class EntityHeaderControllerTest { public class EntityHeaderControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS) @Mock(answer = Answers.RETURNS_DEEP_STUBS)

View File

@@ -38,7 +38,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class FixedLineSummaryPreferenceTest { public class FixedLineSummaryPreferenceTest {
@Mock @Mock

View File

@@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class LoadingViewControllerTest { public class LoadingViewControllerTest {
private Context mContext; private Context mContext;

View File

@@ -40,7 +40,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class MasterSwitchPreferenceTest { public class MasterSwitchPreferenceTest {
private Context mContext; private Context mContext;

View File

@@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PreferenceCategoryControllerTest { public class PreferenceCategoryControllerTest {
private Context mContext; private Context mContext;

View File

@@ -45,7 +45,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RadioButtonPickerFragmentTest { public class RadioButtonPickerFragmentTest {

View File

@@ -31,7 +31,7 @@ import org.robolectric.annotation.Config;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class RingProgressBarTest { public class RingProgressBarTest {
private Context mContext = RuntimeEnvironment.application; private Context mContext = RuntimeEnvironment.application;

View File

@@ -36,7 +36,7 @@ import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config( @Config(
manifest = TestConfig.MANIFEST_PATH, manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION, sdk = TestConfig.SDK_VERSION_O,
shadows = {ShadowTextUtils.class} shadows = {ShadowTextUtils.class}
) )
public class RtlCompatibleViewPagerTest { public class RtlCompatibleViewPagerTest {

View File

@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowView; import org.robolectric.shadows.ShadowView;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ScrollToParentEditTextTest { public class ScrollToParentEditTextTest {
private static final int EDIT_TEXT_SIZE = 20; private static final int EDIT_TEXT_SIZE = 20;

View File

@@ -34,7 +34,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class SummaryUpdaterTest { public class SummaryUpdaterTest {
private Context mContext; private Context mContext;

View File

@@ -42,7 +42,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class ValidatedEditTextPreferenceTest { public class ValidatedEditTextPreferenceTest {
@Mock @Mock

View File

@@ -0,0 +1,151 @@
/*
* Copyright (C) 2017 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.core;
import static junit.framework.Assert.fail;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.UserManager;
import android.platform.test.annotations.Presubmit;
import android.provider.SearchIndexableResource;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import com.android.settings.search.DatabaseIndexingUtils;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableResources;
import com.google.android.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List;
import java.util.Set;
@RunWith(AndroidJUnit4.class)
@MediumTest
public class UserRestrictionTest {
private static final String TAG = "UserRestrictionTest";
private Context mContext;
private static final Set<String> USER_RESTRICTIONS = Sets.newHashSet(
UserManager.DISALLOW_CONFIG_DATE_TIME,
UserManager.DISALLOW_CONFIG_CREDENTIALS,
UserManager.DISALLOW_NETWORK_RESET,
UserManager.DISALLOW_FACTORY_RESET,
UserManager.DISALLOW_CONFIG_TETHERING,
UserManager.DISALLOW_CONFIG_VPN,
UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS
);
@Before
public void setUp() {
mContext = InstrumentationRegistry.getTargetContext();
}
/**
* Verity that userRestriction attributes are entered and parsed successfully.
*/
@Test
public void userRestrictionAttributeShouldBeValid()
throws IOException, XmlPullParserException, Resources.NotFoundException {
for (Class<?> clazz : SearchIndexableResources.providerValues()) {
verifyUserRestriction(clazz);
}
}
private void verifyUserRestriction(Class<?> clazz)
throws IOException, XmlPullParserException, Resources.NotFoundException {
if (clazz == null) {
return;
}
final String className = clazz.getName();
final Indexable.SearchIndexProvider provider =
DatabaseIndexingUtils.getSearchIndexProvider(clazz);
final List<SearchIndexableResource> resourcesToIndex =
provider.getXmlResourcesToIndex(mContext, true);
if (resourcesToIndex == null) {
Log.d(TAG, className + "is not providing SearchIndexableResource, skipping");
return;
}
for (SearchIndexableResource sir : resourcesToIndex) {
if (sir.xmlResId <= 0) {
Log.d(TAG, className + " doesn't have a valid xml to index.");
continue;
}
final XmlResourceParser parser = mContext.getResources().getXml(sir.xmlResId);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
// Parse next until start tag is found
}
final int outerDepth = parser.getDepth();
do {
if (type != XmlPullParser.START_TAG) {
continue;
}
final String nodeName = parser.getName();
if (!nodeName.endsWith("Preference")) {
continue;
}
final AttributeSet attrs = Xml.asAttributeSet(parser);
final String userRestriction = getDataUserRestrictions(mContext, attrs);
if (userRestriction != null) {
if(!isValidRestriction(userRestriction)) {
fail("userRestriction in " + className + " not valid.");
}
}
} while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth));
}
}
boolean isValidRestriction(String userRestriction) {
return USER_RESTRICTIONS.contains(userRestriction);
}
private String getDataUserRestrictions(Context context, AttributeSet attrs) {
return getData(context, attrs,
com.android.settingslib.R.styleable.RestrictedPreference,
com.android.settingslib.R.styleable.RestrictedPreference_userRestriction);
}
private String getData(Context context, AttributeSet set, int[] attrs, int resId) {
final TypedArray ta = context.obtainStyledAttributes(set, attrs);
String data = ta.getString(resId);
ta.recycle();
return data;
}
}