Snap for 4466732 from 03b2d4c44c to pi-release
Change-Id: Ic6099d8dc1c61d3a57b7dda50b094cdc7a53614f
This commit is contained in:
@@ -1920,7 +1920,8 @@
|
||||
android:label="@string/development_settings_title"
|
||||
android:icon="@drawable/ic_settings_development"
|
||||
android:taskAffinity="com.android.settings"
|
||||
android:parentActivityName="Settings">
|
||||
android:parentActivityName="Settings"
|
||||
android:enabled="false">
|
||||
<intent-filter android:priority="1">
|
||||
<action android:name="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" />
|
||||
</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"
|
||||
android:label="@string/select_application"
|
||||
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog" />
|
||||
@@ -2006,15 +1998,6 @@
|
||||
android:label="@string/select_webview_provider_dialog_title">
|
||||
</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 -->
|
||||
|
||||
<activity android:name=".bluetooth.BluetoothPairingDialog"
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/search_bar_margin"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:cardCornerRadius="@dimen/search_bar_half_height"
|
||||
app:cardBackgroundColor="?android:attr/colorBackground"
|
||||
app:cardElevation="2dp">
|
||||
<Toolbar
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
<dimen name="switchbar_subsettings_margin_end">24dp</dimen>
|
||||
|
||||
<dimen name="search_bar_height">64dp</dimen>
|
||||
<dimen name="search_bar_half_height">32dp</dimen>
|
||||
|
||||
<!-- Dimensions for Wifi Assistant Card -->
|
||||
<dimen name="wifi_assistant_padding_top_bottom">24dp</dimen>
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<dimen name="search_bar_negative_margin">-8dp</dimen>
|
||||
|
||||
<dimen name="search_bar_height">48dp</dimen>
|
||||
<dimen name="search_bar_half_height">24dp</dimen>
|
||||
<dimen name="search_bar_text_size">16dp</dimen>
|
||||
|
||||
<!-- Dimensions for Wifi Assistant Card -->
|
||||
|
||||
@@ -29,32 +29,37 @@
|
||||
android:summaryOn="@string/date_time_auto_summaryOn"
|
||||
android:summaryOff="@string/date_time_auto_summaryOff"
|
||||
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: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:title="@string/date_time_set_time"
|
||||
android:summary="@string/summary_placeholder" />
|
||||
android:summary="@string/summary_placeholder"
|
||||
settings:userRestriction="no_config_date_time" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="time_zone_preference_category">
|
||||
<SwitchPreference
|
||||
<com.android.settingslib.RestrictedSwitchPreference
|
||||
android:key="auto_zone"
|
||||
android:title="@string/zone_auto"
|
||||
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:key="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
|
||||
|
||||
@@ -835,7 +835,8 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
|| somethingChanged;
|
||||
|
||||
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,
|
||||
Settings.DevelopmentSettingsDashboardActivity.class.getName()),
|
||||
|
||||
@@ -46,8 +46,10 @@ public class AutoTimePreferenceController extends AbstractPreferenceController
|
||||
if (!(preference instanceof RestrictedSwitchPreference)) {
|
||||
return;
|
||||
}
|
||||
((RestrictedSwitchPreference) preference).setDisabledByAdmin(
|
||||
getEnforcedAdminProperty());
|
||||
if (!((RestrictedSwitchPreference) preference).isDisabledByAdmin()) {
|
||||
((RestrictedSwitchPreference) preference).setDisabledByAdmin(
|
||||
getEnforcedAdminProperty());
|
||||
}
|
||||
((RestrictedSwitchPreference) preference).setChecked(isEnabled());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.text.format.DateFormat;
|
||||
import android.widget.DatePicker;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.Calendar;
|
||||
@@ -59,9 +60,14 @@ public class DatePreferenceController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (!(preference instanceof RestrictedPreference)) {
|
||||
return;
|
||||
}
|
||||
final Calendar now = Calendar.getInstance();
|
||||
preference.setSummary(DateFormat.getLongDateFormat(mContext).format(now.getTime()));
|
||||
preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
|
||||
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
|
||||
preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.text.format.DateFormat;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.Calendar;
|
||||
@@ -60,9 +61,14 @@ public class TimePreferenceController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (!(preference instanceof RestrictedPreference)) {
|
||||
return;
|
||||
}
|
||||
final Calendar now = Calendar.getInstance();
|
||||
preference.setSummary(DateFormat.getTimeFormat(mContext).format(now.getTime()));
|
||||
preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
|
||||
if (!((RestrictedPreference) preference).isDisabledByAdmin()) {
|
||||
preference.setEnabled(!mAutoTimePreferenceController.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.datetime.ZoneGetter;
|
||||
|
||||
@@ -41,8 +42,13 @@ public class TimeZonePreferenceController extends AbstractPreferenceController
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (!(preference instanceof RestrictedPreference)) {
|
||||
return;
|
||||
}
|
||||
preference.setSummary(getTimeZoneOffsetAndName());
|
||||
preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
|
||||
if( !((RestrictedPreference) preference).isDisabledByAdmin()) {
|
||||
preference.setEnabled(!mAutoTimeZonePreferenceController.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -298,12 +298,15 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
Log.d(TAG, "Creating pref screen");
|
||||
return R.xml.development_settings;
|
||||
return Utils.isMonkeyRunning()? R.xml.placeholder_prefs : R.xml.development_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
if (Utils.isMonkeyRunning()) {
|
||||
mPreferenceControllers = new ArrayList<>();
|
||||
return null;
|
||||
}
|
||||
mPreferenceControllers = buildPreferenceControllers(context, getActivity(), getLifecycle(),
|
||||
this /* devOptionsDashboardFragment */,
|
||||
new BluetoothA2dpConfigStore());
|
||||
@@ -326,6 +329,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
}
|
||||
|
||||
private void enableDeveloperOptions() {
|
||||
if (Utils.isMonkeyRunning()) {
|
||||
return;
|
||||
}
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
if (controller instanceof DeveloperOptionsPreferenceController) {
|
||||
@@ -335,6 +341,9 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
}
|
||||
|
||||
private void disableDeveloperOptions() {
|
||||
if (Utils.isMonkeyRunning()) {
|
||||
return;
|
||||
}
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);
|
||||
final SystemPropPoker poker = SystemPropPoker.getInstance();
|
||||
poker.blockPokes();
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.android.settings.password.ChooseLockPattern.IntentBuilder;
|
||||
import com.android.settings.password.SetupChooseLockPattern;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
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.ShadowUtils;
|
||||
|
||||
@@ -44,9 +45,10 @@ import org.robolectric.shadows.ShadowPackageManager.ComponentState;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResourcesImpl.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
ShadowEventLogWriter.class,
|
||||
ShadowUtils.class
|
||||
@@ -62,7 +64,7 @@ public class SetupChooseLockPatternTest {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
|
||||
mActivity = Robolectric.buildActivity(
|
||||
mActivity = Robolectric.buildActivity(
|
||||
SetupChooseLockPattern.class,
|
||||
SetupChooseLockPattern.modifyIntentForSetup(
|
||||
application,
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@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 {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
private static final String TEST_SERVICE_KEY_1 = "abc/123";
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.FragmentTestUtil;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {
|
||||
SettingsShadowResources.class,
|
||||
SettingsShadowResources.SettingsShadowTheme.class,
|
||||
|
||||
@@ -55,15 +55,13 @@ import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@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 {
|
||||
|
||||
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_USER_HANDLE = "user_handle";
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
@@ -129,11 +127,11 @@ public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
@Test
|
||||
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
|
||||
FakeFeatureFactory.setupForTest(mActivity);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
final FakeFeatureFactory featureFactory =
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
final DashboardFeatureProviderImpl dashboardFeatureProvider =
|
||||
new DashboardFeatureProviderImpl(mActivity);
|
||||
new DashboardFeatureProviderImpl(mContext);
|
||||
final PackageManager packageManager = mock(PackageManager.class);
|
||||
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
|
||||
when(packageManager.resolveActivity(any(Intent.class), anyInt()))
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.robolectric.annotation.Implements;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = AccountHeaderPreferenceControllerTest.ShadowAuthenticatorHelper.class
|
||||
)
|
||||
public class AccountHeaderPreferenceControllerTest {
|
||||
|
||||
@@ -68,7 +68,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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})
|
||||
public class AccountPreferenceControllerTest {
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -47,7 +47,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@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})
|
||||
public class AccountSyncPreferenceControllerTest {
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -44,14 +44,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private UserManager mUserManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
@Mock
|
||||
private Fragment mFragment;
|
||||
|
||||
private Preference mPreference;
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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 {
|
||||
|
||||
private static int MANAGED_PROFILE_ID = 10;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.widget.Button;
|
||||
|
||||
@@ -60,7 +61,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@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 {
|
||||
|
||||
private static final String KEY_REMOVE_ACCOUNT = "remove_account";
|
||||
@@ -70,9 +71,11 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
@Mock
|
||||
private PreferenceFragment mFragment;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
@@ -92,7 +95,8 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
mContext = spy(shadowContext.getApplicationContext());
|
||||
|
||||
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(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
||||
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.lang.reflect.Modifier;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@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 {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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 {
|
||||
|
||||
private static final String METADATA_CATEGORY = "com.android.settings.category";
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -48,14 +49,15 @@ public class DatePreferenceControllerTest {
|
||||
@Mock
|
||||
private AutoTimePreferenceController mAutoTimePreferenceController;
|
||||
|
||||
private Preference mPreference;
|
||||
private RestrictedPreference mPreference;
|
||||
private DatePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -72,6 +74,9 @@ public class DatePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeEnabled_shouldDisablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -80,6 +85,9 @@ public class DatePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeDisabled_shouldEnablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
package com.android.settings.datetime;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -31,6 +32,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -46,12 +48,13 @@ public class TimePreferenceControllerTest {
|
||||
private AutoTimePreferenceController mAutoTimePreferenceController;
|
||||
|
||||
private TimePreferenceController mController;
|
||||
private Preference mPreference;
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new Preference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mPreference = new RestrictedPreference(
|
||||
ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new TimePreferenceController(mContext, mHost, mAutoTimePreferenceController);
|
||||
}
|
||||
|
||||
@@ -62,6 +65,9 @@ public class TimePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeEnabled_shouldDisablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mAutoTimePreferenceController.isEnabled()).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -70,6 +76,9 @@ public class TimePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeDisabled_shouldEnablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
when(mAutoTimePreferenceController.isEnabled()).thenReturn(false);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -41,15 +42,16 @@ public class TimeZonePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private AutoTimeZonePreferenceController mAutoTimeZonePreferenceController;
|
||||
|
||||
private Context mContext;
|
||||
private TimeZonePreferenceController mController;
|
||||
private Preference mPreference;
|
||||
private RestrictedPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
mPreference = new Preference(mContext);
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = spy(new TimeZonePreferenceController(mContext,
|
||||
mAutoTimeZonePreferenceController));
|
||||
}
|
||||
@@ -61,6 +63,9 @@ public class TimeZonePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeZoneEnabled_shouldDisablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
|
||||
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(true);
|
||||
mController.updateState(mPreference);
|
||||
@@ -70,6 +75,9 @@ public class TimeZonePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_autoTimeZoneDisabled_shouldEnablePref() {
|
||||
// Make sure not disabled by admin.
|
||||
mPreference.setDisabledByAdmin(null);
|
||||
|
||||
doReturn("test timezone").when(mController).getTimeZoneOffsetAndName();
|
||||
when(mAutoTimeZonePreferenceController.isEnabled()).thenReturn(false);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -101,6 +101,13 @@ public class SettingsShadowResources extends ShadowResources {
|
||||
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
|
||||
public Drawable loadDrawable(TypedValue value, int id, Theme theme)
|
||||
throws NotFoundException {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.robolectric.annotation.Config;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@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 {
|
||||
|
||||
private DefaultIndicatorSeekBar mDefaultIndicatorSeekBar;
|
||||
|
||||
@@ -58,7 +58,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
|
||||
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -45,7 +45,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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 {
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.robolectric.annotation.Config;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext = RuntimeEnvironment.application;
|
||||
|
||||
@@ -36,7 +36,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
sdk = TestConfig.SDK_VERSION_O,
|
||||
shadows = {ShadowTextUtils.class}
|
||||
)
|
||||
public class RtlCompatibleViewPagerTest {
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowView;
|
||||
|
||||
@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 {
|
||||
|
||||
private static final int EDIT_TEXT_SIZE = 20;
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@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 {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@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 {
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user